| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/browser/prerender/prerender_contents.h" | 8 #include "chrome/browser/prerender/prerender_contents.h" |
| 9 #include "chrome/browser/prerender/prerender_manager.h" | 9 #include "chrome/browser/prerender/prerender_manager.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // the page behaves as expected when prerendered. | 30 // the page behaves as expected when prerendered. |
| 31 // | 31 // |
| 32 // The prerendered page is then displayed on a tab. The Javascript function | 32 // The prerendered page is then displayed on a tab. The Javascript function |
| 33 // DidDisplayPass() is called, and returns true if the page behaved as it | 33 // DidDisplayPass() is called, and returns true if the page behaved as it |
| 34 // should while being displayed. | 34 // should while being displayed. |
| 35 | 35 |
| 36 namespace prerender { | 36 namespace prerender { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 bool CreateRedirect(const std::string& dest_url, std::string* redirect_path) { | 40 std::string CreateClientRedirect(const std::string& dest_url) { |
| 41 std::vector<net::TestServer::StringPair> replacement_text; | 41 const char* const kClientRedirectBase = "client-redirect?"; |
| 42 replacement_text.push_back(make_pair("REPLACE_WITH_URL", dest_url)); | 42 return kClientRedirectBase + dest_url; |
| 43 return net::TestServer::GetFilePathWithReplacements( | 43 } |
| 44 "prerender_redirect.html", | 44 |
| 45 replacement_text, | 45 std::string CreateServerRedirect(const std::string& dest_url) { |
| 46 redirect_path); | 46 const char* const kServerRedirectBase = "server-redirect?"; |
| 47 return kServerRedirectBase + dest_url; |
| 47 } | 48 } |
| 48 | 49 |
| 49 // PrerenderContents that stops the UI message loop on DidStopLoading(). | 50 // PrerenderContents that stops the UI message loop on DidStopLoading(). |
| 50 class TestPrerenderContents : public PrerenderContents { | 51 class TestPrerenderContents : public PrerenderContents { |
| 51 public: | 52 public: |
| 52 TestPrerenderContents( | 53 TestPrerenderContents( |
| 53 PrerenderManager* prerender_manager, Profile* profile, const GURL& url, | 54 PrerenderManager* prerender_manager, Profile* profile, const GURL& url, |
| 54 const std::vector<GURL>& alias_urls, | 55 const std::vector<GURL>& alias_urls, |
| 55 const GURL& referrer, | 56 const GURL& referrer, |
| 56 int number_of_loads, | 57 int number_of_loads, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // Check if page behaved as expected when actually displayed. | 174 // Check if page behaved as expected when actually displayed. |
| 174 bool display_test_result = false; | 175 bool display_test_result = false; |
| 175 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 176 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 176 browser()->GetSelectedTabContents()->render_view_host(), L"", | 177 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 177 L"window.domAutomationController.send(DidDisplayPass())", | 178 L"window.domAutomationController.send(DidDisplayPass())", |
| 178 &display_test_result)); | 179 &display_test_result)); |
| 179 EXPECT_TRUE(display_test_result); | 180 EXPECT_TRUE(display_test_result); |
| 180 } | 181 } |
| 181 | 182 |
| 182 bool UrlIsInPrerenderManager(const std::string& html_file) { | 183 bool UrlIsInPrerenderManager(const std::string& html_file) { |
| 183 GURL dest_url = UrlForHtmlFile(html_file); | 184 GURL dest_url = test_server()->GetURL(html_file); |
| 184 | |
| 185 return (prerender_manager()->FindEntry(dest_url) != NULL); | 185 return (prerender_manager()->FindEntry(dest_url) != NULL); |
| 186 } | 186 } |
| 187 | 187 |
| 188 bool UrlIsPendingInPrerenderManager(const std::string& html_file) { | 188 bool UrlIsPendingInPrerenderManager(const std::string& html_file) { |
| 189 GURL dest_url = UrlForHtmlFile(html_file); | 189 GURL dest_url = test_server()->GetURL(html_file); |
| 190 | |
| 191 return (prerender_manager()->FindPendingEntry(dest_url) != NULL); | 190 return (prerender_manager()->FindPendingEntry(dest_url) != NULL); |
| 192 } | 191 } |
| 193 | 192 |
| 194 void set_use_https_src(bool use_https_src_server) { | 193 void set_use_https_src(bool use_https_src_server) { |
| 195 use_https_src_server_ = use_https_src_server; | 194 use_https_src_server_ = use_https_src_server; |
| 196 } | 195 } |
| 197 | 196 |
| 198 TaskManagerModel* model() const { | 197 TaskManagerModel* model() const { |
| 199 return TaskManager::GetInstance()->model(); | 198 return TaskManager::GetInstance()->model(); |
| 200 } | 199 } |
| 201 | 200 |
| 201 void set_dest_url(const GURL& dest_url) { dest_url_ = dest_url; } |
| 202 |
| 202 private: | 203 private: |
| 203 void PrerenderTestURLImpl( | 204 void PrerenderTestURLImpl( |
| 204 const std::string& html_file, | 205 const std::string& html_file, |
| 205 const std::deque<FinalStatus>& expected_final_status_queue, | 206 const std::deque<FinalStatus>& expected_final_status_queue, |
| 206 int total_navigations) { | 207 int total_navigations) { |
| 207 ASSERT_TRUE(test_server()->Start()); | 208 ASSERT_TRUE(test_server()->Start()); |
| 208 dest_url_ = UrlForHtmlFile(html_file); | 209 dest_url_ = test_server()->GetURL(html_file); |
| 209 | 210 |
| 210 std::vector<net::TestServer::StringPair> replacement_text; | 211 std::vector<net::TestServer::StringPair> replacement_text; |
| 211 replacement_text.push_back( | 212 replacement_text.push_back( |
| 212 make_pair("REPLACE_WITH_PREFETCH_URL", dest_url_.spec())); | 213 make_pair("REPLACE_WITH_PREFETCH_URL", dest_url_.spec())); |
| 213 std::string replacement_path; | 214 std::string replacement_path; |
| 214 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( | 215 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( |
| 215 "files/prerender/prerender_loader.html", | 216 "files/prerender/prerender_loader.html", |
| 216 replacement_text, | 217 replacement_text, |
| 217 &replacement_path)); | 218 &replacement_path)); |
| 218 | 219 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 break; | 272 break; |
| 272 } | 273 } |
| 273 } | 274 } |
| 274 | 275 |
| 275 PrerenderManager* prerender_manager() const { | 276 PrerenderManager* prerender_manager() const { |
| 276 Profile* profile = browser()->GetSelectedTabContents()->profile(); | 277 Profile* profile = browser()->GetSelectedTabContents()->profile(); |
| 277 PrerenderManager* prerender_manager = profile->GetPrerenderManager(); | 278 PrerenderManager* prerender_manager = profile->GetPrerenderManager(); |
| 278 return prerender_manager; | 279 return prerender_manager; |
| 279 } | 280 } |
| 280 | 281 |
| 281 // Non-const as test_server()->GetURL() is not const | |
| 282 GURL UrlForHtmlFile(const std::string& html_file) { | |
| 283 std::string dest_path = "files/prerender/"; | |
| 284 dest_path.append(html_file); | |
| 285 return test_server()->GetURL(dest_path); | |
| 286 } | |
| 287 | |
| 288 WaitForLoadPrerenderContentsFactory* prc_factory_; | 282 WaitForLoadPrerenderContentsFactory* prc_factory_; |
| 289 GURL dest_url_; | 283 GURL dest_url_; |
| 290 bool use_https_src_server_; | 284 bool use_https_src_server_; |
| 291 }; | 285 }; |
| 292 | 286 |
| 293 // Checks that a page is correctly prerendered in the case of a | 287 // Checks that a page is correctly prerendered in the case of a |
| 294 // <link rel=prefetch> tag and then loaded into a tab in response to a | 288 // <link rel=prefetch> tag and then loaded into a tab in response to a |
| 295 // navigation. | 289 // navigation. |
| 296 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { | 290 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { |
| 297 PrerenderTestURL("prerender_page.html", FINAL_STATUS_USED, 1); | 291 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 298 NavigateToDestURL(); | 292 NavigateToDestURL(); |
| 299 } | 293 } |
| 300 | 294 |
| 301 // Checks that the prerendering of a page is canceled correctly when a | 295 // Checks that the prerendering of a page is canceled correctly when a |
| 302 // Javascript alert is called. | 296 // Javascript alert is called. |
| 303 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertBeforeOnload) { | 297 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertBeforeOnload) { |
| 304 PrerenderTestURL("prerender_alert_before_onload.html", | 298 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", |
| 305 FINAL_STATUS_JAVASCRIPT_ALERT, 1); | 299 FINAL_STATUS_JAVASCRIPT_ALERT, |
| 300 1); |
| 306 } | 301 } |
| 307 | 302 |
| 308 // Checks that the prerendering of a page is canceled correctly when a | 303 // Checks that the prerendering of a page is canceled correctly when a |
| 309 // Javascript alert is called. | 304 // Javascript alert is called. |
| 310 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertAfterOnload) { | 305 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertAfterOnload) { |
| 311 PrerenderTestURL("prerender_alert_after_onload.html", | 306 PrerenderTestURL("files/prerender/prerender_alert_after_onload.html", |
| 312 FINAL_STATUS_JAVASCRIPT_ALERT, 1); | 307 FINAL_STATUS_JAVASCRIPT_ALERT, |
| 308 1); |
| 313 } | 309 } |
| 314 | 310 |
| 315 // Checks that plugins are not loaded while a page is being preloaded, but | 311 // Checks that plugins are not loaded while a page is being preloaded, but |
| 316 // are loaded when the page is displayed. | 312 // are loaded when the page is displayed. |
| 317 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDelayLoadPlugin) { | 313 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDelayLoadPlugin) { |
| 318 PrerenderTestURL("plugin_delay_load.html", FINAL_STATUS_USED, 1); | 314 PrerenderTestURL("files/prerender/plugin_delay_load.html", |
| 315 FINAL_STATUS_USED, |
| 316 1); |
| 319 NavigateToDestURL(); | 317 NavigateToDestURL(); |
| 320 } | 318 } |
| 321 | 319 |
| 322 // Checks that plugins in an iframe are not loaded while a page is | 320 // Checks that plugins in an iframe are not loaded while a page is |
| 323 // being preloaded, but are loaded when the page is displayed. | 321 // being preloaded, but are loaded when the page is displayed. |
| 324 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderIframeDelayLoadPlugin) { | 322 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderIframeDelayLoadPlugin) { |
| 325 PrerenderTestURL("prerender_iframe_plugin_delay_load.html", | 323 PrerenderTestURL("files/prerender/prerender_iframe_plugin_delay_load.html", |
| 326 FINAL_STATUS_USED, 1); | 324 FINAL_STATUS_USED, |
| 325 1); |
| 327 NavigateToDestURL(); | 326 NavigateToDestURL(); |
| 328 } | 327 } |
| 329 | 328 |
| 330 // Renders a page that contains a prerender link to a page that contains an | 329 // Renders a page that contains a prerender link to a page that contains an |
| 331 // iframe with a source that requires http authentication. This should not | 330 // iframe with a source that requires http authentication. This should not |
| 332 // prerender successfully. | 331 // prerender successfully. |
| 333 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHttpAuthentication) { | 332 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHttpAuthentication) { |
| 334 PrerenderTestURL("prerender_http_auth_container.html", | 333 PrerenderTestURL("files/prerender/prerender_http_auth_container.html", |
| 335 FINAL_STATUS_AUTH_NEEDED, 1); | 334 FINAL_STATUS_AUTH_NEEDED, |
| 335 1); |
| 336 } | 336 } |
| 337 | 337 |
| 338 // Checks that HTML redirects work with prerendering - specifically, checks the | 338 // Checks that client-issued redirects work with prerendering - specifically, |
| 339 // page is used and plugins aren't loaded. | 339 // checks the page is used and plugins aren't loaded. This version navigates to |
| 340 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderRedirect) { | 340 // the first page rather than the second page. |
| 341 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
| 342 PrerenderClientRedirectNavigateToFirst) { |
| 343 PrerenderTestURL( |
| 344 CreateClientRedirect("files/prerender/prerender_page.html"), |
| 345 FINAL_STATUS_USED, |
| 346 2); |
| 347 NavigateToDestURL(); |
| 348 } |
| 349 |
| 350 // Checks that client-issued redirects work with prerendering - specifically, |
| 351 // checks the page is used and plugins aren't loaded. This version navigates to |
| 352 // the second page rather than the first page. |
| 353 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
| 354 PrerenderClientRedirectNavigateToSecond) { |
| 341 std::string redirect_path; | 355 std::string redirect_path; |
| 342 ASSERT_TRUE(CreateRedirect("prerender_page.html", &redirect_path)); | 356 PrerenderTestURL( |
| 343 PrerenderTestURL(redirect_path, FINAL_STATUS_USED, 2); | 357 CreateClientRedirect("files/prerender/prerender_page.html"), |
| 358 FINAL_STATUS_USED, |
| 359 2); |
| 360 set_dest_url(test_server()->GetURL("files/prerender/prerender_page.html")); |
| 361 NavigateToDestURL(); |
| 362 } |
| 363 // Checks that client-issued redirects work with prerendering - specifically, |
| 364 // checks the page is used and plugins aren't loaded. This version navigates to |
| 365 // the first page rather than the second page. |
| 366 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
| 367 PrerenderServerRedirectNavigateToFirst) { |
| 368 PrerenderTestURL( |
| 369 CreateServerRedirect("files/prerender/prerender_page.html"), |
| 370 FINAL_STATUS_USED, |
| 371 1); |
| 372 NavigateToDestURL(); |
| 373 } |
| 374 |
| 375 // Checks that client-issued redirects work with prerendering - specifically, |
| 376 // checks the page is used and plugins aren't loaded. This version navigates to |
| 377 // the second page rather than the first page. |
| 378 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
| 379 PrerenderServerRedirectNavigateToSecond) { |
| 380 std::string redirect_path; |
| 381 PrerenderTestURL( |
| 382 CreateServerRedirect("files/prerender/prerender_page.html"), |
| 383 FINAL_STATUS_USED, |
| 384 1); |
| 385 set_dest_url(test_server()->GetURL("files/prerender/prerender_page.html")); |
| 344 NavigateToDestURL(); | 386 NavigateToDestURL(); |
| 345 } | 387 } |
| 346 | 388 |
| 347 // Prerenders a page that contains an automatic download triggered through an | 389 // Prerenders a page that contains an automatic download triggered through an |
| 348 // iframe. This should not prerender successfully. | 390 // iframe. This should not prerender successfully. |
| 349 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadIFrame) { | 391 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadIFrame) { |
| 350 PrerenderTestURL("prerender_download_iframe.html", FINAL_STATUS_DOWNLOAD, 1); | 392 PrerenderTestURL("files/prerender/prerender_download_iframe.html", |
| 393 FINAL_STATUS_DOWNLOAD, |
| 394 1); |
| 351 } | 395 } |
| 352 | 396 |
| 353 // Prerenders a page that contains an automatic download triggered through | 397 // Prerenders a page that contains an automatic download triggered through |
| 354 // Javascript changing the window.location. This should not prerender | 398 // Javascript changing the window.location. This should not prerender |
| 355 // successfully. | 399 // successfully. |
| 356 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadLocation) { | 400 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadLocation) { |
| 357 std::string redirect_path; | 401 PrerenderTestURL(CreateClientRedirect("files/download-test1.lib"), |
| 358 ASSERT_TRUE(CreateRedirect("../download-test1.lib", &redirect_path)); | 402 FINAL_STATUS_DOWNLOAD, |
| 359 PrerenderTestURL(redirect_path, FINAL_STATUS_DOWNLOAD, 1); | 403 1); |
| 360 } | 404 } |
| 361 | 405 |
| 362 // Prerenders a page that contains an automatic download triggered through a | 406 // Prerenders a page that contains an automatic download triggered through a |
| 363 // <meta http-equiv="refresh"> tag. This should not prerender successfully. | 407 // client-issued redirect. This should not prerender successfully. |
| 364 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadRefresh) { | 408 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadClientRedirect) { |
| 365 PrerenderTestURL("prerender_download_refresh.html", FINAL_STATUS_DOWNLOAD, 1); | 409 PrerenderTestURL("files/prerender/prerender_download_refresh.html", |
| 410 FINAL_STATUS_DOWNLOAD, |
| 411 1); |
| 366 } | 412 } |
| 367 | 413 |
| 368 // Checks that the referrer is set when prerendering. | 414 // Checks that the referrer is set when prerendering. |
| 369 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrer) { | 415 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrer) { |
| 370 PrerenderTestURL("prerender_referrer.html", FINAL_STATUS_USED, 1); | 416 PrerenderTestURL("files/prerender/prerender_referrer.html", |
| 417 FINAL_STATUS_USED, |
| 418 1); |
| 371 NavigateToDestURL(); | 419 NavigateToDestURL(); |
| 372 } | 420 } |
| 373 | 421 |
| 374 // Checks that the referrer is not set when prerendering and the source page is | 422 // Checks that the referrer is not set when prerendering and the source page is |
| 375 // HTTPS. | 423 // HTTPS. |
| 376 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoSSLReferrer) { | 424 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoSSLReferrer) { |
| 377 set_use_https_src(true); | 425 set_use_https_src(true); |
| 378 PrerenderTestURL("prerender_no_referrer.html", FINAL_STATUS_USED, 1); | 426 PrerenderTestURL("files/prerender/prerender_no_referrer.html", |
| 427 FINAL_STATUS_USED, |
| 428 1); |
| 379 NavigateToDestURL(); | 429 NavigateToDestURL(); |
| 380 } | 430 } |
| 381 | 431 |
| 382 // Checks that popups on a prerendered page cause cancellation. | 432 // Checks that popups on a prerendered page cause cancellation. |
| 383 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPopup) { | 433 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPopup) { |
| 384 PrerenderTestURL("prerender_popup.html", FINAL_STATUS_CREATE_NEW_WINDOW, 1); | 434 PrerenderTestURL("files/prerender/prerender_popup.html", |
| 435 FINAL_STATUS_CREATE_NEW_WINDOW, |
| 436 1); |
| 385 } | 437 } |
| 386 | 438 |
| 387 // Test that page-based redirects to https will cancel prerenders. | 439 // Test that client redirects to https will cancel prerenders. |
| 388 // Disabled, http://crbug.com/73580 | 440 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClientRedirectToHttps) { |
| 389 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderRedirectToHttps) { | |
| 390 net::TestServer https_server(net::TestServer::TYPE_HTTPS, | 441 net::TestServer https_server(net::TestServer::TYPE_HTTPS, |
| 391 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 442 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 392 ASSERT_TRUE(https_server.Start()); | 443 ASSERT_TRUE(https_server.Start()); |
| 393 GURL https_url = https_server.GetURL("files/prerender/prerender_page.html"); | 444 GURL https_url = https_server.GetURL("files/prerender/prerender_page.html"); |
| 394 std::string redirect_path; | 445 PrerenderTestURL(CreateClientRedirect(https_url.spec()), |
| 395 ASSERT_TRUE(CreateRedirect(https_url.spec(), &redirect_path)); | 446 FINAL_STATUS_HTTPS, |
| 396 PrerenderTestURL(redirect_path, FINAL_STATUS_HTTPS, 1); | 447 1); |
| 397 } | 448 } |
| 398 | 449 |
| 399 // Checks that renderers using excessive memory will be terminated. | 450 // Checks that renderers using excessive memory will be terminated. |
| 400 // Disabled, http://crbug.com/77870. | 451 // Disabled, http://crbug.com/77870. |
| 401 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 452 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
| 402 DISABLED_PrerenderExcessiveMemory) { | 453 DISABLED_PrerenderExcessiveMemory) { |
| 403 PrerenderTestURL("prerender_excessive_memory.html", | 454 PrerenderTestURL("files/prerender/prerender_excessive_memory.html", |
| 404 FINAL_STATUS_MEMORY_LIMIT_EXCEEDED, 1); | 455 FINAL_STATUS_MEMORY_LIMIT_EXCEEDED, |
| 456 1); |
| 405 } | 457 } |
| 406 | 458 |
| 407 // Checks that we don't prerender in an infinite loop. | 459 // Checks that we don't prerender in an infinite loop. |
| 408 // Disabled, http://crbug.com/77870. | 460 // Disabled, http://crbug.com/77870. |
| 409 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, DISABLED_PrerenderInfiniteLoop) { | 461 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, DISABLED_PrerenderInfiniteLoop) { |
| 410 const char* const kHtmlFileA = "prerender_infinite_a.html"; | 462 const char* const kHtmlFileA = "prerender_infinite_a.html"; |
| 411 const char* const kHtmlFileB = "prerender_infinite_b.html"; | 463 const char* const kHtmlFileB = "prerender_infinite_b.html"; |
| 412 | 464 |
| 413 std::deque<FinalStatus> expected_final_status_queue; | 465 std::deque<FinalStatus> expected_final_status_queue; |
| 414 expected_final_status_queue.push_back(FINAL_STATUS_USED); | 466 expected_final_status_queue.push_back(FINAL_STATUS_USED); |
| 415 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); | 467 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); |
| 416 | 468 |
| 417 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); | 469 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); |
| 418 | 470 |
| 419 // Next url should be in pending list but not an active entry. | 471 // Next url should be in pending list but not an active entry. |
| 420 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); | 472 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); |
| 421 EXPECT_TRUE(UrlIsPendingInPrerenderManager(kHtmlFileB)); | 473 EXPECT_TRUE(UrlIsPendingInPrerenderManager(kHtmlFileB)); |
| 422 | 474 |
| 423 NavigateToDestURL(); | 475 NavigateToDestURL(); |
| 424 | 476 |
| 425 // Make sure the PrerenderContents for the next url is now in the manager | 477 // Make sure the PrerenderContents for the next url is now in the manager |
| 426 // and not pending. | 478 // and not pending. |
| 427 EXPECT_TRUE(UrlIsInPrerenderManager(kHtmlFileB)); | 479 EXPECT_TRUE(UrlIsInPrerenderManager(kHtmlFileB)); |
| 428 EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileB)); | 480 EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileB)); |
| 429 } | 481 } |
| 430 | 482 |
| 431 // Checks that we don't prerender in an infinite loop and multiple links are | 483 // Checks that we don't prerender in an infinite loop and multiple links are |
| 432 // handled correctly. | 484 // handled correctly. |
| 433 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, FLAKY_PrerenderInfiniteLoopMultiple
) { | 485 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
| 434 const char* const kHtmlFileA = "prerender_infinite_a_multiple.html"; | 486 FLAKY_PrerenderInfiniteLoopMultiple) { |
| 435 const char* const kHtmlFileB = "prerender_infinite_b_multiple.html"; | 487 const char* const kHtmlFileA = |
| 436 const char* const kHtmlFileC = "prerender_infinite_c_multiple.html"; | 488 "files/prerender/prerender_infinite_a_multiple.html"; |
| 489 const char* const kHtmlFileB = |
| 490 "files/prerender/prerender_infinite_b_multiple.html"; |
| 491 const char* const kHtmlFileC = |
| 492 "files/prerender/prerender_infinite_c_multiple.html"; |
| 437 | 493 |
| 438 // We need to set the final status to expect here before starting any | 494 // We need to set the final status to expect here before starting any |
| 439 // prerenders. We set them on a queue so whichever we see first is expected to | 495 // prerenders. We set them on a queue so whichever we see first is expected to |
| 440 // be evicted, and the second should stick around until we exit. | 496 // be evicted, and the second should stick around until we exit. |
| 441 std::deque<FinalStatus> expected_final_status_queue; | 497 std::deque<FinalStatus> expected_final_status_queue; |
| 442 expected_final_status_queue.push_back(FINAL_STATUS_USED); | 498 expected_final_status_queue.push_back(FINAL_STATUS_USED); |
| 443 expected_final_status_queue.push_back(FINAL_STATUS_EVICTED); | 499 expected_final_status_queue.push_back(FINAL_STATUS_EVICTED); |
| 444 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); | 500 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); |
| 445 | 501 |
| 446 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); | 502 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 463 EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileB)); | 519 EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileB)); |
| 464 EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileC)); | 520 EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileC)); |
| 465 } | 521 } |
| 466 | 522 |
| 467 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, TaskManager) { | 523 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, TaskManager) { |
| 468 // Show the task manager. This populates the model. | 524 // Show the task manager. This populates the model. |
| 469 browser()->window()->ShowTaskManager(); | 525 browser()->window()->ShowTaskManager(); |
| 470 | 526 |
| 471 // Start with two resources. | 527 // Start with two resources. |
| 472 EXPECT_EQ(2, model()->ResourceCount()); | 528 EXPECT_EQ(2, model()->ResourceCount()); |
| 473 PrerenderTestURL("prerender_page.html", FINAL_STATUS_USED, 1); | 529 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 474 | 530 |
| 475 // The prerender makes three. | 531 // The prerender makes three. |
| 476 EXPECT_EQ(3, model()->ResourceCount()); | 532 EXPECT_EQ(3, model()->ResourceCount()); |
| 477 | 533 |
| 478 // It shouldn't have a TabContents associated with it. | 534 // It shouldn't have a TabContents associated with it. |
| 479 ASSERT_TRUE(model()->GetResourceTabContents(1) == NULL); | 535 ASSERT_TRUE(model()->GetResourceTabContents(1) == NULL); |
| 480 | 536 |
| 481 // The prefix should be "Prerender:" | 537 // The prefix should be "Prerender:" |
| 482 string16 prefix = | 538 string16 prefix = |
| 483 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, | 539 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, |
| 484 string16()); | 540 string16()); |
| 485 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(1), prefix, true)); | 541 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(1), prefix, true)); |
| 486 | 542 |
| 487 NavigateToDestURL(); | 543 NavigateToDestURL(); |
| 488 | 544 |
| 489 // Prerender task should be killed and removed from the Task Manager. | 545 // Prerender task should be killed and removed from the Task Manager. |
| 490 EXPECT_EQ(2, model()->ResourceCount()); | 546 EXPECT_EQ(2, model()->ResourceCount()); |
| 491 } | 547 } |
| 492 | 548 |
| 493 // Checks that prerenderers will terminate when an audio tag is encountered. | 549 // Checks that prerenderers will terminate when an audio tag is encountered. |
| 494 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5Audio) { | 550 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5Audio) { |
| 495 PrerenderTestURL("prerender_html5_audio.html", FINAL_STATUS_HTML5_MEDIA, 1); | 551 PrerenderTestURL("files/prerender/prerender_html5_audio.html", |
| 552 FINAL_STATUS_HTML5_MEDIA, |
| 553 1); |
| 496 } | 554 } |
| 497 | 555 |
| 498 // Checks that prerenderers will terminate when a video tag is encountered. | 556 // Checks that prerenderers will terminate when a video tag is encountered. |
| 499 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5Video) { | 557 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5Video) { |
| 500 PrerenderTestURL("prerender_html5_video.html", FINAL_STATUS_HTML5_MEDIA, 1); | 558 PrerenderTestURL("files/prerender/prerender_html5_video.html", |
| 559 FINAL_STATUS_HTML5_MEDIA, |
| 560 1); |
| 501 } | 561 } |
| 502 | 562 |
| 503 // Checks that prerenderers will terminate when a video tag is inserted via | 563 // Checks that prerenderers will terminate when a video tag is inserted via |
| 504 // javascript. | 564 // javascript. |
| 505 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5VideoJs) { | 565 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5VideoJs) { |
| 506 PrerenderTestURL("prerender_html5_video_script.html", | 566 PrerenderTestURL("files/prerender/prerender_html5_video_script.html", |
| 507 FINAL_STATUS_HTML5_MEDIA, 1); | 567 FINAL_STATUS_HTML5_MEDIA, |
| 568 1); |
| 508 } | 569 } |
| 509 | 570 |
| 510 } // namespace prerender | 571 } // namespace prerender |
| OLD | NEW |