Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3048)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java

Issue 1420913007: customtabs: Create a spare WebContents in warmup() on non low-end devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Naming. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java
index 95c1fdcf8d33458d9ab4f8fd7fb4323f540849ed..453b7ac85047c5c78c249456b9e7b502fd6fc709 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java
@@ -4,15 +4,22 @@
package org.chromium.chrome.browser.customtabs;
+import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE;
+
import android.app.Application;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
+import android.os.Bundle;
import android.os.Process;
import android.support.customtabs.ICustomTabsCallback;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.Restriction;
+import org.chromium.content_public.browser.WebContents;
+
/** Tests for CustomTabsConnection. */
public class CustomTabsConnectionTest extends InstrumentationTestCase {
private CustomTabsConnection mCustomTabsConnection;
@@ -68,6 +75,85 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
assertEquals(true, mCustomTabsConnection.warmup(0));
}
+ @SmallTest
+ @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
+ public void testCreateSpareRenderer() {
+ assertTrue(mCustomTabsConnection.warmup(0));
+ // On UI thread because:
+ // 1. takeSpareWebContents needs to be called from the UI thread.
+ // 2. warmup() is non-blocking and posts tasks to the UI thread, it ensures proper ordering.
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ assertNotNull(mCustomTabsConnection.takeSpareWebContents());
+ assertNull(mCustomTabsConnection.takeSpareWebContents());
+ }
+ });
+ }
+
+ @SmallTest
+ @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
+ public void testCreateSpareRendererCanBeRecreated() {
+ assertTrue(mCustomTabsConnection.warmup(0));
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ assertSpareWebContentsNotNullAndDestroy();
+ assertNull(mCustomTabsConnection.takeSpareWebContents());
+ }
+ });
+ assertTrue(mCustomTabsConnection.warmup(0));
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ assertSpareWebContentsNotNullAndDestroy();
+ }
+ });
+ }
+
+ @SmallTest
+ @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
+ public void testPrerenderDestroysSpareRenderer() {
+ final ICustomTabsCallback cb = assertWarmupAndMayLaunchUrl(null, URL, true);
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ assertNull(mCustomTabsConnection.takeSpareWebContents());
+ String referrer =
+ mCustomTabsConnection.getReferrerForSession(cb.asBinder()).getUrl();
+ WebContents webContents =
+ mCustomTabsConnection.takePrerenderedUrl(cb.asBinder(), URL, referrer);
+ assertNotNull(webContents);
+ webContents.destroy();
+ }
+ });
+ }
+
+ @SmallTest
+ @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
+ public void testMayLaunchUrlKeepsSpareRendererWithoutPrerendering() {
+ assertTrue(mCustomTabsConnection.warmup(0));
+ final ICustomTabsCallback cb = new CustomTabsTestUtils.DummyCallback();
+ assertTrue(mCustomTabsConnection.newSession(cb));
+
+ Bundle extras = new Bundle();
+ extras.putBoolean(CustomTabsConnection.NO_PRERENDERING_KEY, true);
+ assertTrue(mCustomTabsConnection.mayLaunchUrl(cb, Uri.parse(URL), extras, null));
+
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ assertSpareWebContentsNotNullAndDestroy();
+ }
+ });
+ }
+
+ private void assertSpareWebContentsNotNullAndDestroy() {
+ WebContents webContents = mCustomTabsConnection.takeSpareWebContents();
+ assertNotNull(webContents);
+ webContents.destroy();
+ }
+
/**
* Calls warmup() and mayLaunchUrl(), checks for the expected result
* (success or failure) and returns the result code.
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698