OSDN Git Service

Launch the activity with the test root opened for tests
authorAga Wronska <agawronska@google.com>
Wed, 24 Feb 2016 20:57:21 +0000 (12:57 -0800)
committerAga Wronska <agawronska@google.com>
Thu, 25 Feb 2016 00:34:43 +0000 (16:34 -0800)
to reduce some flakiness and save time used on opening test root over
and over again.

Bug: 27271765
Change-Id: I6fa191ed8e0c7e8e071e4dd17c62aab5db1e23a5

packages/DocumentsUI/tests/src/com/android/documentsui/ActivityTest.java
packages/DocumentsUI/tests/src/com/android/documentsui/FilesActivityUiTest.java
packages/DocumentsUI/tests/src/com/android/documentsui/RenameDocumentUiTest.java
packages/DocumentsUI/tests/src/com/android/documentsui/RootsUiTest.java
packages/DocumentsUI/tests/src/com/android/documentsui/SearchViewUiTest.java

index 08d366a..adcfef3 100644 (file)
@@ -20,6 +20,7 @@ import static com.android.documentsui.StubProvider.DEFAULT_AUTHORITY;
 import static com.android.documentsui.StubProvider.ROOT_0_ID;
 import static com.android.documentsui.StubProvider.ROOT_1_ID;
 
+import android.annotation.Nullable;
 import android.app.Activity;
 import android.content.ContentProviderClient;
 import android.content.ContentResolver;
@@ -72,6 +73,17 @@ public abstract class ActivityTest<T extends Activity> extends ActivityInstrumen
         super(activityClass);
     }
 
+    /*
+     * Returns the root that will be opened within the activity.
+     * By default tests are started with one of the test roots.
+     * Override the method if you want to open different root on start.
+     * @return Root that will be opened. Return null if you want to open activity's default root.
+     */
+    @Nullable
+    protected RootInfo getInitialRoot() {
+        return rootDir0;
+    }
+
     @Override
     public void setUp() throws Exception {
         device = UiDevice.getInstance(getInstrumentation());
@@ -106,6 +118,9 @@ public abstract class ActivityTest<T extends Activity> extends ActivityInstrumen
         final Intent intent = context.getPackageManager().getLaunchIntentForPackage(
                 UiBot.TARGET_PKG);
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
+        if (getInitialRoot() != null) {
+            intent.setData(getInitialRoot().getUri());
+        }
         setActivityIntent(intent);
         getActivity();  // Launch the activity.
     }
@@ -127,13 +142,11 @@ public abstract class ActivityTest<T extends Activity> extends ActivityInstrumen
     }
 
     void assertDefaultContentOfTestDir0() throws UiObjectNotFoundException {
-        bots.roots.openRoot(ROOT_0_ID);
         bots.directory.assertDocumentsCount(4);
         bots.directory.assertDocumentsPresent(fileName1, fileName2, dirName1, fileNameNoRename);
     }
 
     void assertDefaultContentOfTestDir1() throws UiObjectNotFoundException {
-        bots.roots.openRoot(ROOT_1_ID);
         bots.directory.assertDocumentsCount(2);
         bots.directory.assertDocumentsPresent(fileName3, fileName4);
     }
index 1ffef05..38e1257 100644 (file)
@@ -23,6 +23,8 @@ import android.os.RemoteException;
 import android.test.suitebuilder.annotation.LargeTest;
 import android.view.KeyEvent;
 
+import com.android.documentsui.model.RootInfo;
+
 @LargeTest
 public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
 
@@ -31,6 +33,11 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
     }
 
     @Override
+    protected RootInfo getInitialRoot() {
+        return null;
+    }
+
+    @Override
     public void initTestFiles() throws RemoteException {
         mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log");
         mDocsHelper.createDocument(rootDir0, "image/png", "file1.png");
index b866033..2833418 100644 (file)
@@ -33,7 +33,6 @@ public class RenameDocumentUiTest extends ActivityTest<FilesActivity> {
     public void setUp() throws Exception {
         super.setUp();
         initTestFiles();
-        bots.roots.openRoot(ROOT_0_ID);
     }
 
     public void testRenameEnabled_SingleSelection() throws Exception {
index dc41a2c..6141832 100644 (file)
@@ -33,7 +33,6 @@ public class RootsUiTest extends ActivityTest<FilesActivity> {
     public void setUp() throws Exception {
         super.setUp();
         initTestFiles();
-        bots.roots.openRoot(ROOT_0_ID);
     }
 
     public void testRootTapped_GoToRootFromChildDir() throws Exception {
index 478c70c..8c3fd90 100644 (file)
@@ -53,7 +53,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
 
     public void testSearch_ResultsFound() throws Exception {
         initTestFiles();
-        bots.roots.openRoot(ROOT_0_ID);
         assertDefaultContentOfTestDir0();
 
         String query = "file1";
@@ -71,7 +70,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
 
     public void testSearchResultsFound_ClearsOnBack() throws Exception {
         initTestFiles();
-        bots.roots.openRoot(ROOT_0_ID);
         assertDefaultContentOfTestDir0();
 
         String query = fileName1;
@@ -86,7 +84,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
 
     public void testSearch_NoResults() throws Exception {
         initTestFiles();
-        bots.roots.openRoot(ROOT_0_ID);
         assertDefaultContentOfTestDir0();
 
         String query = "chocolate";
@@ -106,7 +103,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
 
     public void testSearchNoResults_ClearsOnBack() throws Exception {
         initTestFiles();
-        bots.roots.openRoot(ROOT_0_ID);
         assertDefaultContentOfTestDir0();
 
         String query = "chocolate";
@@ -122,7 +118,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
 
     public void testSearchResultsFound_ClearsOnDirectoryChange() throws Exception {
         initTestFiles();
-        bots.roots.openRoot(ROOT_0_ID);
         assertDefaultContentOfTestDir0();
 
         String query = fileName1;