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

Side by Side 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, 1 month 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.customtabs; 5 package org.chromium.chrome.browser.customtabs;
6 6
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE;
8
7 import android.app.Application; 9 import android.app.Application;
8 import android.content.Context; 10 import android.content.Context;
9 import android.net.Uri; 11 import android.net.Uri;
10 import android.os.Build; 12 import android.os.Build;
13 import android.os.Bundle;
11 import android.os.Process; 14 import android.os.Process;
12 import android.support.customtabs.ICustomTabsCallback; 15 import android.support.customtabs.ICustomTabsCallback;
13 import android.test.InstrumentationTestCase; 16 import android.test.InstrumentationTestCase;
14 import android.test.suitebuilder.annotation.SmallTest; 17 import android.test.suitebuilder.annotation.SmallTest;
15 18
19 import org.chromium.base.ThreadUtils;
20 import org.chromium.base.test.util.Restriction;
21 import org.chromium.content_public.browser.WebContents;
22
16 /** Tests for CustomTabsConnection. */ 23 /** Tests for CustomTabsConnection. */
17 public class CustomTabsConnectionTest extends InstrumentationTestCase { 24 public class CustomTabsConnectionTest extends InstrumentationTestCase {
18 private CustomTabsConnection mCustomTabsConnection; 25 private CustomTabsConnection mCustomTabsConnection;
19 private static final String URL = "http://www.google.com"; 26 private static final String URL = "http://www.google.com";
20 private static final String URL2 = "https://www.android.com"; 27 private static final String URL2 = "https://www.android.com";
21 private static final String INVALID_SCHEME_URL = "intent://www.google.com"; 28 private static final String INVALID_SCHEME_URL = "intent://www.google.com";
22 29
23 private Context mContext; 30 private Context mContext;
24 31
25 @Override 32 @Override
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 /** 68 /**
62 * Tests that {@link CustomTabsConnection#warmup(long)} succeeds and can 69 * Tests that {@link CustomTabsConnection#warmup(long)} succeeds and can
63 * be issued multiple times. 70 * be issued multiple times.
64 */ 71 */
65 @SmallTest 72 @SmallTest
66 public void testCanWarmup() { 73 public void testCanWarmup() {
67 assertEquals(true, mCustomTabsConnection.warmup(0)); 74 assertEquals(true, mCustomTabsConnection.warmup(0));
68 assertEquals(true, mCustomTabsConnection.warmup(0)); 75 assertEquals(true, mCustomTabsConnection.warmup(0));
69 } 76 }
70 77
78 @SmallTest
79 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
80 public void testCreateSpareRenderer() {
81 assertTrue(mCustomTabsConnection.warmup(0));
82 // On UI thread because:
83 // 1. takeSpareWebContents needs to be called from the UI thread.
84 // 2. warmup() is non-blocking and posts tasks to the UI thread, it ensu res proper ordering.
85 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
86 @Override
87 public void run() {
88 assertNotNull(mCustomTabsConnection.takeSpareWebContents());
89 assertNull(mCustomTabsConnection.takeSpareWebContents());
90 }
91 });
92 }
93
94 @SmallTest
95 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
96 public void testCreateSpareRendererCanBeRecreated() {
97 assertTrue(mCustomTabsConnection.warmup(0));
98 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
99 @Override
100 public void run() {
101 assertSpareWebContentsNotNullAndDestroy();
102 assertNull(mCustomTabsConnection.takeSpareWebContents());
103 }
104 });
105 assertTrue(mCustomTabsConnection.warmup(0));
106 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
107 @Override
108 public void run() {
109 assertSpareWebContentsNotNullAndDestroy();
110 }
111 });
112 }
113
114 @SmallTest
115 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
116 public void testPrerenderDestroysSpareRenderer() {
117 final ICustomTabsCallback cb = assertWarmupAndMayLaunchUrl(null, URL, tr ue);
118 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
119 @Override
120 public void run() {
121 assertNull(mCustomTabsConnection.takeSpareWebContents());
122 String referrer =
123 mCustomTabsConnection.getReferrerForSession(cb.asBinder( )).getUrl();
124 WebContents webContents =
125 mCustomTabsConnection.takePrerenderedUrl(cb.asBinder(), URL, referrer);
126 assertNotNull(webContents);
127 webContents.destroy();
128 }
129 });
130 }
131
132 @SmallTest
133 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
134 public void testMayLaunchUrlKeepsSpareRendererWithoutPrerendering() {
135 assertTrue(mCustomTabsConnection.warmup(0));
136 final ICustomTabsCallback cb = new CustomTabsTestUtils.DummyCallback();
137 assertTrue(mCustomTabsConnection.newSession(cb));
138
139 Bundle extras = new Bundle();
140 extras.putBoolean(CustomTabsConnection.NO_PRERENDERING_KEY, true);
141 assertTrue(mCustomTabsConnection.mayLaunchUrl(cb, Uri.parse(URL), extras , null));
142
143 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
144 @Override
145 public void run() {
146 assertSpareWebContentsNotNullAndDestroy();
147 }
148 });
149 }
150
151 private void assertSpareWebContentsNotNullAndDestroy() {
152 WebContents webContents = mCustomTabsConnection.takeSpareWebContents();
153 assertNotNull(webContents);
154 webContents.destroy();
155 }
156
71 /** 157 /**
72 * Calls warmup() and mayLaunchUrl(), checks for the expected result 158 * Calls warmup() and mayLaunchUrl(), checks for the expected result
73 * (success or failure) and returns the result code. 159 * (success or failure) and returns the result code.
74 */ 160 */
75 private ICustomTabsCallback assertWarmupAndMayLaunchUrl( 161 private ICustomTabsCallback assertWarmupAndMayLaunchUrl(
76 ICustomTabsCallback cb, String url, boolean shouldSucceed) { 162 ICustomTabsCallback cb, String url, boolean shouldSucceed) {
77 mCustomTabsConnection.warmup(0); 163 mCustomTabsConnection.warmup(0);
78 if (cb == null) { 164 if (cb == null) {
79 cb = new CustomTabsTestUtils.DummyCallback(); 165 cb = new CustomTabsTestUtils.DummyCallback();
80 mCustomTabsConnection.newSession(cb); 166 mCustomTabsConnection.newSession(cb);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 ICustomTabsCallback cb = assertWarmupAndMayLaunchUrl(null, URL, true); 312 ICustomTabsCallback cb = assertWarmupAndMayLaunchUrl(null, URL, true);
227 mCustomTabsConnection.resetThrottling(mContext, Process.myUid()); 313 mCustomTabsConnection.resetThrottling(mContext, Process.myUid());
228 ICustomTabsCallback cb2 = assertWarmupAndMayLaunchUrl(null, URL, true); 314 ICustomTabsCallback cb2 = assertWarmupAndMayLaunchUrl(null, URL, true);
229 mCustomTabsConnection.resetThrottling(mContext, Process.myUid()); 315 mCustomTabsConnection.resetThrottling(mContext, Process.myUid());
230 for (int i = 0; i < 10; i++) { 316 for (int i = 0; i < 10; i++) {
231 mCustomTabsConnection.mayLaunchUrl(cb, Uri.parse(URL), null, null); 317 mCustomTabsConnection.mayLaunchUrl(cb, Uri.parse(URL), null, null);
232 } 318 }
233 assertWarmupAndMayLaunchUrl(cb2, URL, false); 319 assertWarmupAndMayLaunchUrl(cb2, URL, false);
234 } 320 }
235 } 321 }
OLDNEW
« 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