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

Side by Side Diff: chrome/browser/captive_portal/captive_portal_browsertest.cc

Issue 1004283004: Destroy SSLErrorHandler on new navigations so that it can properly be recreated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Deny the cert to fix the memory leak Created 5 years, 9 months 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
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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 } 810 }
811 } 811 }
812 812
813 // This observer waits for the SSLErrorHandler to fire an interstitial timer for 813 // This observer waits for the SSLErrorHandler to fire an interstitial timer for
814 // the given web contents. 814 // the given web contents.
815 class SSLInterstitialTimerObserver { 815 class SSLInterstitialTimerObserver {
816 public: 816 public:
817 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents); 817 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents);
818 ~SSLInterstitialTimerObserver(); 818 ~SSLInterstitialTimerObserver();
819 819
820 // Waits until the interstitial delay timer in SSLErrorHandler is fired. 820 // Waits until the interstitial delay timer in SSLErrorHandler is fired.
mmenke 2015/03/20 13:33:50 While you're here, can you replace all these "fire
meacer 2015/03/20 17:46:01 Done.
821 void WaitForTimerFired(); 821 void WaitForTimerFired();
822 822
823 private: 823 private:
824 void OnTimerFired(content::WebContents* web_contents); 824 void OnTimerFired(content::WebContents* web_contents);
825 825
826 const content::WebContents* web_contents_; 826 const content::WebContents* web_contents_;
827 SSLErrorHandler::TimerStartedCallback callback_; 827 SSLErrorHandler::TimerStartedCallback callback_;
828 828
829 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 829 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
830 830
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 // there's no detected captive portal. 941 // there's no detected captive portal.
942 void FastTimeoutNoCaptivePortal(Browser* browser, 942 void FastTimeoutNoCaptivePortal(Browser* browser,
943 CaptivePortalResult expected_result); 943 CaptivePortalResult expected_result);
944 944
945 // Navigates the active tab to a slow loading SSL page, which will then 945 // Navigates the active tab to a slow loading SSL page, which will then
946 // trigger a captive portal test. The test is expected to find a captive 946 // trigger a captive portal test. The test is expected to find a captive
947 // portal. The slow loading page will continue to load after the function 947 // portal. The slow loading page will continue to load after the function
948 // returns, until URLRequestTimeoutOnDemandJob::FailJobs() is called, 948 // returns, until URLRequestTimeoutOnDemandJob::FailJobs() is called,
949 // at which point it will timeout. 949 // at which point it will timeout.
950 // 950 //
951 // When |expect_login_tab| is false, no login tab is expected to be opened, 951 // When |expect_open_login_tab| is false, no login tab is expected to be
952 // because one already exists, and the function returns once the captive 952 // opened, because one already exists, and the function returns once the
953 // portal test is complete. 953 // captive portal test is complete.
954 // 954 //
955 // If |expect_login_tab| is true, a login tab is then expected to be opened. 955 // If |expect_open_login_tab| is true, a login tab is then expected to be
956 // It waits until both the login tab has finished loading, and two captive 956 // opened. It waits until both the login tab has finished loading, and two
957 // portal tests complete. The second test is triggered by the load of the 957 // captive portal tests complete. The second test is triggered by the load of
958 // captive portal tab completing. 958 // the captive portal tab completing.
959 // 959 //
960 // This function must not be called when the active tab is currently loading. 960 // This function must not be called when the active tab is currently loading.
961 // Waits for the hanging request to be issued, so other functions can rely 961 // Waits for the hanging request to be issued, so other functions can rely
962 // on URLRequestTimeoutOnDemandJob::WaitForJobs having been called. 962 // on URLRequestTimeoutOnDemandJob::WaitForJobs having been called.
963 void SlowLoadBehindCaptivePortal(Browser* browser, bool expect_login_tab); 963 void SlowLoadBehindCaptivePortal(Browser* browser,
964 bool expect_open_login_tab);
964 965
965 // Same as above, but takes extra parameters. 966 // Same as above, but takes extra parameters.
966 // 967 //
967 // |hanging_url| should either be kMockHttpsUrl or redirect to kMockHttpsUrl. 968 // |hanging_url| should either be kMockHttpsUrl or redirect to kMockHttpsUrl.
968 // 969 //
969 // |expected_portal_checks| and |expected_login_tab_navigations| allow 970 // |expected_portal_checks| and |expected_login_tab_navigations| allow
970 // client-side redirects to be tested. |expected_login_tab_navigations| is 971 // client-side redirects to be tested. |expected_login_tab_navigations| is
971 // ignored when |expect_open_login_tab| is false. 972 // ignored when |expect_open_login_tab| is false.
972 void SlowLoadBehindCaptivePortal(Browser* browser, 973 void SlowLoadBehindCaptivePortal(Browser* browser,
973 bool expect_open_login_tab, 974 bool expect_open_login_tab,
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 EXPECT_EQ(1, portal_observer2.num_results_received()); 2064 EXPECT_EQ(1, portal_observer2.num_results_received());
2064 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, 2065 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
2065 portal_observer2.captive_portal_result()); 2066 portal_observer2.captive_portal_result());
2066 EXPECT_EQ(0, NumLoadingTabs()); 2067 EXPECT_EQ(0, NumLoadingTabs());
2067 EXPECT_FALSE(CheckPending(browser())); 2068 EXPECT_FALSE(CheckPending(browser()));
2068 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2069 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2069 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 2070 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
2070 GetStateOfTabReloaderAt(browser(), 0)); 2071 GetStateOfTabReloaderAt(browser(), 0));
2071 } 2072 }
2072 2073
2073 // This test is very flaky on Linux and is disabled.
2074 // https://crbug.com/453875
2075 #if defined(OS_LINUX)
2076 #define MAYBE_InterstitialTimerReloadWhileLoading \
2077 DISABLED_InterstitialTimerReloadWhileLoading
2078 #else
2079 #define MAYBE_InterstitialTimerReloadWhileLoading \
2080 InterstitialTimerReloadWhileLoading
2081 #endif
2082 // Same as above, but instead of stopping, the loading page is reloaded. The end 2074 // Same as above, but instead of stopping, the loading page is reloaded. The end
2083 // result is the same. (i.e. page load stops, no interstitials shown) 2075 // result is the same. (i.e. page load stops, no interstitials shown)
2084 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, 2076 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest,
2085 MAYBE_InterstitialTimerReloadWhileLoading) { 2077 InterstitialTimerReloadWhileLoading) {
2086 net::SpawnedTestServer::SSLOptions https_options; 2078 net::SpawnedTestServer::SSLOptions https_options;
2087 https_options.server_certificate = 2079 https_options.server_certificate =
2088 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; 2080 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
2089 net::SpawnedTestServer https_server( 2081 net::SpawnedTestServer https_server(
2090 net::SpawnedTestServer::TYPE_HTTPS, https_options, 2082 net::SpawnedTestServer::TYPE_HTTPS, https_options,
2091 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 2083 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
2092 ASSERT_TRUE(https_server.Start()); 2084 ASSERT_TRUE(https_server.Start());
2093 // The path does not matter. 2085 // The path does not matter.
2094 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); 2086 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath);
2095 2087
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 EXPECT_EQ(1, portal_observer2.num_results_received()); 2120 EXPECT_EQ(1, portal_observer2.num_results_received());
2129 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, 2121 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
2130 portal_observer2.captive_portal_result()); 2122 portal_observer2.captive_portal_result());
2131 EXPECT_EQ(0, NumLoadingTabs()); 2123 EXPECT_EQ(0, NumLoadingTabs());
2132 EXPECT_FALSE(CheckPending(browser())); 2124 EXPECT_FALSE(CheckPending(browser()));
2133 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2125 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2134 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 2126 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
2135 GetStateOfTabReloaderAt(browser(), 0)); 2127 GetStateOfTabReloaderAt(browser(), 0));
2136 } 2128 }
2137 2129
2138 // This test is very flaky on Linux and is disabled. 2130 // Same as |InterstitialTimerReloadWhileLoading_NoSSLError|, but instead of
2139 // https://crbug.com/453875 2131 // reloading, the page is navigated away. The new page should load, and no
2140 #if defined(OS_LINUX) 2132 // interstitials should be shown.
2141 #define MAYBE_InterstitialTimerNavigateAwayWhileLoading \
2142 DISABLED_InterstitialTimerNavigateAwayWhileLoading
2143 #else
2144 #define MAYBE_InterstitialTimerNavigateAwayWhileLoading \
2145 InterstitialTimerNavigateAwayWhileLoading
2146 #endif
2147
2148 // Same as above, but instead of reloading, the page is navigated away. The new
2149 // page should load, and no interstitials should be shown.
2150 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, 2133 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest,
2151 MAYBE_InterstitialTimerNavigateAwayWhileLoading) { 2134 InterstitialTimerNavigateAwayWhileLoading) {
2152 net::SpawnedTestServer::SSLOptions https_options; 2135 net::SpawnedTestServer::SSLOptions https_options;
2153 https_options.server_certificate = 2136 https_options.server_certificate =
2154 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; 2137 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
2155 net::SpawnedTestServer https_server( 2138 net::SpawnedTestServer https_server(
2156 net::SpawnedTestServer::TYPE_HTTPS, https_options, 2139 net::SpawnedTestServer::TYPE_HTTPS, https_options,
2157 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 2140 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
2158 ASSERT_TRUE(https_server.Start()); 2141 ASSERT_TRUE(https_server.Start());
2159 // The path does not matter. 2142 // The path does not matter.
2160 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); 2143 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath);
2161 2144
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 EXPECT_EQ(1, portal_observer2.num_results_received()); 2185 EXPECT_EQ(1, portal_observer2.num_results_received());
2203 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, 2186 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
2204 portal_observer2.captive_portal_result()); 2187 portal_observer2.captive_portal_result());
2205 EXPECT_EQ(0, NumLoadingTabs()); 2188 EXPECT_EQ(0, NumLoadingTabs());
2206 EXPECT_FALSE(CheckPending(browser())); 2189 EXPECT_FALSE(CheckPending(browser()));
2207 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2190 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2208 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 2191 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
2209 GetStateOfTabReloaderAt(browser(), 0)); 2192 GetStateOfTabReloaderAt(browser(), 0));
2210 } 2193 }
2211 2194
2195 // Same as above, but the hanging load is interrupted by a navigation to the
2196 // same page, this time committing the navigation. This should end up with an
2197 // SSL interstitial when not behind a captive portal. This ensures that a new
2198 // |SSLErrorHandler| is created on a new navigation, even though the tab's
2199 // WebContents doesn't change.
2200 IN_PROC_BROWSER_TEST_F(
2201 CaptivePortalBrowserTest,
2202 InterstitialTimerNavigateWhileLoading_EndWithSSLInterstitial) {
2203 net::SpawnedTestServer::SSLOptions https_options;
2204 https_options.server_certificate =
2205 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
2206 net::SpawnedTestServer https_server(
2207 net::SpawnedTestServer::TYPE_HTTPS, https_options,
2208 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
2209 ASSERT_TRUE(https_server.Start());
2210 // The path does not matter.
2211 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath);
2212 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false);
2213
2214 TabStripModel* tab_strip_model = browser()->tab_strip_model();
2215 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents();
2216
2217 FastErrorWithInterstitialTimer(browser(), cert_error_url);
2218 // Page appears loading. Turn on response to probe request again, and navigate
2219 // to the same page. This should result in a cert error which should
2220 // instantiate an |SSLErrorHandler| and end up showing an SSL.
mmenke 2015/03/20 13:33:50 "showing an SSL interstitial"?
meacer 2015/03/20 17:46:01 Done.
2221 RespondToProbeRequests(true);
2222 // Can't have ui_test_utils do the navigation because it will wait for loading
2223 // tabs to stop loading before navigating.
2224 CaptivePortalObserver portal_observer(browser()->profile());
2225 MultiNavigationObserver test_navigation_observer;
2226 browser()->OpenURL(content::OpenURLParams(cert_error_url, content::Referrer(),
2227 CURRENT_TAB,
2228 ui::PAGE_TRANSITION_TYPED, false));
2229 // Expect two navigations: First one for stopping the hanging page, second one
2230 // for completing the load of the above navigation.
2231 test_navigation_observer.WaitForNavigations(2);
2232 // Should end up with an SSL interstitial.
2233 WaitForInterstitialAttach(broken_tab_contents);
2234 EXPECT_TRUE(broken_tab_contents->ShowingInterstitialPage());
mmenke 2015/03/20 13:33:50 ASSERT_TRUE?
meacer 2015/03/20 17:46:01 Done.
2235 EXPECT_EQ(SSLBlockingPage::kTypeForTesting,
2236 broken_tab_contents->GetInterstitialPage()
2237 ->GetDelegateForTesting()
2238 ->GetTypeForTesting());
2239 EXPECT_FALSE(broken_tab_contents->IsLoading());
2240 EXPECT_EQ(1, portal_observer.num_results_received());
2241 EXPECT_EQ(captive_portal::RESULT_INTERNET_CONNECTED,
2242 portal_observer.captive_portal_result());
2243 EXPECT_EQ(0, NumLoadingTabs());
2244 EXPECT_FALSE(CheckPending(browser()));
2245 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2246 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
2247 GetStateOfTabReloaderAt(browser(), 0));
2248 }
2249
2250 // Same as above, but this time behind a captive portal.
2251 IN_PROC_BROWSER_TEST_F(
2252 CaptivePortalBrowserTest,
2253 InterstitialTimerNavigateWhileLoading_EndWithCaptivePortalInterstitial) {
2254 net::SpawnedTestServer::SSLOptions https_options;
2255 https_options.server_certificate =
2256 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
2257 net::SpawnedTestServer https_server(
2258 net::SpawnedTestServer::TYPE_HTTPS, https_options,
2259 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
2260 ASSERT_TRUE(https_server.Start());
2261 // The path does not matter.
2262 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath);
2263 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(true);
2264
2265 TabStripModel* tab_strip_model = browser()->tab_strip_model();
2266 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents();
2267 int initial_tab_count = tab_strip_model->count();
2268
2269 FastErrorWithInterstitialTimer(browser(), cert_error_url);
2270 // Page appears loading. Turn on response to probe request again, and navigate
2271 // to the same page. This should result in a cert error which should
2272 // instantiate an |SSLErrorHandler| and end up showing an SSL.
2273 RespondToProbeRequests(true);
2274 // Can't have ui_test_utils do the navigation because it will wait for loading
2275 // tabs to stop loading before navigating.
2276 CaptivePortalObserver portal_observer(browser()->profile());
2277 MultiNavigationObserver test_navigation_observer;
2278 browser()->OpenURL(content::OpenURLParams(cert_error_url, content::Referrer(),
2279 CURRENT_TAB,
2280 ui::PAGE_TRANSITION_TYPED, false));
2281 // Expect three navigations:
2282 // 1- For stopping the hanging page.
2283 // 2- For completing the load of the above navigation.
2284 // 3- For completing the load of the login tab.
2285 test_navigation_observer.WaitForNavigations(3);
2286 // Should end up with a captive portal interstitial and a new login tab.
2287 WaitForInterstitialAttach(broken_tab_contents);
2288 EXPECT_TRUE(broken_tab_contents->ShowingInterstitialPage());
mmenke 2015/03/20 13:33:50 ASSERT_TRUE?
meacer 2015/03/20 17:46:01 Done.
2289 EXPECT_EQ(CaptivePortalBlockingPage::kTypeForTesting,
2290 broken_tab_contents->GetInterstitialPage()
2291 ->GetDelegateForTesting()
2292 ->GetTypeForTesting());
2293 ASSERT_EQ(initial_tab_count + 1, tab_strip_model->count());
2294 EXPECT_EQ(initial_tab_count, tab_strip_model->active_index());
2295 EXPECT_FALSE(broken_tab_contents->IsLoading());
2296 EXPECT_EQ(1, portal_observer.num_results_received());
2297 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
2298 portal_observer.captive_portal_result());
2299 EXPECT_EQ(0, NumLoadingTabs());
2300 EXPECT_FALSE(CheckPending(browser()));
2301 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
2302 GetStateOfTabReloaderAt(browser(), 0));
2303 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
2304 GetStateOfTabReloaderAt(browser(), 1));
2305 EXPECT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(1)));
2306 }
2307
2212 // A cert error triggers a captive portal check and results in opening a login 2308 // A cert error triggers a captive portal check and results in opening a login
2213 // tab. The user then logs in and the page with the error is reloaded. 2309 // tab. The user then logs in and the page with the error is reloaded.
2214 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, SSLCertErrorLogin) { 2310 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, SSLCertErrorLogin) {
2215 // Need an HTTP TestServer to handle a dynamically created server redirect. 2311 // Need an HTTP TestServer to handle a dynamically created server redirect.
2216 ASSERT_TRUE(test_server()->Start()); 2312 ASSERT_TRUE(test_server()->Start());
2217 2313
2218 net::SpawnedTestServer::SSLOptions https_options; 2314 net::SpawnedTestServer::SSLOptions https_options;
2219 https_options.server_certificate = 2315 https_options.server_certificate =
2220 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; 2316 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
2221 net::SpawnedTestServer https_server( 2317 net::SpawnedTestServer https_server(
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 2826
2731 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, 2827 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
2732 GetStateOfTabReloaderAt(browser(), broken_tab_index)); 2828 GetStateOfTabReloaderAt(browser(), broken_tab_index));
2733 2829
2734 WaitForInterstitialAttach(broken_tab_contents); 2830 WaitForInterstitialAttach(broken_tab_contents);
2735 portal_observer.WaitForResults(1); 2831 portal_observer.WaitForResults(1);
2736 2832
2737 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, 2833 EXPECT_EQ(SSLBlockingPage::kTypeForTesting,
2738 GetInterstitialType(broken_tab_contents)); 2834 GetInterstitialType(broken_tab_contents));
2739 } 2835 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ssl/ssl_error_handler.h » ('j') | chrome/browser/ssl/ssl_error_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698