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

Commit 75929877 authored by Aga Wronska's avatar Aga Wronska Committed by Android (Google) Code Review
Browse files

Merge "Add tests for action bar's search icon behavior - Icon hidden when...

Merge "Add tests for action bar's search icon behavior     - Icon hidden when root doesn't support search     - Icon visible whan root supports search"
parents c7861d65 cfba4f68
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.documentsui.StubProvider.ROOT_0_ID;
import static com.android.documentsui.StubProvider.ROOT_1_ID;

import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.LargeTest;

@@ -31,9 +30,6 @@ public class SearchViewUiTest extends InstrumentationTestCase {

    private UiTestEnvironment mEnv;

    private UiObject mDocsList;
    private UiObject mMessageTextView;

    @Override
    public void setUp() throws Exception {
        super.setUp();
@@ -151,4 +147,15 @@ public class SearchViewUiTest extends InstrumentationTestCase {
        mEnv.bot().openRoot(ROOT_0_ID);
        mEnv.assertDefaultContentOfTestDir0();
    }

    public void testSearchIconVisible_RootWithSearchSupport() throws Exception {
        mEnv.bot().openRoot(ROOT_0_ID);
        mEnv.bot().assertSearchTextFiledAndIcon(false, true);
    }

    public void testSearchIconHidden_RootNoSearchSupport() throws Exception {
        mEnv.bot().openRoot(ROOT_1_ID);
        mEnv.bot().assertSearchTextFiledAndIcon(false, false);
    }

}
+18 −3
Original line number Diff line number Diff line
@@ -130,6 +130,11 @@ public class StubProvider extends DocumentsProvider {
                Log.i(TAG, "Created new root directory @ " + file.getPath());
            }
            final RootInfo rootInfo = new RootInfo(file, getSize(rootId));

            if(rootId.equals(ROOT_1_ID)) {
                rootInfo.setSearchEnabled(false);
            }

            mStorage.put(rootInfo.document.documentId, rootInfo.document);
            mRoots.put(rootId, rootInfo);
        }
@@ -152,8 +157,7 @@ public class StubProvider extends DocumentsProvider {
            final RootInfo info = entry.getValue();
            final RowBuilder row = result.newRow();
            row.add(Root.COLUMN_ROOT_ID, id);
            row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD
                    | Root.FLAG_SUPPORTS_SEARCH);
            row.add(Root.COLUMN_FLAGS, info.flags);
            row.add(Root.COLUMN_TITLE, id);
            row.add(Root.COLUMN_DOCUMENT_ID, info.document.documentId);
            row.add(Root.COLUMN_AVAILABLE_BYTES, info.getRemainingCapacity());
@@ -705,22 +709,33 @@ public class StubProvider extends DocumentsProvider {
    }

    final static class RootInfo {
        private static final int DEFAULT_ROOTS_FLAGS = Root.FLAG_SUPPORTS_SEARCH
                | Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD;

        public final String name;
        public final StubDocument document;
        public long capacity;
        public long size;
        public int flags;

        RootInfo(File file, long capacity) {
            this.name = file.getName();
            this.capacity = 1024 * 1024;
            this.document = StubDocument.createRootDocument(file, this);
            this.flags = DEFAULT_ROOTS_FLAGS;
            this.capacity = capacity;
            this.size = 0;
            this.document = StubDocument.createRootDocument(file, this);
        }

        public long getRemainingCapacity() {
            return capacity - size;
        }

        public void setSearchEnabled(boolean enabled) {
            flags = enabled ? (flags | Root.FLAG_SUPPORTS_SEARCH)
                    : (flags & ~Root.FLAG_SUPPORTS_SEARCH);
        }

    }

    final static class StubDocument {
+0 −1
Original line number Diff line number Diff line
@@ -150,7 +150,6 @@ class UiBot {
    void assertSearchTextFiledAndIcon(boolean searchTextFieldExists, boolean searchIconExists) {
        assertEquals(searchTextFieldExists, findSearchViewTextField().exists());
        assertEquals(searchIconExists, findSearchViewIcon().exists());

    }

    void assertHasDocuments(String... labels) throws UiObjectNotFoundException {