summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ben Lin <linben@google.com> 2016-05-11 17:38:18 -0700
committer Ben Lin <linben@google.com> 2016-05-13 15:49:58 -0700
commit8952ec65ae001ccdae98f00d5586881822608c52 (patch)
treea16145dff1c79d41859ef4cc316a79fc87876e44
parentc81f68f6c2795fa961c4f2d43ddc4d5a1486b734 (diff)
Initial effort toward fixing Suppress tests by integration of Espresso.
Bug: 27533946 Change-Id: I0286ff6d4c53b464180e3100b7219e766ca09de3
-rw-r--r--perf-tests/Android.mk2
-rw-r--r--tests/Android.mk2
-rw-r--r--tests/AndroidManifest.xml2
-rw-r--r--tests/src/com/android/documentsui/RenameDocumentUiTest.java6
-rw-r--r--tests/src/com/android/documentsui/RootsUiTest.java2
-rw-r--r--tests/src/com/android/documentsui/SearchViewUiTest.java22
-rw-r--r--tests/src/com/android/documentsui/bots/KeyboardBot.java12
-rw-r--r--tests/src/com/android/documentsui/bots/UiBot.java55
8 files changed, 64 insertions, 39 deletions
diff --git a/perf-tests/Android.mk b/perf-tests/Android.mk
index 5ebf85f74..39a08f741 100644
--- a/perf-tests/Android.mk
+++ b/perf-tests/Android.mk
@@ -11,7 +11,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) \
../tests/src/com/android/documentsui/StubProvider.java
LOCAL_JAVA_LIBRARIES := android-support-v4 android.test.runner
-LOCAL_STATIC_JAVA_LIBRARIES := mockito-target ub-uiautomator ub-janktesthelper
+LOCAL_STATIC_JAVA_LIBRARIES := mockito-target ub-uiautomator ub-janktesthelper espresso-core
LOCAL_PACKAGE_NAME := DocumentsUIPerfTests
LOCAL_INSTRUMENTATION_FOR := DocumentsUI
diff --git a/tests/Android.mk b/tests/Android.mk
index 3983f780a..31b7c496e 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -8,7 +8,7 @@ LOCAL_MODULE_TAGS := tests
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_JAVA_LIBRARIES := android-support-v4 android.test.runner
-LOCAL_STATIC_JAVA_LIBRARIES := mockito-target ub-uiautomator
+LOCAL_STATIC_JAVA_LIBRARIES := mockito-target ub-uiautomator espresso-core
LOCAL_PACKAGE_NAME := DocumentsUITests
LOCAL_INSTRUMENTATION_FOR := DocumentsUI
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index b98628585..0b767662f 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -19,7 +19,7 @@
</provider>
</application>
- <instrumentation android:name="android.test.InstrumentationTestRunner"
+ <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
android:targetPackage="com.android.documentsui"
android:label="Tests for DocumentsUI" />
diff --git a/tests/src/com/android/documentsui/RenameDocumentUiTest.java b/tests/src/com/android/documentsui/RenameDocumentUiTest.java
index 9a06807f0..9ccd72746 100644
--- a/tests/src/com/android/documentsui/RenameDocumentUiTest.java
+++ b/tests/src/com/android/documentsui/RenameDocumentUiTest.java
@@ -72,16 +72,13 @@ public class RenameDocumentUiTest extends ActivityTest<FilesActivity> {
device.pressBack();
}
- @Suppress
public void testRenameFile_OkButton() throws Exception {
bots.directory.selectDocument(fileName1);
bots.main.openOverflowMenu();
bots.main.menuRename().click();
bots.main.setDialogText(newName);
- device.waitForIdle(TIMEOUT);
bots.main.findDialogOkButton().click();
- device.waitForIdle(TIMEOUT);
bots.directory.assertDocumentsAbsent(fileName1);
bots.directory.assertDocumentsPresent(newName);
@@ -101,16 +98,13 @@ public class RenameDocumentUiTest extends ActivityTest<FilesActivity> {
bots.directory.assertDocumentsCount(4);
}
- @Suppress
public void testRenameFile_Cancel() throws Exception {
bots.directory.selectDocument(fileName1);
bots.main.openOverflowMenu();
bots.main.menuRename().click();
bots.main.setDialogText(newName);
- device.waitForIdle(TIMEOUT);
bots.main.findDialogCancelButton().click();
- device.waitForIdle(TIMEOUT);
bots.directory.assertDocumentsPresent(fileName1);
bots.directory.assertDocumentsAbsent(newName);
diff --git a/tests/src/com/android/documentsui/RootsUiTest.java b/tests/src/com/android/documentsui/RootsUiTest.java
index 621410a44..038a20882 100644
--- a/tests/src/com/android/documentsui/RootsUiTest.java
+++ b/tests/src/com/android/documentsui/RootsUiTest.java
@@ -39,7 +39,7 @@ public class RootsUiTest extends ActivityTest<FilesActivity> {
public void testRootTapped_GoToRootFromChildDir() throws Exception {
bots.directory.openDocument(dirName1);
- bots.main.assertWindowTitle(dirName1);
+ bots.main.assertBreadcrumbTitle(dirName1);
bots.roots.openRoot(ROOT_0_ID);
bots.main.assertWindowTitle(ROOT_0_ID);
assertDefaultContentOfTestDir0();
diff --git a/tests/src/com/android/documentsui/SearchViewUiTest.java b/tests/src/com/android/documentsui/SearchViewUiTest.java
index b6190821c..2d0ce2090 100644
--- a/tests/src/com/android/documentsui/SearchViewUiTest.java
+++ b/tests/src/com/android/documentsui/SearchViewUiTest.java
@@ -29,7 +29,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
super(FilesActivity.class);
}
- @Suppress
public void testSearchView_ExpandsOnClick() throws Exception {
bots.main.openSearchView();
bots.main.assertSearchTextFiledAndIcon(true, false);
@@ -43,7 +42,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
bots.main.assertSearchTextFiledAndIcon(false, true);
}
- @Suppress
public void testSearchView_ClearsTextOnBack() throws Exception {
String query = "file2";
bots.main.openSearchView();
@@ -54,7 +52,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
bots.main.assertSearchTextFiledAndIcon(false, true);
}
- @Suppress
public void testSearch_ResultsFound() throws Exception {
initTestFiles();
assertDefaultContentOfTestDir0();
@@ -64,7 +61,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
bots.main.setSearchQuery(query);
bots.main.assertSearchTextField(true, query);
- device.pressEnter();
+ bots.keyboard.pressEnter();
bots.directory.assertDocumentsCountOnList(true, 2);
bots.directory.assertDocumentsPresent(fileName1, fileName2);
@@ -90,7 +87,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
bots.main.openSearchView();
bots.main.setSearchQuery(query);
- device.pressEnter();
+ bots.keyboard.pressEnter();
bots.directory.assertDocumentsCountOnList(true, 1);
bots.directory.assertDocumentsPresent(fileName2);
@@ -98,7 +95,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
device.pressBack();
}
- @Suppress
public void testSearchResultsFound_ClearsOnBack() throws Exception {
initTestFiles();
assertDefaultContentOfTestDir0();
@@ -107,13 +103,12 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
bots.main.openSearchView();
bots.main.setSearchQuery(query);
- device.pressEnter();
+ bots.keyboard.pressEnter();
device.pressBack();
assertDefaultContentOfTestDir0();
}
- @Suppress
public void testSearch_NoResults() throws Exception {
initTestFiles();
assertDefaultContentOfTestDir0();
@@ -122,18 +117,16 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
bots.main.openSearchView();
bots.main.setSearchQuery(query);
- device.pressEnter();
+ bots.keyboard.pressEnter();
- bots.directory.assertDocumentsCountOnList(false, 0);
+ bots.directory.assertDocumentsCountOnList(true, 0);
- device.waitForIdle();
String msg = String.valueOf(context.getString(R.string.no_results));
bots.directory.assertMessageTextView(String.format(msg, "TEST_ROOT_0"));
bots.main.assertSearchTextField(false, query);
}
- @Suppress
public void testSearchNoResults_ClearsOnBack() throws Exception {
initTestFiles();
assertDefaultContentOfTestDir0();
@@ -142,14 +135,13 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
bots.main.openSearchView();
bots.main.setSearchQuery(query);
- device.pressEnter();
+ bots.keyboard.pressEnter();
device.pressBack();
device.waitForIdle();
assertDefaultContentOfTestDir0();
}
- @Suppress
public void testSearchResultsFound_ClearsOnDirectoryChange() throws Exception {
initTestFiles();
assertDefaultContentOfTestDir0();
@@ -158,7 +150,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
bots.main.openSearchView();
bots.main.setSearchQuery(query);
- device.pressEnter();
+ bots.keyboard.pressEnter();
bots.roots.openRoot(ROOT_1_ID);
assertDefaultContentOfTestDir1();
diff --git a/tests/src/com/android/documentsui/bots/KeyboardBot.java b/tests/src/com/android/documentsui/bots/KeyboardBot.java
index 4c47cfaca..b0a4d76f4 100644
--- a/tests/src/com/android/documentsui/bots/KeyboardBot.java
+++ b/tests/src/com/android/documentsui/bots/KeyboardBot.java
@@ -16,9 +16,14 @@
package com.android.documentsui.bots;
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.action.ViewActions.pressImeActionButton;
+import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
+
import android.content.Context;
import android.support.test.uiautomator.UiDevice;
import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
/**
* A test helper class that provides support for keyboard manipulation.
@@ -43,8 +48,9 @@ public class KeyboardBot extends BaseBot {
}
public void pressEnter() {
- waitForIdle();
- mDevice.pressEnter();
- waitForIdle();
+ //TODO: There seems to be a bug on N/Espresso that makes pressing Enter not work
+ // This is a temporary workaround that somehow works
+ // See b/28399576
+ onView(isAssignableFrom(EditText.class)).perform(pressImeActionButton());
}
}
diff --git a/tests/src/com/android/documentsui/bots/UiBot.java b/tests/src/com/android/documentsui/bots/UiBot.java
index b099d1081..22978431e 100644
--- a/tests/src/com/android/documentsui/bots/UiBot.java
+++ b/tests/src/com/android/documentsui/bots/UiBot.java
@@ -16,12 +16,17 @@
package com.android.documentsui.bots;
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
import android.content.Context;
+import android.support.test.espresso.matcher.BoundedMatcher;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
@@ -29,8 +34,15 @@ import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
+import android.util.Log;
+import android.widget.Spinner;
+import android.widget.Toolbar;
import com.android.documentsui.R;
+import com.android.documentsui.model.DocumentInfo;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
import java.util.Iterator;
import java.util.List;
@@ -51,19 +63,13 @@ public class UiBot extends BaseBot {
}
public void assertWindowTitle(String expected) {
- // Turns out the title field on a window does not have
- // an id associated with it at runtime (which confuses the hell out of me)
- // In code we address this via "android.R.id.title".
- UiObject2 o = find(By.text(expected));
- // It's a bit of a conceit that we then *assert* that the title
- // is the value that we used to identify the UiObject2.
- // If the preceeding lookup fails, this'll choke with an NPE.
- // But given the issue described in the comment above, we're
- // going to do it anyway. Because we shouldn't be looking up
- // the uiobject by it's expected content :|
- assertEquals(expected, o.getText());
+ onView(isAssignableFrom(Toolbar.class)).check(matches(withToolbarTitle(is(expected))));
}
+ public void assertBreadcrumbTitle(String expected) {
+ onView(isAssignableFrom(Spinner.class)).check(matches(withBreadcrumbTitle(is(expected))));
+ }
+
public void assertMenuEnabled(int id, boolean enabled) {
UiObject2 menu= findMenuWithName(mContext.getString(id));
assertNotNull(menu);
@@ -228,4 +234,31 @@ public class UiBot extends BaseBot {
public void pressKey(int keyCode, int metaState) {
mDevice.pressKeyCode(keyCode, metaState);
}
+
+ private static Matcher<Object> withToolbarTitle(
+ final Matcher<CharSequence> textMatcher) {
+ return new BoundedMatcher<Object, Toolbar>(Toolbar.class) {
+ @Override public boolean matchesSafely(Toolbar toolbar) {
+ return textMatcher.matches(toolbar.getTitle());
+ }
+ @Override public void describeTo(Description description) {
+ description.appendText("with toolbar title: ");
+ textMatcher.describeTo(description);
+ }
+ };
+ }
+
+ private static Matcher<Object> withBreadcrumbTitle(
+ final Matcher<CharSequence> textMatcher) {
+ return new BoundedMatcher<Object, Spinner>(Spinner.class) {
+ @Override public boolean matchesSafely(Spinner breadcrumb) {
+ DocumentInfo selectedDoc = (DocumentInfo) breadcrumb.getSelectedItem();
+ return textMatcher.matches(selectedDoc.displayName);
+ }
+ @Override public void describeTo(Description description) {
+ description.appendText("with breadcrumb title: ");
+ textMatcher.describeTo(description);
+ }
+ };
+ }
}