Chromium Code Reviews| Index: content/public/android/javatests/src/org/chromium/content/browser/ContentViewLocationTest.java |
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewLocationTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewLocationTest.java |
| index 319e77df3430c6931acf88dc9613bda2c37f23f6..99407cff30d72039d42fef40729cd00f585e14d7 100644 |
| --- a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewLocationTest.java |
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewLocationTest.java |
| @@ -1,4 +1,4 @@ |
| -// Copyright 2013 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. |
| @@ -12,55 +12,67 @@ import org.chromium.content.browser.test.util.CriteriaHelper; |
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper; |
| import org.chromium.content_public.browser.LoadUrlParams; |
| -import org.chromium.content_shell_apk.ContentShellTestBase; |
| import org.chromium.device.geolocation.LocationProviderFactory; |
| import org.chromium.device.geolocation.MockLocationProvider; |
| import java.util.concurrent.Callable; |
| +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.After; |
| +import org.junit.Before; |
| +import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
| /** |
| * Test suite for ensureing that Geolocation interacts as expected |
| * with ContentView APIs - e.g. that it's started and stopped as the |
| * ContentView is hidden or shown. |
| */ |
| -public class ContentViewLocationTest extends ContentShellTestBase { |
| +@RunWith(BaseJUnit4ClassRunner.class) |
| +public class ContentViewLocationTest { |
| + |
| + @Rule |
| + public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule(); |
| private TestCallbackHelperContainer mTestCallbackHelperContainer; |
| private TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper mJavascriptHelper; |
| private MockLocationProvider mMockLocationProvider; |
| private void hideContentViewOnUiThread() { |
| - getInstrumentation().runOnMainSync(new Runnable() { |
| + InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { |
| @Override |
| public void run() { |
| - getContentViewCore().onHide(); |
| + mActivityTestRule.getContentViewCore().onHide(); |
| } |
| }); |
| } |
| private void showContentViewOnUiThread() { |
| - getInstrumentation().runOnMainSync(new Runnable() { |
| + InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { |
| @Override |
| public void run() { |
| - getContentViewCore().onShow(); |
| + mActivityTestRule.getContentViewCore().onShow(); |
| } |
| }); |
| } |
| private void pollForPositionCallback() throws Throwable { |
| - mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(), |
| + mJavascriptHelper.evaluateJavaScriptForTests(mActivityTestRule.getWebContents(), |
| "positionCount = 0"); |
| mJavascriptHelper.waitUntilHasValue(); |
| - assertEquals(0, Integer.parseInt(mJavascriptHelper.getJsonResultAndClear())); |
| + Assert.assertEquals(0, Integer.parseInt(mJavascriptHelper.getJsonResultAndClear())); |
| CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| @Override |
| public boolean isSatisfied() { |
| - mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(), "positionCount"); |
| + mJavascriptHelper.evaluateJavaScriptForTests(mActivityTestRule.getWebContents(), "positionCount"); |
| try { |
| mJavascriptHelper.waitUntilHasValue(); |
| } catch (Exception e) { |
| - fail(); |
| + Assert.fail(); |
| } |
| return Integer.parseInt(mJavascriptHelper.getJsonResultAndClear()) > 0; |
| } |
| @@ -68,7 +80,7 @@ public class ContentViewLocationTest extends ContentShellTestBase { |
| } |
| private void startGeolocationWatchPosition() throws Throwable { |
| - mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(), |
| + mJavascriptHelper.evaluateJavaScriptForTests(mActivityTestRule.getWebContents(), |
| "initiate_watchPosition();"); |
| mJavascriptHelper.waitUntilHasValue(); |
| } |
| @@ -82,31 +94,32 @@ public class ContentViewLocationTest extends ContentShellTestBase { |
| })); |
| } |
| - @Override |
| - protected void setUp() throws Exception { |
| - super.setUp(); |
| + @Before |
| + |
| + public void setUp() throws Exception { |
| mMockLocationProvider = new MockLocationProvider(); |
| LocationProviderFactory.setLocationProviderImpl(mMockLocationProvider); |
| try { |
| - startActivityWithTestUrl("content/test/data/android/geolocation.html"); |
| + mActivityTestRule.launchContentShellWithUrlSync("content/test/data/android/geolocation.html"); |
| } catch (Throwable t) { |
| - fail(); |
| + Assert.fail(); |
| } |
| - mTestCallbackHelperContainer = new TestCallbackHelperContainer(getContentViewCore()); |
| + mTestCallbackHelperContainer = new TestCallbackHelperContainer(mActivityTestRule.getContentViewCore()); |
| mJavascriptHelper = new OnEvaluateJavaScriptResultHelper(); |
| ensureGeolocationRunning(false); |
| } |
| - @Override |
| - protected void tearDown() throws Exception { |
| + @After |
| + |
|
jbudorick
2017/03/01 23:10:19
No bonus line here.
the real yoland
2017/03/08 23:35:31
Done
|
| + public void tearDown() throws Exception { |
| mMockLocationProvider.stopUpdates(); |
| - super.tearDown(); |
| } |
| + @Test |
| @MediumTest |
| @Feature({"Location"}) |
| public void testWatchHideShowStop() throws Throwable { |
| @@ -119,7 +132,7 @@ public class ContentViewLocationTest extends ContentShellTestBase { |
| hideContentViewOnUiThread(); |
| ensureGeolocationRunning(false); |
| - mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(), |
| + mJavascriptHelper.evaluateJavaScriptForTests(mActivityTestRule.getWebContents(), |
| "positionCount = 0"); |
| mJavascriptHelper.waitUntilHasValue(); |
| @@ -129,11 +142,12 @@ public class ContentViewLocationTest extends ContentShellTestBase { |
| ensureGeolocationRunning(true); |
| // Navigate away and ensure that geolocation stops. |
| - loadUrl(getContentViewCore().getWebContents().getNavigationController(), |
| + mActivityTestRule.loadUrl(mActivityTestRule.getContentViewCore().getWebContents().getNavigationController(), |
| mTestCallbackHelperContainer, new LoadUrlParams("about:blank")); |
| ensureGeolocationRunning(false); |
| } |
| + @Test |
| @MediumTest |
| @Feature({"Location"}) |
| public void testHideWatchResume() throws Throwable { |
| @@ -146,6 +160,7 @@ public class ContentViewLocationTest extends ContentShellTestBase { |
| ensureGeolocationRunning(true); |
| } |
| + @Test |
| @MediumTest |
| @Feature({"Location"}) |
| public void testWatchHideNewWatchShow() throws Throwable { |
| @@ -165,6 +180,7 @@ public class ContentViewLocationTest extends ContentShellTestBase { |
| ensureGeolocationRunning(true); |
| } |
| + @Test |
| @MediumTest |
| @Feature({"Location"}) |
| public void testHideWatchStopShow() throws Throwable { |
| @@ -172,7 +188,7 @@ public class ContentViewLocationTest extends ContentShellTestBase { |
| startGeolocationWatchPosition(); |
| ensureGeolocationRunning(false); |
| - loadUrl(getContentViewCore().getWebContents().getNavigationController(), |
| + mActivityTestRule.loadUrl(mActivityTestRule.getContentViewCore().getWebContents().getNavigationController(), |
| mTestCallbackHelperContainer, new LoadUrlParams("about:blank")); |
| showContentViewOnUiThread(); |
| ensureGeolocationRunning(false); |