diff options
author | mkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-04 11:33:36 +0000 |
---|---|---|
committer | mkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-04 11:33:36 +0000 |
commit | 05a57eeff96f909185813f0955985c5f0c4a0fe9 (patch) | |
tree | ba823b59e357b59f2b43bb45fe50394933973928 /android_webview | |
parent | 17bc2274dc055bfec3a187f8f985dc1ce300fb6a (diff) | |
download | chromium_src-05a57eeff96f909185813f0955985c5f0c4a0fe9.zip chromium_src-05a57eeff96f909185813f0955985c5f0c4a0fe9.tar.gz chromium_src-05a57eeff96f909185813f0955985c5f0c4a0fe9.tar.bz2 |
[android_webivew] Send touch events directly to the view.
This changes the test code to send generated touch events directly
to the view instead of going through the Instrumentation class.
This allows us to successfully complete the test case even if a modal
dialog pops over the Activity under test.
BUG=256774
TEST=run AndroidWebViewTest with the 'power off' modal dialog up.
Java-only change, did fine on Android trybots.
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/18259009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210172 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
2 files changed, 82 insertions, 19 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java index 1f0f177..0039080 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java @@ -12,14 +12,13 @@ import android.view.View; import org.chromium.android_webview.AwContents; import org.chromium.android_webview.AwContentsClient; +import org.chromium.android_webview.test.util.AwTestTouchUtils; import org.chromium.android_webview.test.util.CommonResources; import org.chromium.android_webview.test.util.JavascriptEventObserver; import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.Feature; import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.test.util.CallbackHelper; -import org.chromium.content.browser.test.util.CallbackHelper; -import org.chromium.content.browser.test.util.TestTouchUtils; import org.chromium.ui.gfx.DeviceDisplayInfo; import java.util.concurrent.atomic.AtomicBoolean; @@ -293,22 +292,8 @@ public class AndroidScrollIntegrationTest extends AwTestBase { assertScrollOnMainSync(testContainerView, maxScrollXPix, maxScrollYPix); } - private void dragViewBy(AwTestContainerView testContainerView, int dxPix, int dyPix, - int steps) { - int gestureStart[] = new int[2]; - testContainerView.getLocationOnScreen(gestureStart); - int gestureEnd[] = new int[] { gestureStart[0] - dxPix, gestureStart[1] - dyPix }; - - TestTouchUtils.drag(this, gestureStart[0], gestureEnd[0], gestureStart[1], gestureEnd[1], - steps); - } - - /* - * http://crbug.com/256774 - * @SmallTest - * @Feature({"AndroidWebView"}) - */ - @DisabledTest + @SmallTest + @Feature({"AndroidWebView"}) public void testTouchScrollCanBeAlteredByUi() throws Throwable { final TestAwContentsClient contentsClient = new TestAwContentsClient(); final ScrollTestContainerView testContainerView = @@ -339,7 +324,10 @@ public class AndroidScrollIntegrationTest extends AwTestBase { final CallbackHelper onScrollToCallbackHelper = testContainerView.getOnScrollToCallbackHelper(); final int scrollToCallCount = onScrollToCallbackHelper.getCallCount(); - dragViewBy(testContainerView, targetScrollXPix, targetScrollYPix, dragSteps); + AwTestTouchUtils.dragCompleteView(testContainerView, + 0, -targetScrollXPix, // these need to be negative as we're scrolling down. + 0, -targetScrollYPix, + dragSteps); for (int i = 1; i <= dragSteps; ++i) { onScrollToCallbackHelper.waitForCallback(scrollToCallCount, i); diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/util/AwTestTouchUtils.java b/android_webview/javatests/src/org/chromium/android_webview/test/util/AwTestTouchUtils.java new file mode 100644 index 0000000..79e257d --- /dev/null +++ b/android_webview/javatests/src/org/chromium/android_webview/test/util/AwTestTouchUtils.java @@ -0,0 +1,75 @@ +// Copyright 2013 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.android_webview.test.util; + +import android.app.Activity; +import android.os.SystemClock; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewConfiguration; + +/** + * A touch utility class that injects the events directly into the view. + * TODO(mkosiba): Merge with TestTouchUtils. + * + * This is similar to TestTouchUtils but injects the events directly into the view class rather + * than going through Instrumentation. This is so that we can avoid the INJECT_PERMISSIONS + * exception when a modal dialog pops over the test activity. + */ +public class AwTestTouchUtils { + private static void sendAction(View view, int action, long downTime, float x, float y) { + long eventTime = SystemClock.uptimeMillis(); + MotionEvent event = MotionEvent.obtain(downTime, eventTime, action, x, y, 0); + view.onTouchEvent(event); + } + + private static long dragStart(View view, float x, float y) { + long downTime = SystemClock.uptimeMillis(); + sendAction(view, MotionEvent.ACTION_DOWN, downTime, x, y); + return downTime; + } + + private static void dragTo(View view, float fromX, float toX, float fromY, + float toY, int stepCount, long downTime) { + float x = fromX; + float y = fromY; + float yStep = (toY - fromY) / stepCount; + float xStep = (toX - fromX) / stepCount; + for (int i = 0; i < stepCount; ++i) { + y += yStep; + x += xStep; + sendAction(view, MotionEvent.ACTION_MOVE, downTime, x, y); + } + } + + private static void dragEnd(View view, float x, float y, long downTime) { + sendAction(view, MotionEvent.ACTION_UP, downTime, x, y); + } + + /** + * Performs a drag between the given coordinates, specified relative to the given view. + * This is safe to call from the instrumentation thread and will invoke the drag + * asynchronously. + * + * @param view The view the coordinates are relative to. + * @param fromX The relative x-coordinate of the start point of the drag. + * @param toX The relative x-coordinate of the end point of the drag. + * @param fromY The relative y-coordinate of the start point of the drag. + * @param toY The relative y-coordinate of the end point of the drag. + * @param stepCount The total number of motion events that should be generated during the drag. + */ + public static void dragCompleteView(final View view, final int fromX, final int toX, + final int fromY, final int toY, final int stepCount) { + view.post(new Runnable() { + @Override + public void run() { + long downTime = dragStart(view, fromX, fromY); + dragTo(view, fromX, toX, fromY, toY, stepCount, downTime); + dragEnd(view, toX, toY, downTime); + } + }); + } +} + |