OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
pasko
2016/10/03 18:54:17
nit: prerender_nostate_prefetch_browsertest.cc
mattcary
2016/10/04 08:25:12
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/command_line.h" | |
6 #include "base/strings/string_split.h" | |
7 #include "chrome/browser/prerender/prerender_manager.h" | |
8 #include "chrome/browser/prerender/prerender_manager_factory.h" | |
9 #include "chrome/browser/prerender/prerender_test_utils.h" | |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | |
12 #include "chrome/browser/ui/browser.h" | |
13 #include "chrome/browser/ui/browser_commands.h" | |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "chrome/grit/generated_resources.h" | |
17 #include "chrome/test/base/ui_test_utils.h" | |
18 #include "content/public/common/content_switches.h" | |
19 #include "content/public/common/url_constants.h" | |
20 #include "content/public/test/browser_test_utils.h" | |
21 #include "net/base/escape.h" | |
22 #include "net/dns/mock_host_resolver.h" | |
23 #include "net/test/embedded_test_server/request_handler_util.h" | |
24 #include "testing/gtest/include/gtest/gtest.h" | |
25 #include "ui/base/l10n/l10n_util.h" | |
26 | |
27 using prerender::test_utils::CreateCountingInterceptorOnIO; | |
28 using prerender::test_utils::DestructionWaiter; | |
29 using prerender::test_utils::RequestCounter; | |
30 using prerender::test_utils::TestPrerender; | |
31 using prerender::test_utils::TestPrerenderContents; | |
32 using task_manager::browsertest_util::WaitForTaskManagerRows; | |
33 | |
34 namespace { | |
35 // Fetches a boolean value from javascript. Returns whether the fetch | |
36 // succeeded; the value of the variable is returned in value. If | |
37 // javascript_variable does not exist, this returns false and value is | |
38 // unchanged. The function checks that script execution works. | |
39 bool GetJavascriptBoolean(const std::string& javascript_variable, | |
40 content::WebContents* web_contents, | |
41 bool* value) { | |
42 // In order to detect unknown variables a three-valued return is needed. | |
43 int result; | |
44 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | |
45 web_contents, | |
46 "try { if (" + javascript_variable + ") { " + | |
47 "window.domAutomationController.send(1) } else { " + | |
48 "window.domAutomationController.send(0); } } catch(err) {" + | |
49 "window.domAutomationController.send(2) }", | |
50 &result)); | |
51 if (result == 2) { | |
52 // This means an exception was caught, usually because of a missing | |
53 // variable. | |
54 return false; | |
55 } | |
56 *value = (result == 1); | |
57 return true; | |
58 } | |
59 | |
60 // As above, but just checks for a missing variable. | |
61 bool JavascriptVariableMissing(const std::string& javascript_variable, | |
62 content::WebContents* web_contents) { | |
63 bool unused; | |
64 return !GetJavascriptBoolean(javascript_variable, web_contents, &unused); | |
65 } | |
66 | |
67 } // namespace | |
68 | |
69 namespace prerender { | |
70 | |
71 // The various uses of URLs in these tests (the test server, request capture, | |
72 // etc) are fussy about relative versus absolute paths. With the exception of | |
pasko
2016/10/03 18:54:17
I cannot see why the first sentence in this commen
mattcary
2016/10/04 08:25:12
Why don't you give me the exact wording you want--
pasko
2016/10/04 11:52:22
.. because it is more to write? The explanation of
mattcary
2016/10/04 16:24:17
Done, with a slight clarification to make it more
| |
73 // kPrefetchLoaderPath, which is only used in PrerenderTestURLImpl, all other | |
74 // paths should be relative. | |
75 const char kPrefetchImagePage[] = "prerender/prefetch_image.html"; | |
76 const char kPrefetchLoopPage[] = "prerender/prefetch_loop.html"; | |
77 const char kPrefetchJpeg[] = "prerender/image.jpeg"; | |
78 const char kPrefetchLoaderPath[] = "/prerender/prefetch_loader.html"; | |
79 const char kPrefetchPage[] = "prerender/prefetch_page.html"; | |
80 const char kPrefetchPage2[] = "prerender/prefetch_page2.html"; | |
81 const char kPrefetchPng[] = "prerender/image.png"; | |
82 const char kPrefetchScript[] = "prerender/prefetch.js"; | |
83 const char kPrefetchScript2[] = "prerender/prefetch2.js"; | |
84 const char kPrefetchSubresourceRedirectPage[] = | |
85 "prerender/prefetch_subresource_redirect.html"; | |
86 | |
87 const char kPageBool[] = "pageBool"; | |
88 const char kScriptBool[] = "scriptBool"; | |
89 | |
90 class NoStatePrefetchBrowserTest | |
91 : public test_utils::PrerenderInProcessBrowserTest { | |
92 public: | |
93 NoStatePrefetchBrowserTest() {} | |
94 | |
95 void SetUpCommandLine(base::CommandLine* command_line) override { | |
96 PrerenderInProcessBrowserTest::SetUpCommandLine(command_line); | |
97 command_line->AppendSwitchASCII( | |
98 switches::kPrerenderMode, switches::kPrerenderModeSwitchValuePrefetch); | |
99 } | |
100 | |
101 // Set up a request counter for the path. | |
102 void CountRequestFor(const std::string& path, RequestCounter* counter) { | |
103 GURL::Replacements replacement; | |
104 replacement.SetPathStr(path); | |
105 const GURL url = src_server()->base_url().ReplaceComponents(replacement); | |
106 base::FilePath url_file = | |
107 ui_test_utils::GetTestFilePath(base::FilePath(), base::FilePath(path)); | |
108 content::BrowserThread::PostTask( | |
109 content::BrowserThread::IO, FROM_HERE, | |
110 base::Bind(&CreateCountingInterceptorOnIO, url, url_file, | |
111 counter->AsWeakPtr())); | |
112 } | |
113 | |
114 private: | |
115 ScopedVector<TestPrerender> PrerenderTestURLImpl( | |
116 const GURL& prerender_url, | |
117 const std::vector<FinalStatus>& expected_final_status_queue, | |
118 int expected_number_of_loads) override { | |
119 base::StringPairs replacement_text; | |
120 replacement_text.push_back( | |
121 make_pair("REPLACE_WITH_PREFETCH_URL", prerender_url.spec())); | |
122 std::string replacement_path; | |
123 net::test_server::GetFilePathWithReplacements( | |
124 kPrefetchLoaderPath, replacement_text, &replacement_path); | |
125 GURL loader_url = src_server()->GetURL(replacement_path); | |
126 | |
127 ScopedVector<TestPrerender> prerenders = NavigateWithPrerenders( | |
128 loader_url, expected_final_status_queue, expected_number_of_loads); | |
129 | |
130 TestPrerenderContents* prerender_contents = prerenders[0]->contents(); | |
131 CHECK(prerender_contents); | |
132 // Checks that the prerender contents final status is unchanged from its | |
133 // default value, meaning that the contents has not been destroyed. | |
134 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); | |
135 | |
136 EXPECT_EQ(expected_number_of_loads, prerenders[0]->number_of_loads()); | |
137 | |
138 return prerenders; | |
139 } | |
140 }; | |
141 | |
142 // Perform a full load of the target page and check that javascript values are | |
pasko
2016/10/03 18:54:17
nit: s/Perform/Performs/
mattcary
2016/10/04 08:25:12
Done.
| |
143 // set as expected. This confirms that our test system is working correctly, so | |
144 // that when the target page is prefetched it can be confirmed that javascript | |
145 // is not executed. | |
146 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, CheckJavascript) { | |
147 ui_test_utils::NavigateToURL( | |
148 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage))); | |
149 content::WebContents* web_contents = | |
150 current_browser()->tab_strip_model()->GetActiveWebContents(); | |
151 | |
152 // Confirm we can get true and false values. | |
153 bool value = false; | |
154 EXPECT_TRUE(GetJavascriptBoolean(kPageBool, web_contents, &value)); | |
155 EXPECT_TRUE(value); | |
156 value = true; | |
157 EXPECT_TRUE(GetJavascriptBoolean("pageAntiBool", web_contents, &value)); | |
158 EXPECT_FALSE(value); | |
159 | |
160 // Confirm a value from the script is plumbed through. | |
161 value = false; | |
162 EXPECT_TRUE(GetJavascriptBoolean(kScriptBool, web_contents, &value)); | |
163 EXPECT_TRUE(value); | |
164 | |
165 // Confirm that the expected happens when a value doesn't exist. | |
166 EXPECT_TRUE(JavascriptVariableMissing("iDontExist", web_contents)); | |
167 } | |
168 | |
169 // Checks that a page is correctly prefetched in the case of a | |
170 // <link rel=prerender> tag and then loaded into a tab in response to a | |
171 // navigation, when NoState Prefetch is enabled, but that the page is not loaded | |
172 // (which confirmed by checking that javascript is not executed). | |
173 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchSimple) { | |
174 RequestCounter script_counter; | |
175 CountRequestFor(kPrefetchScript, &script_counter); | |
176 RequestCounter main_counter; | |
177 CountRequestFor(kPrefetchPage, &main_counter); | |
178 | |
179 std::unique_ptr<TestPrerender> test_prerender = | |
180 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
181 main_counter.WaitForCount(1); | |
182 script_counter.WaitForCount(1); | |
183 | |
184 content::WebContents* contents = | |
185 test_prerender->contents()->prerender_contents(); | |
186 content::WebContents* active_contents = | |
187 current_browser()->tab_strip_model()->GetActiveWebContents(); | |
188 EXPECT_TRUE(JavascriptVariableMissing(kPageBool, contents)); | |
189 EXPECT_TRUE(JavascriptVariableMissing(kScriptBool, contents)); | |
190 EXPECT_TRUE(JavascriptVariableMissing(kPageBool, active_contents)); | |
191 EXPECT_TRUE(JavascriptVariableMissing(kScriptBool, active_contents)); | |
192 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 1); | |
193 histogram_tester().ExpectBucketCount( | |
194 "Prerender.websame_NoStatePrefetchResponseTypes", | |
195 4 /* cacheable, main resource */, 1); | |
196 histogram_tester().ExpectBucketCount( | |
197 "Prerender.websame_NoStatePrefetchResponseTypes", | |
198 0 /* cacheable, non-main resource */, 1); | |
199 histogram_tester().ExpectTotalCount("Prerender.none_MainResourceRedirects", | |
200 0); | |
201 histogram_tester().ExpectTotalCount("Prerender.none_SubResourceRedirects", 0); | |
202 } | |
203 | |
204 // Checks the TTFCP histograms on reuse of a prefetch. | |
pasko
2016/10/03 18:54:17
// Checks the TTFCP histograms on fast reuse of a
mattcary
2016/10/04 08:25:12
Done.
| |
205 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, | |
206 PrefetchReusedWarmHistograms) { | |
207 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
208 GetTestPrerenderManager()->AdvanceTime(base::TimeDelta::FromSeconds(10)); | |
209 ui_test_utils::NavigateToURL( | |
210 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage))); | |
211 histogram_tester().ExpectTotalCount( | |
212 "Prerender.websame_NoStatePrefetchTTFCP.Warm.Cacheable", 1); | |
213 histogram_tester().ExpectTotalCount( | |
214 "Prerender.websame_NoStatePrefetchTTFCP.Cold.Cacheable", 0); | |
215 } | |
216 | |
217 // Checks the histograms on reuse of a prefetch. | |
218 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, | |
219 PrefetchReusedColdHistograms) { | |
220 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_TIMED_OUT, 1); | |
221 GetTestPrerenderManager()->AdvanceTime(base::TimeDelta::FromSeconds(600)); | |
222 ui_test_utils::NavigateToURL( | |
223 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage))); | |
224 | |
225 histogram_tester().ExpectTotalCount( | |
226 "Prerender.websame_NoStatePrefetchTTFCP.Warm.Cacheable", 0); | |
227 histogram_tester().ExpectTotalCount( | |
228 "Prerender.websame_NoStatePrefetchTTFCP.Cold.Cacheable", 1); | |
229 } | |
230 | |
231 // Checks the prefetch of an img tag. | |
232 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchImage) { | |
233 RequestCounter image_counter; | |
234 CountRequestFor(kPrefetchJpeg, &image_counter); | |
235 base::StringPairs replacement_text; | |
236 replacement_text.push_back( | |
237 std::make_pair("REPLACE_WITH_IMAGE_URL", MakeAbsolute(kPrefetchJpeg))); | |
238 std::string main_page_path; | |
239 net::test_server::GetFilePathWithReplacements( | |
240 kPrefetchImagePage, replacement_text, &main_page_path); | |
241 // Note that we can't CountRequestFor the main page as we use the test server | |
242 // for handling the image url replacement. | |
243 PrerenderTestURL(main_page_path, FINAL_STATUS_APP_TERMINATING, 1); | |
244 image_counter.WaitForCount(1); | |
245 } | |
246 | |
247 // Checks that a cross-domain prefetching works correctly by looking at | |
248 // histograms. | |
249 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchCrossDomain) { | |
250 static const std::string secondary_domain = "www.foo.com"; | |
251 host_resolver()->AddRule(secondary_domain, "127.0.0.1"); | |
252 GURL cross_domain_url(base::StringPrintf( | |
253 "http://%s:%d/%s", secondary_domain.c_str(), | |
254 embedded_test_server()->host_port_pair().port(), kPrefetchPage)); | |
255 PrerenderTestURL(cross_domain_url, FINAL_STATUS_APP_TERMINATING, 1); | |
256 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 1); | |
pasko
2016/10/03 18:54:17
would it be possible to check the Prefetch histogr
mattcary
2016/10/04 08:25:12
There are PLT histograms everywhere, let's do that
pasko
2016/10/04 11:52:22
I was not aware that this requires new histograms.
mattcary
2016/10/04 16:24:17
Acknowledged.
| |
257 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1); | |
258 histogram_tester().ExpectTotalCount( | |
259 "Prerender.webcross_PrerenderNotSwappedInPLT", 1); | |
260 } | |
261 | |
262 // Checks that we support simultaneous prefetch. | |
pasko
2016/10/03 18:54:17
I did not realize that we allow it. Sounds like a
mattcary
2016/10/04 08:25:12
Yup, probably.... I feel like there are several te
pasko
2016/10/04 11:52:22
OK, added this as our future task. Could be a TODO
mattcary
2016/10/04 16:24:17
Acknowledged.
| |
263 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchSimultaneous) { | |
264 RequestCounter first_main_counter; | |
265 CountRequestFor(kPrefetchPage, &first_main_counter); | |
266 RequestCounter second_main_counter; | |
267 CountRequestFor(kPrefetchPage2, &second_main_counter); | |
268 RequestCounter first_script_counter; | |
269 CountRequestFor(kPrefetchScript, &first_script_counter); | |
270 RequestCounter second_script_counter; | |
271 CountRequestFor(kPrefetchScript2, &second_script_counter); | |
272 | |
273 // The first prerender is marked as canceled as when the second starts, it | |
274 // sees that the first has been abandoned (presumably because we detach | |
275 // immediately and so it dies quickly). | |
276 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_CANCELLED, 1); | |
277 PrerenderTestURL(kPrefetchPage2, FINAL_STATUS_APP_TERMINATING, 1); | |
278 first_main_counter.WaitForCount(1); | |
279 second_main_counter.WaitForCount(1); | |
280 first_script_counter.WaitForCount(1); | |
281 second_script_counter.WaitForCount(1); | |
282 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 2); | |
283 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 2); | |
284 } | |
285 | |
286 // Checks that we correctly handle a prefetch to a nonexisting page. | |
pasko
2016/10/03 18:54:17
'correctly handle' is too general. Please avoid 'w
mattcary
2016/10/04 08:25:12
Done.
| |
287 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchNonexisting) { | |
288 PrerenderTestURL("nonexisting-page.html", FINAL_STATUS_APP_TERMINATING, 0); | |
289 // TODO(mattcary): we fire up a prerenderer before we discover that the main | |
290 // page doesn't exist, we still count this as a prerender. Also we don't fail | |
291 // the renderer (presumably because we've detached the resource, etc). Is this | |
292 // what we want? | |
pasko
2016/10/03 18:54:17
Will this leave the renderer up until it expires?
mattcary
2016/10/04 08:25:12
Yeah, see comment above.
pasko
2016/10/04 11:52:22
Acknowledged.
| |
293 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 1); | |
294 } | |
295 | |
296 // Checks that we follow a 301 redirect. | |
297 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Redirect) { | |
298 RequestCounter script_counter; | |
299 CountRequestFor(kPrefetchScript, &script_counter); | |
300 PrerenderTestURL( | |
301 "/server-redirect/?" + | |
302 net::EscapeQueryParamValue(MakeAbsolute(kPrefetchPage), false), | |
303 FINAL_STATUS_APP_TERMINATING, 1); | |
304 script_counter.WaitForCount(1); | |
305 histogram_tester().ExpectTotalCount( | |
306 "Prerender.websame_NoStatePrefetchMainResourceRedirects", 1); | |
307 } | |
308 | |
309 // Checks that we follow a subresource 301 redirect. | |
310 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Subresource) { | |
311 RequestCounter script_counter; | |
312 CountRequestFor(kPrefetchScript, &script_counter); | |
313 PrerenderTestURL(kPrefetchSubresourceRedirectPage, | |
314 FINAL_STATUS_APP_TERMINATING, 1); | |
315 script_counter.WaitForCount(1); | |
316 histogram_tester().ExpectTotalCount( | |
317 "Prerender.websame_NoStatePrefetchMainResourceRedirects", 1); | |
318 } | |
319 | |
320 // Checks that we don't follow a client redirect. | |
321 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchClientRedirect) { | |
322 RequestCounter script_counter; | |
323 CountRequestFor(kPrefetchScript, &script_counter); | |
324 // We use a sentinel via a complete load kPrefetchPage2. Otherwise we end | |
325 // before script_counter would reliable see the load of kPrefetchScript, were | |
326 // it to happen. | |
327 RequestCounter sentinel_counter; | |
328 CountRequestFor(kPrefetchScript2, &sentinel_counter); | |
329 PrerenderTestURL( | |
330 "/client-redirect/?" + | |
331 net::EscapeQueryParamValue(MakeAbsolute(kPrefetchPage), false), | |
332 FINAL_STATUS_APP_TERMINATING, 1); | |
333 ui_test_utils::NavigateToURL( | |
334 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage2))); | |
335 sentinel_counter.WaitForCount(1); | |
336 script_counter.WaitForCount(0); | |
337 } | |
338 | |
339 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchHttps) { | |
340 UseHttpsSrcServer(); | |
341 RequestCounter main_counter; | |
342 CountRequestFor(kPrefetchPage, &main_counter); | |
343 RequestCounter script_counter; | |
344 CountRequestFor(kPrefetchScript, &script_counter); | |
345 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
346 main_counter.WaitForCount(1); | |
347 script_counter.WaitForCount(1); | |
348 } | |
349 | |
350 // Checks that if an SSL error happens we don't fetch. | |
351 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, SSLError) { | |
352 // We only send the loaded page, not the loader, through SSL. | |
353 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | |
354 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | |
355 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); | |
356 ASSERT_TRUE(https_server.Start()); | |
357 std::unique_ptr<TestPrerender> prerender = | |
358 PrerenderTestURL(https_server.GetURL(MakeAbsolute(kPrefetchPage)), | |
359 FINAL_STATUS_SSL_ERROR, 0); | |
360 DestructionWaiter waiter(prerender->contents(), FINAL_STATUS_SSL_ERROR); | |
361 EXPECT_TRUE(waiter.WaitForDestroy()); | |
362 } | |
363 | |
364 // We should not have a problem if a subresource fails SSL. | |
pasko
2016/10/03 18:54:17
'a problem' is a bit too general, how can we clari
mattcary
2016/10/04 08:25:12
Done.
| |
365 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, SSLSubresourceError) { | |
366 // First confirm that the image loads as expected. | |
367 | |
368 // Note that we start a separate HTTPS server for the subresource; | |
369 // src_server() is non-HTTPS. | |
370 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | |
371 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | |
372 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); | |
373 ASSERT_TRUE(https_server.Start()); | |
374 GURL https_url = https_server.GetURL("/prerender/image.jpeg"); | |
375 base::StringPairs replacement_text; | |
376 replacement_text.push_back( | |
377 std::make_pair("REPLACE_WITH_IMAGE_URL", https_url.spec())); | |
378 std::string main_page_path; | |
379 net::test_server::GetFilePathWithReplacements( | |
380 kPrefetchImagePage, replacement_text, &main_page_path); | |
381 RequestCounter script_counter; | |
382 CountRequestFor(kPrefetchScript, &script_counter); | |
383 | |
384 std::unique_ptr<TestPrerender> prerender = | |
385 PrerenderTestURL(main_page_path, FINAL_STATUS_APP_TERMINATING, 1); | |
386 // Checks that the presumed failure of the image load didn't affect the script | |
387 // fetch. This assumes waiting for the script load is enough to see any error | |
388 // from the image load. | |
389 script_counter.WaitForCount(1); | |
390 } | |
391 | |
392 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Loop) { | |
393 RequestCounter script_counter; | |
394 CountRequestFor(kPrefetchScript, &script_counter); | |
395 RequestCounter main_counter; | |
396 CountRequestFor(kPrefetchLoopPage, &main_counter); | |
397 | |
398 std::unique_ptr<TestPrerender> test_prerender = | |
399 PrerenderTestURL(kPrefetchLoopPage, FINAL_STATUS_APP_TERMINATING, 1); | |
400 main_counter.WaitForCount(1); | |
401 script_counter.WaitForCount(1); | |
402 } | |
403 | |
404 #if defined(ENABLE_TASK_MANAGER) | |
405 | |
406 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, | |
407 OpenTaskManagerBeforePrefetch) { | |
408 const base::string16 any_prerender = MatchTaskManagerPrerender("*"); | |
409 const base::string16 any_tab = MatchTaskManagerTab("*"); | |
410 const base::string16 original = MatchTaskManagerTab("Prefetch Loader"); | |
411 // Presumably we don't see the title in the task manager as the page has not | |
412 // been fully parsed. | |
413 const base::string16 prerender = | |
414 MatchTaskManagerPrerender("*prefetch_page.html*"); | |
415 | |
416 // Show the task manager. This populates the model. | |
417 chrome::OpenTaskManager(current_browser()); | |
418 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); | |
419 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); | |
420 | |
421 // Prerender a page in addition to the original tab. | |
422 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
423 | |
424 // A TaskManager entry should appear like "Prerender: Prerender Page" | |
425 // alongside the original tab entry. There should be just these two entries. | |
426 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, prerender)); | |
427 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, original)); | |
428 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_prerender)); | |
429 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); | |
430 } | |
431 | |
432 #endif // defined(ENABLE_TASK_MANAGER) | |
433 | |
434 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, RendererCrash) { | |
435 std::unique_ptr<TestPrerender> prerender = | |
436 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_RENDERER_CRASHED, 1); | |
437 prerender->contents()->prerender_contents()->GetController().LoadURL( | |
438 GURL(content::kChromeUICrashURL), content::Referrer(), | |
439 ui::PAGE_TRANSITION_TYPED, std::string()); | |
440 prerender->WaitForStop(); | |
441 } | |
442 | |
443 // Checks that the prefetch of png correctly loads only the png. | |
pasko
2016/10/03 18:54:17
is it essential to check different img types? Are
mattcary
2016/10/04 08:25:12
We do pull the favicon on prefetch, and we could c
pasko
2016/10/04 11:52:22
OK, got it. This slightly excessive testing is OK
mattcary
2016/10/04 16:24:17
Oh, I see what you mean. Done
| |
444 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Png) { | |
445 RequestCounter counter; | |
446 CountRequestFor(kPrefetchPng, &counter); | |
447 PrerenderTestURL(kPrefetchPng, FINAL_STATUS_APP_TERMINATING, 1); | |
448 counter.WaitForCount(1); | |
449 } | |
450 | |
451 // Checks that the prefetch of png correctly loads only the jpeg. | |
452 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Jpeg) { | |
453 RequestCounter counter; | |
454 CountRequestFor(kPrefetchJpeg, &counter); | |
455 PrerenderTestURL(kPrefetchJpeg, FINAL_STATUS_APP_TERMINATING, 1); | |
456 counter.WaitForCount(1); | |
457 } | |
458 | |
459 // Checks that nothing is prefetched from malware sites. | |
460 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, | |
461 PrerenderSafeBrowsingTopLevel) { | |
462 GURL url = src_server()->GetURL(MakeAbsolute(kPrefetchPage)); | |
463 GetFakeSafeBrowsingDatabaseManager()->SetThreatTypeForUrl( | |
464 url, safe_browsing::SB_THREAT_TYPE_URL_MALWARE); | |
465 // Prefetch resource are blocked, but the prerender is not killed in any | |
pasko
2016/10/03 18:54:17
s/resource/resources/
mattcary
2016/10/04 08:25:12
Done.
| |
466 // special way. | |
467 // TODO(mattcary): do we care about detecting if the main resource is fetched | |
pasko
2016/10/03 18:54:17
We should not prefetch the main resource to cache
mattcary
2016/10/04 08:25:12
The prerender terminates with FINAL_STATUS_SAFE_BR
pasko
2016/10/04 11:52:22
OK. Agreed.
Later we will need some sort of way t
mattcary
2016/10/04 16:24:17
Done.
| |
468 // and preload scanning has started? | |
469 std::unique_ptr<TestPrerender> prerender = | |
470 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 0); | |
471 } | |
472 | |
473 } // namespace prerender | |
OLD | NEW |