OSDN Git Service

Add tests for action bar's search icon behavior
authorAga Wronska <agawronska@google.com>
Mon, 1 Feb 2016 20:23:48 +0000 (12:23 -0800)
committerAga Wronska <agawronska@google.com>
Tue, 2 Feb 2016 01:16:44 +0000 (17:16 -0800)
    - Icon hidden when root doesn't support search
    - Icon visible whan root supports search

Bug: 26903635
Change-Id: I7a73d44e83c87be7d25abe55477fa54572833e32

packages/DocumentsUI/tests/src/com/android/documentsui/SearchViewUiTest.java
packages/DocumentsUI/tests/src/com/android/documentsui/StubProvider.java
packages/DocumentsUI/tests/src/com/android/documentsui/UiBot.java

index ce54725..042ec85 100644 (file)
@@ -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);
+    }
+
 }
index 980627b..9855427 100644 (file)
@@ -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 {
index f12ae10..d609fa8 100644 (file)
@@ -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 {