OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <deque> | 5 #include <deque> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 2968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2979 } | 2979 } |
2980 | 2980 |
2981 // Checks that we cancel correctly when window.print() is called. | 2981 // Checks that we cancel correctly when window.print() is called. |
2982 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPrint) { | 2982 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPrint) { |
2983 DisableLoadEventCheck(); | 2983 DisableLoadEventCheck(); |
2984 PrerenderTestURL("files/prerender/prerender_print.html", | 2984 PrerenderTestURL("files/prerender/prerender_print.html", |
2985 FINAL_STATUS_WINDOW_PRINT, | 2985 FINAL_STATUS_WINDOW_PRINT, |
2986 0); | 2986 0); |
2987 } | 2987 } |
2988 | 2988 |
2989 // Checks that if a page is opened in a new window by javascript and both the | |
2990 // pages are in the same domain, the prerendered page is not used, due to | |
2991 // there being other tabs in the same browsing instance. | |
2992 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
2993 PrerenderSameDomainWindowOpenerWindowOpen) { | |
2994 PrerenderTestURL("files/prerender/prerender_page.html", | |
2995 FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE, | |
2996 1); | |
2997 OpenDestURLViaWindowOpen(); | |
2998 } | |
2999 | |
3000 // Checks that if a page is opened due to click on a href with target="_blank" | |
3001 // and both pages are in the same domain the prerendered page is not used, due | |
3002 // there being other tabs in the same browsing instance. | |
3003 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
3004 PrerenderSameDomainWindowOpenerClickTarget) { | |
3005 PrerenderTestURL("files/prerender/prerender_page.html", | |
3006 FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE, | |
3007 1); | |
3008 OpenDestURLViaClickTarget(); | |
3009 } | |
3010 | |
3011 // Checks that prerenders do not get swapped into target pages that have opened | 2989 // Checks that prerenders do not get swapped into target pages that have opened |
3012 // a popup, even if the target page itself does not have an opener. | 2990 // popups; the BrowsingInstance is not empty. |
3013 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTargetHasPopup) { | 2991 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTargetHasPopup) { |
3014 PrerenderTestURL("files/prerender/prerender_page.html", | 2992 PrerenderTestURL("files/prerender/prerender_page.html", |
3015 FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE, | 2993 FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE, |
3016 1); | 2994 1); |
3017 OpenURLViaWindowOpen(GURL(url::kAboutBlankURL)); | 2995 OpenURLViaWindowOpen(GURL(url::kAboutBlankURL)); |
| 2996 |
| 2997 // Switch back to the current tab and attempt to swap it in. |
| 2998 current_browser()->tab_strip_model()->ActivateTabAt(0, true); |
3018 NavigateToDestURLWithDisposition(CURRENT_TAB, false); | 2999 NavigateToDestURLWithDisposition(CURRENT_TAB, false); |
3019 } | 3000 } |
3020 | 3001 |
3021 class TestClientCertStore : public net::ClientCertStore { | 3002 class TestClientCertStore : public net::ClientCertStore { |
3022 public: | 3003 public: |
3023 TestClientCertStore() {} | 3004 TestClientCertStore() {} |
3024 ~TestClientCertStore() override {} | 3005 ~TestClientCertStore() override {} |
3025 | 3006 |
3026 // net::ClientCertStore: | 3007 // net::ClientCertStore: |
3027 void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info, | 3008 void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info, |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3365 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNavigateGoBack) { | 3346 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNavigateGoBack) { |
3366 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 3347 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
3367 FINAL_STATUS_USED, | 3348 FINAL_STATUS_USED, |
3368 1); | 3349 1); |
3369 OpenDestURLViaClick(); | 3350 OpenDestURLViaClick(); |
3370 NavigateToNextPageAfterPrerender(); | 3351 NavigateToNextPageAfterPrerender(); |
3371 GoBackToPrerender(); | 3352 GoBackToPrerender(); |
3372 } | 3353 } |
3373 | 3354 |
3374 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewWindow) { | 3355 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewWindow) { |
3375 // Prerender currently doesn't interpose on this navigation. | |
3376 // http://crbug.com/345474. | |
3377 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 3356 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
3378 FINAL_STATUS_USED, | 3357 FINAL_STATUS_APP_TERMINATING, 1); |
3379 1); | |
3380 OpenDestURLViaClickNewWindow(); | 3358 OpenDestURLViaClickNewWindow(); |
3381 } | 3359 } |
3382 | 3360 |
3383 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewForegroundTab) { | 3361 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewForegroundTab) { |
3384 // Prerender currently doesn't interpose on this navigation. | |
3385 // http://crbug.com/345474. | |
3386 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 3362 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
3387 FINAL_STATUS_USED, | 3363 FINAL_STATUS_APP_TERMINATING, 1); |
3388 1); | |
3389 OpenDestURLViaClickNewForegroundTab(); | 3364 OpenDestURLViaClickNewForegroundTab(); |
3390 } | 3365 } |
3391 | 3366 |
3392 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 3367 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
3393 NavigateToPrerenderedPageWhenDevToolsAttached) { | 3368 NavigateToPrerenderedPageWhenDevToolsAttached) { |
3394 DisableJavascriptCalls(); | 3369 DisableJavascriptCalls(); |
3395 WebContents* web_contents = | 3370 WebContents* web_contents = |
3396 current_browser()->tab_strip_model()->GetActiveWebContents(); | 3371 current_browser()->tab_strip_model()->GetActiveWebContents(); |
3397 scoped_refptr<DevToolsAgentHost> agent( | 3372 scoped_refptr<DevToolsAgentHost> agent( |
3398 DevToolsAgentHost::GetOrCreateFor(web_contents)); | 3373 DevToolsAgentHost::GetOrCreateFor(web_contents)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3462 "Prerender.websame_PrerenderNotSwappedInPLT", 1); | 3437 "Prerender.websame_PrerenderNotSwappedInPLT", 1); |
3463 | 3438 |
3464 NavigateToDestURL(); | 3439 NavigateToDestURL(); |
3465 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1); | 3440 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1); |
3466 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", | 3441 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", |
3467 0); | 3442 0); |
3468 histogram_tester().ExpectTotalCount( | 3443 histogram_tester().ExpectTotalCount( |
3469 "Prerender.websame_PerceivedPLTMatchedComplete", 1); | 3444 "Prerender.websame_PerceivedPLTMatchedComplete", 1); |
3470 } | 3445 } |
3471 | 3446 |
3472 // Verify that a navigation that hits a MatchComplete dummy while another is in | |
3473 // progress does not also classify the previous navigation as a MatchComplete. | |
3474 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
3475 MatchCompleteDummyCancelNavigation) { | |
3476 RestorePrerenderMode restore_prerender_mode; | |
3477 PrerenderManager::SetMode( | |
3478 PrerenderManager::PRERENDER_MODE_EXPERIMENT_MATCH_COMPLETE_GROUP); | |
3479 | |
3480 // Arrange for a URL to hang. | |
3481 const GURL kNoCommitUrl("http://never-respond.example.com"); | |
3482 base::FilePath file(FILE_PATH_LITERAL( | |
3483 "chrome/test/data/prerender/prerender_page.html")); | |
3484 base::RunLoop hang_loop; | |
3485 BrowserThread::PostTask( | |
3486 BrowserThread::IO, FROM_HERE, | |
3487 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, kNoCommitUrl, | |
3488 file, hang_loop.QuitClosure())); | |
3489 | |
3490 // First, fire a prerender that aborts after it completes its load. | |
3491 std::vector<FinalStatus> expected_final_status_queue; | |
3492 expected_final_status_queue.push_back(FINAL_STATUS_INVALID_HTTP_METHOD); | |
3493 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED); | |
3494 PrerenderTestURL("files/prerender/prerender_xhr_put.html", | |
3495 expected_final_status_queue, 1); | |
3496 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1); | |
3497 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); | |
3498 histogram_tester().ExpectTotalCount( | |
3499 "Prerender.none_PerceivedPLTMatchedComplete", 0); | |
3500 histogram_tester().ExpectTotalCount( | |
3501 "Prerender.websame_PrerenderNotSwappedInPLT", 1); | |
3502 | |
3503 // Open the hanging URL in a new tab. Wait for both the new tab to open and | |
3504 // the hanging request to be scheduled. | |
3505 ui_test_utils::NavigateToURLWithDisposition( | |
3506 current_browser(), kNoCommitUrl, NEW_FOREGROUND_TAB, | |
3507 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | |
3508 hang_loop.Run(); | |
3509 | |
3510 // Now interrupt that navigation and navigate to the destination URL. This | |
3511 // should forcibly complete the previous navigation and also complete a | |
3512 // WOULD_HAVE_BEEN_PRERENDERED navigation. | |
3513 NavigateToDestURL(); | |
3514 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 2); | |
3515 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); | |
3516 histogram_tester().ExpectTotalCount( | |
3517 "Prerender.none_PerceivedPLTMatchedComplete", 0); | |
3518 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1); | |
3519 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", | |
3520 0); | |
3521 histogram_tester().ExpectTotalCount( | |
3522 "Prerender.websame_PerceivedPLTMatchedComplete", 1); | |
3523 } | |
3524 | |
3525 class PrerenderBrowserTestWithNaCl : public PrerenderBrowserTest { | 3447 class PrerenderBrowserTestWithNaCl : public PrerenderBrowserTest { |
3526 public: | 3448 public: |
3527 PrerenderBrowserTestWithNaCl() {} | 3449 PrerenderBrowserTestWithNaCl() {} |
3528 ~PrerenderBrowserTestWithNaCl() override {} | 3450 ~PrerenderBrowserTestWithNaCl() override {} |
3529 | 3451 |
3530 void SetUpCommandLine(base::CommandLine* command_line) override { | 3452 void SetUpCommandLine(base::CommandLine* command_line) override { |
3531 PrerenderBrowserTest::SetUpCommandLine(command_line); | 3453 PrerenderBrowserTest::SetUpCommandLine(command_line); |
3532 command_line->AppendSwitch(switches::kEnableNaCl); | 3454 command_line->AppendSwitch(switches::kEnableNaCl); |
3533 } | 3455 } |
3534 }; | 3456 }; |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4039 } | 3961 } |
4040 | 3962 |
4041 // Checks that the prerendering of a page is canceled correctly when the | 3963 // Checks that the prerendering of a page is canceled correctly when the |
4042 // prerendered page tries to make a second navigation entry. | 3964 // prerendered page tries to make a second navigation entry. |
4043 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNewNavigationEntry) { | 3965 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNewNavigationEntry) { |
4044 PrerenderTestURL("files/prerender/prerender_new_entry.html", | 3966 PrerenderTestURL("files/prerender/prerender_new_entry.html", |
4045 FINAL_STATUS_NEW_NAVIGATION_ENTRY, | 3967 FINAL_STATUS_NEW_NAVIGATION_ENTRY, |
4046 1); | 3968 1); |
4047 } | 3969 } |
4048 | 3970 |
4049 // Attempt a swap-in in a new tab, verifying that session storage namespace | 3971 // Attempt a swap-in in a new tab. The session storage doesn't match, so it |
4050 // merging works. | 3972 // should not swap. |
4051 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageNewTab) { | 3973 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageNewTab) { |
4052 // Mock out some URLs and count the number of requests to one of them. Both | 3974 PrerenderTestURL("files/prerender/prerender_page.html", |
4053 // prerender_session_storage.html and init_session_storage.html need to be | |
4054 // mocked so they are same-origin. | |
4055 const GURL kInitURL("http://prerender.test/init_session_storage.html"); | |
4056 base::FilePath init_file = GetTestPath("init_session_storage.html"); | |
4057 BrowserThread::PostTask( | |
4058 BrowserThread::IO, FROM_HERE, | |
4059 base::Bind(&CreateMockInterceptorOnIO, kInitURL, init_file)); | |
4060 | |
4061 const GURL kTestURL("http://prerender.test/prerender_session_storage.html"); | |
4062 base::FilePath test_file = GetTestPath("prerender_session_storage.html"); | |
4063 RequestCounter counter; | |
4064 BrowserThread::PostTask( | |
4065 BrowserThread::IO, FROM_HERE, | |
4066 base::Bind(&CreateCountingInterceptorOnIO, | |
4067 kTestURL, test_file, counter.AsWeakPtr())); | |
4068 | |
4069 PrerenderTestURL(kTestURL, FINAL_STATUS_USED, 1); | |
4070 | |
4071 // Open a new tab to navigate in. | |
4072 ui_test_utils::NavigateToURLWithDisposition( | |
4073 current_browser(), kInitURL, NEW_FOREGROUND_TAB, | |
4074 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
4075 | |
4076 // Now navigate in the new tab. Set expect_swap_to_succeed to false because | |
4077 // the swap does not occur synchronously. | |
4078 // | |
4079 // TODO(davidben): When all swaps become asynchronous, remove the OpenURL | |
4080 // return value assertion and let this go through the usual successful-swap | |
4081 // codepath. | |
4082 NavigateToDestURLWithDisposition(CURRENT_TAB, false); | |
4083 | |
4084 // Verify DidDisplayPass manually since the previous call skipped it. | |
4085 EXPECT_TRUE(DidDisplayPass( | |
4086 current_browser()->tab_strip_model()->GetActiveWebContents())); | |
4087 | |
4088 // Only one request to the test URL started. | |
4089 // | |
4090 // TODO(davidben): Re-enable this check when the races in attaching the | |
4091 // throttle are resolved. http://crbug.com/335835 | |
4092 // EXPECT_EQ(1, counter.count()); | |
4093 } | |
4094 | |
4095 // Attempt a swap-in in a new tab, verifying that session storage namespace | |
4096 // merging works. Unlike the above test, the swap is for a navigation that would | |
4097 // normally be cross-process. | |
4098 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageNewTabCrossProcess) { | |
4099 base::FilePath test_data_dir; | |
4100 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); | |
4101 | |
4102 // Mock out some URLs and count the number of requests to one of them. Both | |
4103 // prerender_session_storage.html and init_session_storage.html need to be | |
4104 // mocked so they are same-origin. | |
4105 const GURL kInitURL("http://prerender.test/init_session_storage.html"); | |
4106 base::FilePath init_file = GetTestPath("init_session_storage.html"); | |
4107 BrowserThread::PostTask( | |
4108 BrowserThread::IO, FROM_HERE, | |
4109 base::Bind(&CreateMockInterceptorOnIO, kInitURL, init_file)); | |
4110 | |
4111 const GURL kTestURL("http://prerender.test/prerender_session_storage.html"); | |
4112 base::FilePath test_file = GetTestPath("prerender_session_storage.html"); | |
4113 RequestCounter counter; | |
4114 BrowserThread::PostTask( | |
4115 BrowserThread::IO, FROM_HERE, | |
4116 base::Bind(&CreateCountingInterceptorOnIO, | |
4117 kTestURL, test_file, counter.AsWeakPtr())); | |
4118 | |
4119 PrerenderTestURL(kTestURL, FINAL_STATUS_USED, 1); | |
4120 | |
4121 // Open a new tab to navigate in. | |
4122 ui_test_utils::NavigateToURLWithDisposition( | |
4123 current_browser(), kInitURL, NEW_FOREGROUND_TAB, | |
4124 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
4125 | |
4126 // Navigate to about:blank so the next navigation is cross-process. | |
4127 ui_test_utils::NavigateToURL(current_browser(), GURL(url::kAboutBlankURL)); | |
4128 | |
4129 // Now navigate in the new tab. Set expect_swap_to_succeed to false because | |
4130 // the swap does not occur synchronously. | |
4131 // | |
4132 // TODO(davidben): When all swaps become asynchronous, remove the OpenURL | |
4133 // return value assertion and let this go through the usual successful-swap | |
4134 // codepath. | |
4135 NavigateToDestURLWithDisposition(CURRENT_TAB, false); | |
4136 | |
4137 // Verify DidDisplayPass manually since the previous call skipped it. | |
4138 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents())); | |
4139 | |
4140 // Only one request to the test URL started. | |
4141 // | |
4142 // TODO(davidben): Re-enable this check when the races in attaching the | |
4143 // throttle are resolved. http://crbug.com/335835 | |
4144 // EXPECT_EQ(1, counter.count()); | |
4145 } | |
4146 | |
4147 // Verify that session storage conflicts don't merge. | |
4148 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderSessionStorageConflict) { | |
4149 PrerenderTestURL("files/prerender/prerender_session_storage_conflict.html", | |
4150 FINAL_STATUS_APP_TERMINATING, 1); | 3975 FINAL_STATUS_APP_TERMINATING, 1); |
4151 | 3976 |
4152 // Open a new tab to navigate in. | 3977 // Open a new tab to navigate in. |
4153 ui_test_utils::NavigateToURLWithDisposition( | 3978 ui_test_utils::NavigateToURLWithDisposition( |
4154 current_browser(), | 3979 current_browser(), GURL(url::kAboutBlankURL), NEW_FOREGROUND_TAB, |
4155 test_server()->GetURL("files/prerender/init_session_storage.html"), | |
4156 NEW_FOREGROUND_TAB, | |
4157 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 3980 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
4158 | 3981 |
4159 // Now navigate in the new tab. | 3982 // Now navigate in the new tab. |
4160 NavigateToDestURLWithDisposition(CURRENT_TAB, false); | 3983 NavigateToDestURLWithDisposition(CURRENT_TAB, false); |
4161 | |
4162 // Verify DidDisplayPass in the new tab. | |
4163 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents())); | |
4164 } | 3984 } |
4165 | 3985 |
4166 // Checks that prerenders honor |should_replace_current_entry|. | 3986 // Checks that prerenders honor |should_replace_current_entry|. |
4167 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReplaceCurrentEntry) { | 3987 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReplaceCurrentEntry) { |
4168 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 3988 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
4169 | 3989 |
4170 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB, | 3990 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB, |
4171 ui::PAGE_TRANSITION_TYPED, false); | 3991 ui::PAGE_TRANSITION_TYPED, false); |
4172 params.should_replace_current_entry = true; | 3992 params.should_replace_current_entry = true; |
4173 NavigateToURLWithParams(params, false); | 3993 NavigateToURLWithParams(params, false); |
4174 | 3994 |
4175 const NavigationController& controller = | 3995 const NavigationController& controller = |
4176 GetActiveWebContents()->GetController(); | 3996 GetActiveWebContents()->GetController(); |
4177 // First entry is about:blank, second is prerender_page.html. | 3997 // First entry is about:blank, second is prerender_page.html. |
4178 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 3998 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
4179 EXPECT_EQ(2, controller.GetEntryCount()); | 3999 EXPECT_EQ(2, controller.GetEntryCount()); |
4180 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetEntryAtIndex(0)->GetURL()); | 4000 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetEntryAtIndex(0)->GetURL()); |
4181 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL()); | 4001 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL()); |
4182 } | 4002 } |
4183 | 4003 |
4184 // Checks prerender does not hit DCHECKs and behaves properly if two pending | |
4185 // swaps occur in a row. | |
4186 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDoublePendingSwap) { | |
4187 GetPrerenderManager()->mutable_config().max_link_concurrency = 2; | |
4188 GetPrerenderManager()->mutable_config().max_link_concurrency_per_launcher = 2; | |
4189 | |
4190 GURL url1 = test_server()->GetURL("files/prerender/prerender_page.html?1"); | |
4191 scoped_ptr<TestPrerender> prerender1 = | |
4192 PrerenderTestURL(url1, FINAL_STATUS_APP_TERMINATING, 1); | |
4193 | |
4194 GURL url2 = test_server()->GetURL("files/prerender/prerender_page.html?2"); | |
4195 scoped_ptr<TestPrerender> prerender2 = ExpectPrerender(FINAL_STATUS_USED); | |
4196 AddPrerender(url2, 1); | |
4197 prerender2->WaitForStart(); | |
4198 prerender2->WaitForLoads(1); | |
4199 | |
4200 // There's no reason the second prerender can't be used, but the swap races | |
4201 // with didStartProvisionalLoad and didFailProvisionalLoad from the previous | |
4202 // navigation. The current logic will conservatively fail to swap under such | |
4203 // races. However, if the renderer is slow enough, it's possible for the | |
4204 // prerender to still be used, so don't program in either expectation. | |
4205 ASSERT_TRUE(prerender2->contents()); | |
4206 prerender2->contents()->set_skip_final_checks(true); | |
4207 | |
4208 // Open a new tab to navigate in. | |
4209 ui_test_utils::NavigateToURLWithDisposition( | |
4210 current_browser(), | |
4211 GURL(url::kAboutBlankURL), | |
4212 NEW_FOREGROUND_TAB, | |
4213 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
4214 | |
4215 // Fire off two navigations, without running the event loop between them. | |
4216 NavigationOrSwapObserver swap_observer( | |
4217 current_browser()->tab_strip_model(), | |
4218 GetActiveWebContents(), 2); | |
4219 current_browser()->OpenURL(OpenURLParams( | |
4220 url1, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | |
4221 current_browser()->OpenURL(OpenURLParams( | |
4222 url2, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | |
4223 swap_observer.Wait(); | |
4224 | |
4225 // The WebContents should be on url2. There may be 2 or 3 entries, depending | |
4226 // on whether the first one managed to complete. | |
4227 // | |
4228 // TODO(davidben): When http://crbug.com/335835 is fixed, the 3 entry case | |
4229 // shouldn't be possible because it's throttled by the pending swap that | |
4230 // cannot complete. | |
4231 const NavigationController& controller = | |
4232 GetActiveWebContents()->GetController(); | |
4233 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | |
4234 EXPECT_LE(2, controller.GetEntryCount()); | |
4235 EXPECT_GE(3, controller.GetEntryCount()); | |
4236 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetEntryAtIndex(0)->GetURL()); | |
4237 EXPECT_EQ(url2, controller.GetEntryAtIndex( | |
4238 controller.GetEntryCount() - 1)->GetURL()); | |
4239 } | |
4240 | |
4241 // Verify that pending swaps get aborted on new navigations. | |
4242 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
4243 PrerenderPendingSwapNewNavigation) { | |
4244 PrerenderManager::HangSessionStorageMergesForTesting(); | |
4245 | |
4246 PrerenderTestURL("files/prerender/prerender_page.html", | |
4247 FINAL_STATUS_APP_TERMINATING, 1); | |
4248 | |
4249 // Open a new tab to navigate in. | |
4250 ui_test_utils::NavigateToURLWithDisposition( | |
4251 current_browser(), | |
4252 GURL(url::kAboutBlankURL), | |
4253 NEW_FOREGROUND_TAB, | |
4254 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
4255 | |
4256 // Navigate to the URL. Wait for DidStartLoading, just so it's definitely | |
4257 // progressed somewhere. | |
4258 content::WindowedNotificationObserver page_load_observer( | |
4259 content::NOTIFICATION_LOAD_START, | |
4260 content::Source<NavigationController>( | |
4261 &GetActiveWebContents()->GetController())); | |
4262 current_browser()->OpenURL(OpenURLParams( | |
4263 dest_url(), Referrer(), CURRENT_TAB, | |
4264 ui::PAGE_TRANSITION_TYPED, false)); | |
4265 page_load_observer.Wait(); | |
4266 | |
4267 // Navigate somewhere else. This should succeed and abort the pending swap. | |
4268 TestNavigationObserver nav_observer(GetActiveWebContents()); | |
4269 current_browser()->OpenURL(OpenURLParams(GURL(url::kAboutBlankURL), | |
4270 Referrer(), | |
4271 CURRENT_TAB, | |
4272 ui::PAGE_TRANSITION_TYPED, | |
4273 false)); | |
4274 nav_observer.Wait(); | |
4275 } | |
4276 | |
4277 // Checks that <a ping> requests are not dropped in prerender. | 4004 // Checks that <a ping> requests are not dropped in prerender. |
4278 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) { | 4005 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) { |
4279 // Count hits to a certain URL. | 4006 // Count hits to a certain URL. |
4280 const GURL kPingURL("http://prerender.test/ping"); | 4007 const GURL kPingURL("http://prerender.test/ping"); |
4281 base::FilePath empty_file = ui_test_utils::GetTestFilePath( | 4008 base::FilePath empty_file = ui_test_utils::GetTestFilePath( |
4282 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); | 4009 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); |
4283 RequestCounter ping_counter; | 4010 RequestCounter ping_counter; |
4284 BrowserThread::PostTask( | 4011 BrowserThread::PostTask( |
4285 BrowserThread::IO, FROM_HERE, | 4012 BrowserThread::IO, FROM_HERE, |
4286 base::Bind(&CreateCountingInterceptorOnIO, | 4013 base::Bind(&CreateCountingInterceptorOnIO, |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4595 TestShouldDisableLocalPredictorPreferenceNetworkMatrix( | 4322 TestShouldDisableLocalPredictorPreferenceNetworkMatrix( |
4596 true /*preference_wifi_network_wifi*/, | 4323 true /*preference_wifi_network_wifi*/, |
4597 true /*preference_wifi_network_4g*/, | 4324 true /*preference_wifi_network_4g*/, |
4598 true /*preference_always_network_wifi*/, | 4325 true /*preference_always_network_wifi*/, |
4599 false /*preference_always_network_4g*/, | 4326 false /*preference_always_network_4g*/, |
4600 true /*preference_never_network_wifi*/, | 4327 true /*preference_never_network_wifi*/, |
4601 true /*preference_never_network_4g*/); | 4328 true /*preference_never_network_4g*/); |
4602 } | 4329 } |
4603 | 4330 |
4604 } // namespace prerender | 4331 } // namespace prerender |
OLD | NEW |