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;
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());
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.
}
}
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);
}
import android.test.suitebuilder.annotation.LargeTest;
import android.view.KeyEvent;
+import com.android.documentsui.model.RootInfo;
+
@LargeTest
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");
public void testSearch_ResultsFound() throws Exception {
initTestFiles();
- bots.roots.openRoot(ROOT_0_ID);
assertDefaultContentOfTestDir0();
String query = "file1";
public void testSearchResultsFound_ClearsOnBack() throws Exception {
initTestFiles();
- bots.roots.openRoot(ROOT_0_ID);
assertDefaultContentOfTestDir0();
String query = fileName1;
public void testSearch_NoResults() throws Exception {
initTestFiles();
- bots.roots.openRoot(ROOT_0_ID);
assertDefaultContentOfTestDir0();
String query = "chocolate";
public void testSearchNoResults_ClearsOnBack() throws Exception {
initTestFiles();
- bots.roots.openRoot(ROOT_0_ID);
assertDefaultContentOfTestDir0();
String query = "chocolate";
public void testSearchResultsFound_ClearsOnDirectoryChange() throws Exception {
initTestFiles();
- bots.roots.openRoot(ROOT_0_ID);
assertDefaultContentOfTestDir0();
String query = fileName1;