| Index: chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeTabbedActivityTestCommon.java
|
| diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeTabbedActivityTestBase.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeTabbedActivityTestCommon.java
|
| similarity index 57%
|
| copy from chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeTabbedActivityTestBase.java
|
| copy to chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeTabbedActivityTestCommon.java
|
| index 3fb042749aa0316c4a1428d51cb13909458d9e4b..eaf09b64004d5819c0dfe0cb9e22551d850b8ce6 100644
|
| --- a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeTabbedActivityTestBase.java
|
| +++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeTabbedActivityTestCommon.java
|
| @@ -1,12 +1,15 @@
|
| -// Copyright 2015 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.
|
|
|
| package org.chromium.chrome.test;
|
|
|
| +import android.app.Instrumentation;
|
| import android.text.TextUtils;
|
| import android.view.View;
|
|
|
| +import org.junit.Assert;
|
| +
|
| import org.chromium.base.test.util.CallbackHelper;
|
| import org.chromium.chrome.browser.ChromeTabbedActivity;
|
| import org.chromium.chrome.browser.tab.EmptyTabObserver;
|
| @@ -19,35 +22,23 @@ import org.chromium.content.browser.test.util.TestTouchUtils;
|
|
|
| import java.util.concurrent.TimeoutException;
|
|
|
| -/**
|
| - * The base class of the ChromeTabbedActivity specific tests. It provides the common methods
|
| - * to access the ChromeTabbedActivity UI.
|
| - */
|
| -public abstract class ChromeTabbedActivityTestBase extends
|
| - ChromeActivityTestCaseBase<ChromeTabbedActivity> {
|
| - private static final String TAG = "ChromeTabbedActivityTestBase";
|
| +// TODO(yolandyan): Remove this class once all tests have been migrated to JUnit4.
|
| +final class ChromeTabbedActivityTestCommon {
|
| + private final ChromeTabbedActivityTestCommonCallback mCallback;
|
|
|
| - public ChromeTabbedActivityTestBase() {
|
| - super(ChromeTabbedActivity.class);
|
| + ChromeTabbedActivityTestCommon(ChromeTabbedActivityTestCommonCallback callback) {
|
| + mCallback = callback;
|
| }
|
|
|
| - /**
|
| - * Load a url in multiple new tabs in parallel. Each {@link Tab} will pretend to be
|
| - * created from a link.
|
| - *
|
| - * @param url The url of the page to load.
|
| - * @param numTabs The number of tabs to open.
|
| - */
|
| - public void loadUrlInManyNewTabs(final String url, final int numTabs)
|
| - throws InterruptedException {
|
| + void loadUrlInManyNewTabs(final String url, final int numTabs) throws InterruptedException {
|
| final CallbackHelper[] pageLoadedCallbacks = new CallbackHelper[numTabs];
|
| final int[] tabIds = new int[numTabs];
|
| for (int i = 0; i < numTabs; ++i) {
|
| final int index = i;
|
| - getInstrumentation().runOnMainSync(new Runnable() {
|
| + mCallback.getInstrumentation().runOnMainSync(new Runnable() {
|
| @Override
|
| public void run() {
|
| - Tab currentTab = getActivity().getCurrentTabCreator().launchUrl(
|
| + Tab currentTab = mCallback.getActivity().getCurrentTabCreator().launchUrl(
|
| url, TabLaunchType.FROM_LINK);
|
| final CallbackHelper pageLoadCallback = new CallbackHelper();
|
| pageLoadedCallbacks[index] = pageLoadCallback;
|
| @@ -65,9 +56,9 @@ public abstract class ChromeTabbedActivityTestBase extends
|
| // When opening many tabs some may be frozen due to memory pressure and won't send
|
| // PAGE_LOAD_FINISHED events. Iterate over the newly opened tabs and wait for each to load.
|
| for (int i = 0; i < numTabs; ++i) {
|
| - final TabModel tabModel = getActivity().getCurrentTabModel();
|
| + final TabModel tabModel = mCallback.getActivity().getCurrentTabModel();
|
| final Tab tab = TabModelUtils.getTabById(tabModel, tabIds[i]);
|
| - getInstrumentation().runOnMainSync(new Runnable() {
|
| + mCallback.getInstrumentation().runOnMainSync(new Runnable() {
|
| @Override
|
| public void run() {
|
| TabModelUtils.setIndex(tabModel, tabModel.indexOf(tab));
|
| @@ -76,23 +67,16 @@ public abstract class ChromeTabbedActivityTestBase extends
|
| try {
|
| pageLoadedCallbacks[i].waitForCallback(0);
|
| } catch (TimeoutException e) {
|
| - fail("PAGE_LOAD_FINISHED was not received for tabId=" + tabIds[i]);
|
| + Assert.fail("PAGE_LOAD_FINISHED was not received for tabId=" + tabIds[i]);
|
| }
|
| }
|
| }
|
|
|
| - /**
|
| - * Long presses the view, selects an item from the context menu, and
|
| - * asserts that a new tab is opened and is incognito iff expectIncognito is true.
|
| - * @param view The View to long press.
|
| - * @param contextMenuItemId The context menu item to select on the view.
|
| - * @param expectIncognito Whether the opened tab is expected to be incognito.
|
| - * @param expectedUrl The expected url for the new tab.
|
| - */
|
| - protected void invokeContextMenuAndOpenInANewTab(View view, int contextMenuItemId,
|
| + void invokeContextMenuAndOpenInANewTab(View view, int contextMenuItemId,
|
| boolean expectIncognito, final String expectedUrl) throws InterruptedException {
|
| final CallbackHelper createdCallback = new CallbackHelper();
|
| - final TabModel tabModel = getActivity().getTabModelSelector().getModel(expectIncognito);
|
| + final TabModel tabModel =
|
| + mCallback.getActivity().getTabModelSelector().getModel(expectIncognito);
|
| tabModel.addObserver(new EmptyTabModelObserver() {
|
| @Override
|
| public void didAddTab(Tab tab, TabLaunchType type) {
|
| @@ -103,20 +87,25 @@ public abstract class ChromeTabbedActivityTestBase extends
|
| }
|
| });
|
|
|
| - TestTouchUtils.longClickView(getInstrumentation(), view);
|
| - assertTrue(getInstrumentation().invokeContextMenuAction(getActivity(),
|
| - contextMenuItemId, 0));
|
| + TestTouchUtils.longClickView(mCallback.getInstrumentation(), view);
|
| + Assert.assertTrue(mCallback.getInstrumentation().invokeContextMenuAction(
|
| + mCallback.getActivity(), contextMenuItemId, 0));
|
|
|
| try {
|
| createdCallback.waitForCallback(0);
|
| } catch (TimeoutException e) {
|
| - fail("Never received tab creation event");
|
| + Assert.fail("Never received tab creation event");
|
| }
|
|
|
| if (expectIncognito) {
|
| - assertTrue(getActivity().getTabModelSelector().isIncognitoSelected());
|
| + Assert.assertTrue(mCallback.getActivity().getTabModelSelector().isIncognitoSelected());
|
| } else {
|
| - assertFalse(getActivity().getTabModelSelector().isIncognitoSelected());
|
| + Assert.assertFalse(mCallback.getActivity().getTabModelSelector().isIncognitoSelected());
|
| }
|
| }
|
| +
|
| + public interface ChromeTabbedActivityTestCommonCallback {
|
| + ChromeTabbedActivity getActivity();
|
| + Instrumentation getInstrumentation();
|
| + }
|
| }
|
|
|