Merge "Launch the activity with the test root opened for tests to reduce some flakiness and save time used on opening test root over and over again." into nyc-dev

This commit is contained in:
Aga Wronska
2016-02-25 02:06:32 +00:00
committed by Android (Google) Code Review
5 changed files with 22 additions and 9 deletions

View 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);
}

View 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> {
@@ -30,6 +32,11 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
super(FilesActivity.class);
}
@Override
protected RootInfo getInitialRoot() {
return null;
}
@Override
public void initTestFiles() throws RemoteException {
mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log");

View 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 {

View 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 {

View 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;