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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/prerender/PrerenderServiceTest.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.prerender;
6
7 import android.test.suitebuilder.annotation.SmallTest;
8 import android.widget.EditText;
9
10 import com.google.android.apps.chrome.R;
11
12 import org.chromium.base.SysUtils;
13 import org.chromium.base.ThreadUtils;
14 import org.chromium.base.test.BaseActivityInstrumentationTestCase;
15 import org.chromium.base.test.util.CommandLineFlags;
16 import org.chromium.base.test.util.Feature;
17 import org.chromium.chrome.browser.ChromeActivity;
18 import org.chromium.chrome.browser.ChromeSwitches;
19 import org.chromium.chrome.browser.ChromeTabbedActivity;
20 import org.chromium.chrome.browser.WarmupManager;
21 import org.chromium.chrome.browser.document.DocumentActivity;
22 import org.chromium.chrome.browser.util.FeatureUtilities;
23 import org.chromium.chrome.test.util.ActivityUtils;
24 import org.chromium.chrome.test.util.TestHttpServerClient;
25 import org.chromium.content.browser.test.util.Criteria;
26 import org.chromium.content.browser.test.util.CriteriaHelper;
27 import org.chromium.content.browser.test.util.TouchCommon;
28
29 import java.util.concurrent.Callable;
30
31 /**
32 * A test suite for the ChromeBowserPrerenderService. This makes sure the servic e initializes the
33 * browser process and the UI and also can carry out prerendering related operat ions without causing
34 * any issues with Chrome launching from external intents afterwards.
35 */
36 @CommandLineFlags.Add(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
37 public class PrerenderServiceTest extends
38 BaseActivityInstrumentationTestCase<PrerenderAPITestActivity> {
39
40 public PrerenderServiceTest() {
41 super(PrerenderAPITestActivity.class);
42 }
43
44 private static final String GOOGLE_URL =
45 TestHttpServerClient.getUrl("chrome/test/data/android/prerender/goog le.html");
46 private static final String YOUTUBE_URL =
47 TestHttpServerClient.getUrl("chrome/test/data/android/prerender/yout ube.html");
48 private static final String REDIRECT_GOOGLE_URL =
49 TestHttpServerClient.getUrl("chrome/test/data/android/prerender/goog le_redirect.html");
50
51 @Override
52 protected void setUp() throws Exception {
53 super.setUp();
54 setActivityInitialTouchMode(true);
55 TestHttpServerClient.checkServerIsUp();
56 }
57
58 /**
59 * Test that binding and initializing the UI works and Chrome can be launche d
60 * without issues afterwards.
61 * @throws InterruptedException
62 */
63 @SmallTest
64 @Feature({"PrerenderService"})
65 public void testBindingAndInitializing() throws InterruptedException {
66 if (SysUtils.isLowEndDevice()) return;
67 ensureBindingAndInitializingUI();
68 loadChromeWithUrl(GOOGLE_URL);
69 }
70
71 /**
72 * Test that a prerender request can be sent via the service and Chrome can be launched
73 * from that same url without any issues. This doesn't test whether the url has actually
74 * finished prerendering.
75 * @throws InterruptedException
76 */
77 /*
78 * @Feature({"PrerenderService"})
79 * @SmallTest
80 */
81 public void testPrerenderingSameUrl() throws InterruptedException {
82 if (SysUtils.isLowEndDevice()) return;
83 ensureBindingAndInitializingUI();
84 ensurePrerendering(GOOGLE_URL);
85 loadChromeWithUrl(GOOGLE_URL);
86 }
87
88 /**
89 * Test that a prerender request can be sent via the service and Chrome can be launched
90 * from that different url without any issues. This doesn't test whether the url has actually
91 * finished prerendering.
92 * @throws InterruptedException
93 */
94 @SmallTest
95 @Feature({"PrerenderService"})
96 public void testPrerenderingDifferentUrl() throws InterruptedException {
97 if (SysUtils.isLowEndDevice()) return;
98 ensureBindingAndInitializingUI();
99 ensurePrerendering(GOOGLE_URL);
100 loadChromeWithUrl(YOUTUBE_URL);
101 }
102
103 /**
104 * Test that a prerender request with a redirect can be sent via the service and the final
105 * target url can still be used to fetch that prerendered page.
106 * @throws Exception
107 */
108 @SmallTest
109 @Feature({"PrerenderService"})
110 public void testPrerenderingRedirectUrl() throws Exception {
111 if (SysUtils.isLowEndDevice()) return;
112 ensureBindingAndInitializingUI();
113 ensurePrerendering(REDIRECT_GOOGLE_URL);
114 assertServiceHasPrerenderedUrl(GOOGLE_URL);
115 }
116
117 private void ensureBindingAndInitializingUI() {
118 assertNotNull(getActivity());
119 // TODO(yusufo): Add a check for native library loaded notification bein g received.
120
121 // TODO(dtrainor): Reenable this once ChromeNotificationCenter can handl e non-Activity
122 // contexts.
123 /*
124 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
125 @Override
126 public boolean isSatisfied() {
127 return WarmupManager.getInstance().hasBuiltViewHierarchy();
128 }
129 }));
130 */
131 }
132
133 private void ensurePrerendering(final String url) throws InterruptedExceptio n {
134 ensureBindingAndInitializingUI();
135 getInstrumentation().runOnMainSync(new Runnable() {
136 @Override
137 public void run() {
138 ((EditText) getActivity().findViewById(R.id.url_to_load)).setTex t(url);
139 }
140 });
141 TouchCommon.singleClickView(getActivity().findViewById(R.id.preload_butt on));
142 assertServiceHasPrerenderedUrl(url);
143 }
144
145 private void loadChromeWithUrl(final String url) throws InterruptedException {
146 assertNotNull(getActivity());
147 ThreadUtils.runOnUiThreadBlocking(new Runnable(){
148 public void run() {
149 ((EditText) getActivity().findViewById(R.id.url_to_load)).setTex t(url);
150 }
151 });
152 // TODO(dtrainor): Make this assertTrue once ChromeNotificationCenter ca n handle
153 // non-Activity contexts.
154 ThreadUtils.runOnUiThreadBlocking(new Runnable(){
155 public void run() {
156 assertFalse(WarmupManager.getInstance().hasBuiltViewHierarchy()) ;
157 }
158 });
159 final ChromeActivity chromeActivity = ActivityUtils.waitForActivity(
160 getInstrumentation(),
161 FeatureUtilities.isDocumentMode(getActivity())
162 ? DocumentActivity.class : ChromeTabbedActivity.class, n ew Runnable() {
163 @Override
164 public void run() {
165 TouchCommon.singleClickView(getActivity().findVi ewById(
166 R.id.load_button));
167 }
168 });
169 ThreadUtils.runOnUiThreadBlocking(new Runnable(){
170 public void run() {
171 assertFalse(WarmupManager.getInstance().hasBuiltViewHierarchy()) ;
172 }
173 });
174 // TODO(yusufo): We should be using the NotificationCenter for checking the page loading.
175 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
176 @Override
177 public boolean isSatisfied() {
178 return chromeActivity.getActivityTab() != null
179 && chromeActivity.getActivityTab().isLoadingAndRendering Done();
180 }
181 }));
182 assertTrue(chromeActivity.getActivityTab().getUrl().equals(url));
183 ThreadUtils.runOnUiThreadBlocking(new Runnable(){
184 public void run() {
185 assertFalse(WarmupManager.getInstance().hasAnyPrerenderedUrl());
186 }
187 });
188 }
189
190 private void assertServiceHasPrerenderedUrl(final String url) throws Interru ptedException {
191 final Callable<Boolean> callable = new Callable<Boolean>() {
192 @Override
193 public Boolean call() throws Exception {
194 return WarmupManager.getInstance().hasPrerenderedUrl(url);
195 }
196 };
197
198 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
199 @Override
200 public boolean isSatisfied() {
201 return ThreadUtils.runOnUiThreadBlockingNoException(callable);
202 }
203 }));
204 }
205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698