| Index: chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeTabbedActivityTestBase.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/ChromeTabbedActivityTestBase.java
|
| index 3fb042749aa0316c4a1428d51cb13909458d9e4b..e6d223e1de1025dd17615ee1cc544efb40a85f4d 100644
|
| --- a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeTabbedActivityTestBase.java
|
| +++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeTabbedActivityTestBase.java
|
| @@ -4,31 +4,23 @@
|
|
|
| package org.chromium.chrome.test;
|
|
|
| -import android.text.TextUtils;
|
| import android.view.View;
|
|
|
| -import org.chromium.base.test.util.CallbackHelper;
|
| import org.chromium.chrome.browser.ChromeTabbedActivity;
|
| -import org.chromium.chrome.browser.tab.EmptyTabObserver;
|
| -import org.chromium.chrome.browser.tab.Tab;
|
| -import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
|
| -import org.chromium.chrome.browser.tabmodel.TabModel;
|
| -import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
|
| -import org.chromium.chrome.browser.tabmodel.TabModelUtils;
|
| -import org.chromium.content.browser.test.util.TestTouchUtils;
|
| -
|
| -import java.util.concurrent.TimeoutException;
|
| +import org.chromium.chrome.test.ChromeTabbedActivityTestCommon.ChromeTabbedActivityTestCommonCallback;
|
|
|
| /**
|
| * 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";
|
| +public abstract class ChromeTabbedActivityTestBase
|
| + extends ChromeActivityTestCaseBase<ChromeTabbedActivity>
|
| + implements ChromeTabbedActivityTestCommonCallback {
|
| + private ChromeTabbedActivityTestCommon mTestCommon;
|
|
|
| public ChromeTabbedActivityTestBase() {
|
| super(ChromeTabbedActivity.class);
|
| + mTestCommon = new ChromeTabbedActivityTestCommon(this);
|
| }
|
|
|
| /**
|
| @@ -38,52 +30,13 @@ public abstract class ChromeTabbedActivityTestBase extends
|
| * @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 {
|
| - 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() {
|
| - @Override
|
| - public void run() {
|
| - Tab currentTab = getActivity().getCurrentTabCreator().launchUrl(
|
| - url, TabLaunchType.FROM_LINK);
|
| - final CallbackHelper pageLoadCallback = new CallbackHelper();
|
| - pageLoadedCallbacks[index] = pageLoadCallback;
|
| - currentTab.addObserver(new EmptyTabObserver() {
|
| - @Override
|
| - public void onPageLoadFinished(Tab tab) {
|
| - pageLoadCallback.notifyCalled();
|
| - tab.removeObserver(this);
|
| - }
|
| - });
|
| - tabIds[index] = currentTab.getId();
|
| - }
|
| - });
|
| - }
|
| - // 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 Tab tab = TabModelUtils.getTabById(tabModel, tabIds[i]);
|
| - getInstrumentation().runOnMainSync(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - TabModelUtils.setIndex(tabModel, tabModel.indexOf(tab));
|
| - }
|
| - });
|
| - try {
|
| - pageLoadedCallbacks[i].waitForCallback(0);
|
| - } catch (TimeoutException e) {
|
| - fail("PAGE_LOAD_FINISHED was not received for tabId=" + tabIds[i]);
|
| - }
|
| - }
|
| + public void loadUrlInManyNewTabs(String url, int numTabs) throws InterruptedException {
|
| + mTestCommon.loadUrlInManyNewTabs(url, numTabs);
|
| }
|
|
|
| /**
|
| * 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.
|
| + * asserts that a new tab is opened and is incognito if 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.
|
| @@ -91,32 +44,7 @@ public abstract class ChromeTabbedActivityTestBase extends
|
| */
|
| protected 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);
|
| - tabModel.addObserver(new EmptyTabModelObserver() {
|
| - @Override
|
| - public void didAddTab(Tab tab, TabLaunchType type) {
|
| - if (TextUtils.equals(expectedUrl, tab.getUrl())) {
|
| - createdCallback.notifyCalled();
|
| - tabModel.removeObserver(this);
|
| - }
|
| - }
|
| - });
|
| -
|
| - TestTouchUtils.longClickView(getInstrumentation(), view);
|
| - assertTrue(getInstrumentation().invokeContextMenuAction(getActivity(),
|
| - contextMenuItemId, 0));
|
| -
|
| - try {
|
| - createdCallback.waitForCallback(0);
|
| - } catch (TimeoutException e) {
|
| - fail("Never received tab creation event");
|
| - }
|
| -
|
| - if (expectIncognito) {
|
| - assertTrue(getActivity().getTabModelSelector().isIncognitoSelected());
|
| - } else {
|
| - assertFalse(getActivity().getTabModelSelector().isIncognitoSelected());
|
| - }
|
| + mTestCommon.invokeContextMenuAndOpenInANewTab(
|
| + view, contextMenuItemId, expectIncognito, expectedUrl);
|
| }
|
| }
|
|
|