Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 107b5f5b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Show correct sort header after root switch." into nyc-andromeda-dev

parents 7c66209d 743bc1be
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -267,6 +267,7 @@ public abstract class BaseActivity extends Activity
        }
        }


        mState.derivedMode = LocalPreferences.getViewMode(this, root, MODE_GRID);
        mState.derivedMode = LocalPreferences.getViewMode(this, root, MODE_GRID);
        mSortController.onViewModeChanged(mState.derivedMode);


        // Set summary header's visibility. Only recents and downloads root may have summary in
        // Set summary header's visibility. Only recents and downloads root may have summary in
        // their docs.
        // their docs.
+23 −0
Original line number Original line Diff line number Diff line
@@ -83,4 +83,27 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
        bots.breadcrumb.clickItem("TEST_ROOT_0");
        bots.breadcrumb.clickItem("TEST_ROOT_0");
        bots.directory.waitForDocument(dirName1);
        bots.directory.waitForDocument(dirName1);
    }
    }

    public void testRootChange_UpdatesSortHeader() throws Exception {

        // switch to separate display modes for two separate roots. Each
        // mode has its own distinct sort header. This should be remembered
        // by files app.
        bots.roots.openRoot("Images");
        bots.main.switchToGridMode();
        bots.roots.openRoot("Videos");
        bots.main.switchToListMode();

        // Now switch back and assert the correct mode sort header mode
        // is restored when we load the root with that display mode.
        bots.roots.openRoot("Images");
        bots.sortHeader.assertDropdownMode();
        if (bots.main.inFixedLayout()) {
            bots.roots.openRoot("Videos");
            bots.sortHeader.assertColumnMode();
        } else {
            bots.roots.openRoot("Videos");
            bots.sortHeader.assertDropdownMode();
        }
    }
}
}
+10 −10
Original line number Original line Diff line number Diff line
@@ -90,7 +90,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {


        bots.main.switchToListMode();
        bots.main.switchToListMode();


        bots.directory.sortBy(
        bots.sortHeader.sortBy(
                SortModel.SORT_DIMENSION_ID_TITLE, SortDimension.SORT_DIRECTION_DESCENDING);
                SortModel.SORT_DIMENSION_ID_TITLE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_DESC, FILES_IN_NAME_DESC);
        bots.directory.assertOrder(DIRS_IN_NAME_DESC, FILES_IN_NAME_DESC);
    }
    }
@@ -100,7 +100,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {


        bots.main.switchToListMode();
        bots.main.switchToListMode();


        bots.directory.sortBy(
        bots.sortHeader.sortBy(
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_ASCENDING);
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_ASC);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_ASC);
    }
    }
@@ -110,7 +110,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {


        bots.main.switchToListMode();
        bots.main.switchToListMode();


        bots.directory.sortBy(
        bots.sortHeader.sortBy(
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_DESCENDING);
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_DESC);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_DESC);
    }
    }
@@ -120,7 +120,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {


        bots.main.switchToListMode();
        bots.main.switchToListMode();


        bots.directory.sortBy(
        bots.sortHeader.sortBy(
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_ASCENDING);
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.directory.assertOrder(DIRS, FILES);
        bots.directory.assertOrder(DIRS, FILES);
    }
    }
@@ -130,7 +130,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {


        bots.main.switchToListMode();
        bots.main.switchToListMode();


        bots.directory.sortBy(
        bots.sortHeader.sortBy(
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_DESCENDING);
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_MODIFIED_DESC, FILES_IN_MODIFIED_DESC);
        bots.directory.assertOrder(DIRS_IN_MODIFIED_DESC, FILES_IN_MODIFIED_DESC);
    }
    }
@@ -140,7 +140,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {


        bots.main.switchToGridMode();
        bots.main.switchToGridMode();


        bots.directory.sortBy(
        bots.sortHeader.sortBy(
                SortModel.SORT_DIMENSION_ID_TITLE, SortDimension.SORT_DIRECTION_DESCENDING);
                SortModel.SORT_DIMENSION_ID_TITLE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_DESC, FILES_IN_NAME_DESC);
        bots.directory.assertOrder(DIRS_IN_NAME_DESC, FILES_IN_NAME_DESC);
    }
    }
@@ -150,7 +150,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {


        bots.main.switchToGridMode();
        bots.main.switchToGridMode();


        bots.directory.sortBy(
        bots.sortHeader.sortBy(
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_ASCENDING);
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_ASC);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_ASC);
    }
    }
@@ -160,7 +160,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {


        bots.main.switchToGridMode();
        bots.main.switchToGridMode();


        bots.directory.sortBy(
        bots.sortHeader.sortBy(
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_DESCENDING);
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_DESC);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_DESC);
    }
    }
@@ -170,7 +170,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {


        bots.main.switchToGridMode();
        bots.main.switchToGridMode();


        bots.directory.sortBy(
        bots.sortHeader.sortBy(
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_ASCENDING);
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.directory.assertOrder(DIRS, FILES);
        bots.directory.assertOrder(DIRS, FILES);
    }
    }
@@ -180,7 +180,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {


        bots.main.switchToGridMode();
        bots.main.switchToGridMode();


        bots.directory.sortBy(
        bots.sortHeader.sortBy(
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_DESCENDING);
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_MODIFIED_DESC, FILES_IN_MODIFIED_DESC);
        bots.directory.assertOrder(DIRS_IN_MODIFIED_DESC, FILES_IN_MODIFIED_DESC);
    }
    }
+3 −1
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ public final class Bots {


    public final BreadBot breadcrumb;
    public final BreadBot breadcrumb;
    public final DirectoryListBot directory;
    public final DirectoryListBot directory;
    public final SortHeaderBot sortHeader;
    public final KeyboardBot keyboard;
    public final KeyboardBot keyboard;
    public final RootsListBot roots;
    public final RootsListBot roots;
    public final SearchBot search;
    public final SearchBot search;
@@ -46,6 +47,7 @@ public final class Bots {
        breadcrumb = new BreadBot(device, context, TIMEOUT, main);
        breadcrumb = new BreadBot(device, context, TIMEOUT, main);
        roots = new RootsListBot(device, context, TIMEOUT);
        roots = new RootsListBot(device, context, TIMEOUT);
        directory = new DirectoryListBot(device, context, TIMEOUT);
        directory = new DirectoryListBot(device, context, TIMEOUT);
        sortHeader = new SortHeaderBot(device, context, TIMEOUT);
        keyboard = new KeyboardBot(device, context, TIMEOUT);
        keyboard = new KeyboardBot(device, context, TIMEOUT);
        search = new SearchBot(device, context, TIMEOUT);
        search = new SearchBot(device, context, TIMEOUT);
    }
    }
@@ -55,7 +57,7 @@ public final class Bots {
     * and making assertions against the state of it.
     * and making assertions against the state of it.
     */
     */
    static abstract class BaseBot {
    static abstract class BaseBot {
        final UiDevice mDevice;
        public final UiDevice mDevice;
        final Context mContext;
        final Context mContext;
        final int mTimeout;
        final int mTimeout;


+3 −135
Original line number Original line Diff line number Diff line
@@ -16,26 +16,13 @@


package com.android.documentsui.bots;
package com.android.documentsui.bots;


import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.withChild;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

import static com.android.documentsui.sorting.SortDimension.SORT_DIRECTION_ASCENDING;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.assertTrue;

import static junit.framework.Assert.fail;
import static org.hamcrest.Matchers.allOf;


import android.content.Context;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.Rect;
import android.support.annotation.StringRes;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.Configurator;
import android.support.test.uiautomator.Configurator;
@@ -49,16 +36,6 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View;


import com.android.documentsui.R;
import com.android.documentsui.sorting.SortDimension;
import com.android.documentsui.sorting.SortDimension.SortDirection;
import com.android.documentsui.sorting.SortModel;
import com.android.documentsui.sorting.SortModel.SortDimensionId;

import junit.framework.Assert;

import org.hamcrest.Matcher;

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.List;
import java.util.List;
@@ -75,15 +52,8 @@ public class DirectoryListBot extends Bots.BaseBot {
    private static final BySelector SNACK_DELETE =
    private static final BySelector SNACK_DELETE =
            By.desc(Pattern.compile("^Deleting [0-9]+ file.+"));
            By.desc(Pattern.compile("^Deleting [0-9]+ file.+"));


    private final SortModel mSortModel = SortModel.createModel();

    private final DropdownSortBot mDropdownBot;
    private final HeaderSortBot mHeaderBot;

    public DirectoryListBot(UiDevice device, Context context, int timeout) {
    public DirectoryListBot(UiDevice device, Context context, int timeout) {
        super(device, context, timeout);
        super(device, context, timeout);
        mDropdownBot = new DropdownSortBot();
        mHeaderBot = new HeaderSortBot();
    }
    }


    public void assertDocumentsCount(int count) throws UiObjectNotFoundException {
    public void assertDocumentsCount(int count) throws UiObjectNotFoundException {
@@ -99,7 +69,7 @@ public class DirectoryListBot extends Bots.BaseBot {
            }
            }
        }
        }
        if (!absent.isEmpty()) {
        if (!absent.isEmpty()) {
            Assert.fail("Expected documents " + Arrays.asList(labels)
            fail("Expected documents " + Arrays.asList(labels)
                    + ", but missing " + absent);
                    + ", but missing " + absent);
        }
        }
    }
    }
@@ -112,7 +82,7 @@ public class DirectoryListBot extends Bots.BaseBot {
            }
            }
        }
        }
        if (!found.isEmpty()) {
        if (!found.isEmpty()) {
            Assert.fail("Expected documents not present" + Arrays.asList(labels)
            fail("Expected documents not present" + Arrays.asList(labels)
                    + ", but present " + found);
                    + ", but present " + found);
        }
        }
    }
    }
@@ -234,22 +204,6 @@ public class DirectoryListBot extends Bots.BaseBot {
        assertHasFocus(DIR_LIST_ID);
        assertHasFocus(DIR_LIST_ID);
    }
    }


    public void sortBy(@SortDimensionId int id, @SortDirection int direction) {
        assert(direction != SortDimension.SORT_DIRECTION_NONE);

        final @StringRes int labelId = mSortModel.getDimensionById(id).getLabelId();
        final String label = mContext.getString(labelId);
        final boolean result;
        if (Matchers.present(mDropdownBot.MATCHER)) {
            result = mDropdownBot.sortBy(label, direction);
        } else {
            result = mHeaderBot.sortBy(label, direction);
        }

        assertTrue("Sorting by id: " + id + " in direction: " + direction + " failed.",
                result);
    }

    public void assertOrder(String[] dirs, String[] files) throws UiObjectNotFoundException {
    public void assertOrder(String[] dirs, String[] files) throws UiObjectNotFoundException {
        for (int i = 0; i < dirs.length - 1; ++i) {
        for (int i = 0; i < dirs.length - 1; ++i) {
            assertOrder(dirs[i], dirs[i + 1]);
            assertOrder(dirs[i], dirs[i + 1]);
@@ -284,90 +238,4 @@ public class DirectoryListBot extends Bots.BaseBot {
                    firstBound.bottom < secondBound.top || firstBound.left > secondBound.right);
                    firstBound.bottom < secondBound.top || firstBound.left > secondBound.right);
        }
        }
    }
    }

    private static class DropdownSortBot {

        private static final Matcher<View> MATCHER = withId(R.id.dropdown_sort_widget);
        private static final Matcher<View> DROPDOWN_MATCHER = allOf(
                withId(R.id.sort_dimen_dropdown),
                withParent(MATCHER));
        private static final Matcher<View> SORT_ARROW_MATCHER = allOf(
                withId(R.id.sort_arrow),
                withParent(MATCHER));

        private boolean sortBy(String label, @SortDirection int direction) {
            onView(DROPDOWN_MATCHER).perform(click());
            onView(withText(label)).perform(click());

            if (direction != getDirection()) {
                onView(SORT_ARROW_MATCHER).perform(click());
            }

            return Matchers.present(allOf(
                    DROPDOWN_MATCHER,
                    withText(label)))
                    && getDirection() == direction;
        }

        private @SortDirection int getDirection() {
            final boolean ascending = Matchers.present(
                    allOf(
                            SORT_ARROW_MATCHER,
                            withContentDescription(R.string.sort_direction_ascending)));

            if (ascending) {
                return SORT_DIRECTION_ASCENDING;
            }

            final boolean descending = Matchers.present(
                    allOf(
                            SORT_ARROW_MATCHER,
                            withContentDescription(R.string.sort_direction_descending)));

            return descending
                    ? SortDimension.SORT_DIRECTION_DESCENDING
                    : SortDimension.SORT_DIRECTION_NONE;
        }
    }

    private static class HeaderSortBot {

        private static final Matcher<View> MATCHER = withId(R.id.table_header);

        private boolean sortBy(String label, @SortDirection int direction) {
            final Matcher<View> cellMatcher = allOf(
                    withChild(withText(label)),
                    isDescendantOfA(MATCHER));
            onView(cellMatcher).perform(click());

            final @SortDirection int viewDirection = getDirection(cellMatcher);

            if (viewDirection != direction) {
                onView(cellMatcher).perform(click());
            }

            return getDirection(cellMatcher) == direction;
        }

        private @SortDirection int getDirection(Matcher<View> cellMatcher) {
            final boolean ascending =
                    Matchers.present(
                            allOf(
                                    withContentDescription(R.string.sort_direction_ascending),
                                    withParent(cellMatcher)));
            if (ascending) {
                return SORT_DIRECTION_ASCENDING;
            }

            final boolean descending =
                    Matchers.present(
                            allOf(
                                    withContentDescription(R.string.sort_direction_descending),
                                    withParent(cellMatcher)));

            return descending
                    ? SortDimension.SORT_DIRECTION_DESCENDING
                    : SortDimension.SORT_DIRECTION_NONE;
        }
    }
}
}
Loading