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

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 757723002: [Tests not passing yet] Remove prerender sessionStorage namespace merging. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years 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 | « no previous file | chrome/browser/prerender/prerender_contents.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2950 matching lines...) Expand 10 before | Expand all | Expand 10 after
2961 } 2961 }
2962 2962
2963 // Checks that we cancel correctly when window.print() is called. 2963 // Checks that we cancel correctly when window.print() is called.
2964 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPrint) { 2964 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPrint) {
2965 DisableLoadEventCheck(); 2965 DisableLoadEventCheck();
2966 PrerenderTestURL("files/prerender/prerender_print.html", 2966 PrerenderTestURL("files/prerender/prerender_print.html",
2967 FINAL_STATUS_WINDOW_PRINT, 2967 FINAL_STATUS_WINDOW_PRINT,
2968 0); 2968 0);
2969 } 2969 }
2970 2970
2971 // Checks that if a page is opened in a new window by javascript and both the
2972 // pages are in the same domain, the prerendered page is not used, due to
2973 // there being other tabs in the same browsing instance.
2974 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
2975 PrerenderSameDomainWindowOpenerWindowOpen) {
2976 PrerenderTestURL("files/prerender/prerender_page.html",
2977 FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE,
2978 1);
2979 OpenDestURLViaWindowOpen();
2980 }
2981
2982 // Checks that if a page is opened due to click on a href with target="_blank"
2983 // and both pages are in the same domain the prerendered page is not used, due
2984 // there being other tabs in the same browsing instance.
2985 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
2986 PrerenderSameDomainWindowOpenerClickTarget) {
2987 PrerenderTestURL("files/prerender/prerender_page.html",
2988 FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE,
2989 1);
2990 OpenDestURLViaClickTarget();
2991 }
2992
2993 // Checks that prerenders do not get swapped into target pages that have opened 2971 // Checks that prerenders do not get swapped into target pages that have opened
2994 // a popup, even if the target page itself does not have an opener. 2972 // popups; the BrowsingInstance is not empty.
2995 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTargetHasPopup) { 2973 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTargetHasPopup) {
2996 PrerenderTestURL("files/prerender/prerender_page.html", 2974 PrerenderTestURL("files/prerender/prerender_page.html",
2997 FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE, 2975 FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE,
2998 1); 2976 1);
2999 OpenURLViaWindowOpen(GURL(url::kAboutBlankURL)); 2977 OpenURLViaWindowOpen(GURL(url::kAboutBlankURL));
2978
2979 // Switch back to the current tab and attempt to swap it in.
2980 current_browser()->tab_strip_model()->ActivateTabAt(0, true);
3000 NavigateToDestURLWithDisposition(CURRENT_TAB, false); 2981 NavigateToDestURLWithDisposition(CURRENT_TAB, false);
3001 } 2982 }
3002 2983
3003 class TestClientCertStore : public net::ClientCertStore { 2984 class TestClientCertStore : public net::ClientCertStore {
3004 public: 2985 public:
3005 TestClientCertStore() {} 2986 TestClientCertStore() {}
3006 ~TestClientCertStore() override {} 2987 ~TestClientCertStore() override {}
3007 2988
3008 // net::ClientCertStore: 2989 // net::ClientCertStore:
3009 void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info, 2990 void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info,
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
3347 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNavigateGoBack) { 3328 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNavigateGoBack) {
3348 PrerenderTestURL("files/prerender/prerender_page_with_link.html", 3329 PrerenderTestURL("files/prerender/prerender_page_with_link.html",
3349 FINAL_STATUS_USED, 3330 FINAL_STATUS_USED,
3350 1); 3331 1);
3351 OpenDestURLViaClick(); 3332 OpenDestURLViaClick();
3352 NavigateToNextPageAfterPrerender(); 3333 NavigateToNextPageAfterPrerender();
3353 GoBackToPrerender(); 3334 GoBackToPrerender();
3354 } 3335 }
3355 3336
3356 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewWindow) { 3337 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewWindow) {
3357 // Prerender currently doesn't interpose on this navigation.
3358 // http://crbug.com/345474.
3359 PrerenderTestURL("files/prerender/prerender_page_with_link.html", 3338 PrerenderTestURL("files/prerender/prerender_page_with_link.html",
3360 FINAL_STATUS_USED, 3339 FINAL_STATUS_APP_TERMINATING, 1);
3361 1);
3362 OpenDestURLViaClickNewWindow(); 3340 OpenDestURLViaClickNewWindow();
3363 } 3341 }
3364 3342
3365 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewForegroundTab) { 3343 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewForegroundTab) {
3366 // Prerender currently doesn't interpose on this navigation.
3367 // http://crbug.com/345474.
3368 PrerenderTestURL("files/prerender/prerender_page_with_link.html", 3344 PrerenderTestURL("files/prerender/prerender_page_with_link.html",
3369 FINAL_STATUS_USED, 3345 FINAL_STATUS_APP_TERMINATING, 1);
3370 1);
3371 OpenDestURLViaClickNewForegroundTab(); 3346 OpenDestURLViaClickNewForegroundTab();
3372 } 3347 }
3373 3348
3374 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 3349 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
3375 NavigateToPrerenderedPageWhenDevToolsAttached) { 3350 NavigateToPrerenderedPageWhenDevToolsAttached) {
3376 DisableJavascriptCalls(); 3351 DisableJavascriptCalls();
3377 WebContents* web_contents = 3352 WebContents* web_contents =
3378 current_browser()->tab_strip_model()->GetActiveWebContents(); 3353 current_browser()->tab_strip_model()->GetActiveWebContents();
3379 scoped_refptr<DevToolsAgentHost> agent( 3354 scoped_refptr<DevToolsAgentHost> agent(
3380 DevToolsAgentHost::GetOrCreateFor(web_contents)); 3355 DevToolsAgentHost::GetOrCreateFor(web_contents));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3444 "Prerender.websame_PrerenderNotSwappedInPLT", 1); 3419 "Prerender.websame_PrerenderNotSwappedInPLT", 1);
3445 3420
3446 NavigateToDestURL(); 3421 NavigateToDestURL();
3447 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1); 3422 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
3448 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", 3423 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched",
3449 0); 3424 0);
3450 histogram_tester().ExpectTotalCount( 3425 histogram_tester().ExpectTotalCount(
3451 "Prerender.websame_PerceivedPLTMatchedComplete", 1); 3426 "Prerender.websame_PerceivedPLTMatchedComplete", 1);
3452 } 3427 }
3453 3428
3454 // Verify that a navigation that hits a MatchComplete dummy while another is in
3455 // progress does not also classify the previous navigation as a MatchComplete.
3456 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
3457 MatchCompleteDummyCancelNavigation) {
3458 RestorePrerenderMode restore_prerender_mode;
3459 PrerenderManager::SetMode(
3460 PrerenderManager::PRERENDER_MODE_EXPERIMENT_MATCH_COMPLETE_GROUP);
3461
3462 // Arrange for a URL to hang.
3463 const GURL kNoCommitUrl("http://never-respond.example.com");
3464 base::FilePath file(FILE_PATH_LITERAL(
3465 "chrome/test/data/prerender/prerender_page.html"));
3466 base::RunLoop hang_loop;
3467 BrowserThread::PostTask(
3468 BrowserThread::IO, FROM_HERE,
3469 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, kNoCommitUrl,
3470 file, hang_loop.QuitClosure()));
3471
3472 // First, fire a prerender that aborts after it completes its load.
3473 std::vector<FinalStatus> expected_final_status_queue;
3474 expected_final_status_queue.push_back(FINAL_STATUS_INVALID_HTTP_METHOD);
3475 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED);
3476 PrerenderTestURL("files/prerender/prerender_xhr_put.html",
3477 expected_final_status_queue, 1);
3478 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
3479 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
3480 histogram_tester().ExpectTotalCount(
3481 "Prerender.none_PerceivedPLTMatchedComplete", 0);
3482 histogram_tester().ExpectTotalCount(
3483 "Prerender.websame_PrerenderNotSwappedInPLT", 1);
3484
3485 // Open the hanging URL in a new tab. Wait for both the new tab to open and
3486 // the hanging request to be scheduled.
3487 ui_test_utils::NavigateToURLWithDisposition(
3488 current_browser(), kNoCommitUrl, NEW_FOREGROUND_TAB,
3489 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
3490 hang_loop.Run();
3491
3492 // Now interrupt that navigation and navigate to the destination URL. This
3493 // should forcibly complete the previous navigation and also complete a
3494 // WOULD_HAVE_BEEN_PRERENDERED navigation.
3495 NavigateToDestURL();
3496 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 2);
3497 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
3498 histogram_tester().ExpectTotalCount(
3499 "Prerender.none_PerceivedPLTMatchedComplete", 0);
3500 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
3501 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched",
3502 0);
3503 histogram_tester().ExpectTotalCount(
3504 "Prerender.websame_PerceivedPLTMatchedComplete", 1);
3505 }
3506
3507 class PrerenderBrowserTestWithNaCl : public PrerenderBrowserTest { 3429 class PrerenderBrowserTestWithNaCl : public PrerenderBrowserTest {
3508 public: 3430 public:
3509 PrerenderBrowserTestWithNaCl() {} 3431 PrerenderBrowserTestWithNaCl() {}
3510 ~PrerenderBrowserTestWithNaCl() override {} 3432 ~PrerenderBrowserTestWithNaCl() override {}
3511 3433
3512 void SetUpCommandLine(CommandLine* command_line) override { 3434 void SetUpCommandLine(CommandLine* command_line) override {
3513 PrerenderBrowserTest::SetUpCommandLine(command_line); 3435 PrerenderBrowserTest::SetUpCommandLine(command_line);
3514 command_line->AppendSwitch(switches::kEnableNaCl); 3436 command_line->AppendSwitch(switches::kEnableNaCl);
3515 } 3437 }
3516 }; 3438 };
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
4020 } 3942 }
4021 3943
4022 // Checks that the prerendering of a page is canceled correctly when the 3944 // Checks that the prerendering of a page is canceled correctly when the
4023 // prerendered page tries to make a second navigation entry. 3945 // prerendered page tries to make a second navigation entry.
4024 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNewNavigationEntry) { 3946 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNewNavigationEntry) {
4025 PrerenderTestURL("files/prerender/prerender_new_entry.html", 3947 PrerenderTestURL("files/prerender/prerender_new_entry.html",
4026 FINAL_STATUS_NEW_NAVIGATION_ENTRY, 3948 FINAL_STATUS_NEW_NAVIGATION_ENTRY,
4027 1); 3949 1);
4028 } 3950 }
4029 3951
4030 // Attempt a swap-in in a new tab, verifying that session storage namespace 3952 // Attempt a swap-in in a new tab. The session storage doesn't match, so it
4031 // merging works. 3953 // should not swap.
4032 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageNewTab) { 3954 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageNewTab) {
4033 // Mock out some URLs and count the number of requests to one of them. Both 3955 PrerenderTestURL("files/prerender/prerender_page.html",
4034 // prerender_session_storage.html and init_session_storage.html need to be
4035 // mocked so they are same-origin.
4036 const GURL kInitURL("http://prerender.test/init_session_storage.html");
4037 base::FilePath init_file = GetTestPath("init_session_storage.html");
4038 BrowserThread::PostTask(
4039 BrowserThread::IO, FROM_HERE,
4040 base::Bind(&CreateMockInterceptorOnIO, kInitURL, init_file));
4041
4042 const GURL kTestURL("http://prerender.test/prerender_session_storage.html");
4043 base::FilePath test_file = GetTestPath("prerender_session_storage.html");
4044 RequestCounter counter;
4045 BrowserThread::PostTask(
4046 BrowserThread::IO, FROM_HERE,
4047 base::Bind(&CreateCountingInterceptorOnIO,
4048 kTestURL, test_file, counter.AsWeakPtr()));
4049
4050 PrerenderTestURL(kTestURL, FINAL_STATUS_USED, 1);
4051
4052 // Open a new tab to navigate in.
4053 ui_test_utils::NavigateToURLWithDisposition(
4054 current_browser(), kInitURL, NEW_FOREGROUND_TAB,
4055 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
4056
4057 // Now navigate in the new tab. Set expect_swap_to_succeed to false because
4058 // the swap does not occur synchronously.
4059 //
4060 // TODO(davidben): When all swaps become asynchronous, remove the OpenURL
4061 // return value assertion and let this go through the usual successful-swap
4062 // codepath.
4063 NavigateToDestURLWithDisposition(CURRENT_TAB, false);
4064
4065 // Verify DidDisplayPass manually since the previous call skipped it.
4066 EXPECT_TRUE(DidDisplayPass(
4067 current_browser()->tab_strip_model()->GetActiveWebContents()));
4068
4069 // Only one request to the test URL started.
4070 //
4071 // TODO(davidben): Re-enable this check when the races in attaching the
4072 // throttle are resolved. http://crbug.com/335835
4073 // EXPECT_EQ(1, counter.count());
4074 }
4075
4076 // Attempt a swap-in in a new tab, verifying that session storage namespace
4077 // merging works. Unlike the above test, the swap is for a navigation that would
4078 // normally be cross-process.
4079 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageNewTabCrossProcess) {
4080 base::FilePath test_data_dir;
4081 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
4082
4083 // Mock out some URLs and count the number of requests to one of them. Both
4084 // prerender_session_storage.html and init_session_storage.html need to be
4085 // mocked so they are same-origin.
4086 const GURL kInitURL("http://prerender.test/init_session_storage.html");
4087 base::FilePath init_file = GetTestPath("init_session_storage.html");
4088 BrowserThread::PostTask(
4089 BrowserThread::IO, FROM_HERE,
4090 base::Bind(&CreateMockInterceptorOnIO, kInitURL, init_file));
4091
4092 const GURL kTestURL("http://prerender.test/prerender_session_storage.html");
4093 base::FilePath test_file = GetTestPath("prerender_session_storage.html");
4094 RequestCounter counter;
4095 BrowserThread::PostTask(
4096 BrowserThread::IO, FROM_HERE,
4097 base::Bind(&CreateCountingInterceptorOnIO,
4098 kTestURL, test_file, counter.AsWeakPtr()));
4099
4100 PrerenderTestURL(kTestURL, FINAL_STATUS_USED, 1);
4101
4102 // Open a new tab to navigate in.
4103 ui_test_utils::NavigateToURLWithDisposition(
4104 current_browser(), kInitURL, NEW_FOREGROUND_TAB,
4105 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
4106
4107 // Navigate to about:blank so the next navigation is cross-process.
4108 ui_test_utils::NavigateToURL(current_browser(), GURL(url::kAboutBlankURL));
4109
4110 // Now navigate in the new tab. Set expect_swap_to_succeed to false because
4111 // the swap does not occur synchronously.
4112 //
4113 // TODO(davidben): When all swaps become asynchronous, remove the OpenURL
4114 // return value assertion and let this go through the usual successful-swap
4115 // codepath.
4116 NavigateToDestURLWithDisposition(CURRENT_TAB, false);
4117
4118 // Verify DidDisplayPass manually since the previous call skipped it.
4119 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents()));
4120
4121 // Only one request to the test URL started.
4122 //
4123 // TODO(davidben): Re-enable this check when the races in attaching the
4124 // throttle are resolved. http://crbug.com/335835
4125 // EXPECT_EQ(1, counter.count());
4126 }
4127
4128 // Verify that session storage conflicts don't merge.
4129 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderSessionStorageConflict) {
4130 PrerenderTestURL("files/prerender/prerender_session_storage_conflict.html",
4131 FINAL_STATUS_APP_TERMINATING, 1); 3956 FINAL_STATUS_APP_TERMINATING, 1);
4132 3957
4133 // Open a new tab to navigate in. 3958 // Open a new tab to navigate in.
4134 ui_test_utils::NavigateToURLWithDisposition( 3959 ui_test_utils::NavigateToURLWithDisposition(
4135 current_browser(), 3960 current_browser(), GURL(url::kAboutBlankURL), NEW_FOREGROUND_TAB,
4136 test_server()->GetURL("files/prerender/init_session_storage.html"),
4137 NEW_FOREGROUND_TAB,
4138 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 3961 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
4139 3962
4140 // Now navigate in the new tab. 3963 // Now navigate in the new tab.
4141 NavigateToDestURLWithDisposition(CURRENT_TAB, false); 3964 NavigateToDestURLWithDisposition(CURRENT_TAB, false);
4142
4143 // Verify DidDisplayPass in the new tab.
4144 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents()));
4145 } 3965 }
4146 3966
4147 // Checks that prerenders honor |should_replace_current_entry|. 3967 // Checks that prerenders honor |should_replace_current_entry|.
4148 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReplaceCurrentEntry) { 3968 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReplaceCurrentEntry) {
4149 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 3969 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
4150 3970
4151 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB, 3971 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB,
4152 ui::PAGE_TRANSITION_TYPED, false); 3972 ui::PAGE_TRANSITION_TYPED, false);
4153 params.should_replace_current_entry = true; 3973 params.should_replace_current_entry = true;
4154 NavigateToURLWithParams(params, false); 3974 NavigateToURLWithParams(params, false);
4155 3975
4156 const NavigationController& controller = 3976 const NavigationController& controller =
4157 GetActiveWebContents()->GetController(); 3977 GetActiveWebContents()->GetController();
4158 // First entry is about:blank, second is prerender_page.html. 3978 // First entry is about:blank, second is prerender_page.html.
4159 EXPECT_TRUE(controller.GetPendingEntry() == NULL); 3979 EXPECT_TRUE(controller.GetPendingEntry() == NULL);
4160 EXPECT_EQ(2, controller.GetEntryCount()); 3980 EXPECT_EQ(2, controller.GetEntryCount());
4161 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetEntryAtIndex(0)->GetURL()); 3981 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetEntryAtIndex(0)->GetURL());
4162 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL()); 3982 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL());
4163 } 3983 }
4164 3984
4165 // Checks prerender does not hit DCHECKs and behaves properly if two pending
4166 // swaps occur in a row.
4167 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDoublePendingSwap) {
4168 GetPrerenderManager()->mutable_config().max_link_concurrency = 2;
4169 GetPrerenderManager()->mutable_config().max_link_concurrency_per_launcher = 2;
4170
4171 GURL url1 = test_server()->GetURL("files/prerender/prerender_page.html?1");
4172 scoped_ptr<TestPrerender> prerender1 =
4173 PrerenderTestURL(url1, FINAL_STATUS_APP_TERMINATING, 1);
4174
4175 GURL url2 = test_server()->GetURL("files/prerender/prerender_page.html?2");
4176 scoped_ptr<TestPrerender> prerender2 = ExpectPrerender(FINAL_STATUS_USED);
4177 AddPrerender(url2, 1);
4178 prerender2->WaitForStart();
4179 prerender2->WaitForLoads(1);
4180
4181 // There's no reason the second prerender can't be used, but the swap races
4182 // with didStartProvisionalLoad and didFailProvisionalLoad from the previous
4183 // navigation. The current logic will conservatively fail to swap under such
4184 // races. However, if the renderer is slow enough, it's possible for the
4185 // prerender to still be used, so don't program in either expectation.
4186 ASSERT_TRUE(prerender2->contents());
4187 prerender2->contents()->set_skip_final_checks(true);
4188
4189 // Open a new tab to navigate in.
4190 ui_test_utils::NavigateToURLWithDisposition(
4191 current_browser(),
4192 GURL(url::kAboutBlankURL),
4193 NEW_FOREGROUND_TAB,
4194 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
4195
4196 // Fire off two navigations, without running the event loop between them.
4197 NavigationOrSwapObserver swap_observer(
4198 current_browser()->tab_strip_model(),
4199 GetActiveWebContents(), 2);
4200 current_browser()->OpenURL(OpenURLParams(
4201 url1, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
4202 current_browser()->OpenURL(OpenURLParams(
4203 url2, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
4204 swap_observer.Wait();
4205
4206 // The WebContents should be on url2. There may be 2 or 3 entries, depending
4207 // on whether the first one managed to complete.
4208 //
4209 // TODO(davidben): When http://crbug.com/335835 is fixed, the 3 entry case
4210 // shouldn't be possible because it's throttled by the pending swap that
4211 // cannot complete.
4212 const NavigationController& controller =
4213 GetActiveWebContents()->GetController();
4214 EXPECT_TRUE(controller.GetPendingEntry() == NULL);
4215 EXPECT_LE(2, controller.GetEntryCount());
4216 EXPECT_GE(3, controller.GetEntryCount());
4217 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetEntryAtIndex(0)->GetURL());
4218 EXPECT_EQ(url2, controller.GetEntryAtIndex(
4219 controller.GetEntryCount() - 1)->GetURL());
4220 }
4221
4222 // Verify that pending swaps get aborted on new navigations.
4223 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
4224 PrerenderPendingSwapNewNavigation) {
4225 PrerenderManager::HangSessionStorageMergesForTesting();
4226
4227 PrerenderTestURL("files/prerender/prerender_page.html",
4228 FINAL_STATUS_APP_TERMINATING, 1);
4229
4230 // Open a new tab to navigate in.
4231 ui_test_utils::NavigateToURLWithDisposition(
4232 current_browser(),
4233 GURL(url::kAboutBlankURL),
4234 NEW_FOREGROUND_TAB,
4235 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
4236
4237 // Navigate to the URL. Wait for DidStartLoading, just so it's definitely
4238 // progressed somewhere.
4239 content::WindowedNotificationObserver page_load_observer(
4240 content::NOTIFICATION_LOAD_START,
4241 content::Source<NavigationController>(
4242 &GetActiveWebContents()->GetController()));
4243 current_browser()->OpenURL(OpenURLParams(
4244 dest_url(), Referrer(), CURRENT_TAB,
4245 ui::PAGE_TRANSITION_TYPED, false));
4246 page_load_observer.Wait();
4247
4248 // Navigate somewhere else. This should succeed and abort the pending swap.
4249 TestNavigationObserver nav_observer(GetActiveWebContents());
4250 current_browser()->OpenURL(OpenURLParams(GURL(url::kAboutBlankURL),
4251 Referrer(),
4252 CURRENT_TAB,
4253 ui::PAGE_TRANSITION_TYPED,
4254 false));
4255 nav_observer.Wait();
4256 }
4257
4258 // Checks that <a ping> requests are not dropped in prerender. 3985 // Checks that <a ping> requests are not dropped in prerender.
4259 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) { 3986 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) {
4260 // Count hits to a certain URL. 3987 // Count hits to a certain URL.
4261 const GURL kPingURL("http://prerender.test/ping"); 3988 const GURL kPingURL("http://prerender.test/ping");
4262 base::FilePath empty_file = ui_test_utils::GetTestFilePath( 3989 base::FilePath empty_file = ui_test_utils::GetTestFilePath(
4263 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); 3990 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html")));
4264 RequestCounter ping_counter; 3991 RequestCounter ping_counter;
4265 BrowserThread::PostTask( 3992 BrowserThread::PostTask(
4266 BrowserThread::IO, FROM_HERE, 3993 BrowserThread::IO, FROM_HERE,
4267 base::Bind(&CreateCountingInterceptorOnIO, 3994 base::Bind(&CreateCountingInterceptorOnIO,
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
4576 TestShouldDisableLocalPredictorPreferenceNetworkMatrix( 4303 TestShouldDisableLocalPredictorPreferenceNetworkMatrix(
4577 true /*preference_wifi_network_wifi*/, 4304 true /*preference_wifi_network_wifi*/,
4578 true /*preference_wifi_network_4g*/, 4305 true /*preference_wifi_network_4g*/,
4579 true /*preference_always_network_wifi*/, 4306 true /*preference_always_network_wifi*/,
4580 false /*preference_always_network_4g*/, 4307 false /*preference_always_network_4g*/,
4581 true /*preference_never_network_wifi*/, 4308 true /*preference_never_network_wifi*/,
4582 true /*preference_never_network_4g*/); 4309 true /*preference_never_network_4g*/);
4583 } 4310 }
4584 4311
4585 } // namespace prerender 4312 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698