| Index: content/public/android/javatests/src/org/chromium/content/browser/ContentViewScrollingTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewScrollingTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewScrollingTest.java
|
| index 4f77f08f1c27bf515ac7e0cac99dcf1bbc7f834d..f2cbcbcc63ad3273a0c72d2c336b11000ff94765 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewScrollingTest.java
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewScrollingTest.java
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2017 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.
|
|
|
| @@ -18,11 +18,24 @@ import org.chromium.content.browser.ContentViewCore.InternalAccessDelegate;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content_shell_apk.ContentShellTestBase;
|
| +import org.chromium.content_shell_apk.ContentShellActivityTestRule.RerunWithUpdatedContainerView;
|
| +import org.junit.Rule;
|
| +import org.junit.Test;
|
| +import org.chromium.base.test.BaseJUnit4ClassRunner;
|
| +import org.junit.runner.RunWith;
|
| +import android.support.test.InstrumentationRegistry;
|
| +import org.junit.Assert;
|
| +import org.junit.Before;
|
| +import org.chromium.content_shell_apk.ContentShellActivityTestRule;
|
|
|
| /**
|
| * Tests that we can scroll and fling a ContentView running inside ContentShell.
|
| */
|
| -public class ContentViewScrollingTest extends ContentShellTestBase {
|
| +@RunWith(BaseJUnit4ClassRunner.class)
|
| +public class ContentViewScrollingTest {
|
| +
|
| + @Rule
|
| + public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule();
|
|
|
| private static final String LARGE_PAGE = UrlUtils.encodeHtmlDataUri("<html><head>"
|
| + "<meta name=\"viewport\" content=\"width=device-width, "
|
| @@ -95,46 +108,46 @@ public class ContentViewScrollingTest extends ContentShellTestBase {
|
| final int maxThreshold = 100;
|
|
|
| boolean xCorrect = hugLeft
|
| - ? getContentViewCore().getNativeScrollXForTest() < minThreshold
|
| - : getContentViewCore().getNativeScrollXForTest() > maxThreshold;
|
| + ? mActivityTestRule.getContentViewCore().getNativeScrollXForTest() < minThreshold
|
| + : mActivityTestRule.getContentViewCore().getNativeScrollXForTest() > maxThreshold;
|
| boolean yCorrect = hugTop
|
| - ? getContentViewCore().getNativeScrollYForTest() < minThreshold
|
| - : getContentViewCore().getNativeScrollYForTest() > maxThreshold;
|
| + ? mActivityTestRule.getContentViewCore().getNativeScrollYForTest() < minThreshold
|
| + : mActivityTestRule.getContentViewCore().getNativeScrollYForTest() > maxThreshold;
|
| return xCorrect && yCorrect;
|
| }
|
| });
|
| }
|
|
|
| private void fling(final int vx, final int vy) throws Throwable {
|
| - runTestOnUiThread(new Runnable() {
|
| + mActivityTestRule.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getContentViewCore().flingViewport(SystemClock.uptimeMillis(), vx, vy);
|
| + mActivityTestRule.getContentViewCore().flingViewport(SystemClock.uptimeMillis(), vx, vy);
|
| }
|
| });
|
| }
|
|
|
| private void scrollTo(final int x, final int y) throws Throwable {
|
| - runTestOnUiThread(new Runnable() {
|
| + mActivityTestRule.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getContentViewCore().getContainerView().scrollTo(x, y);
|
| + mActivityTestRule.getContentViewCore().getContainerView().scrollTo(x, y);
|
| }
|
| });
|
| }
|
|
|
| private void scrollBy(final int dx, final int dy) throws Throwable {
|
| - runTestOnUiThread(new Runnable() {
|
| + mActivityTestRule.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getContentViewCore().getContainerView().scrollBy(dx, dy);
|
| + mActivityTestRule.getContentViewCore().getContainerView().scrollBy(dx, dy);
|
| }
|
| });
|
| }
|
|
|
| private void scrollWithJoystick(final float deltaAxisX, final float deltaAxisY)
|
| throws Throwable {
|
| - runTestOnUiThread(new Runnable() {
|
| + mActivityTestRule.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| // Synthesize joystick motion event and send to ContentViewCore.
|
| @@ -143,23 +156,24 @@ public class ContentViewScrollingTest extends ContentShellTestBase {
|
| deltaAxisX, deltaAxisY, 0);
|
| leftJoystickMotionEvent.setSource(
|
| leftJoystickMotionEvent.getSource() | InputDevice.SOURCE_CLASS_JOYSTICK);
|
| - getContentViewCore().getContainerView().onGenericMotionEvent(
|
| + mActivityTestRule.getContentViewCore().getContainerView().onGenericMotionEvent(
|
| leftJoystickMotionEvent);
|
| }
|
| });
|
| }
|
|
|
| - @Override
|
| - protected void setUp() throws Exception {
|
| - super.setUp();
|
| + @Before
|
| +
|
| + public void setUp() throws Exception {
|
|
|
| - launchContentShellWithUrl(LARGE_PAGE);
|
| - waitForActiveShellToBeDoneLoading();
|
| + mActivityTestRule.launchContentShellWithUrl(LARGE_PAGE);
|
| + mActivityTestRule.waitForActiveShellToBeDoneLoading();
|
|
|
| - assertEquals(0, getContentViewCore().getNativeScrollXForTest());
|
| - assertEquals(0, getContentViewCore().getNativeScrollYForTest());
|
| + Assert.assertEquals(0, mActivityTestRule.getContentViewCore().getNativeScrollXForTest());
|
| + Assert.assertEquals(0, mActivityTestRule.getContentViewCore().getNativeScrollYForTest());
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Main"})
|
| @RetryOnFailure
|
| @@ -167,7 +181,7 @@ public class ContentViewScrollingTest extends ContentShellTestBase {
|
| // Scaling the initial velocity by the device scale factor ensures that
|
| // it's of sufficient magnitude for all displays densities.
|
| float deviceScaleFactor =
|
| - getInstrumentation().getTargetContext().getResources().getDisplayMetrics().density;
|
| + InstrumentationRegistry.getInstrumentation().getTargetContext().getResources().getDisplayMetrics().density;
|
| int velocity = (int) (1000 * deviceScaleFactor);
|
|
|
| // Vertical fling to lower-left.
|
| @@ -191,6 +205,7 @@ public class ContentViewScrollingTest extends ContentShellTestBase {
|
| assertWaitForScroll(false, false);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @RerunWithUpdatedContainerView
|
| @Feature({"Main"})
|
| @@ -217,6 +232,7 @@ public class ContentViewScrollingTest extends ContentShellTestBase {
|
| assertWaitForScroll(false, false);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @RerunWithUpdatedContainerView
|
| @Feature({"Main"})
|
| @@ -250,6 +266,7 @@ public class ContentViewScrollingTest extends ContentShellTestBase {
|
| assertWaitForScroll(false, false);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Main"})
|
| public void testJoystickScroll() throws Throwable {
|
| @@ -282,6 +299,7 @@ public class ContentViewScrollingTest extends ContentShellTestBase {
|
| * To ensure the device properly responds to bounds-exceeding scrolls, e.g., overscroll
|
| * effects are properly initialized.
|
| */
|
| + @Test
|
| @SmallTest
|
| @RerunWithUpdatedContainerView
|
| @Feature({"Main"})
|
| @@ -312,18 +330,19 @@ public class ContentViewScrollingTest extends ContentShellTestBase {
|
| * To ensure the AccessibilityEvent notifications (Eg:TYPE_VIEW_SCROLLED) are being sent
|
| * properly on scrolling a page.
|
| */
|
| + @Test
|
| @SmallTest
|
| @RerunWithUpdatedContainerView
|
| @Feature({"Main"})
|
| @RetryOnFailure
|
| public void testOnScrollChanged() throws Throwable {
|
| - final int scrollToX = getContentViewCore().getNativeScrollXForTest() + 2500;
|
| - final int scrollToY = getContentViewCore().getNativeScrollYForTest() + 2500;
|
| + final int scrollToX = mActivityTestRule.getContentViewCore().getNativeScrollXForTest() + 2500;
|
| + final int scrollToY = mActivityTestRule.getContentViewCore().getNativeScrollYForTest() + 2500;
|
| final TestInternalAccessDelegate containerViewInternals = new TestInternalAccessDelegate();
|
| - runTestOnUiThread(new Runnable() {
|
| + mActivityTestRule.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getContentViewCore().setContainerViewInternals(containerViewInternals);
|
| + mActivityTestRule.getContentViewCore().setContainerViewInternals(containerViewInternals);
|
| }
|
| });
|
| scrollTo(scrollToX, scrollToY);
|
|
|