Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2396)

Unified Diff: android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/ActionModeTest.java

Issue 2722463004: Revert of Wait for popup animation using idling resource for ActionMode Tests (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/util/WebViewUiTestRule.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/ActionModeTest.java
diff --git a/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/ActionModeTest.java b/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/ActionModeTest.java
index efba68533f5c1d3d5c8ac1051fb52b3296217ec9..f7269eb8f496743e8acef9132a2e849e0daf9f91 100644
--- a/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/ActionModeTest.java
+++ b/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/ActionModeTest.java
@@ -41,17 +41,16 @@
import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
+import android.animation.ValueAnimator;
import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.os.Build;
import android.support.test.InstrumentationRegistry;
-import android.support.test.espresso.Espresso;
-import android.support.test.espresso.IdlingResource;
-import android.support.test.espresso.IdlingResource.ResourceCallback;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.PerformException;
import android.support.test.espresso.Root;
+import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.GeneralClickAction;
import android.support.test.espresso.action.GeneralLocation;
import android.support.test.espresso.action.Press;
@@ -69,17 +68,19 @@
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.chromium.base.Log;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.webview_ui_test.R;
import org.chromium.webview_ui_test.WebViewUiTestActivity;
import org.chromium.webview_ui_test.test.util.UseLayout;
import org.chromium.webview_ui_test.test.util.WebViewUiTestRule;
+
+import java.lang.reflect.Method;
/**
* Tests for WebView ActionMode.
@@ -103,8 +104,6 @@
@Rule
public WebViewUiTestRule mWebViewActivityRule =
new WebViewUiTestRule(WebViewUiTestActivity.class);
-
- private ActionBarIdlingResource mActionBarIdlingResource;
@Before
public void setUp() {
@@ -115,13 +114,21 @@
onWebView(withId(R.id.webview))
.withElement(findElement(Locator.TAG_NAME, "p"))
.check(webMatches(getText(), containsString("Hello world")));
- mActionBarIdlingResource = new ActionBarIdlingResource();
- Espresso.registerIdlingResources(mActionBarIdlingResource);
- }
-
- @After
- public void tearDown() {
- Espresso.unregisterIdlingResources(mActionBarIdlingResource);
+ disableAnimation();
+ }
+
+ /**
+ * Only way to disable popup animations.
+ */
+ private void disableAnimation() {
+ try {
+ // This is a hidden method to disable animations. It is also being used by CTS tests.
+ Method setDurationScale = ValueAnimator.class.getMethod(
+ "setDurationScale", float.class);
+ setDurationScale.invoke(null, 0.0f);
+ } catch (Exception e) {
+ Log.e(TAG, "Couldn't disable animation", e);
+ }
}
/**
@@ -131,9 +138,9 @@
@SmallTest
@UseLayout("edittext_webview")
public void testCopyPaste() {
- longClickOnLastWord(R.id.webview);
+ onView(withId(R.id.webview)).perform(longClickOnLastWord());
clickPopupAction(COPY_ACTION);
- longClickOnLastWord(R.id.edittext);
+ onView(withId(R.id.edittext)).perform(longClickOnLastWord());
clickPopupAction(PASTE_ACTION);
onView(withId(R.id.edittext))
.check(matches(withText("world")));
@@ -146,10 +153,10 @@
@SmallTest
@UseLayout("edittext_webview")
public void testSelectAll() {
- longClickOnLastWord(R.id.webview);
+ onView(withId(R.id.webview)).perform(longClickOnLastWord());
clickPopupAction("Select all");
clickPopupAction(COPY_ACTION);
- longClickOnLastWord(R.id.edittext);
+ onView(withId(R.id.edittext)).perform(longClickOnLastWord());
clickPopupAction(PASTE_ACTION);
onView(withId(R.id.edittext))
.check(matches(withText("Hello world")));
@@ -166,7 +173,7 @@
intending(anyIntent())
.respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent()));
- longClickOnLastWord(R.id.webview);
+ onView(withId(R.id.webview)).perform(longClickOnLastWord());
clickPopupAction(SHARE_ACTION);
intended(allOf(hasAction(Intent.ACTION_CHOOSER),
@@ -187,7 +194,7 @@
Intents.init();
intending(anyIntent())
.respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent()));
- longClickOnLastWord(R.id.webview);
+ onView(withId(R.id.webview)).perform(longClickOnLastWord());
clickPopupAction(WEB_SEARCH_ACTION);
intended(allOf(hasAction(Intent.ACTION_WEB_SEARCH),
hasExtras(allOf(hasEntry("com.android.browser.application_id",
@@ -206,7 +213,7 @@
public void testAssist() {
// TODO(aluo): Get SdkSuppress to work with the test runner
if (Build.VERSION.SDK_INT < 24) return;
- longClickOnLastWord(R.id.webview);
+ onView(withId(R.id.webview)).perform(longClickOnLastWord());
clickPopupAction(ASSIST_ACTION);
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject assistUi = device.findObject(new UiSelector().packageName(QUICK_SEARCH_BOX_PKG));
@@ -223,7 +230,7 @@
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
try {
// On L and lower, use the espresso DEFAULT root matcher if ActionBar is detected
- onView(withClassName(endsWith("ActionBarContextView")))
+ onView(withClassName(endsWith("widget.ActionBarContextView")))
.check(matches(isDisplayed()));
rootMatcher = DEFAULT;
} catch (NoMatchingViewException | AssertionFailedError e) {
@@ -234,30 +241,27 @@
// On M and above, can use the decoreView matcher
rootMatcher = withDecorView(isEnabled());
}
-
try {
onView(anyOf(withText(name), withContentDescription(name)))
.inRoot(rootMatcher)
.perform(click());
- } catch (PerformException | NoMatchingViewException e) {
+ } catch (PerformException e) {
// Take care of case when the item is in the overflow menu
onView(withContentDescription(MORE_OPTIONS_ACTION))
- .inRoot(rootMatcher)
+ .inRoot(withDecorView(isEnabled()))
.perform(click());
onData(new MenuItemMatcher(equalTo(name))).inRoot(rootMatcher).perform(click());
}
}
/**
- * Perform a view action that clicks on the last word and start the idling resource
- * to wait for completion of the popup menu
- */
- private final void longClickOnLastWord(int viewId) {
+ * This view action clicks on center right of a view to select the last word
+ */
+ private static final ViewAction longClickOnLastWord() {
// TODO(aluo): This function is not guaranteed to click on element. Change to
// implementation that gets bounding box for elements using Javascript.
- onView(withId(viewId)).perform(actionWithAssertions(
- new GeneralClickAction(Tap.LONG, GeneralLocation.CENTER_RIGHT, Press.FINGER)));
- mActionBarIdlingResource.start();
+ return actionWithAssertions(
+ new GeneralClickAction(Tap.LONG, GeneralLocation.CENTER_RIGHT, Press.FINGER));
}
/**
@@ -281,38 +285,4 @@
description.appendDescriptionOf(mTitleMatcher);
}
}
-
- private class ActionBarIdlingResource implements IdlingResource {
- private boolean mActionStarting;
- private ResourceCallback mResourceCallback;
-
- ActionBarIdlingResource() {
- mActionStarting = false;
- mResourceCallback = null;
- }
-
- @Override
- public String getName() {
- return "ActionBarIdlingResource";
- }
-
- @Override
- public boolean isIdleNow() {
- if (!mActionStarting) return true;
- if (mWebViewActivityRule.isActionBarDisplayed()) {
- mActionStarting = false;
- if (mResourceCallback != null) mResourceCallback.onTransitionToIdle();
- }
- return !mActionStarting;
- }
-
- @Override
- public void registerIdleTransitionCallback(ResourceCallback callback) {
- mResourceCallback = callback;
- }
-
- public void start() {
- mActionStarting = true;
- }
- }
}
« no previous file with comments | « no previous file | android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/util/WebViewUiTestRule.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698