| 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 2889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2900 1); | 2900 1); |
| 2901 OpenDestURLViaClickTarget(); | 2901 OpenDestURLViaClickTarget(); |
| 2902 } | 2902 } |
| 2903 | 2903 |
| 2904 // Checks that prerenders do not get swapped into target pages that have opened | 2904 // Checks that prerenders do not get swapped into target pages that have opened |
| 2905 // a popup, even if the target page itself does not have an opener. | 2905 // a popup, even if the target page itself does not have an opener. |
| 2906 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTargetHasPopup) { | 2906 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTargetHasPopup) { |
| 2907 PrerenderTestURL("files/prerender/prerender_page.html", | 2907 PrerenderTestURL("files/prerender/prerender_page.html", |
| 2908 FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE, | 2908 FINAL_STATUS_NON_EMPTY_BROWSING_INSTANCE, |
| 2909 1); | 2909 1); |
| 2910 OpenURLViaWindowOpen(GURL(content::kAboutBlankURL)); | 2910 OpenURLViaWindowOpen(GURL(url::kAboutBlankURL)); |
| 2911 NavigateToDestURLWithDisposition(CURRENT_TAB, false); | 2911 NavigateToDestURLWithDisposition(CURRENT_TAB, false); |
| 2912 } | 2912 } |
| 2913 | 2913 |
| 2914 class TestClientCertStore : public net::ClientCertStore { | 2914 class TestClientCertStore : public net::ClientCertStore { |
| 2915 public: | 2915 public: |
| 2916 TestClientCertStore() {} | 2916 TestClientCertStore() {} |
| 2917 virtual ~TestClientCertStore() {} | 2917 virtual ~TestClientCertStore() {} |
| 2918 | 2918 |
| 2919 // net::ClientCertStore: | 2919 // net::ClientCertStore: |
| 2920 virtual void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info, | 2920 virtual void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info, |
| (...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4007 | 4007 |
| 4008 PrerenderTestURL(kTestURL, FINAL_STATUS_USED, 1); | 4008 PrerenderTestURL(kTestURL, FINAL_STATUS_USED, 1); |
| 4009 | 4009 |
| 4010 // Open a new tab to navigate in. | 4010 // Open a new tab to navigate in. |
| 4011 ui_test_utils::NavigateToURLWithDisposition( | 4011 ui_test_utils::NavigateToURLWithDisposition( |
| 4012 current_browser(), kInitURL, NEW_FOREGROUND_TAB, | 4012 current_browser(), kInitURL, NEW_FOREGROUND_TAB, |
| 4013 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 4013 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 4014 | 4014 |
| 4015 // Navigate to about:blank so the next navigation is cross-process. | 4015 // Navigate to about:blank so the next navigation is cross-process. |
| 4016 ui_test_utils::NavigateToURL(current_browser(), | 4016 ui_test_utils::NavigateToURL(current_browser(), |
| 4017 GURL(content::kAboutBlankURL)); | 4017 GURL(url::kAboutBlankURL)); |
| 4018 | 4018 |
| 4019 // Now navigate in the new tab. Set expect_swap_to_succeed to false because | 4019 // Now navigate in the new tab. Set expect_swap_to_succeed to false because |
| 4020 // the swap does not occur synchronously. | 4020 // the swap does not occur synchronously. |
| 4021 // | 4021 // |
| 4022 // TODO(davidben): When all swaps become asynchronous, remove the OpenURL | 4022 // TODO(davidben): When all swaps become asynchronous, remove the OpenURL |
| 4023 // return value assertion and let this go through the usual successful-swap | 4023 // return value assertion and let this go through the usual successful-swap |
| 4024 // codepath. | 4024 // codepath. |
| 4025 NavigateToDestURLWithDisposition(CURRENT_TAB, false); | 4025 NavigateToDestURLWithDisposition(CURRENT_TAB, false); |
| 4026 | 4026 |
| 4027 // Verify DidDisplayPass manually since the previous call skipped it. | 4027 // Verify DidDisplayPass manually since the previous call skipped it. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4060 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB, | 4060 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB, |
| 4061 content::PAGE_TRANSITION_TYPED, false); | 4061 content::PAGE_TRANSITION_TYPED, false); |
| 4062 params.should_replace_current_entry = true; | 4062 params.should_replace_current_entry = true; |
| 4063 NavigateToURLWithParams(params, false); | 4063 NavigateToURLWithParams(params, false); |
| 4064 | 4064 |
| 4065 const NavigationController& controller = | 4065 const NavigationController& controller = |
| 4066 GetActiveWebContents()->GetController(); | 4066 GetActiveWebContents()->GetController(); |
| 4067 // First entry is about:blank, second is prerender_page.html. | 4067 // First entry is about:blank, second is prerender_page.html. |
| 4068 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 4068 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
| 4069 EXPECT_EQ(2, controller.GetEntryCount()); | 4069 EXPECT_EQ(2, controller.GetEntryCount()); |
| 4070 EXPECT_EQ(GURL(content::kAboutBlankURL), | 4070 EXPECT_EQ(GURL(url::kAboutBlankURL), |
| 4071 controller.GetEntryAtIndex(0)->GetURL()); | 4071 controller.GetEntryAtIndex(0)->GetURL()); |
| 4072 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL()); | 4072 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL()); |
| 4073 } | 4073 } |
| 4074 | 4074 |
| 4075 // Checks prerender does not hit DCHECKs and behaves properly if two pending | 4075 // Checks prerender does not hit DCHECKs and behaves properly if two pending |
| 4076 // swaps occur in a row. | 4076 // swaps occur in a row. |
| 4077 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDoublePendingSwap) { | 4077 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDoublePendingSwap) { |
| 4078 GetPrerenderManager()->mutable_config().max_link_concurrency = 2; | 4078 GetPrerenderManager()->mutable_config().max_link_concurrency = 2; |
| 4079 GetPrerenderManager()->mutable_config().max_link_concurrency_per_launcher = 2; | 4079 GetPrerenderManager()->mutable_config().max_link_concurrency_per_launcher = 2; |
| 4080 | 4080 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4091 // There's no reason the second prerender can't be used, but the swap races | 4091 // There's no reason the second prerender can't be used, but the swap races |
| 4092 // with didStartProvisionalLoad and didFailProvisionalLoad from the previous | 4092 // with didStartProvisionalLoad and didFailProvisionalLoad from the previous |
| 4093 // navigation. The current logic will conservatively fail to swap under such | 4093 // navigation. The current logic will conservatively fail to swap under such |
| 4094 // races. However, if the renderer is slow enough, it's possible for the | 4094 // races. However, if the renderer is slow enough, it's possible for the |
| 4095 // prerender to still be used, so don't program in either expectation. | 4095 // prerender to still be used, so don't program in either expectation. |
| 4096 ASSERT_TRUE(prerender2->contents()); | 4096 ASSERT_TRUE(prerender2->contents()); |
| 4097 prerender2->contents()->set_skip_final_checks(true); | 4097 prerender2->contents()->set_skip_final_checks(true); |
| 4098 | 4098 |
| 4099 // Open a new tab to navigate in. | 4099 // Open a new tab to navigate in. |
| 4100 ui_test_utils::NavigateToURLWithDisposition( | 4100 ui_test_utils::NavigateToURLWithDisposition( |
| 4101 current_browser(), GURL(content::kAboutBlankURL), NEW_FOREGROUND_TAB, | 4101 current_browser(), GURL(url::kAboutBlankURL), NEW_FOREGROUND_TAB, |
| 4102 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 4102 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 4103 | 4103 |
| 4104 // Fire off two navigations, without running the event loop between them. | 4104 // Fire off two navigations, without running the event loop between them. |
| 4105 NavigationOrSwapObserver swap_observer( | 4105 NavigationOrSwapObserver swap_observer( |
| 4106 current_browser()->tab_strip_model(), | 4106 current_browser()->tab_strip_model(), |
| 4107 GetActiveWebContents(), 2); | 4107 GetActiveWebContents(), 2); |
| 4108 current_browser()->OpenURL(OpenURLParams( | 4108 current_browser()->OpenURL(OpenURLParams( |
| 4109 url1, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 4109 url1, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
| 4110 current_browser()->OpenURL(OpenURLParams( | 4110 current_browser()->OpenURL(OpenURLParams( |
| 4111 url2, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 4111 url2, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
| 4112 swap_observer.Wait(); | 4112 swap_observer.Wait(); |
| 4113 | 4113 |
| 4114 // The WebContents should be on url2. There may be 2 or 3 entries, depending | 4114 // The WebContents should be on url2. There may be 2 or 3 entries, depending |
| 4115 // on whether the first one managed to complete. | 4115 // on whether the first one managed to complete. |
| 4116 // | 4116 // |
| 4117 // TODO(davidben): When http://crbug.com/335835 is fixed, the 3 entry case | 4117 // TODO(davidben): When http://crbug.com/335835 is fixed, the 3 entry case |
| 4118 // shouldn't be possible because it's throttled by the pending swap that | 4118 // shouldn't be possible because it's throttled by the pending swap that |
| 4119 // cannot complete. | 4119 // cannot complete. |
| 4120 const NavigationController& controller = | 4120 const NavigationController& controller = |
| 4121 GetActiveWebContents()->GetController(); | 4121 GetActiveWebContents()->GetController(); |
| 4122 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 4122 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
| 4123 EXPECT_LE(2, controller.GetEntryCount()); | 4123 EXPECT_LE(2, controller.GetEntryCount()); |
| 4124 EXPECT_GE(3, controller.GetEntryCount()); | 4124 EXPECT_GE(3, controller.GetEntryCount()); |
| 4125 EXPECT_EQ(GURL(content::kAboutBlankURL), | 4125 EXPECT_EQ(GURL(url::kAboutBlankURL), |
| 4126 controller.GetEntryAtIndex(0)->GetURL()); | 4126 controller.GetEntryAtIndex(0)->GetURL()); |
| 4127 EXPECT_EQ(url2, controller.GetEntryAtIndex( | 4127 EXPECT_EQ(url2, controller.GetEntryAtIndex( |
| 4128 controller.GetEntryCount() - 1)->GetURL()); | 4128 controller.GetEntryCount() - 1)->GetURL()); |
| 4129 } | 4129 } |
| 4130 | 4130 |
| 4131 // Verify that pending swaps get aborted on new navigations. | 4131 // Verify that pending swaps get aborted on new navigations. |
| 4132 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 4132 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
| 4133 PrerenderPendingSwapNewNavigation) { | 4133 PrerenderPendingSwapNewNavigation) { |
| 4134 PrerenderManager::HangSessionStorageMergesForTesting(); | 4134 PrerenderManager::HangSessionStorageMergesForTesting(); |
| 4135 | 4135 |
| 4136 PrerenderTestURL("files/prerender/prerender_page.html", | 4136 PrerenderTestURL("files/prerender/prerender_page.html", |
| 4137 FINAL_STATUS_APP_TERMINATING, 1); | 4137 FINAL_STATUS_APP_TERMINATING, 1); |
| 4138 | 4138 |
| 4139 // Open a new tab to navigate in. | 4139 // Open a new tab to navigate in. |
| 4140 ui_test_utils::NavigateToURLWithDisposition( | 4140 ui_test_utils::NavigateToURLWithDisposition( |
| 4141 current_browser(), GURL(content::kAboutBlankURL), NEW_FOREGROUND_TAB, | 4141 current_browser(), GURL(url::kAboutBlankURL), NEW_FOREGROUND_TAB, |
| 4142 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 4142 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 4143 | 4143 |
| 4144 // Navigate to the URL. Wait for DidStartLoading, just so it's definitely | 4144 // Navigate to the URL. Wait for DidStartLoading, just so it's definitely |
| 4145 // progressed somewhere. | 4145 // progressed somewhere. |
| 4146 content::WindowedNotificationObserver page_load_observer( | 4146 content::WindowedNotificationObserver page_load_observer( |
| 4147 content::NOTIFICATION_LOAD_START, | 4147 content::NOTIFICATION_LOAD_START, |
| 4148 content::Source<NavigationController>( | 4148 content::Source<NavigationController>( |
| 4149 &GetActiveWebContents()->GetController())); | 4149 &GetActiveWebContents()->GetController())); |
| 4150 current_browser()->OpenURL(OpenURLParams( | 4150 current_browser()->OpenURL(OpenURLParams( |
| 4151 dest_url(), Referrer(), CURRENT_TAB, | 4151 dest_url(), Referrer(), CURRENT_TAB, |
| 4152 content::PAGE_TRANSITION_TYPED, false)); | 4152 content::PAGE_TRANSITION_TYPED, false)); |
| 4153 page_load_observer.Wait(); | 4153 page_load_observer.Wait(); |
| 4154 | 4154 |
| 4155 // Navigate somewhere else. This should succeed and abort the pending swap. | 4155 // Navigate somewhere else. This should succeed and abort the pending swap. |
| 4156 TestNavigationObserver nav_observer(GetActiveWebContents()); | 4156 TestNavigationObserver nav_observer(GetActiveWebContents()); |
| 4157 current_browser()->OpenURL(OpenURLParams( | 4157 current_browser()->OpenURL(OpenURLParams( |
| 4158 GURL(content::kAboutBlankURL), Referrer(), CURRENT_TAB, | 4158 GURL(url::kAboutBlankURL), Referrer(), CURRENT_TAB, |
| 4159 content::PAGE_TRANSITION_TYPED, false)); | 4159 content::PAGE_TRANSITION_TYPED, false)); |
| 4160 nav_observer.Wait(); | 4160 nav_observer.Wait(); |
| 4161 } | 4161 } |
| 4162 | 4162 |
| 4163 // Checks that <a ping> requests are not dropped in prerender. | 4163 // Checks that <a ping> requests are not dropped in prerender. |
| 4164 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) { | 4164 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) { |
| 4165 // Count hits to a certain URL. | 4165 // Count hits to a certain URL. |
| 4166 const GURL kPingURL("http://prerender.test/ping"); | 4166 const GURL kPingURL("http://prerender.test/ping"); |
| 4167 base::FilePath empty_file = ui_test_utils::GetTestFilePath( | 4167 base::FilePath empty_file = ui_test_utils::GetTestFilePath( |
| 4168 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); | 4168 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4411 | 4411 |
| 4412 // Navigate to the URL entered. | 4412 // Navigate to the URL entered. |
| 4413 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); | 4413 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); |
| 4414 | 4414 |
| 4415 // Prerender should be running, but abandoned. | 4415 // Prerender should be running, but abandoned. |
| 4416 EXPECT_TRUE( | 4416 EXPECT_TRUE( |
| 4417 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); | 4417 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); |
| 4418 } | 4418 } |
| 4419 | 4419 |
| 4420 } // namespace prerender | 4420 } // namespace prerender |
| OLD | NEW |