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 <map> | 5 #include <map> |
6 #include <memory> | 6 #include <memory> |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 #include "content/public/browser/interstitial_page.h" | 46 #include "content/public/browser/interstitial_page.h" |
47 #include "content/public/browser/interstitial_page_delegate.h" | 47 #include "content/public/browser/interstitial_page_delegate.h" |
48 #include "content/public/browser/navigation_controller.h" | 48 #include "content/public/browser/navigation_controller.h" |
49 #include "content/public/browser/navigation_entry.h" | 49 #include "content/public/browser/navigation_entry.h" |
50 #include "content/public/browser/notification_observer.h" | 50 #include "content/public/browser/notification_observer.h" |
51 #include "content/public/browser/notification_registrar.h" | 51 #include "content/public/browser/notification_registrar.h" |
52 #include "content/public/browser/notification_service.h" | 52 #include "content/public/browser/notification_service.h" |
53 #include "content/public/browser/notification_types.h" | 53 #include "content/public/browser/notification_types.h" |
54 #include "content/public/browser/render_frame_host.h" | 54 #include "content/public/browser/render_frame_host.h" |
55 #include "content/public/browser/web_contents.h" | 55 #include "content/public/browser/web_contents.h" |
56 #include "content/public/common/browser_side_navigation_policy.h" | |
56 #include "content/public/common/url_constants.h" | 57 #include "content/public/common/url_constants.h" |
57 #include "content/public/test/browser_test_utils.h" | 58 #include "content/public/test/browser_test_utils.h" |
58 #include "net/base/net_errors.h" | 59 #include "net/base/net_errors.h" |
59 #include "net/cert/x509_certificate.h" | 60 #include "net/cert/x509_certificate.h" |
60 #include "net/http/transport_security_state.h" | 61 #include "net/http/transport_security_state.h" |
61 #include "net/test/cert_test_util.h" | 62 #include "net/test/cert_test_util.h" |
62 #include "net/test/embedded_test_server/embedded_test_server.h" | 63 #include "net/test/embedded_test_server/embedded_test_server.h" |
63 #include "net/test/test_data_directory.h" | 64 #include "net/test/test_data_directory.h" |
64 #include "net/test/url_request/url_request_failed_job.h" | 65 #include "net/test/url_request/url_request_failed_job.h" |
65 #include "net/test/url_request/url_request_mock_http_job.h" | 66 #include "net/test/url_request/url_request_mock_http_job.h" |
(...skipping 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2108 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2109 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
2109 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | 2110 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
2110 | 2111 |
2111 CaptivePortalObserver portal_observer(browser()->profile()); | 2112 CaptivePortalObserver portal_observer(browser()->profile()); |
2112 FastErrorWithInterstitialTimer(browser(), cert_error_url); | 2113 FastErrorWithInterstitialTimer(browser(), cert_error_url); |
2113 | 2114 |
2114 // Page appears loading. Reloading it cancels the page load. Since the load is | 2115 // Page appears loading. Reloading it cancels the page load. Since the load is |
2115 // stopped, no cert error occurs and SSLErrorHandler isn't instantiated. | 2116 // stopped, no cert error occurs and SSLErrorHandler isn't instantiated. |
2116 MultiNavigationObserver test_navigation_observer; | 2117 MultiNavigationObserver test_navigation_observer; |
2117 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 2118 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
2118 test_navigation_observer.WaitForNavigations(2); | 2119 test_navigation_observer.WaitForNavigations( |
2120 content::IsBrowserSideNavigationEnabled() ? 1 : 2); | |
2119 | 2121 |
2120 // Make sure that the |ssl_error_handler| is deleted. | 2122 // Make sure that the |ssl_error_handler| is deleted. |
2121 EXPECT_TRUE(nullptr == SSLErrorHandler::FromWebContents(broken_tab_contents)); | 2123 EXPECT_TRUE(nullptr == SSLErrorHandler::FromWebContents(broken_tab_contents)); |
2122 | 2124 |
2123 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | 2125 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); |
2124 EXPECT_FALSE(broken_tab_contents->IsLoading()); | 2126 EXPECT_FALSE(broken_tab_contents->IsLoading()); |
2125 EXPECT_EQ(0, portal_observer.num_results_received()); | 2127 EXPECT_EQ(0, portal_observer.num_results_received()); |
2126 EXPECT_EQ(2, test_navigation_observer.num_navigations()); | |
2127 EXPECT_EQ(0, NumLoadingTabs()); | 2128 EXPECT_EQ(0, NumLoadingTabs()); |
2128 EXPECT_FALSE(CheckPending(browser())); | 2129 EXPECT_FALSE(CheckPending(browser())); |
2129 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 2130 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
2130 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 2131 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
2131 GetStateOfTabReloaderAt(browser(), 0)); | 2132 GetStateOfTabReloaderAt(browser(), 0)); |
2132 | 2133 |
2133 // Re-enable captive portal checks and fire one. The result should be ignored. | 2134 // Re-enable captive portal checks and fire one. The result should be ignored. |
2134 RespondToProbeRequests(true); | 2135 RespondToProbeRequests(true); |
2135 CaptivePortalObserver portal_observer2(browser()->profile()); | 2136 CaptivePortalObserver portal_observer2(browser()->profile()); |
2136 CaptivePortalService* captive_portal_service = | 2137 CaptivePortalService* captive_portal_service = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2168 CaptivePortalObserver portal_observer(browser()->profile()); | 2169 CaptivePortalObserver portal_observer(browser()->profile()); |
2169 FastErrorWithInterstitialTimer(browser(), cert_error_url); | 2170 FastErrorWithInterstitialTimer(browser(), cert_error_url); |
2170 | 2171 |
2171 // Page appears loading. Navigating away shouldn't result in any interstitial. | 2172 // Page appears loading. Navigating away shouldn't result in any interstitial. |
2172 // Can't use ui_test_utils::NavigateToURLWithDisposition because it waits for | 2173 // Can't use ui_test_utils::NavigateToURLWithDisposition because it waits for |
2173 // a load stop notification before starting a new navigation. | 2174 // a load stop notification before starting a new navigation. |
2174 MultiNavigationObserver test_navigation_observer; | 2175 MultiNavigationObserver test_navigation_observer; |
2175 browser()->OpenURL(content::OpenURLParams( | 2176 browser()->OpenURL(content::OpenURLParams( |
2176 URLRequestMockHTTPJob::GetMockUrl("title2.html"), content::Referrer(), | 2177 URLRequestMockHTTPJob::GetMockUrl("title2.html"), content::Referrer(), |
2177 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | 2178 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); |
2178 // Expect two navigations: First one for stopping the hanging page, second one | 2179 // With PlzNavigate: expect one navigation. |
2179 // for completing the load of the above navigation. | 2180 // WIthout PlzNavigate: expect two navigations: First one for stopping the |
mmenke
2016/09/23 21:41:18
WIthout -> Without
jam
2016/09/23 21:49:22
Done.
| |
2180 test_navigation_observer.WaitForNavigations(2); | 2181 // hanging page, second one for completing the load of the above navigation. |
2182 test_navigation_observer.WaitForNavigations( | |
2183 content::IsBrowserSideNavigationEnabled() ? 1 : 2); | |
2181 | 2184 |
2182 // Make sure that the |ssl_error_handler| is deleted. | 2185 // Make sure that the |ssl_error_handler| is deleted. |
2183 EXPECT_TRUE(nullptr == SSLErrorHandler::FromWebContents(broken_tab_contents)); | 2186 EXPECT_TRUE(nullptr == SSLErrorHandler::FromWebContents(broken_tab_contents)); |
2184 | 2187 |
2185 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | 2188 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); |
2186 EXPECT_FALSE(broken_tab_contents->IsLoading()); | 2189 EXPECT_FALSE(broken_tab_contents->IsLoading()); |
2187 EXPECT_EQ(0, portal_observer.num_results_received()); | 2190 EXPECT_EQ(0, portal_observer.num_results_received()); |
2188 EXPECT_EQ(2, test_navigation_observer.num_navigations()); | |
2189 EXPECT_EQ(0, NumLoadingTabs()); | 2191 EXPECT_EQ(0, NumLoadingTabs()); |
2190 EXPECT_FALSE(CheckPending(browser())); | 2192 EXPECT_FALSE(CheckPending(browser())); |
2191 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 2193 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
2192 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 2194 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
2193 GetStateOfTabReloaderAt(browser(), 0)); | 2195 GetStateOfTabReloaderAt(browser(), 0)); |
2194 | 2196 |
2195 // Re-enable captive portal checks and fire one. The result should be ignored. | 2197 // Re-enable captive portal checks and fire one. The result should be ignored. |
2196 RespondToProbeRequests(true); | 2198 RespondToProbeRequests(true); |
2197 CaptivePortalObserver portal_observer2(browser()->profile()); | 2199 CaptivePortalObserver portal_observer2(browser()->profile()); |
2198 CaptivePortalService* captive_portal_service = | 2200 CaptivePortalService* captive_portal_service = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2236 // to the same page. This should result in a cert error which should | 2238 // to the same page. This should result in a cert error which should |
2237 // instantiate an |SSLErrorHandler| and end up showing an SSL interstitial. | 2239 // instantiate an |SSLErrorHandler| and end up showing an SSL interstitial. |
2238 RespondToProbeRequests(true); | 2240 RespondToProbeRequests(true); |
2239 // Can't have ui_test_utils do the navigation because it will wait for loading | 2241 // Can't have ui_test_utils do the navigation because it will wait for loading |
2240 // tabs to stop loading before navigating. | 2242 // tabs to stop loading before navigating. |
2241 CaptivePortalObserver portal_observer(browser()->profile()); | 2243 CaptivePortalObserver portal_observer(browser()->profile()); |
2242 MultiNavigationObserver test_navigation_observer; | 2244 MultiNavigationObserver test_navigation_observer; |
2243 browser()->OpenURL(content::OpenURLParams(cert_error_url, content::Referrer(), | 2245 browser()->OpenURL(content::OpenURLParams(cert_error_url, content::Referrer(), |
2244 WindowOpenDisposition::CURRENT_TAB, | 2246 WindowOpenDisposition::CURRENT_TAB, |
2245 ui::PAGE_TRANSITION_TYPED, false)); | 2247 ui::PAGE_TRANSITION_TYPED, false)); |
2246 // Expect two navigations: First one for stopping the hanging page, second one | 2248 // With PlzNavigate: expect one navigation. |
2247 // for completing the load of the above navigation. | 2249 // WIthout PlzNavigate: expect two navigations: First one for stopping the |
mmenke
2016/09/23 21:41:18
Without
jam
2016/09/23 21:49:22
Done.
| |
2248 test_navigation_observer.WaitForNavigations(2); | 2250 // hanging page, second one for completing the load of the above navigation. |
2251 test_navigation_observer.WaitForNavigations( | |
2252 content::IsBrowserSideNavigationEnabled() ? 1 : 2); | |
2249 // Should end up with an SSL interstitial. | 2253 // Should end up with an SSL interstitial. |
2250 WaitForInterstitialAttach(broken_tab_contents); | 2254 WaitForInterstitialAttach(broken_tab_contents); |
2251 ASSERT_TRUE(broken_tab_contents->ShowingInterstitialPage()); | 2255 ASSERT_TRUE(broken_tab_contents->ShowingInterstitialPage()); |
2252 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | 2256 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
2253 broken_tab_contents->GetInterstitialPage() | 2257 broken_tab_contents->GetInterstitialPage() |
2254 ->GetDelegateForTesting() | 2258 ->GetDelegateForTesting() |
2255 ->GetTypeForTesting()); | 2259 ->GetTypeForTesting()); |
2256 EXPECT_FALSE(broken_tab_contents->IsLoading()); | 2260 EXPECT_FALSE(broken_tab_contents->IsLoading()); |
2257 EXPECT_EQ(1, portal_observer.num_results_received()); | 2261 EXPECT_EQ(1, portal_observer.num_results_received()); |
2258 EXPECT_EQ(captive_portal::RESULT_INTERNET_CONNECTED, | 2262 EXPECT_EQ(captive_portal::RESULT_INTERNET_CONNECTED, |
(...skipping 30 matching lines...) Expand all Loading... | |
2289 // tabs to stop loading before navigating. | 2293 // tabs to stop loading before navigating. |
2290 CaptivePortalObserver portal_observer(browser()->profile()); | 2294 CaptivePortalObserver portal_observer(browser()->profile()); |
2291 MultiNavigationObserver test_navigation_observer; | 2295 MultiNavigationObserver test_navigation_observer; |
2292 browser()->OpenURL(content::OpenURLParams(cert_error_url, content::Referrer(), | 2296 browser()->OpenURL(content::OpenURLParams(cert_error_url, content::Referrer(), |
2293 WindowOpenDisposition::CURRENT_TAB, | 2297 WindowOpenDisposition::CURRENT_TAB, |
2294 ui::PAGE_TRANSITION_TYPED, false)); | 2298 ui::PAGE_TRANSITION_TYPED, false)); |
2295 // Expect three navigations: | 2299 // Expect three navigations: |
2296 // 1- For stopping the hanging page. | 2300 // 1- For stopping the hanging page. |
2297 // 2- For completing the load of the above navigation. | 2301 // 2- For completing the load of the above navigation. |
2298 // 3- For completing the load of the login tab. | 2302 // 3- For completing the load of the login tab. |
2299 test_navigation_observer.WaitForNavigations(3); | 2303 // NOTE: for PlzNaviate the first one doesn't show up. |
2304 test_navigation_observer.WaitForNavigations( | |
2305 content::IsBrowserSideNavigationEnabled() ? 2 : 3); | |
2300 // Should end up with a captive portal interstitial and a new login tab. | 2306 // Should end up with a captive portal interstitial and a new login tab. |
2301 WaitForInterstitialAttach(broken_tab_contents); | 2307 WaitForInterstitialAttach(broken_tab_contents); |
2302 ASSERT_TRUE(broken_tab_contents->ShowingInterstitialPage()); | 2308 ASSERT_TRUE(broken_tab_contents->ShowingInterstitialPage()); |
2303 EXPECT_EQ(CaptivePortalBlockingPage::kTypeForTesting, | 2309 EXPECT_EQ(CaptivePortalBlockingPage::kTypeForTesting, |
2304 broken_tab_contents->GetInterstitialPage() | 2310 broken_tab_contents->GetInterstitialPage() |
2305 ->GetDelegateForTesting() | 2311 ->GetDelegateForTesting() |
2306 ->GetTypeForTesting()); | 2312 ->GetTypeForTesting()); |
2307 ASSERT_EQ(initial_tab_count + 1, tab_strip_model->count()); | 2313 ASSERT_EQ(initial_tab_count + 1, tab_strip_model->count()); |
2308 EXPECT_EQ(initial_tab_count, tab_strip_model->active_index()); | 2314 EXPECT_EQ(initial_tab_count, tab_strip_model->active_index()); |
2309 EXPECT_FALSE(broken_tab_contents->IsLoading()); | 2315 EXPECT_FALSE(broken_tab_contents->IsLoading()); |
(...skipping 25 matching lines...) Expand all Loading... | |
2335 // of a captive portal error page. | 2341 // of a captive portal error page. |
2336 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); | 2342 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); |
2337 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2343 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
2338 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | 2344 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
2339 | 2345 |
2340 // Setting the delay to zero above has a race condition: A captive portal | 2346 // Setting the delay to zero above has a race condition: A captive portal |
2341 // result triggered by a cert error can arrive before the SSL interstitial | 2347 // result triggered by a cert error can arrive before the SSL interstitial |
2342 // display timer is fired, even though it's set to zero. | 2348 // display timer is fired, even though it's set to zero. |
2343 // To avoid this, disable captive portal checks until the SSL interstitial is | 2349 // To avoid this, disable captive portal checks until the SSL interstitial is |
2344 // displayed. Once it's displayed, enable portal checks and fire one. | 2350 // displayed. Once it's displayed, enable portal checks and fire one. |
2345 bool delay_portal_response_until_interstital = true; | 2351 // NOTE: this doesn't occur with PlzNavigate, since the SSL interstitial timer |
2352 // is fired synchronously due to different timings when | |
2353 // CaptivePortalTabReloader gets the load start callback. | |
2354 bool delay_portal_response_until_interstital = | |
2355 !content::IsBrowserSideNavigationEnabled(); | |
2346 | 2356 |
2347 // The path does not matter. | 2357 // The path does not matter. |
2348 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | 2358 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); |
2349 // A captive portal check is triggered in FastErrorBehindCaptivePortal. | 2359 // A captive portal check is triggered in FastErrorBehindCaptivePortal. |
2350 FastErrorBehindCaptivePortal( | 2360 FastErrorBehindCaptivePortal( |
2351 browser(), | 2361 browser(), |
2352 true, | 2362 true, |
2353 cert_error_url, | 2363 cert_error_url, |
2354 delay_portal_response_until_interstital); | 2364 delay_portal_response_until_interstital); |
2355 | 2365 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2828 | 2838 |
2829 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 2839 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
2830 GetStateOfTabReloaderAt(browser(), broken_tab_index)); | 2840 GetStateOfTabReloaderAt(browser(), broken_tab_index)); |
2831 | 2841 |
2832 WaitForInterstitialAttach(broken_tab_contents); | 2842 WaitForInterstitialAttach(broken_tab_contents); |
2833 portal_observer.WaitForResults(1); | 2843 portal_observer.WaitForResults(1); |
2834 | 2844 |
2835 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | 2845 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
2836 GetInterstitialType(broken_tab_contents)); | 2846 GetInterstitialType(broken_tab_contents)); |
2837 } | 2847 } |
OLD | NEW |