| Index: chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java
|
| index 859228eefc1695ce4657121179f6515db225f1e9..39363a6e060e6e5ea4f6445bf55a4efd6f55f554 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/UrlOverridingTest.java
|
| @@ -12,35 +12,23 @@
|
| import android.content.IntentFilter;
|
| import android.net.Uri;
|
| import android.os.SystemClock;
|
| -import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.SmallTest;
|
| import android.text.TextUtils;
|
| import android.util.Base64;
|
|
|
| -import org.junit.After;
|
| -import org.junit.Assert;
|
| -import org.junit.Before;
|
| -import org.junit.Rule;
|
| -import org.junit.Test;
|
| -import org.junit.runner.RunWith;
|
| -
|
| import org.chromium.base.test.util.CallbackHelper;
|
| -import org.chromium.base.test.util.CommandLineFlags;
|
| import org.chromium.base.test.util.Restriction;
|
| import org.chromium.base.test.util.RetryOnFailure;
|
| import org.chromium.chrome.browser.ChromeActivity;
|
| -import org.chromium.chrome.browser.ChromeSwitches;
|
| import org.chromium.chrome.browser.document.ChromeLauncherActivity;
|
| import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.OverrideUrlLoadingResult;
|
| import org.chromium.chrome.browser.tab.EmptyTabObserver;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
|
| -import org.chromium.chrome.test.ChromeActivityTestRule;
|
| -import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| +import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| import org.chromium.chrome.test.util.ChromeRestriction;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
| -import org.chromium.content.browser.test.util.TouchCommon;
|
| import org.chromium.content_public.browser.LoadUrlParams;
|
| import org.chromium.net.test.EmbeddedTestServer;
|
| import org.chromium.ui.base.PageTransition;
|
| @@ -53,14 +41,7 @@
|
| /**
|
| * Test suite for verifying the behavior of various URL overriding actions.
|
| */
|
| -@RunWith(ChromeJUnit4ClassRunner.class)
|
| -@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| - ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| -public class UrlOverridingTest {
|
| - @Rule
|
| - public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| - new ChromeActivityTestRule<>(ChromeActivity.class);
|
| -
|
| +public class UrlOverridingTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| private static final String BASE_PATH = "/chrome/test/data/android/url_overriding/";
|
| private static final String NAVIGATION_FROM_TIMEOUT_PAGE =
|
| BASE_PATH + "navigation_from_timer.html";
|
| @@ -121,21 +102,25 @@
|
| private ActivityMonitor mActivityMonitor;
|
| private EmbeddedTestServer mTestServer;
|
|
|
| - @Before
|
| - public void setUp() throws Exception {
|
| - mActivityTestRule.startMainActivityOnBlankPage();
|
| + public UrlOverridingTest() {
|
| + super(ChromeActivity.class);
|
| + }
|
| +
|
| + @Override
|
| + protected void setUp() throws Exception {
|
| + super.setUp();
|
| IntentFilter filter = new IntentFilter(Intent.ACTION_VIEW);
|
| filter.addCategory(Intent.CATEGORY_BROWSABLE);
|
| filter.addDataScheme("market");
|
| - mActivityMonitor = InstrumentationRegistry.getInstrumentation().addMonitor(
|
| + mActivityMonitor = getInstrumentation().addMonitor(
|
| filter, new Instrumentation.ActivityResult(Activity.RESULT_OK, null), true);
|
| - mTestServer = EmbeddedTestServer.createAndStartServer(
|
| - InstrumentationRegistry.getInstrumentation().getContext());
|
| - }
|
| -
|
| - @After
|
| - public void tearDown() throws Exception {
|
| + mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
|
| + }
|
| +
|
| + @Override
|
| + protected void tearDown() throws Exception {
|
| mTestServer.stopAndDestroyServer();
|
| + super.tearDown();
|
| }
|
|
|
| private void loadUrlAndWaitForIntentUrl(final String url, boolean needClick,
|
| @@ -150,24 +135,23 @@
|
| final CallbackHelper failCallback = new CallbackHelper();
|
| final CallbackHelper newTabCallback = new CallbackHelper();
|
|
|
| - final Tab tab = mActivityTestRule.getActivity().getActivityTab();
|
| + final Tab tab = getActivity().getActivityTab();
|
| final Tab[] latestTabHolder = new Tab[1];
|
| latestTabHolder[0] = tab;
|
| tab.addObserver(new TestTabObserver(finishCallback, failCallback));
|
| if (expectedNewTabCount > 0) {
|
| - mActivityTestRule.getActivity().getTabModelSelector().addObserver(
|
| - new EmptyTabModelSelectorObserver() {
|
| - @Override
|
| - public void onNewTabCreated(Tab newTab) {
|
| - newTabCallback.notifyCalled();
|
| - newTab.addObserver(new TestTabObserver(finishCallback, failCallback));
|
| - latestTabHolder[0] = newTab;
|
| - }
|
| - });
|
| - }
|
| -
|
| - mActivityTestRule.getActivity().onUserInteraction();
|
| - InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
|
| + getActivity().getTabModelSelector().addObserver(new EmptyTabModelSelectorObserver() {
|
| + @Override
|
| + public void onNewTabCreated(Tab newTab) {
|
| + newTabCallback.notifyCalled();
|
| + newTab.addObserver(new TestTabObserver(finishCallback, failCallback));
|
| + latestTabHolder[0] = newTab;
|
| + }
|
| + });
|
| + }
|
| +
|
| + getActivity().onUserInteraction();
|
| + getInstrumentation().runOnMainSync(new Runnable() {
|
| @Override
|
| public void run() {
|
| tab.loadUrl(new LoadUrlParams(url, PageTransition.LINK));
|
| @@ -178,22 +162,22 @@
|
| try {
|
| finishCallback.waitForCallback(0, 1, 20, TimeUnit.SECONDS);
|
| } catch (TimeoutException ex) {
|
| - Assert.fail();
|
| + fail();
|
| return;
|
| }
|
| }
|
|
|
| SystemClock.sleep(1);
|
| - mActivityTestRule.getActivity().onUserInteraction();
|
| + getActivity().onUserInteraction();
|
| if (needClick) {
|
| - TouchCommon.singleClickView(tab.getView());
|
| + singleClickView(tab.getView());
|
| }
|
|
|
| if (failCallback.getCallCount() == 0) {
|
| try {
|
| failCallback.waitForCallback(0, 1, 20, TimeUnit.SECONDS);
|
| } catch (TimeoutException ex) {
|
| - Assert.fail("Haven't received navigation failure of intents.");
|
| + fail("Haven't received navigation failure of intents.");
|
| return;
|
| }
|
| }
|
| @@ -206,13 +190,13 @@
|
| try {
|
| finishCallback.waitForCallback(1, 1, 20, TimeUnit.SECONDS);
|
| } catch (TimeoutException ex) {
|
| - Assert.fail("Fallback URL is not loaded");
|
| + fail("Fallback URL is not loaded");
|
| return;
|
| }
|
| }
|
| }
|
|
|
| - Assert.assertEquals(expectedNewTabCount, newTabCallback.getCallCount());
|
| + assertEquals(expectedNewTabCount, newTabCallback.getCallCount());
|
| // For sub frames, the |loadFailCallback| run through different threads
|
| // from the ExternalNavigationHandler. As a result, there is no guarantee
|
| // when url override result would come.
|
| @@ -245,11 +229,10 @@
|
| return mActivityMonitor.getHits();
|
| }
|
| }));
|
| - Assert.assertEquals(1 + (hasFallbackUrl ? 1 : 0), finishCallback.getCallCount());
|
| - Assert.assertEquals(1, failCallback.getCallCount());
|
| - }
|
| -
|
| - @Test
|
| + assertEquals(1 + (hasFallbackUrl ? 1 : 0), finishCallback.getCallCount());
|
| + assertEquals(1, failCallback.getCallCount());
|
| + }
|
| +
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testNavigationFromTimer() throws InterruptedException {
|
| @@ -257,7 +240,6 @@
|
| mTestServer.getURL(NAVIGATION_FROM_TIMEOUT_PAGE), false, false, true);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testNavigationFromTimerInSubFrame() throws InterruptedException {
|
| @@ -266,7 +248,6 @@
|
| false, false);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testNavigationFromUserGesture() throws InterruptedException {
|
| @@ -274,7 +255,6 @@
|
| mTestServer.getURL(NAVIGATION_FROM_USER_GESTURE_PAGE), true, true, true);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| public void testNavigationFromUserGestureInSubFrame() throws InterruptedException {
|
| loadUrlAndWaitForIntentUrl(
|
| @@ -282,7 +262,6 @@
|
| true, false);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testNavigationFromXHRCallback() throws InterruptedException {
|
| @@ -290,7 +269,6 @@
|
| mTestServer.getURL(NAVIGATION_FROM_XHR_CALLBACK_PAGE), true, true, true);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testNavigationFromXHRCallbackInSubFrame() throws InterruptedException {
|
| @@ -299,7 +277,6 @@
|
| true, false);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testNavigationFromXHRCallbackAndShortTimeout() throws InterruptedException {
|
| @@ -308,7 +285,6 @@
|
| true, true, true);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testNavigationFromXHRCallbackAndLongTimeout() throws InterruptedException {
|
| @@ -317,7 +293,6 @@
|
| true, false, true);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testNavigationWithFallbackURL()
|
| @@ -330,7 +305,6 @@
|
| loadUrlAndWaitForIntentUrl(originalUrl, true, 0, false, fallbackUrl, true);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testNavigationWithFallbackURLInSubFrame()
|
| @@ -358,7 +332,6 @@
|
| loadUrlAndWaitForIntentUrl(originalUrl, true, false, false);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| @Restriction(ChromeRestriction.RESTRICTION_TYPE_TABLET)
|
| public void testOpenWindowFromUserGesture() throws InterruptedException {
|
| @@ -366,13 +339,12 @@
|
| true, 1, true, null, true);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testRedirectionFromIntent() {
|
| Intent intent = new Intent(Intent.ACTION_VIEW,
|
| Uri.parse(mTestServer.getURL(NAVIGATION_FROM_JAVA_REDIRECTION_PAGE)));
|
| - Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
| + Context targetContext = getInstrumentation().getTargetContext();
|
| intent.setClassName(targetContext, ChromeLauncherActivity.class.getName());
|
| intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
| targetContext.startActivity(intent);
|
| @@ -384,4 +356,9 @@
|
| }
|
| }));
|
| }
|
| +
|
| + @Override
|
| + public void startMainActivity() throws InterruptedException {
|
| + startMainActivityOnBlankPage();
|
| + }
|
| }
|
|
|