Commit 433ebba4 authored by boliu's avatar boliu Committed by Commit bot

Revert of Android: Make the spare renderer accessible to all Chrome tabs....

Revert of Android: Make the spare renderer accessible to all Chrome tabs. (patchset #7 id:120001 of https://codereview.chromium.org/2199393002/ )

Reason for revert:
New test WarmupManagerTest#testCreateAndTakeSpareRenderer failing on 3 different bots:
https://build.chromium.org/p/chromium.linux/builders/Android%20Tests%20%28dbg%29/builds/35784
https://build.chromium.org/p/chromium.android/builders/KitKat%20Tablet%20Tester/builds/5165
https://build.chromium.org/p/chromium.android/builders/Jelly%20Bean%20Tester/builds/5527

Original issue's description:
> Android: Make the spare renderer accessible to all Chrome tabs.
>
> In Custom Tabs, an external application can "warm up" Chrome. This
> creates and initializes a spare renderer, and has been found to be a
> significant optimization for loading performance.
>
> This patch moves the spare renderer logic out of Custom Tabs, and makes
> it accessible and useful for regular navigations in Chrome. Note that
> this patch doesn't add new call sites for the spare renderer creation.
>
> BUG=633964
>
> Committed: https://crrev.com/f7ce563033df1df90b314e4f727596c93c2b3d6d
> Cr-Commit-Position: refs/heads/master@{#412510}

TBR=yusufo@chromium.org,mariakhomenko@chromium.org,lizeb@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=633964

Review-Url: https://codereview.chromium.org/2254863002
Cr-Commit-Position: refs/heads/master@{#412565}
parent cf5bc93d
...@@ -15,13 +15,11 @@ import android.view.ViewStub; ...@@ -15,13 +15,11 @@ import android.view.ViewStub;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.SysUtils;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.content_public.browser.WebContents;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
...@@ -48,7 +46,6 @@ public final class WarmupManager { ...@@ -48,7 +46,6 @@ public final class WarmupManager {
private int mToolbarContainerId; private int mToolbarContainerId;
private ViewGroup mMainView; private ViewGroup mMainView;
private WebContents mSpareWebContents;
/** /**
* @return The singleton instance for the WarmupManager, creating one if necessary. * @return The singleton instance for the WarmupManager, creating one if necessary.
...@@ -195,50 +192,5 @@ public final class WarmupManager { ...@@ -195,50 +192,5 @@ public final class WarmupManager {
} }
} }
/**
* Creates and initializes a spare WebContents, to be used in a subsequent navigation.
*
* This creates a renderer that is suitable for any navigation. It can be picked up by any tab.
* Can be called multiple times, and must be called from the UI thread.
* Note that this is a no-op on low-end devices.
*/
public void createSpareWebContents() {
ThreadUtils.assertOnUiThread();
if (mSpareWebContents != null || SysUtils.isLowEndDevice()) return;
mSpareWebContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
}
/**
* Destroys the spare WebContents if there is one.
*/
public void destroySpareWebContents() {
ThreadUtils.assertOnUiThread();
if (mSpareWebContents == null) return;
mSpareWebContents.destroy();
mSpareWebContents = null;
}
/**
* Returns a spare WebContents or null, depending on the availability of one.
*
* The parameters are the same as for {@link WebContentsFactory#createWebContents()}.
*
* @return a WebContents, or null.
*/
public WebContents takeSpareWebContents(boolean incognito, boolean initiallyHidden) {
ThreadUtils.assertOnUiThread();
if (incognito || initiallyHidden) return null;
WebContents result = mSpareWebContents;
mSpareWebContents = null;
return result;
}
/**
* @return Whether a spare renderer is available.
*/
public boolean hasSpareWebContents() {
return mSpareWebContents != null;
}
private static native void nativePreconnectUrlAndSubresources(Profile profile, String url); private static native void nativePreconnectUrlAndSubresources(Profile profile, String url);
} }
...@@ -40,7 +40,6 @@ import org.chromium.chrome.browser.ChromeTabbedActivity; ...@@ -40,7 +40,6 @@ import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.IntentHandler; import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.IntentHandler.ExternalAppId; import org.chromium.chrome.browser.IntentHandler.ExternalAppId;
import org.chromium.chrome.browser.KeyboardShortcuts; import org.chromium.chrome.browser.KeyboardShortcuts;
import org.chromium.chrome.browser.WarmupManager;
import org.chromium.chrome.browser.WebContentsFactory; import org.chromium.chrome.browser.WebContentsFactory;
import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate;
import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument;
...@@ -96,12 +95,10 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -96,12 +95,10 @@ public class CustomTabActivity extends ChromeActivity {
private boolean mHasCreatedTabEarly; private boolean mHasCreatedTabEarly;
private boolean mIsInitialStart = true; private boolean mIsInitialStart = true;
// Whether there is any prerender associated with the session.
private boolean mHasPrerender; private boolean mHasPrerender;
private CustomTabObserver mTabObserver; private CustomTabObserver mTabObserver;
private String mPrerenderedUrl; private String mPrerenderedUrl;
// Whether a prerender is being used.
private boolean mHasPrerendered; private boolean mHasPrerendered;
private static class PageLoadMetricsObserver implements PageLoadMetrics.Observer { private static class PageLoadMetricsObserver implements PageLoadMetrics.Observer {
...@@ -255,8 +252,7 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -255,8 +252,7 @@ public class CustomTabActivity extends ChromeActivity {
@Override @Override
public boolean shouldAllocateChildConnection() { public boolean shouldAllocateChildConnection() {
return !mHasCreatedTabEarly && !mHasPrerender return !mHasCreatedTabEarly && !mHasPrerender;
&& !WarmupManager.getInstance().hasSpareWebContents();
} }
@Override @Override
...@@ -423,9 +419,7 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -423,9 +419,7 @@ public class CustomTabActivity extends ChromeActivity {
WebContents webContents = WebContents webContents =
customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl); customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl);
mHasPrerendered = webContents != null; mHasPrerendered = webContents != null;
if (!mHasPrerendered) { if (webContents == null) webContents = customTabsConnection.takeSpareWebContents();
webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
}
if (webContents == null) webContents = WebContentsFactory.createWebContents(false, false); if (webContents == null) webContents = WebContentsFactory.createWebContents(false, false);
tab.initialize(webContents, getTabContentManager(), tab.initialize(webContents, getTabContentManager(),
new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding()), false, new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding()), false,
......
...@@ -38,6 +38,7 @@ import org.chromium.chrome.R; ...@@ -38,6 +38,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeApplication; import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.IntentHandler; import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.WarmupManager; import org.chromium.chrome.browser.WarmupManager;
import org.chromium.chrome.browser.WebContentsFactory;
import org.chromium.chrome.browser.device.DeviceClassManager; import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer; import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
...@@ -105,6 +106,7 @@ public class CustomTabsConnection { ...@@ -105,6 +106,7 @@ public class CustomTabsConnection {
private final AtomicBoolean mWarmupHasBeenCalled = new AtomicBoolean(); private final AtomicBoolean mWarmupHasBeenCalled = new AtomicBoolean();
private final AtomicBoolean mWarmupHasBeenFinished = new AtomicBoolean(); private final AtomicBoolean mWarmupHasBeenFinished = new AtomicBoolean();
private ExternalPrerenderHandler mExternalPrerenderHandler; private ExternalPrerenderHandler mExternalPrerenderHandler;
private WebContents mSpareWebContents;
// TODO(lizeb): Remove once crbug.com/630303 is fixed. // TODO(lizeb): Remove once crbug.com/630303 is fixed.
private boolean mPageLoadMetricsEnabled; private boolean mPageLoadMetricsEnabled;
...@@ -220,7 +222,7 @@ public class CustomTabsConnection { ...@@ -220,7 +222,7 @@ public class CustomTabsConnection {
public void run() { public void run() {
if (!initialized) initializeBrowser(mApplication); if (!initialized) initializeBrowser(mApplication);
if (mayCreateSpareWebContents && mPrerender == null && !SysUtils.isLowEndDevice()) { if (mayCreateSpareWebContents && mPrerender == null && !SysUtils.isLowEndDevice()) {
WarmupManager.getInstance().createSpareWebContents(); createSpareWebContents();
} }
mWarmupHasBeenFinished.set(true); mWarmupHasBeenFinished.set(true);
} }
...@@ -228,6 +230,13 @@ public class CustomTabsConnection { ...@@ -228,6 +230,13 @@ public class CustomTabsConnection {
return true; return true;
} }
/** Creates a spare {@link WebContents}, if none exists. */
private void createSpareWebContents() {
ThreadUtils.assertOnUiThread();
if (mSpareWebContents != null) return;
mSpareWebContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
}
/** @return the URL converted to string, or null if it's invalid. */ /** @return the URL converted to string, or null if it's invalid. */
private static String checkAndConvertUri(Uri uri) { private static String checkAndConvertUri(Uri uri) {
if (uri == null) return null; if (uri == null) return null;
...@@ -262,7 +271,7 @@ public class CustomTabsConnection { ...@@ -262,7 +271,7 @@ public class CustomTabsConnection {
didStartPrerender = prerenderUrl(session, url, extras, uid); didStartPrerender = prerenderUrl(session, url, extras, uid);
} }
preconnectUrls(otherLikelyBundles); preconnectUrls(otherLikelyBundles);
if (!didStartPrerender) WarmupManager.getInstance().createSpareWebContents(); if (!didStartPrerender) createSpareWebContents();
} }
/** /**
...@@ -274,7 +283,7 @@ public class CustomTabsConnection { ...@@ -274,7 +283,7 @@ public class CustomTabsConnection {
boolean lowConfidenceMayLaunchUrl(List<Bundle> likelyBundles) { boolean lowConfidenceMayLaunchUrl(List<Bundle> likelyBundles) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
if (!preconnectUrls(likelyBundles)) return false; if (!preconnectUrls(likelyBundles)) return false;
WarmupManager.getInstance().createSpareWebContents(); createSpareWebContents();
return true; return true;
} }
...@@ -343,6 +352,20 @@ public class CustomTabsConnection { ...@@ -343,6 +352,20 @@ public class CustomTabsConnection {
return null; return null;
} }
/** @return a spare WebContents, or null. */
WebContents takeSpareWebContents() {
ThreadUtils.assertOnUiThread();
WebContents result = mSpareWebContents;
mSpareWebContents = null;
return result;
}
private void destroySpareWebContents() {
ThreadUtils.assertOnUiThread();
WebContents webContents = takeSpareWebContents();
if (webContents != null) webContents.destroy();
}
public boolean updateVisuals(final CustomTabsSessionToken session, Bundle bundle) { public boolean updateVisuals(final CustomTabsSessionToken session, Bundle bundle) {
final Bundle actionButtonBundle = IntentUtils.safeGetBundle(bundle, final Bundle actionButtonBundle = IntentUtils.safeGetBundle(bundle,
CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE); CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE);
...@@ -735,7 +758,7 @@ public class CustomTabsConnection { ...@@ -735,7 +758,7 @@ public class CustomTabsConnection {
if (throttle && !mClientManager.isPrerenderingAllowed(uid)) return false; if (throttle && !mClientManager.isPrerenderingAllowed(uid)) return false;
// A prerender will be requested. Time to destroy the spare WebContents. // A prerender will be requested. Time to destroy the spare WebContents.
WarmupManager.getInstance().destroySpareWebContents(); destroySpareWebContents();
Intent extrasIntent = new Intent(); Intent extrasIntent = new Intent();
if (extras != null) extrasIntent.putExtras(extras); if (extras != null) extrasIntent.putExtras(extras);
...@@ -763,6 +786,8 @@ public class CustomTabsConnection { ...@@ -763,6 +786,8 @@ public class CustomTabsConnection {
return true; return true;
} }
@VisibleForTesting @VisibleForTesting
void resetThrottling(Context context, int uid) { void resetThrottling(Context context, int uid) {
mClientManager.resetThrottling(uid); mClientManager.resetThrottling(uid);
......
...@@ -52,7 +52,6 @@ import org.chromium.chrome.browser.SwipeRefreshHandler; ...@@ -52,7 +52,6 @@ import org.chromium.chrome.browser.SwipeRefreshHandler;
import org.chromium.chrome.browser.TabState; import org.chromium.chrome.browser.TabState;
import org.chromium.chrome.browser.TabState.WebContentsState; import org.chromium.chrome.browser.TabState.WebContentsState;
import org.chromium.chrome.browser.UrlConstants; import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.WarmupManager;
import org.chromium.chrome.browser.WebContentsFactory; import org.chromium.chrome.browser.WebContentsFactory;
import org.chromium.chrome.browser.banners.AppBannerManager; import org.chromium.chrome.browser.banners.AppBannerManager;
import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
...@@ -1462,12 +1461,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, ...@@ -1462,12 +1461,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
boolean creatingWebContents = webContents == null; boolean creatingWebContents = webContents == null;
if (creatingWebContents) { if (creatingWebContents) {
webContents = WarmupManager.getInstance().takeSpareWebContents( webContents = WebContentsFactory.createWebContents(isIncognito(), initiallyHidden);
isIncognito(), initiallyHidden);
if (webContents == null) {
webContents =
WebContentsFactory.createWebContents(isIncognito(), initiallyHidden);
}
} }
ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webContents); ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webContents);
......
...@@ -1095,7 +1095,6 @@ chrome_test_java_sources = [ ...@@ -1095,7 +1095,6 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/TabsTest.java", "javatests/src/org/chromium/chrome/browser/TabsTest.java",
"javatests/src/org/chromium/chrome/browser/UrlSchemeTest.java", "javatests/src/org/chromium/chrome/browser/UrlSchemeTest.java",
"javatests/src/org/chromium/chrome/browser/UsbChooserDialogTest.java", "javatests/src/org/chromium/chrome/browser/UsbChooserDialogTest.java",
"javatests/src/org/chromium/chrome/browser/WarmupManagerTest.java",
"javatests/src/org/chromium/chrome/browser/accessibility/FontSizePrefsTest.java", "javatests/src/org/chromium/chrome/browser/accessibility/FontSizePrefsTest.java",
"javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java", "javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java",
"javatests/src/org/chromium/chrome/browser/autofill/AutofillKeyboardAccessoryTest.java", "javatests/src/org/chromium/chrome/browser/autofill/AutofillKeyboardAccessoryTest.java",
......
// Copyright 2016 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;
import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_LOW_END_DEVICE;
import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE;
import android.test.UiThreadTest;
import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Restriction;
import org.chromium.content.browser.test.NativeLibraryTestBase;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContentsObserver;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
/** Tests for {@link WarmupManager} */
public class WarmupManagerTest extends NativeLibraryTestBase {
private WarmupManager mWarmupManager;
@Override
protected void setUp() throws Exception {
super.setUp();
loadNativeLibraryAndInitBrowserProcess();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
mWarmupManager = WarmupManager.getInstance();
}
});
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
mWarmupManager.destroySpareWebContents();
}
});
}
@SmallTest
@Restriction(RESTRICTION_TYPE_LOW_END_DEVICE)
@UiThreadTest
public void testNoSpareRendererOnLowEndDevices() {
mWarmupManager.createSpareWebContents();
assertFalse(mWarmupManager.hasSpareWebContents());
}
@SmallTest
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testCreateAndTakeSpareRenderer() throws Exception {
final AtomicBoolean isRenderViewReady = new AtomicBoolean();
final AtomicReference<WebContents> webContentsReference = new AtomicReference<>();
final WebContentsObserver observer = new WebContentsObserver() {
@Override
public void renderViewReady() {
isRenderViewReady.set(true);
}
};
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
mWarmupManager.createSpareWebContents();
assertTrue(mWarmupManager.hasSpareWebContents());
WebContents webContents = mWarmupManager.takeSpareWebContents(false, false);
assertNotNull(webContents);
assertFalse(mWarmupManager.hasSpareWebContents());
// This is not racy because {@link WebContentsObserver} methods are called on the UI
// thread by posting a task. See {@link RenderViewHostImpl::PostRenderViewReady}.
webContents.addObserver(observer);
webContentsReference.set(webContents);
}
});
CriteriaHelper.pollUiThread(new Criteria("Spare renderer is not initialized") {
@Override
public boolean isSatisfied() {
return isRenderViewReady.get();
}
});
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
webContentsReference.get().destroy();
}
});
}
/** Tests that taking a spare WebContents makes it unavailable to subsequent callers. */
@SmallTest
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@UiThreadTest
public void testTakeSpareWebContents() throws Exception {
mWarmupManager.createSpareWebContents();
WebContents webContents = mWarmupManager.takeSpareWebContents(false, false);
assertNotNull(webContents);
assertFalse(mWarmupManager.hasSpareWebContents());
webContents.destroy();
}
@SmallTest
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@UiThreadTest
public void testTakeSpareWebContentsChecksArguments() throws Exception {
mWarmupManager.createSpareWebContents();
assertNull(mWarmupManager.takeSpareWebContents(true, false));
assertNull(mWarmupManager.takeSpareWebContents(false, true));
assertNull(mWarmupManager.takeSpareWebContents(true, true));
assertTrue(mWarmupManager.hasSpareWebContents());
}
}
...@@ -1061,13 +1061,9 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { ...@@ -1061,13 +1061,9 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
} catch (InterruptedException e) { } catch (InterruptedException e) {
fail(); fail();
} }
ThreadUtils.runOnUiThreadBlocking(new Runnable() { assertFalse(
@Override "Warmup() should have allocated a child connection",
public void run() { mActivity.shouldAllocateChildConnection());
assertFalse("Warmup() should have allocated a child connection",
mActivity.shouldAllocateChildConnection());
}
});
} }
/** /**
...@@ -1088,13 +1084,9 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { ...@@ -1088,13 +1084,9 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
} catch (InterruptedException e) { } catch (InterruptedException e) {
fail(); fail();
} }
ThreadUtils.runOnUiThreadBlocking(new Runnable() { assertTrue(
@Override "No spare renderer available, should allocate a child connection.",
public void run() { mActivity.shouldAllocateChildConnection());
assertTrue("No spare renderer available, should allocate a child connection.",
mActivity.shouldAllocateChildConnection());
}
});
} }
/** /**
...@@ -1114,13 +1106,9 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { ...@@ -1114,13 +1106,9 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
} catch (InterruptedException e) { } catch (InterruptedException e) {
fail(); fail();
} }
ThreadUtils.runOnUiThreadBlocking(new Runnable() { assertFalse(
@Override "Prerendering should have allocated a child connection",
public void run() { mActivity.shouldAllocateChildConnection());
assertFalse("Prerendering should have allocated a child connection",
mActivity.shouldAllocateChildConnection());
}
});
} }
/** /**
......
...@@ -23,7 +23,6 @@ import org.chromium.base.ThreadUtils; ...@@ -23,7 +23,6 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType; import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.WarmupManager;
import org.chromium.chrome.browser.preferences.PrefServiceBridge; import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
...@@ -58,12 +57,6 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase { ...@@ -58,12 +57,6 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
super.tearDown(); super.tearDown();
CustomTabsTestUtils.cleanupSessions(mCustomTabsConnection); CustomTabsTestUtils.cleanupSessions(mCustomTabsConnection);
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
WarmupManager.getInstance().destroySpareWebContents();
}
});
} }
/** /**
...@@ -109,12 +102,8 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase { ...@@ -109,12 +102,8 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
WarmupManager warmupManager = WarmupManager.getInstance(); assertNotNull(mCustomTabsConnection.takeSpareWebContents());
assertTrue(warmupManager.hasSpareWebContents()); assertNull(mCustomTabsConnection.takeSpareWebContents());
WebContents webContents = warmupManager.takeSpareWebContents(false, false);
assertNotNull(webContents);
assertFalse(warmupManager.hasSpareWebContents());
webContents.destroy();
} }
}); });
} }
...@@ -127,7 +116,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase { ...@@ -127,7 +116,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
@Override @Override
public void run() { public void run() {
assertSpareWebContentsNotNullAndDestroy(); assertSpareWebContentsNotNullAndDestroy();
assertFalse(WarmupManager.getInstance().hasSpareWebContents()); assertNull(mCustomTabsConnection.takeSpareWebContents());
} }
}); });
assertTrue(mCustomTabsConnection.warmup(0)); assertTrue(mCustomTabsConnection.warmup(0));
...@@ -146,7 +135,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase { ...@@ -146,7 +135,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
assertFalse(WarmupManager.getInstance().hasSpareWebContents()); assertNull(mCustomTabsConnection.takeSpareWebContents());
String referrer = String referrer =
mCustomTabsConnection.getReferrerForSession(token).getUrl(); mCustomTabsConnection.getReferrerForSession(token).getUrl();
WebContents webContents = WebContents webContents =
...@@ -295,7 +284,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase { ...@@ -295,7 +284,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
assertNull(WarmupManager.getInstance().takeSpareWebContents(false, false)); assertNull(mCustomTabsConnection.takeSpareWebContents());
String referrer = mCustomTabsConnection.getReferrerForSession(token).getUrl(); String referrer = mCustomTabsConnection.getReferrerForSession(token).getUrl();
assertNotNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer)); assertNotNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
} }
...@@ -309,7 +298,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase { ...@@ -309,7 +298,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
assertNull(WarmupManager.getInstance().takeSpareWebContents(false, false)); assertNull(mCustomTabsConnection.takeSpareWebContents());
} }
}); });
assertTrue(mCustomTabsConnection.mayLaunchUrl(token, null, null, null)); assertTrue(mCustomTabsConnection.mayLaunchUrl(token, null, null, null));
...@@ -324,7 +313,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase { ...@@ -324,7 +313,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
} }
private void assertSpareWebContentsNotNullAndDestroy() { private void assertSpareWebContentsNotNullAndDestroy() {
WebContents webContents = WarmupManager.getInstance().takeSpareWebContents(false, false); WebContents webContents = mCustomTabsConnection.takeSpareWebContents();
assertNotNull(webContents); assertNotNull(webContents);
webContents.destroy(); webContents.destroy();
} }
...@@ -528,7 +517,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase { ...@@ -528,7 +517,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
assertNull(WarmupManager.getInstance().takeSpareWebContents(false, false)); assertNull(mCustomTabsConnection.takeSpareWebContents());
String referrer = mCustomTabsConnection.getReferrerForSession(token).getUrl(); String referrer = mCustomTabsConnection.getReferrerForSession(token).getUrl();
WebContents prerender = mCustomTabsConnection.takePrerenderedUrl( WebContents prerender = mCustomTabsConnection.takePrerenderedUrl(
token, URL, referrer); token, URL, referrer);
......
...@@ -8,13 +8,11 @@ import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_LOW_END_D ...@@ -8,13 +8,11 @@ import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_LOW_END_D
import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE; import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE;
import android.os.Environment; import android.os.Environment;
import android.test.UiThreadTest;
import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.MediumTest;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.WarmupManager;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.test.ChromeTabbedActivityTestBase; import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
...@@ -105,26 +103,6 @@ public class ChromeTabCreatorTest extends ChromeTabbedActivityTestBase { ...@@ -105,26 +103,6 @@ public class ChromeTabCreatorTest extends ChromeTabbedActivityTestBase {
ChromeTabUtils.waitForTabPageLoaded(bgTab, mTestServer.getURL(TEST_PATH)); ChromeTabUtils.waitForTabPageLoaded(bgTab, mTestServer.getURL(TEST_PATH));
} }
/**
* Verify that the spare WebContents is used.
*
* Spare WebContents are not created on low-devices, so don't run the test.
*/
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@MediumTest
@Feature({"Browser"})
@UiThreadTest
public void testCreateNewTabTakesSpareWebContents()
throws ExecutionException, InterruptedException {
Tab currentTab = getActivity().getActivityTab();
WarmupManager.getInstance().createSpareWebContents();
assertTrue(WarmupManager.getInstance().hasSpareWebContents());
getActivity().getCurrentTabCreator().createNewTab(
new LoadUrlParams(mTestServer.getURL(TEST_PATH)), TabLaunchType.FROM_EXTERNAL_APP,
currentTab);
assertFalse(WarmupManager.getInstance().hasSpareWebContents());
}
/** /**
* @return the index of the given tab in the current tab model * @return the index of the given tab in the current tab model
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment