Fixing some tests for Phone form-factor.
Bug: 27533946 Change-Id: I70e15dee2ae7c14c1768d56ee04f87d05dd0f926 (cherry picked from commit 316c39b94c129652e7569fc7e4cd47af3cfb80d3)
This commit is contained in:
@@ -133,7 +133,7 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
|
||||
device.waitForIdle();
|
||||
bots.main.menuDelete().click();
|
||||
|
||||
bots.main.findDialogOkButton().click();
|
||||
bots.main.clickDialogOkButton();
|
||||
|
||||
bots.directory.assertDocumentsAbsent("file1.png");
|
||||
}
|
||||
@@ -152,8 +152,7 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.roots.openRoot(ROOT_1_ID);
|
||||
bots.main.pressKey(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON);
|
||||
|
||||
device.waitForIdle();
|
||||
|
||||
bots.directory.waitForDocument("file1.png");
|
||||
bots.directory.assertDocumentsPresent("file1.png");
|
||||
|
||||
bots.roots.openRoot(ROOT_0_ID);
|
||||
@@ -174,8 +173,7 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.roots.openRoot(ROOT_1_ID);
|
||||
bots.main.pressKey(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON);
|
||||
|
||||
device.waitForIdle();
|
||||
|
||||
bots.directory.waitForDocument("file1.png");
|
||||
bots.directory.assertDocumentsPresent("file1.png");
|
||||
|
||||
bots.roots.openRoot(ROOT_0_ID);
|
||||
@@ -191,7 +189,7 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
|
||||
device.waitForIdle();
|
||||
bots.main.menuDelete().click();
|
||||
|
||||
bots.main.findDialogCancelButton().click();
|
||||
bots.main.clickDialogCancelButton();
|
||||
|
||||
bots.directory.assertDocumentsPresent("file1.png");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
|
||||
package com.android.documentsui;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeLeft;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static com.android.documentsui.StubProvider.ROOT_0_ID;
|
||||
import static com.android.documentsui.StubProvider.ROOT_1_ID;
|
||||
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.test.suitebuilder.annotation.Suppress;
|
||||
|
||||
@@ -32,6 +39,7 @@ public class RenameDocumentUiTest extends ActivityTest<FilesActivity> {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
initTestFiles();
|
||||
bots.roots.closeDrawer();
|
||||
}
|
||||
|
||||
public void testRenameEnabled_SingleSelection() throws Exception {
|
||||
@@ -78,7 +86,7 @@ public class RenameDocumentUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.main.menuRename().click();
|
||||
bots.main.setDialogText(newName);
|
||||
|
||||
bots.main.findDialogOkButton().click();
|
||||
bots.main.clickDialogOkButton();
|
||||
|
||||
bots.directory.assertDocumentsAbsent(fileName1);
|
||||
bots.directory.assertDocumentsPresent(newName);
|
||||
@@ -104,7 +112,7 @@ public class RenameDocumentUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.main.menuRename().click();
|
||||
bots.main.setDialogText(newName);
|
||||
|
||||
bots.main.findDialogCancelButton().click();
|
||||
bots.main.clickDialogCancelButton();
|
||||
|
||||
bots.directory.assertDocumentsPresent(fileName1);
|
||||
bots.directory.assertDocumentsAbsent(newName);
|
||||
|
||||
@@ -16,9 +16,14 @@
|
||||
|
||||
package com.android.documentsui;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeLeft;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static com.android.documentsui.StubProvider.ROOT_0_ID;
|
||||
import static com.android.documentsui.StubProvider.ROOT_1_ID;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.support.v7.recyclerview.R;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.test.suitebuilder.annotation.Suppress;
|
||||
|
||||
@@ -29,6 +34,13 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
super(FilesActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// Drawer interferes with a lot of search action; going to try to close any opened ones
|
||||
bots.roots.closeDrawer();
|
||||
}
|
||||
|
||||
public void testSearchView_ExpandsOnClick() throws Exception {
|
||||
bots.main.openSearchView();
|
||||
bots.main.assertSearchTextFiledAndIcon(true, false);
|
||||
@@ -79,7 +91,8 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.roots.openRoot("Downloads");
|
||||
bots.directory.pasteFilesFromClipboard();
|
||||
|
||||
//TODO: linben Why do we need to click on Downloads again so this will work?
|
||||
//TODO: Why do we need to click on Downloads again so this will work?
|
||||
bots.roots.openRoot(ROOT_0_ID);
|
||||
bots.roots.openRoot("Downloads");
|
||||
device.waitForIdle();
|
||||
|
||||
@@ -119,8 +132,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
|
||||
bots.keyboard.pressEnter();
|
||||
|
||||
bots.directory.assertDocumentsCountOnList(true, 0);
|
||||
|
||||
String msg = String.valueOf(context.getString(R.string.no_results));
|
||||
bots.directory.assertMessageTextView(String.format(msg, "TEST_ROOT_0"));
|
||||
|
||||
@@ -142,7 +153,14 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
assertDefaultContentOfTestDir0();
|
||||
}
|
||||
|
||||
|
||||
public void testSearchResultsFound_ClearsOnDirectoryChange() throws Exception {
|
||||
// Skipping this test for phones since currently there's no way to open the drawer on
|
||||
// phones after doing a search (it's a back button instead of a hamburger button)
|
||||
if (!bots.main.isTablet()) {
|
||||
return;
|
||||
}
|
||||
|
||||
initTestFiles();
|
||||
assertDefaultContentOfTestDir0();
|
||||
|
||||
@@ -177,7 +195,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.directory.clickDocument(fileName2);
|
||||
device.waitForIdle();
|
||||
bots.main.menuDelete().click();
|
||||
bots.main.findDialogOkButton().click();
|
||||
bots.main.clickDialogOkButton();
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
super.tearDown();
|
||||
|
||||
@@ -16,20 +16,34 @@
|
||||
|
||||
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.matcher.ViewMatchers.withId;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeLeft;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeRight;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.espresso.ViewAction;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject;
|
||||
import android.support.test.uiautomator.UiObjectNotFoundException;
|
||||
import android.support.test.uiautomator.UiScrollable;
|
||||
import android.support.test.uiautomator.UiSelector;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import android.view.View;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import com.android.documentsui.R;
|
||||
|
||||
/**
|
||||
* A test helper class that provides support for controlling and asserting against
|
||||
* the roots list drawer.
|
||||
@@ -66,7 +80,25 @@ public class RootsListBot extends BaseBot {
|
||||
|
||||
public void openRoot(String label) throws UiObjectNotFoundException {
|
||||
findRoot(label).click();
|
||||
mDevice.waitForIdle();
|
||||
// Close the drawer in case we select a pre-selected root already
|
||||
closeDrawer();
|
||||
}
|
||||
|
||||
public void closeDrawer() {
|
||||
// Espresso will try to close the drawer if it's opened
|
||||
// But if no drawer exists (Tablet devices), we will have to catch the exception
|
||||
// and continue on the test
|
||||
// Why can't we do something like .exist() first?
|
||||
// http://stackoverflow.com/questions/20807131/espresso-return-boolean-if-view-exists
|
||||
try {
|
||||
if (mContext.getResources().getConfiguration()
|
||||
.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
|
||||
onView(withId(R.id.drawer_layout)).perform(swipeRight());
|
||||
} else {
|
||||
onView(withId(R.id.drawer_layout)).perform(swipeLeft());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void assertRootsPresent(String... labels) throws UiObjectNotFoundException {
|
||||
|
||||
@@ -18,14 +18,22 @@ 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.matcher.ViewMatchers.withResourceName;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static android.support.test.espresso.action.ViewActions.click;
|
||||
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
|
||||
import static android.support.test.espresso.action.ViewActions.typeText;
|
||||
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 static org.hamcrest.CoreMatchers.allOf;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.support.test.espresso.matcher.BoundedMatcher;
|
||||
import android.support.test.uiautomator.By;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
@@ -34,12 +42,16 @@ 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.support.v7.widget.SearchView;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toolbar;
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import com.android.documentsui.R;
|
||||
import com.android.documentsui.model.DocumentInfo;
|
||||
import com.android.internal.view.menu.ActionMenuItemView;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
@@ -63,11 +75,12 @@ public class UiBot extends BaseBot {
|
||||
}
|
||||
|
||||
public void assertWindowTitle(String expected) {
|
||||
onView(isAssignableFrom(Toolbar.class)).check(matches(withToolbarTitle(is(expected))));
|
||||
onView(allOf(isAssignableFrom(Toolbar.class), withId(R.id.toolbar)))
|
||||
.check(matches(withToolbarTitle(is(expected))));
|
||||
}
|
||||
|
||||
public void assertBreadcrumbTitle(String expected) {
|
||||
onView(isAssignableFrom(Spinner.class)).check(matches(withBreadcrumbTitle(is(expected))));
|
||||
onView(isAssignableFrom(Spinner.class)).check(matches(withBreadcrumbTitle(is(expected))));
|
||||
}
|
||||
|
||||
public void assertMenuEnabled(int id, boolean enabled) {
|
||||
@@ -77,11 +90,11 @@ public class UiBot extends BaseBot {
|
||||
}
|
||||
|
||||
public void assertSearchTextField(boolean isFocused, String query)
|
||||
throws UiObjectNotFoundException {
|
||||
throws UiObjectNotFoundException {
|
||||
UiObject textField = findSearchViewTextField();
|
||||
UiObject searchIcon = findSearchViewIcon();
|
||||
boolean searchIconVisible = isSearchIconVisible();
|
||||
|
||||
assertFalse(searchIcon.exists());
|
||||
assertFalse(searchIconVisible);
|
||||
assertTrue(textField.exists());
|
||||
assertEquals(isFocused, textField.isFocused());
|
||||
if(query != null) {
|
||||
@@ -89,9 +102,11 @@ public class UiBot extends BaseBot {
|
||||
}
|
||||
}
|
||||
|
||||
public void assertSearchTextFiledAndIcon(boolean searchTextFieldExists, boolean searchIconExists) {
|
||||
assertEquals(searchTextFieldExists, findSearchViewTextField().exists());
|
||||
assertEquals(searchIconExists, findSearchViewIcon().exists());
|
||||
public void assertSearchTextFiledAndIcon(boolean searchTextFieldExists,
|
||||
boolean searchIconExists) {
|
||||
assertEquals(searchTextFieldExists, findSearchViewTextField().exists());
|
||||
boolean searchIconVisible = isSearchIconVisible();
|
||||
assertEquals(searchIconExists, searchIconVisible);
|
||||
}
|
||||
|
||||
public void assertInActionMode(boolean inActionMode) {
|
||||
@@ -106,11 +121,7 @@ public class UiBot extends BaseBot {
|
||||
}
|
||||
|
||||
public void setSearchQuery(String query) throws UiObjectNotFoundException {
|
||||
UiObject searchView = findSearchView();
|
||||
assertTrue(searchView.exists());
|
||||
UiObject searchTextField = findSearchViewTextField();
|
||||
searchTextField.setText(query);
|
||||
assertSearchTextField(true, query);
|
||||
onView(allOf(withId(R.id.menu_search), isDisplayed())).perform(typeText(query));
|
||||
}
|
||||
|
||||
public UiObject openOverflowMenu() throws UiObjectNotFoundException {
|
||||
@@ -124,6 +135,11 @@ public class UiBot extends BaseBot {
|
||||
findDialogEditText().setText(text);
|
||||
}
|
||||
|
||||
public boolean isTablet() {
|
||||
return (mContext.getResources().getConfiguration().screenLayout &
|
||||
Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
|
||||
}
|
||||
|
||||
void switchViewMode() {
|
||||
UiObject2 mode = menuGridMode();
|
||||
if (mode != null) {
|
||||
@@ -133,6 +149,25 @@ public class UiBot extends BaseBot {
|
||||
}
|
||||
}
|
||||
|
||||
boolean isSearchIconVisible() {
|
||||
boolean searchIconVisible = true;
|
||||
boolean isTablet = isTablet();
|
||||
try {
|
||||
if (isTablet) {
|
||||
// Tablets use ImageView for its search icon, and has search_button as its res name
|
||||
onView(allOf(isAssignableFrom(ImageView.class), withResourceName("search_button")))
|
||||
.check(matches(isDisplayed()));
|
||||
} else {
|
||||
// Phones use ActionMenuItemView for its search icon, and has menu_search as its res name
|
||||
onView(allOf(isAssignableFrom(ActionMenuItemView.class), withResourceName("menu_search")))
|
||||
.check(matches(isDisplayed()));
|
||||
}
|
||||
} catch (Exception | AssertionFailedError e) {
|
||||
searchIconVisible = false;
|
||||
}
|
||||
return searchIconVisible;
|
||||
}
|
||||
|
||||
UiObject2 menuGridMode() {
|
||||
// Note that we're using By.desc rather than By.res, because of b/25285770
|
||||
return find(By.desc("Grid view"));
|
||||
@@ -188,16 +223,16 @@ public class UiBot extends BaseBot {
|
||||
return title;
|
||||
}
|
||||
|
||||
public UiObject findDialogOkButton() {
|
||||
UiObject object = findObject("android:id/content", "android:id/button1");
|
||||
object.waitForExists(mTimeout);
|
||||
return object;
|
||||
public void clickDialogOkButton() {
|
||||
// Espresso has flaky results when keyboard shows up, so hiding it for now
|
||||
// before trying to click on any dialog button
|
||||
onView(withId(android.R.id.button1)).perform(closeSoftKeyboard(), click());
|
||||
}
|
||||
|
||||
public UiObject findDialogCancelButton() {
|
||||
UiObject object = findObject("android:id/content", "android:id/button2");
|
||||
object.waitForExists(mTimeout);
|
||||
return object;
|
||||
public void clickDialogCancelButton() throws UiObjectNotFoundException {
|
||||
// Espresso has flaky results when keyboard shows up, so hiding it for now
|
||||
// before trying to click on any dialog button
|
||||
onView(withId(android.R.id.button2)).perform(closeSoftKeyboard(), click());
|
||||
}
|
||||
|
||||
UiObject findMenuLabelWithName(String label) {
|
||||
|
||||
Reference in New Issue
Block a user