Index: android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/util/Actions.java |
diff --git a/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/util/Actions.java b/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/util/Actions.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bf2fecc085a0e33b78453c820b12a6445ad686ed |
--- /dev/null |
+++ b/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/util/Actions.java |
@@ -0,0 +1,82 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.webview_ui_test.test.util; |
+ |
+import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; |
+import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA; |
+import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; |
+ |
+import static org.hamcrest.Matchers.allOf; |
+ |
+import android.support.annotation.NonNull; |
+import android.support.test.espresso.UiController; |
+import android.support.test.espresso.ViewAction; |
+import android.support.test.espresso.matcher.ViewMatchers; |
+import android.view.View; |
+import android.webkit.WebView; |
+ |
+import org.hamcrest.Matcher; |
+ |
+/** |
+ * Actions to help with WebView tests |
+ */ |
+public class Actions { |
+ |
+ public static ViewAction setUseWideViewPort() { |
+ return setUseWideViewPort(true); |
+ } |
+ public static ViewAction setUseWideViewPort(final boolean useWideViewPort) { |
+ return new ViewAction() { |
+ @Override |
+ public Matcher<View> getConstraints() { |
+ return isAssignableFrom(WebView.class); |
+ } |
+ |
+ @Override |
+ public String getDescription() { |
+ return "use wide viewport: " + useWideViewPort; |
+ } |
+ |
+ /** |
+ * Performs setUseWideViewPort then waits for completion. |
+ * |
+ * @param uiController the controller to use to interact with the UI. |
+ * @param view the view to act upon. Must be webview or a subclass thereof. |
+ */ |
+ @Override |
+ public void perform(UiController uiController, @NonNull View view) { |
+ WebView webview = (WebView) view; |
+ webview.getSettings().setUseWideViewPort(useWideViewPort); |
+ uiController.loopMainThreadUntilIdle(); |
+ } |
+ }; |
+ } |
+ public static ViewAction scrollBy(final int x, final int y) { |
+ return new ViewAction() { |
+ @Override |
+ public Matcher<View> getConstraints() { |
+ return allOf(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), |
+ isDescendantOfA(isAssignableFrom(View.class))); |
the real yoland
2016/12/16 18:04:42
nits: this is also only used for WebView?
|
+ } |
+ |
+ @Override |
+ public String getDescription() { |
+ return "scroll by: " + x + "," + y; |
+ } |
+ |
+ /** |
+ * Performs setUseWideViewPort then waits for completion. |
+ * |
+ * @param uiController the controller to use to interact with the UI. |
+ * @param view the view to act upon. |
+ */ |
+ @Override |
+ public void perform(UiController uiController, @NonNull View view) { |
+ view.scrollBy(x, y); |
+ uiController.loopMainThreadUntilIdle(); |
+ } |
+ }; |
+ } |
+} |