From 05c376f220bbffbc20ba6f5d8f1b42091467f12a Mon Sep 17 00:00:00 2001 From: dfalcantara Date: Thu, 11 Jun 2015 18:05:22 -0700 Subject: [PATCH] Start unifying document-mode and tabbed-mode tab creation * TabDelegate, which is used to create tabs in document-mode now subclasses the TabCreator class that tabbed-mode uses. * Being consolidating methods for creating tabs in the TabDelegate class. - Various methods for opening new Tabs under specific conditions (e.g. for devtools, or for opening an NTP) in document mode are cleaned up. - DocumentActivity's SingleTabModelSelector now defers to the DocumentTabModelSelector when opening new Tabs. - DocumentTabModelImpl uses generic methods in TabDelegate to create Tabs as similarly as possible to the TabModelImpl. In contrast to how TabModelImpl works with ChromeTabbedActivity, the DocumentTabModel has no specific Activity to grab TabCreators from. Instead, the DocumentTabModelSelector becomes a TabCreatorManager and passes out its TabCreators when necessary. * TabCreator.createFrozenTab now returns a Tab to line up with how document mode creates frozen tabs. * DocumentTabChromeWebContentsDelegateAndroidImpl no longer stores a mapping between the WebContents' URL and its native pointer. Instead, the URL is grabbed via JNI before the new Activity is launched. BUG=451453 Review URL: https://codereview.chromium.org/1176943002 Cr-Commit-Position: refs/heads/master@{#334098} --- .../chrome/browser/tabmodel/TabCreatorManager.java | 2 +- .../tabmodel/document/DocumentTabModelImpl.java | 43 ++++--- .../document/DocumentTabModelSelector.java | 26 +++-- .../browser/tabmodel/document/TabDelegate.java | 92 ++++++--------- .../chrome/browser/ChromeMobileApplication.java | 2 +- .../chrome/browser/document/DocumentActivity.java | 27 +---- .../browser/document/DocumentMigrationHelper.java | 13 ++- .../chrome/browser/document/DocumentTab.java | 27 +---- .../chrome/browser/document/TabDelegateImpl.java | 110 ++++++++++++++---- .../chrome/browser/tabmodel/ChromeTabCreator.java | 3 +- .../chrome/browser/document/DocumentModeTest.java | 129 ++++++++++++++++++--- .../browser/tabmodel/TabPersistentStoreTest.java | 3 +- .../document/DocumentTabModelImplTest.java | 10 +- .../document/OffTheRecordDocumentTabModelTest.java | 10 +- .../document/MockDocumentTabCreatorManager.java | 18 +++ .../browser/tabmodel/document/MockTabDelegate.java | 30 +++-- 16 files changed, 356 insertions(+), 189 deletions(-) rewrite chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java (71%) create mode 100644 chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/tabmodel/document/MockDocumentTabCreatorManager.java diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabCreatorManager.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabCreatorManager.java index c06de536b663..c0a544955af2 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabCreatorManager.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabCreatorManager.java @@ -34,7 +34,7 @@ public interface TabCreatorManager { * @param id The id to give the new tab. * @param index The index for where to place the tab. */ - void createFrozenTab(TabState state, int id, int index); + Tab createFrozenTab(TabState state, int id, int index); /** * Creates a tab around the native web contents pointer. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java index 052e55d8b82b..5a67c3768b88 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java @@ -25,7 +25,9 @@ import org.chromium.base.ThreadUtils; import org.chromium.base.VisibleForTesting; import org.chromium.chrome.browser.Tab; import org.chromium.chrome.browser.TabState; +import org.chromium.chrome.browser.document.DocumentMetricIds; import org.chromium.chrome.browser.document.IncognitoNotificationManager; +import org.chromium.chrome.browser.tabmodel.TabCreatorManager; import org.chromium.chrome.browser.tabmodel.TabList; import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModelJniBridge; @@ -34,6 +36,7 @@ import org.chromium.chrome.browser.tabmodel.TabModelUtils; import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelInfo.DocumentEntry; import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelInfo.DocumentList; import org.chromium.chrome.browser.util.MathUtils; +import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.WebContents; import java.io.File; @@ -117,7 +120,7 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT private final StorageDelegate mStorageDelegate; /** Delegate that provides Tabs to the DocumentTabModel. */ - private final TabDelegate mTabDelegate; + private final TabCreatorManager mTabCreatorManager; /** ID of a Tab whose state should be loaded immediately, if it belongs to this TabList. */ private final int mPrioritizedTabId; @@ -140,13 +143,13 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT /** * Construct a DocumentTabModelImpl. * @param activityDelegate Used to interact with DocumentActivities. - * @param tabDelegate Used to create/get Tabs. + * @param tabCreatorManager Used to create/get Tabs. * @param isIncognito Whether or not the TabList is managing incognito tabs. * @param prioritizedTabId ID of the tab to prioritize when loading. */ - public DocumentTabModelImpl(ActivityDelegate activityDelegate, TabDelegate tabDelegate, - boolean isIncognito, int prioritizedTabId) { - this(activityDelegate, new StorageDelegate(), tabDelegate, isIncognito, + public DocumentTabModelImpl(ActivityDelegate activityDelegate, + TabCreatorManager tabCreatorManager, boolean isIncognito, int prioritizedTabId) { + this(activityDelegate, new StorageDelegate(), tabCreatorManager, isIncognito, prioritizedTabId, ApplicationStatus.getApplicationContext()); } @@ -162,11 +165,12 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT * TODO(dfalcantara): Reduce visibility once DocumentMigrationHelper is upstreamed. */ public DocumentTabModelImpl(ActivityDelegate activityDelegate, StorageDelegate storageDelegate, - TabDelegate tabDelegate, boolean isIncognito, int prioritizedTabId, Context context) { + TabCreatorManager tabCreatorManager, boolean isIncognito, int prioritizedTabId, + Context context) { super(isIncognito); mActivityDelegate = activityDelegate; mStorageDelegate = storageDelegate; - mTabDelegate = tabDelegate; + mTabCreatorManager = tabCreatorManager; mPrioritizedTabId = prioritizedTabId; mContext = context; @@ -271,8 +275,8 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT int tabId = mTabIdList.get(index); List> activities = ApplicationStatus.getRunningActivities(); for (WeakReference activityRef : activities) { - Tab tab = mTabDelegate.getActivityTab( - isIncognito(), mActivityDelegate, activityRef.get()); + Tab tab = getTabDelegate(isIncognito()).getActivityTab( + mActivityDelegate, activityRef.get()); int documentId = tab == null ? Tab.INVALID_TAB_ID : tab.getId(); if (documentId == tabId) return tab; } @@ -289,7 +293,8 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT // Create a frozen Tab if we are capable, or if the previous Tab is just a placeholder. if (entry.getTabState() != null && isNativeInitialized() && (entry.placeholderTab == null || !entry.placeholderTab.isInitialized())) { - entry.placeholderTab = mTabDelegate.createFrozenTab(entry); + entry.placeholderTab = getTabDelegate(isIncognito()).createFrozenTab( + entry.getTabState(), entry.tabId, TabModel.INVALID_TAB_INDEX); entry.placeholderTab.initializeNative(); } @@ -345,14 +350,20 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT @Override protected Tab createTabWithWebContents( boolean isIncognito, WebContents webContents, int parentTabId) { - mTabDelegate.createTabWithWebContents(isIncognito, webContents, parentTabId); - return null; + // Tabs created along this pathway are currently only created via JNI, which includes + // session restore tabs. Differs from TabModelImpl because we explicitly open tabs in the + // foreground -- opening tabs in affiliated mode is disallowed by ChromeLauncherActivity + // when a WebContents has already been created. + return getTabDelegate(isIncognito).createTabWithWebContents( + webContents, parentTabId, TabLaunchType.FROM_LONGPRESS_FOREGROUND, + DocumentMetricIds.STARTED_BY_CHROME_HOME_RECENT_TABS); } @Override protected Tab createNewTabForDevTools(String url) { - mTabDelegate.createTabForDevTools(url); - return null; + // TODO(dfalcantara): Move upwards once we delete ChromeShellTabModel. + return getTabDelegate(false).createNewTab(new LoadUrlParams(url), + TabModel.TabLaunchType.FROM_MENU_OR_OVERVIEW, null); } @Override @@ -958,4 +969,8 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT } return false; } + + private TabDelegate getTabDelegate(boolean incognito) { + return (TabDelegate) mTabCreatorManager.getTabCreator(incognito); + } } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelSelector.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelSelector.java index a2ab80e9f67b..74f26e49e741 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelSelector.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelSelector.java @@ -23,6 +23,7 @@ import org.chromium.chrome.browser.UrlConstants; import org.chromium.chrome.browser.document.DocumentUtils; import org.chromium.chrome.browser.document.PendingDocumentData; import org.chromium.chrome.browser.tabmodel.OffTheRecordTabModel.OffTheRecordTabModelDelegate; +import org.chromium.chrome.browser.tabmodel.TabCreatorManager; import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.TabModelSelectorBase; @@ -35,7 +36,7 @@ import org.chromium.content_public.browser.LoadUrlParams; */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class DocumentTabModelSelector extends TabModelSelectorBase - implements ActivityStateListener { + implements ActivityStateListener, TabCreatorManager { public static final String PREF_PACKAGE = "com.google.android.apps.chrome.document"; public static final String PREF_IS_INCOGNITO_SELECTED = "is_incognito_selected"; @@ -52,7 +53,8 @@ public class DocumentTabModelSelector extends TabModelSelectorBase /** * Creates new Tabs. */ - private final TabDelegate mTabDelegate; + private final TabDelegate mRegularTabDelegate; + private final TabDelegate mIncognitoTabDelegate; /** * TabModel that keeps track of regular tabs. This is always not null. @@ -78,17 +80,19 @@ public class DocumentTabModelSelector extends TabModelSelectorBase sPrioritizedTabId = prioritizedTabId; } - public DocumentTabModelSelector(ActivityDelegate activityDelegate, TabDelegate tabDelegate) { + public DocumentTabModelSelector(ActivityDelegate activityDelegate, + TabDelegate regularTabDelegate, TabDelegate incognitoTabDelegate) { mActivityDelegate = activityDelegate; - mTabDelegate = tabDelegate; + mRegularTabDelegate = regularTabDelegate; + mIncognitoTabDelegate = incognitoTabDelegate; mRegularTabModel = new DocumentTabModelImpl( - activityDelegate, tabDelegate, false, sPrioritizedTabId); + activityDelegate, this, false, sPrioritizedTabId); mIncognitoTabModel = new OffTheRecordDocumentTabModel(new OffTheRecordTabModelDelegate() { @Override public TabModel createTabModel() { DocumentTabModel incognitoModel = new DocumentTabModelImpl( - mActivityDelegate, mTabDelegate, true, sPrioritizedTabId); + mActivityDelegate, DocumentTabModelSelector.this, true, sPrioritizedTabId); if (mRegularTabModel.isNativeInitialized()) { incognitoModel.initializeNative(); } @@ -113,6 +117,11 @@ public class DocumentTabModelSelector extends TabModelSelectorBase ApplicationStatus.registerStateListenerForAllActivities(this); } + @Override + public TabDelegate getTabCreator(boolean incognito) { + return incognito ? mIncognitoTabDelegate : mRegularTabDelegate; + } + private void initializeTabIdCounter() { int biggestId = getLargestTaskIdFromRecents(); biggestId = getMaxTabId(mRegularTabModel, biggestId); @@ -168,7 +177,10 @@ public class DocumentTabModelSelector extends TabModelSelectorBase Activity parentActivity = parent == null ? null : parent.getWindowAndroid().getActivity().get(); - mTabDelegate.createTabInForeground(parentActivity, incognito, loadUrlParams, params); + + TabDelegate delegate = getTabCreator(incognito); + Tab parentTab = delegate.getActivityTab(mActivityDelegate, parentActivity); + delegate.createNewTab(loadUrlParams, type, parentTab); return null; } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java dissimilarity index 71% index 1bc89862bf44..aae8306d29df 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java @@ -1,57 +1,35 @@ -// Copyright 2014 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.browser.tabmodel.document; - -import android.app.Activity; - -import org.chromium.chrome.browser.Tab; -import org.chromium.chrome.browser.document.PendingDocumentData; -import org.chromium.chrome.browser.tabmodel.document.DocumentTabModel.Entry; -import org.chromium.content_public.browser.LoadUrlParams; -import org.chromium.content_public.browser.WebContents; - -/** - * Provides Tabs to a DocumentTabModel. - * TODO(dfalcantara): Make this a TabCreatorManager.TabCreator subclass. - */ -public interface TabDelegate { - /** - * Returns the Tab for the given Activity. - * @param incognito Whether the Activity is supposed to hold an incognito Tab. - * @param delgate Sotres information about DocumentActivities. - * @param activity Activity to grab the Tab of. - * @return Tab for the DocumentActivity, if it is a valid DocumentActivity. Null otherwise. - */ - Tab getActivityTab(boolean incognito, ActivityDelegate delgate, Activity activity); - - /** - * Opens a new Tab in the foreground. - * Assumed to be triggered by a window.open(). - */ - void createTabInForeground(Activity parentActivity, boolean incognito, - LoadUrlParams loadUrlParams, PendingDocumentData documentParams); - - /** - * Creates a frozen Tab for the Entry. This Tab is not meant to be used or unfrozen -- it is - * only used as a placeholder until the real Tab can be created. - * @param entry Entry containing TabState. - * @return A frozen Tab. - */ - Tab createFrozenTab(Entry entry); - - /** - * Creates a new Activity for the pre-created WebContents. - * @param isIncognito Whether the Activity is supposed to hold an incognito Tab. - * @param webContents WebContents to use with the new Tab. - * @param parentTabId ID of the spawning Tab. - */ - void createTabWithWebContents(boolean isIncognito, WebContents webContents, int parentTabId); - - /** - * Creates a new Tab for a URL typed into DevTools. - * @param url URL to spawn a Tab for. - */ - void createTabForDevTools(String url); -} \ No newline at end of file +// Copyright 2014 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.browser.tabmodel.document; + +import android.app.Activity; + +import org.chromium.chrome.browser.Tab; +import org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator; +import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; +import org.chromium.content_public.browser.WebContents; + +/** + * Provides Tabs to a DocumentTabModel. + */ +public interface TabDelegate extends TabCreator { + /** + * Returns the Tab for the given Activity. + * @param delgate Stores information about DocumentActivities. + * @param activity Activity to grab the Tab of. + * @return Tab for the DocumentActivity, if it is a valid DocumentActivity. Null otherwise. + */ + Tab getActivityTab(ActivityDelegate activityDelegate, Activity activity); + + /** + * Creates a Tab to host the given WebContents. + * @param webContents WebContents that has been pre-created. + * @param parentId ID of the parent Tab. + * @param type Launch type for the Tab. + * @param startedBy See {@link DocumentMetricIds}. + */ + Tab createTabWithWebContents( + WebContents webContents, int parentId, TabLaunchType type, int startedBy); +} \ No newline at end of file diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/ChromeMobileApplication.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/ChromeMobileApplication.java index 0582f2238bf0..613005dca914 100644 --- a/chrome/android/java_staging/src/org/chromium/chrome/browser/ChromeMobileApplication.java +++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/ChromeMobileApplication.java @@ -583,7 +583,7 @@ public class ChromeMobileApplication extends ChromiumApplication { if (sDocumentTabModelSelector == null) { sDocumentTabModelSelector = new DocumentTabModelSelector( new ActivityDelegate(DocumentActivity.class, IncognitoDocumentActivity.class), - new TabDelegateImpl()); + new TabDelegateImpl(false), new TabDelegateImpl(true)); } return sDocumentTabModelSelector; } diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentActivity.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentActivity.java index 0651c6b0278e..0b352c49bb41 100644 --- a/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentActivity.java +++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentActivity.java @@ -5,7 +5,6 @@ package org.chromium.chrome.browser.document; import android.annotation.TargetApi; -import android.app.Activity; import android.content.Intent; import android.content.res.Configuration; import android.graphics.Bitmap; @@ -156,30 +155,14 @@ public class DocumentActivity extends CompositorChromeActivity { @Override public Tab openNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent, boolean incognito) { - PendingDocumentData params = null; - if (loadUrlParams.getPostData() != null - || loadUrlParams.getVerbatimHeaders() != null - || loadUrlParams.getReferrer() != null) { - params = new PendingDocumentData(); - params.postData = loadUrlParams.getPostData(); - params.extraHeaders = loadUrlParams.getVerbatimHeaders(); - params.referrer = loadUrlParams.getReferrer(); - } - - // Incognito never opens in the background. - int launchMode = type == TabLaunchType.FROM_LONGPRESS_BACKGROUND && !incognito - ? ChromeLauncherActivity.LAUNCH_MODE_AFFILIATED - : ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND; - Activity parentActivity = - parent == null ? null : parent.getWindowAndroid().getActivity().get(); - ChromeLauncherActivity.launchDocumentInstance(parentActivity, incognito, - launchMode, loadUrlParams.getUrl(), - DocumentMetricIds.STARTED_BY_WINDOW_OPEN, - loadUrlParams.getTransitionType(), false, params); - return null; + // Triggered via open in new tab context menu on NTP. + return ChromeMobileApplication.getDocumentTabModelSelector().openNewTab( + loadUrlParams, type, parent, incognito); } }; setTabModelSelector(selector); + setTabCreators(ChromeMobileApplication.getDocumentTabModelSelector().getTabCreator(false), + ChromeMobileApplication.getDocumentTabModelSelector().getTabCreator(true)); super.preInflationStartup(); diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentMigrationHelper.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentMigrationHelper.java index 07f2d62bfbb5..aa371b781522 100644 --- a/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentMigrationHelper.java +++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentMigrationHelper.java @@ -42,6 +42,7 @@ import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; import org.chromium.chrome.browser.ntp.NativePageFactory; import org.chromium.chrome.browser.preferences.ChromePreferenceManager; import org.chromium.chrome.browser.profiles.Profile; +import org.chromium.chrome.browser.tabmodel.TabCreatorManager; import org.chromium.chrome.browser.tabmodel.TabPersistentStore; import org.chromium.chrome.browser.tabmodel.TabPersistentStore.OnTabStateReadCallback; import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate; @@ -122,6 +123,16 @@ public class DocumentMigrationHelper { } } + private static class MigrationTabCreatorManager implements TabCreatorManager { + TabDelegateImpl mRegularTabCreator = new TabDelegateImpl(false); + TabDelegateImpl mIncognitoTabCreator = new TabDelegateImpl(true); + + @Override + public TabDelegateImpl getTabCreator(boolean incognito) { + return incognito ? mIncognitoTabCreator : mRegularTabCreator; + } + } + private static class MigrationTabModel extends DocumentTabModelImpl { private final SparseArray mTitleList; @@ -132,7 +143,7 @@ public class DocumentMigrationHelper { */ MigrationTabModel(MigrationActivityDelegate activityDelegate, StorageDelegate storageDelegate) { - super(activityDelegate, storageDelegate, new TabDelegateImpl(), false, + super(activityDelegate, storageDelegate, new MigrationTabCreatorManager(), false, Tab.INVALID_TAB_ID, ApplicationStatus.getApplicationContext()); startTabStateLoad(); mTitleList = new SparseArray(); diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentTab.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentTab.java index 2d33a7d7e2ad..05bb9cfbfe23 100644 --- a/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentTab.java +++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/document/DocumentTab.java @@ -6,7 +6,6 @@ package org.chromium.chrome.browser.document; import android.graphics.Bitmap; import android.graphics.Rect; -import android.util.Pair; import org.chromium.base.ObserverList.RewindableIterator; import org.chromium.base.VisibleForTesting; @@ -239,8 +238,6 @@ public class DocumentTab extends ChromeTab { */ public class DocumentTabChromeWebContentsDelegateAndroidImpl extends TabChromeWebContentsDelegateAndroidImpl { - private Pair mContentsToUrlMapping = null; - @Override public void webContentsCreated(WebContents sourceWebContents, long openerRenderFrameId, String frameName, String targetUrl, WebContents newWebContents) { @@ -248,35 +245,17 @@ public class DocumentTab extends ChromeTab { // WebContentsDelegateAndroidImpl. super.webContentsCreated(sourceWebContents, openerRenderFrameId, frameName, targetUrl, newWebContents); - - // Save the URL for the WebContents for use in addNewContents(). - assert mContentsToUrlMapping == null; - mContentsToUrlMapping = Pair.create(newWebContents, targetUrl); DocumentWebContentsDelegate.getInstance().attachDelegate(newWebContents); } @Override public boolean addNewContents(WebContents sourceWebContents, WebContents webContents, int disposition, Rect initialPosition, boolean userGesture) { - // TODO(dfalcantara): Set TabCreators on DocumentActivity, replace with super method. if (isClosing()) return false; + mActivity.getTabCreator(isIncognito()).createTabWithWebContents( + webContents, getId(), TabLaunchType.FROM_LONGPRESS_FOREGROUND); - // Grab the URL from the WebContents set in webContentsCreated(). - assert mContentsToUrlMapping != null && mContentsToUrlMapping.first == webContents; - String url = mContentsToUrlMapping.second; - mContentsToUrlMapping = null; - - if (url == null) url = ""; - PendingDocumentData data = new PendingDocumentData(); - data.webContents = webContents; - data.webContentsPaused = true; - ChromeLauncherActivity.launchDocumentInstance( - getWindowAndroid().getActivity().get(), isIncognito(), - ChromeLauncherActivity.LAUNCH_MODE_AFFILIATED, url, - DocumentMetricIds.STARTED_BY_WINDOW_OPEN, - PageTransition.AUTO_TOPLEVEL, - false, data); - + // Returns true because Tabs are created asynchronously. return true; } diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/document/TabDelegateImpl.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/document/TabDelegateImpl.java index a22b3133e614..2e18030e87f5 100644 --- a/chrome/android/java_staging/src/org/chromium/chrome/browser/document/TabDelegateImpl.java +++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/document/TabDelegateImpl.java @@ -6,11 +6,13 @@ package org.chromium.chrome.browser.document; import android.app.Activity; +import org.chromium.chrome.browser.ChromeMobileApplication; import org.chromium.chrome.browser.Tab; import org.chromium.chrome.browser.TabState; +import org.chromium.chrome.browser.UrlConstants; import org.chromium.chrome.browser.tab.ChromeTab; +import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate; -import org.chromium.chrome.browser.tabmodel.document.DocumentTabModel.Entry; import org.chromium.chrome.browser.tabmodel.document.TabDelegate; import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.WebContents; @@ -21,47 +23,107 @@ import org.chromium.ui.base.PageTransition; * TODO(dfalcantara): delete or refactor this after upstreaming. */ public class TabDelegateImpl implements TabDelegate { + private boolean mIsIncognito; + + /** + * Creates a TabDelegate. + * @param incognito Whether or not the TabDelegate handles the creation of incognito tabs. + */ + public TabDelegateImpl(boolean incognito) { + mIsIncognito = incognito; + } + @Override - public Tab getActivityTab( - boolean incognito, ActivityDelegate activityDelegate, Activity activity) { + public Tab getActivityTab(ActivityDelegate activityDelegate, Activity activity) { if (!(activity instanceof DocumentActivity) - || !activityDelegate.isValidActivity(incognito, activity.getIntent())) return null; + || !activityDelegate.isValidActivity(mIsIncognito, activity.getIntent())) { + return null; + } return ((DocumentActivity) activity).getActivityTab(); } + /** + * Creates a frozen Tab. This Tab is not meant to be used or unfrozen -- it is only used as a + * placeholder until the real Tab can be created. + * The index is ignored in DocumentMode because Android handles the ordering of Tabs. + */ @Override - public void createTabInForeground(Activity parentActivity, boolean incognito, - LoadUrlParams loadUrlParams, PendingDocumentData documentParams) { - ChromeLauncherActivity.launchDocumentInstance(parentActivity, incognito, - ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND, loadUrlParams.getUrl(), - DocumentMetricIds.STARTED_BY_WINDOW_OPEN, - loadUrlParams.getTransitionType(), false, documentParams); + public Tab createFrozenTab(TabState state, int id, int index) { + return ChromeTab.createFrozenTabFromState(id, null, state.isIncognito(), null, + Tab.INVALID_TAB_ID, state); } @Override - public Tab createFrozenTab(Entry entry) { - TabState state = entry.getTabState(); - assert state != null; - return ChromeTab.createFrozenTabFromState(entry.tabId, null, state.isIncognito(), null, - Tab.INVALID_TAB_ID, state); + public Tab createTabWithWebContents( + WebContents webContents, int parentId, TabLaunchType type) { + return createTabWithWebContents( + webContents, parentId, type, DocumentMetricIds.STARTED_BY_WINDOW_OPEN); } @Override - public void createTabWithWebContents( - boolean isIncognito, WebContents webContents, int parentTabId) { + public Tab createTabWithWebContents( + WebContents webContents, int parentId, TabLaunchType type, int startedBy) { + // Tabs can't be launched in affiliated mode when a webcontents exists. + assert type != TabLaunchType.FROM_LONGPRESS_BACKGROUND; + + // TODO(dfalcantara): Pipe information about paused WebContents from native. PendingDocumentData data = new PendingDocumentData(); data.webContents = webContents; - ChromeLauncherActivity.launchDocumentInstance( - null, isIncognito, ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND, null, - DocumentMetricIds.STARTED_BY_CHROME_HOME_RECENT_TABS, - PageTransition.RELOAD, false, data); + data.webContentsPaused = startedBy != DocumentMetricIds.STARTED_BY_CHROME_HOME_RECENT_TABS; + + String url = webContents.getUrl(); + if (url == null) url = ""; + + // Determine information about the parent Activity. + Tab parentTab = parentId == Tab.INVALID_TAB_ID + ? null : ChromeMobileApplication.getDocumentTabModelSelector().getTabById(parentId); + Activity activity = getActivityFromTab(parentTab); + + int pageTransition = startedBy == DocumentMetricIds.STARTED_BY_CHROME_HOME_RECENT_TABS + ? PageTransition.RELOAD : PageTransition.AUTO_TOPLEVEL; + ChromeLauncherActivity.launchDocumentInstance(activity, mIsIncognito, + ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND, url, startedBy, pageTransition, + false, data); + + return null; + } + + @Override + public Tab launchUrl(String url, TabLaunchType type) { + return createNewTab(new LoadUrlParams(url), type, null); + } + + @Override + public Tab launchNTP() { + return launchUrl(UrlConstants.NTP_URL, TabLaunchType.FROM_MENU_OR_OVERVIEW); } @Override - public void createTabForDevTools(String url) { + public Tab createNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent) { + PendingDocumentData params = null; + if (loadUrlParams.getPostData() != null + || loadUrlParams.getVerbatimHeaders() != null + || loadUrlParams.getReferrer() != null) { + params = new PendingDocumentData(); + params.postData = loadUrlParams.getPostData(); + params.extraHeaders = loadUrlParams.getVerbatimHeaders(); + params.referrer = loadUrlParams.getReferrer(); + } + + // TODO(dfalcantara): Is this really only triggered via NTP/Recent Tabs? + Activity parentActivity = getActivityFromTab(parent); + int launchMode = type == TabLaunchType.FROM_LONGPRESS_BACKGROUND && !mIsIncognito + ? ChromeLauncherActivity.LAUNCH_MODE_AFFILIATED + : ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND; ChromeLauncherActivity.launchDocumentInstance( - null, false, ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND, url, + parentActivity, mIsIncognito, launchMode, loadUrlParams.getUrl(), DocumentMetricIds.STARTED_BY_CHROME_HOME_RECENT_TABS, - PageTransition.RELOAD, false, null); + PageTransition.RELOAD, false, params); + return null; + } + + private Activity getActivityFromTab(Tab tab) { + return tab == null || tab.getWindowAndroid() == null + ? null : tab.getWindowAndroid().getActivity().get(); } } \ No newline at end of file diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/tabmodel/ChromeTabCreator.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/tabmodel/ChromeTabCreator.java index 80ca244d3600..b45a45a7b8a8 100644 --- a/chrome/android/java_staging/src/org/chromium/chrome/browser/tabmodel/ChromeTabCreator.java +++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/tabmodel/ChromeTabCreator.java @@ -261,7 +261,7 @@ public class ChromeTabCreator implements TabCreatorManager.TabCreator { } @Override - public void createFrozenTab(TabState state, int id, int index) { + public Tab createFrozenTab(TabState state, int id, int index) { ChromeTab tab = ChromeTab.createFrozenTabFromState( id, mActivity, state.isIncognito(), mNativeWindow, state.parentId, state); boolean selectTab = mOrderController.willOpenInForeground(TabLaunchType.FROM_RESTORE, @@ -269,6 +269,7 @@ public class ChromeTabCreator implements TabCreatorManager.TabCreator { tab.initialize(null, mTabContentManager, !selectTab); assert state.isIncognito() == mIncognito; mTabModel.addTab(tab, index, TabLaunchType.FROM_RESTORE); + return tab; } /** diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTest.java index 2c9741f8abdd..68d523b77c49 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTest.java @@ -51,6 +51,7 @@ import org.chromium.content.app.SandboxedProcessService; import org.chromium.content.browser.test.util.CallbackHelper; import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.CriteriaHelper; +import org.chromium.content.browser.test.util.DOMUtils; import org.chromium.content.browser.test.util.TouchCommon; import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.ui.base.PageTransition; @@ -69,6 +70,7 @@ import java.util.concurrent.Callable; @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) @DisableInTabbedMode public class DocumentModeTest extends MultiActivityTestBase { + private static final float FLOAT_EPSILON = 0.001f; private static final int ACTIVITY_START_TIMEOUT = 1000; private static final String URL_1 = "data:text/html;charset=utf-8,Page%201"; @@ -76,11 +78,48 @@ public class DocumentModeTest extends MultiActivityTestBase { private static final String URL_3 = "data:text/html;charset=utf-8,Page%203"; private static final String URL_4 = "data:text/html;charset=utf-8,Page%204"; - private static final String HTML_LINK = "" - + "" - + "
"; + private static final String LANDING_PAGE = UrlUtils.encodeHtmlDataUri( + "" + + " " + + " " + + " " + + " " + + " Second page" + + ""); + private static final float LANDING_PAGE_SCALE = 1.0f; + + // Defines one gigantic link spanning the whole page that creates a new window. + private static final String HREF_LINK = UrlUtils.encodeHtmlDataUri( + "" + + " " + + " " + + " " + + " " + + " " + + "
" + + " " + + ""); + + // Clicking the body triggers a window.open() call. + private static final String ONCLICK_LINK = UrlUtils.encodeHtmlDataUri( + "" + + " " + + " " + + " " + + " " + + " " + + "
" + + " " + + ""); private static final float HTML_SCALE = 0.5f; private boolean mInitializationCompleted; @@ -764,7 +803,7 @@ public class DocumentModeTest extends MultiActivityTestBase { */ @MediumTest public void testIncognitoOpensInForegroundViaLinkContextMenu() throws Exception { - launchLinkDocument(); + launchTestPageDocument(HREF_LINK); // Save the current tab info. final DocumentActivity regularActivity = @@ -818,11 +857,60 @@ public class DocumentModeTest extends MultiActivityTestBase { } /** + * Tests that tabs opened via window.open() load properly. + */ + @MediumTest + public void testWindowOpen() throws Exception { + launchTestPageDocument(ONCLICK_LINK); + + final DocumentActivity firstActivity = + (DocumentActivity) ApplicationStatus.getLastTrackedFocusedActivity(); + + // Save the current tab ID. + final DocumentTabModelSelector selector = + ChromeMobileApplication.getDocumentTabModelSelector(); + final TabModel tabModel = selector.getModel(false); + final int firstTabId = selector.getCurrentTabId(); + final int firstTabIndex = tabModel.index(); + + // Do a plain click to make the link open in a new foreground Document via a window.open(). + Runnable fgTrigger = new Runnable() { + @Override + public void run() { + try { + DOMUtils.clickNode(null, firstActivity.getCurrentContentViewCore(), "body"); + } catch (Exception e) { + + } + } + }; + + // The WebContents gets paused because of the window.open. Checking that the page scale + // factor is set correctly both checks that the page loaded and that the WebContents was + // when the new Activity starts. + ChromeActivity secondActivity = (ChromeActivity) ActivityUtils.waitForActivity( + getInstrumentation(), DocumentActivity.class, fgTrigger); + assertWaitForPageScaleFactorMatch(secondActivity, LANDING_PAGE_SCALE); + + assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { + @Override + public boolean isSatisfied() { + if (2 != tabModel.getCount()) return false; + if (firstTabIndex == tabModel.index()) return false; + if (firstTabId == selector.getCurrentTabId()) return false; + return true; + } + })); + MoreAsserts.assertNotEqual( + firstActivity, ApplicationStatus.getLastTrackedFocusedActivity()); + } + + /** * Tests that tab ID is properly set when tabs change. */ @MediumTest public void testLastTabIdUpdates() throws Exception { - launchLinkDocument(); + launchTestPageDocument(HREF_LINK); final DocumentActivity firstActivity = (DocumentActivity) ApplicationStatus.getLastTrackedFocusedActivity(); @@ -866,7 +954,7 @@ public class DocumentModeTest extends MultiActivityTestBase { @Restriction(RESTRICTION_TYPE_LOW_END_DEVICE) @MediumTest public void testNewTabLoadLowEnd() throws Exception { - launchLinkDocument(); + launchTestPageDocument(HREF_LINK); final CallbackHelper tabCreatedCallback = new CallbackHelper(); final CallbackHelper tabLoadStartedCallback = new CallbackHelper(); @@ -908,7 +996,7 @@ public class DocumentModeTest extends MultiActivityTestBase { @Restriction(RESTRICTION_TYPE_LOW_END_DEVICE) @MediumTest public void testNewTabRenderersLowEnd() throws Exception { - launchLinkDocument(); + launchTestPageDocument(HREF_LINK); // Ignore any side effects that the first background tab might produce. openLinkInBackgroundTab(); @@ -1010,19 +1098,25 @@ public class DocumentModeTest extends MultiActivityTestBase { } /** - * Launches DocumentActivity with the special URL suitable for openLinkInBackgroundTab() - * invocations. + * Launches DocumentActivity with a page that can be used to create a second page. */ - private void launchLinkDocument() throws Exception { - // Load HTML that defines one gigantic link spanning the whole page. - launchViaLaunchDocumentInstance(false, UrlUtils.encodeHtmlDataUri(HTML_LINK)); + private void launchTestPageDocument(String link) throws Exception { + launchViaLaunchDocumentInstance(false, link); final DocumentActivity activity = (DocumentActivity) ApplicationStatus.getLastTrackedFocusedActivity(); + assertWaitForPageScaleFactorMatch(activity, HTML_SCALE); + } + + // TODO(dfalcantara): Combine this one and ChromeActivityTestCaseBase's. + private void assertWaitForPageScaleFactorMatch( + final ChromeActivity activity, final float expectedScale) throws Exception { assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { @Override public boolean isSatisfied() { - return Float.compare( - activity.getCurrentContentViewCore().getScale(), HTML_SCALE) == 0; + if (activity.getCurrentContentViewCore() == null) return false; + + return Math.abs(activity.getCurrentContentViewCore().getScale() - expectedScale) + < FLOAT_EPSILON; } })); } @@ -1082,7 +1176,7 @@ public class DocumentModeTest extends MultiActivityTestBase { activity.getActivityTab().removeObserver(observer); // Select the "open in new tab" option to open a tab in the background. - ActivityUtils.waitForActivity(getInstrumentation(), + ChromeActivity newActivity = ActivityUtils.waitForActivity(getInstrumentation(), incognito ? IncognitoDocumentActivity.class : DocumentActivity.class, new Runnable() { @Override @@ -1097,6 +1191,7 @@ public class DocumentModeTest extends MultiActivityTestBase { } } ); + assertWaitForPageScaleFactorMatch(newActivity, LANDING_PAGE_SCALE); } /** diff --git a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/TabPersistentStoreTest.java b/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/TabPersistentStoreTest.java index c0f32611d444..5b61ea1518a1 100644 --- a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/TabPersistentStoreTest.java +++ b/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/TabPersistentStoreTest.java @@ -55,10 +55,11 @@ public class TabPersistentStoreTest extends ChromeShellTestBase { } @Override - public void createFrozenTab(TabState state, int id, int index) { + public Tab createFrozenTab(TabState state, int id, int index) { if (created.size() == 0) idOfFirstCreatedTab = id; created.put(id, state); notifyCalled(); + return null; } @Override diff --git a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImplTest.java b/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImplTest.java index a9d28b075caa..5e96d3c1d492 100644 --- a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImplTest.java +++ b/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImplTest.java @@ -18,8 +18,8 @@ import org.chromium.chrome.browser.Tab; import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModelUtils; import org.chromium.chrome.test.util.browser.tabmodel.document.MockActivityDelegate; +import org.chromium.chrome.test.util.browser.tabmodel.document.MockDocumentTabCreatorManager; import org.chromium.chrome.test.util.browser.tabmodel.document.MockStorageDelegate; -import org.chromium.chrome.test.util.browser.tabmodel.document.MockTabDelegate; import org.chromium.chrome.test.util.browser.tabmodel.document.TestInitializationObserver; import org.chromium.content.browser.test.NativeLibraryTestBase; @@ -78,7 +78,7 @@ public class DocumentTabModelImplTest extends NativeLibraryTestBase { private MockActivityDelegate mActivityDelegate; private MockStorageDelegate mStorageDelegate; - private MockTabDelegate mTabDelegate; + private MockDocumentTabCreatorManager mTabCreatorManager; private DocumentTabModel mTabModel; private AdvancedMockContext mContext; @@ -89,7 +89,7 @@ public class DocumentTabModelImplTest extends NativeLibraryTestBase { loadNativeLibraryAndInitBrowserProcess(); mActivityDelegate = new MockActivityDelegate(); - mTabDelegate = new MockTabDelegate(); + mTabCreatorManager = new MockDocumentTabCreatorManager(); mContext = new AdvancedMockContext(getInstrumentation().getTargetContext()); mStorageDelegate = new MockStorageDelegate(mContext.getCacheDir()); } @@ -112,8 +112,8 @@ public class DocumentTabModelImplTest extends NativeLibraryTestBase { ThreadUtils.runOnUiThreadBlocking(new Runnable() { @Override public void run() { - mTabModel = new DocumentTabModelImpl( - mActivityDelegate, mStorageDelegate, mTabDelegate, false, 1010, mContext); + mTabModel = new DocumentTabModelImpl(mActivityDelegate, mStorageDelegate, + mTabCreatorManager, false, 1010, mContext); mTabModel.startTabStateLoad(); } }); diff --git a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/document/OffTheRecordDocumentTabModelTest.java b/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/document/OffTheRecordDocumentTabModelTest.java index 82f91dce1fdb..9a21a3868ef9 100644 --- a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/document/OffTheRecordDocumentTabModelTest.java +++ b/chrome/android/javatests_shell/src/org/chromium/chrome/browser/tabmodel/document/OffTheRecordDocumentTabModelTest.java @@ -16,8 +16,8 @@ import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.tabmodel.OffTheRecordTabModel.OffTheRecordTabModelDelegate; import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.test.util.browser.tabmodel.document.MockActivityDelegate; +import org.chromium.chrome.test.util.browser.tabmodel.document.MockDocumentTabCreatorManager; import org.chromium.chrome.test.util.browser.tabmodel.document.MockStorageDelegate; -import org.chromium.chrome.test.util.browser.tabmodel.document.MockTabDelegate; import org.chromium.chrome.test.util.browser.tabmodel.document.TestInitializationObserver; import org.chromium.content.browser.test.NativeLibraryTestBase; @@ -31,7 +31,7 @@ import org.chromium.content.browser.test.NativeLibraryTestBase; public class OffTheRecordDocumentTabModelTest extends NativeLibraryTestBase { private MockActivityDelegate mActivityDelegate; private MockStorageDelegate mStorageDelegate; - private MockTabDelegate mTabDelegate; + private MockDocumentTabCreatorManager mTabCreatorManager; private OffTheRecordDocumentTabModel mTabModel; private Profile mProfile; @@ -48,7 +48,7 @@ public class OffTheRecordDocumentTabModelTest extends NativeLibraryTestBase { mContext = getInstrumentation().getTargetContext(); mStorageDelegate = new MockStorageDelegate(mContext.getCacheDir()); mActivityDelegate = new MockActivityDelegate(); - mTabDelegate = new MockTabDelegate(); + mTabCreatorManager = new MockDocumentTabCreatorManager(); } private void createTabModel() { @@ -57,8 +57,8 @@ public class OffTheRecordDocumentTabModelTest extends NativeLibraryTestBase { @Override public TabModel createTabModel() { - mModel = new DocumentTabModelImpl(mActivityDelegate, mStorageDelegate, mTabDelegate, - true, Tab.INVALID_TAB_ID, mContext); + mModel = new DocumentTabModelImpl(mActivityDelegate, mStorageDelegate, + mTabCreatorManager, true, Tab.INVALID_TAB_ID, mContext); return mModel; } diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/tabmodel/document/MockDocumentTabCreatorManager.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/tabmodel/document/MockDocumentTabCreatorManager.java new file mode 100644 index 000000000000..1e0fcc1c83f6 --- /dev/null +++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/tabmodel/document/MockDocumentTabCreatorManager.java @@ -0,0 +1,18 @@ +// Copyright 2015 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.util.browser.tabmodel.document; + +import org.chromium.chrome.browser.tabmodel.TabCreatorManager; + +/** Mocks out calls to the TabCreatorManager and TabCreators. */ +public class MockDocumentTabCreatorManager implements TabCreatorManager { + MockTabDelegate mRegularTabCreator = new MockTabDelegate(); + MockTabDelegate mIncognitoTabCreator = new MockTabDelegate(); + + @Override + public MockTabDelegate getTabCreator(boolean incognito) { + return incognito ? mIncognitoTabCreator : mRegularTabCreator; + } +} \ No newline at end of file diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/tabmodel/document/MockTabDelegate.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/tabmodel/document/MockTabDelegate.java index 00a132a83b57..c9a8b1966804 100644 --- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/tabmodel/document/MockTabDelegate.java +++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/tabmodel/document/MockTabDelegate.java @@ -7,9 +7,9 @@ package org.chromium.chrome.test.util.browser.tabmodel.document; import android.app.Activity; import org.chromium.chrome.browser.Tab; -import org.chromium.chrome.browser.document.PendingDocumentData; +import org.chromium.chrome.browser.TabState; +import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate; -import org.chromium.chrome.browser.tabmodel.document.DocumentTabModel.Entry; import org.chromium.chrome.browser.tabmodel.document.TabDelegate; import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.WebContents; @@ -19,26 +19,38 @@ import org.chromium.content_public.browser.WebContents; */ public class MockTabDelegate implements TabDelegate { @Override - public Tab getActivityTab(boolean incognito, ActivityDelegate delgate, Activity activity) { + public Tab getActivityTab(ActivityDelegate delgate, Activity activity) { return null; } @Override - public void createTabInForeground(Activity parentActivity, boolean incognito, - LoadUrlParams loadUrlParams, PendingDocumentData documentParams) { + public Tab createNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent) { + return null; + } + + @Override + public Tab createFrozenTab(TabState state, int id, int index) { + return null; } @Override - public Tab createFrozenTab(Entry entry) { + public Tab createTabWithWebContents(WebContents webContents, int parentId, TabLaunchType type) { return null; } @Override - public void createTabWithWebContents(boolean isIncognito, WebContents webContents, - int parentTabId) { + public Tab createTabWithWebContents( + WebContents webContents, int parentId, TabLaunchType type, int startedBy) { + return null; } @Override - public void createTabForDevTools(String url) { + public Tab launchUrl(String url, TabLaunchType type) { + return null; + } + + @Override + public Tab launchNTP() { + return null; } } \ No newline at end of file -- 2.11.4.GIT