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

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

Issue 242483003: Move CaptivePortalDetector to src/components/captive_portal (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
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 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "net/base/net_errors.h" 46 #include "net/base/net_errors.h"
47 #include "net/http/transport_security_state.h" 47 #include "net/http/transport_security_state.h"
48 #include "net/url_request/url_request.h" 48 #include "net/url_request/url_request.h"
49 #include "net/url_request/url_request_context.h" 49 #include "net/url_request/url_request_context.h"
50 #include "net/url_request/url_request_context_getter.h" 50 #include "net/url_request/url_request_context_getter.h"
51 #include "net/url_request/url_request_filter.h" 51 #include "net/url_request/url_request_filter.h"
52 #include "net/url_request/url_request_job.h" 52 #include "net/url_request/url_request_job.h"
53 #include "net/url_request/url_request_status.h" 53 #include "net/url_request/url_request_status.h"
54 #include "testing/gtest/include/gtest/gtest.h" 54 #include "testing/gtest/include/gtest/gtest.h"
55 55
56 using captive_portal::CaptivePortalResult;
56 using content::BrowserThread; 57 using content::BrowserThread;
57 using content::URLRequestFailedJob; 58 using content::URLRequestFailedJob;
58 using content::URLRequestMockHTTPJob; 59 using content::URLRequestMockHTTPJob;
59 using content::WebContents; 60 using content::WebContents;
60 61
61 namespace captive_portal {
62
63 namespace { 62 namespace {
64 63
65 // Path of the fake login page, when using the TestServer. 64 // Path of the fake login page, when using the TestServer.
66 const char* const kTestServerLoginPath = "files/captive_portal/login.html"; 65 const char* const kTestServerLoginPath = "files/captive_portal/login.html";
67 66
68 // Path of a page with an iframe that has a mock SSL timeout, when using the 67 // Path of a page with an iframe that has a mock SSL timeout, when using the
69 // TestServer. 68 // TestServer.
70 const char* const kTestServerIframeTimeoutPath = 69 const char* const kTestServerIframeTimeoutPath =
71 "files/captive_portal/iframe_timeout.html"; 70 "files/captive_portal/iframe_timeout.html";
72 71
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 public: 677 public:
679 explicit CaptivePortalObserver(Profile* profile); 678 explicit CaptivePortalObserver(Profile* profile);
680 679
681 // Runs the message loop until until at exactly |update_count| capitive portal 680 // Runs the message loop until until at exactly |update_count| capitive portal
682 // results have been received, since this creation of |this|. Expects no 681 // results have been received, since this creation of |this|. Expects no
683 // additional captive portal results. 682 // additional captive portal results.
684 void WaitForResults(int num_results_to_wait_for); 683 void WaitForResults(int num_results_to_wait_for);
685 684
686 int num_results_received() const { return num_results_received_; } 685 int num_results_received() const { return num_results_received_; }
687 686
688 Result captive_portal_result() const { 687 CaptivePortalResult captive_portal_result() const {
689 return captive_portal_result_; 688 return captive_portal_result_;
690 } 689 }
691 690
692 private: 691 private:
693 // Records results and exits the message loop, if needed. 692 // Records results and exits the message loop, if needed.
694 virtual void Observe(int type, 693 virtual void Observe(int type,
695 const content::NotificationSource& source, 694 const content::NotificationSource& source,
696 const content::NotificationDetails& details) OVERRIDE; 695 const content::NotificationDetails& details) OVERRIDE;
697 696
698 // Number of times OnPortalResult has been called since construction. 697 // Number of times OnPortalResult has been called since construction.
699 int num_results_received_; 698 int num_results_received_;
700 699
701 // If WaitForResults was called, the total number of updates for which to 700 // If WaitForResults was called, the total number of updates for which to
702 // wait. Value doesn't matter when |waiting_for_result_| is false. 701 // wait. Value doesn't matter when |waiting_for_result_| is false.
703 int num_results_to_wait_for_; 702 int num_results_to_wait_for_;
704 703
705 bool waiting_for_result_; 704 bool waiting_for_result_;
706 705
707 Profile* profile_; 706 Profile* profile_;
708 707
709 CaptivePortalService* captive_portal_service_; 708 CaptivePortalService* captive_portal_service_;
710 709
711 // Last result received. 710 // Last result received.
712 Result captive_portal_result_; 711 CaptivePortalResult captive_portal_result_;
713 712
714 content::NotificationRegistrar registrar_; 713 content::NotificationRegistrar registrar_;
715 714
716 DISALLOW_COPY_AND_ASSIGN(CaptivePortalObserver); 715 DISALLOW_COPY_AND_ASSIGN(CaptivePortalObserver);
717 }; 716 };
718 717
719 CaptivePortalObserver::CaptivePortalObserver(Profile* profile) 718 CaptivePortalObserver::CaptivePortalObserver(Profile* profile)
720 : num_results_received_(0), 719 : num_results_received_(0),
721 num_results_to_wait_for_(0), 720 num_results_to_wait_for_(0),
722 waiting_for_result_(false), 721 waiting_for_result_(false),
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // active tab will end up being navigated. It should be 1, except for the 827 // active tab will end up being navigated. It should be 1, except for the
829 // Link Doctor page, which acts like two navigations. 828 // Link Doctor page, which acts like two navigations.
830 void NavigateToPageExpectNoTest(Browser* browser, 829 void NavigateToPageExpectNoTest(Browser* browser,
831 const GURL& url, 830 const GURL& url,
832 int expected_navigations); 831 int expected_navigations);
833 832
834 // Navigates |browser|'s active tab to an SSL tab that takes a while to load, 833 // Navigates |browser|'s active tab to an SSL tab that takes a while to load,
835 // triggering a captive portal check, which is expected to give the result 834 // triggering a captive portal check, which is expected to give the result
836 // |expected_result|. The page finishes loading, with a timeout, after the 835 // |expected_result|. The page finishes loading, with a timeout, after the
837 // captive portal check. 836 // captive portal check.
838 void SlowLoadNoCaptivePortal(Browser* browser, Result expected_result); 837 void SlowLoadNoCaptivePortal(Browser* browser,
838 CaptivePortalResult expected_result);
839 839
840 // Navigates |browser|'s active tab to an SSL timeout, expecting a captive 840 // Navigates |browser|'s active tab to an SSL timeout, expecting a captive
841 // portal check to be triggered and return a result which will indicates 841 // portal check to be triggered and return a result which will indicates
842 // there's no detected captive portal. 842 // there's no detected captive portal.
843 void FastTimeoutNoCaptivePortal(Browser* browser, Result expected_result); 843 void FastTimeoutNoCaptivePortal(Browser* browser,
844 CaptivePortalResult expected_result);
844 845
845 // Navigates the active tab to a slow loading SSL page, which will then 846 // Navigates the active tab to a slow loading SSL page, which will then
846 // trigger a captive portal test. The test is expected to find a captive 847 // trigger a captive portal test. The test is expected to find a captive
847 // portal. The slow loading page will continue to load after the function 848 // portal. The slow loading page will continue to load after the function
848 // returns, until URLRequestTimeoutOnDemandJob::FailJobs() is called, 849 // returns, until URLRequestTimeoutOnDemandJob::FailJobs() is called,
849 // at which point it will timeout. 850 // at which point it will timeout.
850 // 851 //
851 // When |expect_login_tab| is false, no login tab is expected to be opened, 852 // When |expect_login_tab| is false, no login tab is expected to be opened,
852 // because one already exists, and the function returns once the captive 853 // because one already exists, and the function returns once the captive
853 // portal test is complete. 854 // portal test is complete.
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 EXPECT_EQ(0, portal_observer.num_results_received()); 1045 EXPECT_EQ(0, portal_observer.num_results_received());
1045 EXPECT_FALSE(CheckPending(browser)); 1046 EXPECT_FALSE(CheckPending(browser));
1046 EXPECT_EQ(1, browser->tab_strip_model()->count()); 1047 EXPECT_EQ(1, browser->tab_strip_model()->count());
1047 EXPECT_EQ(expected_navigations, navigation_observer.num_navigations()); 1048 EXPECT_EQ(expected_navigations, navigation_observer.num_navigations());
1048 EXPECT_EQ(0, NumLoadingTabs()); 1049 EXPECT_EQ(0, NumLoadingTabs());
1049 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 1050 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
1050 GetStateOfTabReloaderAt(browser, 0)); 1051 GetStateOfTabReloaderAt(browser, 0));
1051 } 1052 }
1052 1053
1053 void CaptivePortalBrowserTest::SlowLoadNoCaptivePortal( 1054 void CaptivePortalBrowserTest::SlowLoadNoCaptivePortal(
1054 Browser* browser, Result expected_result) { 1055 Browser* browser,
1056 CaptivePortalResult expected_result) {
1055 CaptivePortalTabReloader* tab_reloader = 1057 CaptivePortalTabReloader* tab_reloader =
1056 GetTabReloader(browser->tab_strip_model()->GetActiveWebContents()); 1058 GetTabReloader(browser->tab_strip_model()->GetActiveWebContents());
1057 ASSERT_TRUE(tab_reloader); 1059 ASSERT_TRUE(tab_reloader);
1058 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); 1060 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta());
1059 1061
1060 MultiNavigationObserver navigation_observer; 1062 MultiNavigationObserver navigation_observer;
1061 CaptivePortalObserver portal_observer(browser->profile()); 1063 CaptivePortalObserver portal_observer(browser->profile());
1062 ui_test_utils::NavigateToURLWithDisposition(browser, 1064 ui_test_utils::NavigateToURLWithDisposition(browser,
1063 GURL(kMockHttpsUrl), 1065 GURL(kMockHttpsUrl),
1064 CURRENT_TAB, 1066 CURRENT_TAB,
(...skipping 18 matching lines...) Expand all
1083 ASSERT_EQ(1, browser->tab_strip_model()->count()); 1085 ASSERT_EQ(1, browser->tab_strip_model()->count());
1084 EXPECT_EQ(1, portal_observer.num_results_received()); 1086 EXPECT_EQ(1, portal_observer.num_results_received());
1085 EXPECT_FALSE(CheckPending(browser)); 1087 EXPECT_FALSE(CheckPending(browser));
1086 EXPECT_EQ(0, NumLoadingTabs()); 1088 EXPECT_EQ(0, NumLoadingTabs());
1087 1089
1088 // Set a slow SSL load time to prevent the timer from triggering. 1090 // Set a slow SSL load time to prevent the timer from triggering.
1089 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1)); 1091 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1));
1090 } 1092 }
1091 1093
1092 void CaptivePortalBrowserTest::FastTimeoutNoCaptivePortal( 1094 void CaptivePortalBrowserTest::FastTimeoutNoCaptivePortal(
1093 Browser* browser, Result expected_result) { 1095 Browser* browser,
1094 ASSERT_NE(expected_result, RESULT_BEHIND_CAPTIVE_PORTAL); 1096 CaptivePortalResult expected_result) {
1097 ASSERT_NE(expected_result, captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL);
1095 1098
1096 // Set the load time to be large, so the timer won't trigger. The value is 1099 // Set the load time to be large, so the timer won't trigger. The value is
1097 // not restored at the end of the function. 1100 // not restored at the end of the function.
1098 CaptivePortalTabReloader* tab_reloader = 1101 CaptivePortalTabReloader* tab_reloader =
1099 GetTabReloader(browser->tab_strip_model()->GetActiveWebContents()); 1102 GetTabReloader(browser->tab_strip_model()->GetActiveWebContents());
1100 ASSERT_TRUE(tab_reloader); 1103 ASSERT_TRUE(tab_reloader);
1101 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); 1104 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1));
1102 1105
1103 MultiNavigationObserver navigation_observer; 1106 MultiNavigationObserver navigation_observer;
1104 CaptivePortalObserver portal_observer(browser->profile()); 1107 CaptivePortalObserver portal_observer(browser->profile());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 ASSERT_EQ(initial_tab_count, tab_strip_model->count()); 1208 ASSERT_EQ(initial_tab_count, tab_strip_model->count());
1206 EXPECT_EQ(initial_active_index, tab_strip_model->active_index()); 1209 EXPECT_EQ(initial_active_index, tab_strip_model->active_index());
1207 } 1210 }
1208 1211
1209 // Wait for all the expect resource loads to actually start, so subsequent 1212 // Wait for all the expect resource loads to actually start, so subsequent
1210 // functions can rely on them having started. 1213 // functions can rely on them having started.
1211 URLRequestTimeoutOnDemandJob::WaitForJobs(initial_loading_tabs + 1); 1214 URLRequestTimeoutOnDemandJob::WaitForJobs(initial_loading_tabs + 1);
1212 1215
1213 EXPECT_EQ(initial_loading_tabs + 1, NumLoadingTabs()); 1216 EXPECT_EQ(initial_loading_tabs + 1, NumLoadingTabs());
1214 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs()); 1217 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs());
1215 EXPECT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, 1218 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
1216 portal_observer.captive_portal_result()); 1219 portal_observer.captive_portal_result());
1217 EXPECT_EQ(expected_portal_checks, portal_observer.num_results_received()); 1220 EXPECT_EQ(expected_portal_checks, portal_observer.num_results_received());
1218 EXPECT_FALSE(CheckPending(browser)); 1221 EXPECT_FALSE(CheckPending(browser));
1219 1222
1220 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, 1223 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
1221 GetStateOfTabReloaderAt(browser, initial_active_index)); 1224 GetStateOfTabReloaderAt(browser, initial_active_index));
1222 1225
1223 // Reset the load time to be large, so the timer won't trigger on a reload. 1226 // Reset the load time to be large, so the timer won't trigger on a reload.
1224 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); 1227 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1));
1225 } 1228 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 navigation_observer.WaitForNavigations(1); 1287 navigation_observer.WaitForNavigations(1);
1285 EXPECT_EQ(initial_active_index, tab_strip_model->active_index()); 1288 EXPECT_EQ(initial_active_index, tab_strip_model->active_index());
1286 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( 1289 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab(
1287 tab_strip_model->GetWebContentsAt(initial_active_index))); 1290 tab_strip_model->GetWebContentsAt(initial_active_index)));
1288 ASSERT_EQ(initial_tab_count, tab_strip_model->count()); 1291 ASSERT_EQ(initial_tab_count, tab_strip_model->count());
1289 EXPECT_EQ(initial_active_index, tab_strip_model->active_index()); 1292 EXPECT_EQ(initial_active_index, tab_strip_model->active_index());
1290 } 1293 }
1291 1294
1292 EXPECT_EQ(initial_loading_tabs, NumLoadingTabs()); 1295 EXPECT_EQ(initial_loading_tabs, NumLoadingTabs());
1293 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs()); 1296 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs());
1294 EXPECT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, 1297 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
1295 portal_observer.captive_portal_result()); 1298 portal_observer.captive_portal_result());
1296 EXPECT_EQ(1, portal_observer.num_results_received()); 1299 EXPECT_EQ(1, portal_observer.num_results_received());
1297 EXPECT_FALSE(CheckPending(browser)); 1300 EXPECT_FALSE(CheckPending(browser));
1298 1301
1299 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, 1302 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
1300 GetStateOfTabReloaderAt(browser, initial_active_index)); 1303 GetStateOfTabReloaderAt(browser, initial_active_index));
1301 } 1304 }
1302 1305
1303 void CaptivePortalBrowserTest::NavigateLoginTab(Browser* browser, 1306 void CaptivePortalBrowserTest::NavigateLoginTab(Browser* browser,
1304 int num_loading_tabs, 1307 int num_loading_tabs,
(...skipping 13 matching lines...) Expand all
1318 1321
1319 // Do the navigation. 1322 // Do the navigation.
1320 content::RenderFrameHost* render_frame_host = 1323 content::RenderFrameHost* render_frame_host =
1321 tab_strip_model->GetActiveWebContents()->GetMainFrame(); 1324 tab_strip_model->GetActiveWebContents()->GetMainFrame();
1322 render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("submitForm()")); 1325 render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("submitForm()"));
1323 1326
1324 portal_observer.WaitForResults(1); 1327 portal_observer.WaitForResults(1);
1325 navigation_observer.WaitForNavigations(1); 1328 navigation_observer.WaitForNavigations(1);
1326 1329
1327 // Check the captive portal result. 1330 // Check the captive portal result.
1328 EXPECT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, 1331 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
1329 portal_observer.captive_portal_result()); 1332 portal_observer.captive_portal_result());
1330 EXPECT_EQ(1, portal_observer.num_results_received()); 1333 EXPECT_EQ(1, portal_observer.num_results_received());
1331 EXPECT_FALSE(CheckPending(browser)); 1334 EXPECT_FALSE(CheckPending(browser));
1332 1335
1333 // Make sure not much has changed. 1336 // Make sure not much has changed.
1334 EXPECT_EQ(initial_tab_count, tab_strip_model->count()); 1337 EXPECT_EQ(initial_tab_count, tab_strip_model->count());
1335 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); 1338 EXPECT_EQ(num_loading_tabs, NumLoadingTabs());
1336 EXPECT_EQ(num_loading_tabs + num_timed_out_tabs, NumBrokenTabs()); 1339 EXPECT_EQ(num_loading_tabs + num_timed_out_tabs, NumBrokenTabs());
1337 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 1340 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
1338 GetStateOfTabReloaderAt(browser, login_tab_index)); 1341 GetStateOfTabReloaderAt(browser, login_tab_index));
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 NavigateToPageExpectNoTest(browser(), url, 1); 1567 NavigateToPageExpectNoTest(browser(), url, 1);
1565 } 1568 }
1566 1569
1567 // Check the captive portal result when the test request reports a network 1570 // Check the captive portal result when the test request reports a network
1568 // error. The check is triggered by a slow loading page, and the page 1571 // error. The check is triggered by a slow loading page, and the page
1569 // errors out only after getting a captive portal result. 1572 // errors out only after getting a captive portal result.
1570 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, RequestFails) { 1573 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, RequestFails) {
1571 SetUpCaptivePortalService( 1574 SetUpCaptivePortalService(
1572 browser()->profile(), 1575 browser()->profile(),
1573 URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_CLOSED)); 1576 URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_CLOSED));
1574 SlowLoadNoCaptivePortal(browser(), RESULT_NO_RESPONSE); 1577 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_NO_RESPONSE);
1575 } 1578 }
1576 1579
1577 // Same as above, but for the rather unlikely case that the connection times out 1580 // Same as above, but for the rather unlikely case that the connection times out
1578 // before the timer triggers. 1581 // before the timer triggers.
1579 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, RequestFailsFastTimout) { 1582 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, RequestFailsFastTimout) {
1580 SetUpCaptivePortalService( 1583 SetUpCaptivePortalService(
1581 browser()->profile(), 1584 browser()->profile(),
1582 URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_CLOSED)); 1585 URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_CLOSED));
1583 FastTimeoutNoCaptivePortal(browser(), RESULT_NO_RESPONSE); 1586 FastTimeoutNoCaptivePortal(browser(), captive_portal::RESULT_NO_RESPONSE);
1584 } 1587 }
1585 1588
1586 // Checks the case that captive portal detection is disabled. 1589 // Checks the case that captive portal detection is disabled.
1587 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, Disabled) { 1590 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, Disabled) {
1588 EnableCaptivePortalDetection(browser()->profile(), false); 1591 EnableCaptivePortalDetection(browser()->profile(), false);
1589 SlowLoadNoCaptivePortal(browser(), RESULT_INTERNET_CONNECTED); 1592 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_INTERNET_CONNECTED);
1590 } 1593 }
1591 1594
1592 // Checks that we look for a captive portal on HTTPS timeouts and don't reload 1595 // Checks that we look for a captive portal on HTTPS timeouts and don't reload
1593 // the error tab when the captive portal probe gets a 204 response, indicating 1596 // the error tab when the captive portal probe gets a 204 response, indicating
1594 // there is no captive portal. 1597 // there is no captive portal.
1595 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, InternetConnected) { 1598 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, InternetConnected) {
1596 // Can't just use SetBehindCaptivePortal(false), since then there wouldn't 1599 // Can't just use SetBehindCaptivePortal(false), since then there wouldn't
1597 // be a timeout. 1600 // be a timeout.
1598 ASSERT_TRUE(test_server()->Start()); 1601 ASSERT_TRUE(test_server()->Start());
1599 SetUpCaptivePortalService(browser()->profile(), 1602 SetUpCaptivePortalService(browser()->profile(),
1600 test_server()->GetURL("nocontent")); 1603 test_server()->GetURL("nocontent"));
1601 SlowLoadNoCaptivePortal(browser(), RESULT_INTERNET_CONNECTED); 1604 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_INTERNET_CONNECTED);
1602 } 1605 }
1603 1606
1604 // Checks that no login page is opened when the HTTP test URL redirects to an 1607 // Checks that no login page is opened when the HTTP test URL redirects to an
1605 // SSL certificate error. 1608 // SSL certificate error.
1606 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, RedirectSSLCertError) { 1609 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, RedirectSSLCertError) {
1607 // Need an HTTP TestServer to handle a dynamically created server redirect. 1610 // Need an HTTP TestServer to handle a dynamically created server redirect.
1608 ASSERT_TRUE(test_server()->Start()); 1611 ASSERT_TRUE(test_server()->Start());
1609 1612
1610 net::SpawnedTestServer::SSLOptions ssl_options; 1613 net::SpawnedTestServer::SSLOptions ssl_options;
1611 ssl_options.server_certificate = 1614 ssl_options.server_certificate =
1612 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; 1615 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
1613 net::SpawnedTestServer https_server( 1616 net::SpawnedTestServer https_server(
1614 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, 1617 net::SpawnedTestServer::TYPE_HTTPS, ssl_options,
1615 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 1618 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1616 ASSERT_TRUE(https_server.Start()); 1619 ASSERT_TRUE(https_server.Start());
1617 1620
1618 GURL ssl_login_url = https_server.GetURL(kTestServerLoginPath); 1621 GURL ssl_login_url = https_server.GetURL(kTestServerLoginPath);
1619 1622
1620 CaptivePortalService* captive_portal_service = 1623 CaptivePortalService* captive_portal_service =
1621 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); 1624 CaptivePortalServiceFactory::GetForProfile(browser()->profile());
1622 ASSERT_TRUE(captive_portal_service); 1625 ASSERT_TRUE(captive_portal_service);
1623 SetUpCaptivePortalService( 1626 SetUpCaptivePortalService(
1624 browser()->profile(), 1627 browser()->profile(),
1625 test_server()->GetURL(CreateServerRedirect(ssl_login_url.spec()))); 1628 test_server()->GetURL(CreateServerRedirect(ssl_login_url.spec())));
1626 1629
1627 SlowLoadNoCaptivePortal(browser(), RESULT_NO_RESPONSE); 1630 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_NO_RESPONSE);
1628 } 1631 }
1629 1632
1630 // A slow SSL load triggers a captive portal check. The user logs on before 1633 // A slow SSL load triggers a captive portal check. The user logs on before
1631 // the SSL page times out. We wait for the timeout and subsequent reload. 1634 // the SSL page times out. We wait for the timeout and subsequent reload.
1632 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, Login) { 1635 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, Login) {
1633 // Load starts, detect captive portal and open up a login tab. 1636 // Load starts, detect captive portal and open up a login tab.
1634 SlowLoadBehindCaptivePortal(browser(), true); 1637 SlowLoadBehindCaptivePortal(browser(), true);
1635 1638
1636 // Log in. One loading tab, no timed out ones. 1639 // Log in. One loading tab, no timed out ones.
1637 Login(browser(), 1, 0); 1640 Login(browser(), 1, 0);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 GetStateOfTabReloaderAt(browser(), 0)); 1944 GetStateOfTabReloaderAt(browser(), 0));
1942 EXPECT_EQ(0, portal_observer.num_results_received()); 1945 EXPECT_EQ(0, portal_observer.num_results_received());
1943 } 1946 }
1944 1947
1945 // Checks that navigating back to a timeout triggers captive portal detection. 1948 // Checks that navigating back to a timeout triggers captive portal detection.
1946 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, GoBackToTimeout) { 1949 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, GoBackToTimeout) {
1947 // Disable captive portal detection so the first navigation doesn't open a 1950 // Disable captive portal detection so the first navigation doesn't open a
1948 // login tab. 1951 // login tab.
1949 EnableCaptivePortalDetection(browser()->profile(), false); 1952 EnableCaptivePortalDetection(browser()->profile(), false);
1950 1953
1951 SlowLoadNoCaptivePortal(browser(), RESULT_INTERNET_CONNECTED); 1954 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_INTERNET_CONNECTED);
1952 1955
1953 // Navigate to a working page. 1956 // Navigate to a working page.
1954 ui_test_utils::NavigateToURL( 1957 ui_test_utils::NavigateToURL(
1955 browser(), URLRequestMockHTTPJob::GetMockUrl( 1958 browser(), URLRequestMockHTTPJob::GetMockUrl(
1956 base::FilePath(FILE_PATH_LITERAL("title2.html")))); 1959 base::FilePath(FILE_PATH_LITERAL("title2.html"))));
1957 ASSERT_EQ(CaptivePortalTabReloader::STATE_NONE, 1960 ASSERT_EQ(CaptivePortalTabReloader::STATE_NONE,
1958 GetStateOfTabReloaderAt(browser(), 0)); 1961 GetStateOfTabReloaderAt(browser(), 0));
1959 1962
1960 EnableCaptivePortalDetection(browser()->profile(), true); 1963 EnableCaptivePortalDetection(browser()->profile(), true);
1961 1964
(...skipping 10 matching lines...) Expand all
1972 1975
1973 // Wait for the check triggered by the broken tab and for the login tab to 1976 // Wait for the check triggered by the broken tab and for the login tab to
1974 // stop loading. 1977 // stop loading.
1975 portal_observer.WaitForResults(1); 1978 portal_observer.WaitForResults(1);
1976 navigation_observer.WaitForNavigations(1); 1979 navigation_observer.WaitForNavigations(1);
1977 // Make sure the request has been issued. 1980 // Make sure the request has been issued.
1978 URLRequestTimeoutOnDemandJob::WaitForJobs(1); 1981 URLRequestTimeoutOnDemandJob::WaitForJobs(1);
1979 1982
1980 EXPECT_EQ(1, portal_observer.num_results_received()); 1983 EXPECT_EQ(1, portal_observer.num_results_received());
1981 ASSERT_FALSE(CheckPending(browser())); 1984 ASSERT_FALSE(CheckPending(browser()));
1982 ASSERT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, 1985 ASSERT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
1983 portal_observer.captive_portal_result()); 1986 portal_observer.captive_portal_result());
1984 1987
1985 ASSERT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, 1988 ASSERT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
1986 GetStateOfTabReloaderAt(browser(), 0)); 1989 GetStateOfTabReloaderAt(browser(), 0));
1987 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 1990 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
1988 GetStateOfTabReloaderAt(browser(), 1)); 1991 GetStateOfTabReloaderAt(browser(), 1));
1989 ASSERT_TRUE(IsLoginTab(browser()->tab_strip_model()->GetWebContentsAt(1))); 1992 ASSERT_TRUE(IsLoginTab(browser()->tab_strip_model()->GetWebContentsAt(1)));
1990 1993
1991 ASSERT_EQ(2, tab_strip_model->count()); 1994 ASSERT_EQ(2, tab_strip_model->count());
1992 EXPECT_EQ(1, tab_strip_model->active_index()); 1995 EXPECT_EQ(1, tab_strip_model->active_index());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 2028
2026 // Wait for the check triggered by the broken tab and for the login tab to 2029 // Wait for the check triggered by the broken tab and for the login tab to
2027 // stop loading. 2030 // stop loading.
2028 portal_observer.WaitForResults(1); 2031 portal_observer.WaitForResults(1);
2029 navigation_observer.WaitForNavigations(1); 2032 navigation_observer.WaitForNavigations(1);
2030 // Make sure the request has been issued. 2033 // Make sure the request has been issued.
2031 URLRequestTimeoutOnDemandJob::WaitForJobs(1); 2034 URLRequestTimeoutOnDemandJob::WaitForJobs(1);
2032 2035
2033 ASSERT_EQ(1, portal_observer.num_results_received()); 2036 ASSERT_EQ(1, portal_observer.num_results_received());
2034 ASSERT_FALSE(CheckPending(browser())); 2037 ASSERT_FALSE(CheckPending(browser()));
2035 ASSERT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, 2038 ASSERT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
2036 portal_observer.captive_portal_result()); 2039 portal_observer.captive_portal_result());
2037 2040
2038 ASSERT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, 2041 ASSERT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
2039 GetStateOfTabReloaderAt(browser(), 0)); 2042 GetStateOfTabReloaderAt(browser(), 0));
2040 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 2043 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
2041 GetStateOfTabReloaderAt(browser(), 1)); 2044 GetStateOfTabReloaderAt(browser(), 1));
2042 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(1))); 2045 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(1)));
2043 2046
2044 ASSERT_EQ(2, tab_strip_model->count()); 2047 ASSERT_EQ(2, tab_strip_model->count());
2045 EXPECT_EQ(1, tab_strip_model->active_index()); 2048 EXPECT_EQ(1, tab_strip_model->active_index());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 // Check that the only two navigated tabs were the new error tab in the 2108 // Check that the only two navigated tabs were the new error tab in the
2106 // backround windows, and the login tab in the active window. 2109 // backround windows, and the login tab in the active window.
2107 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( 2110 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab(
2108 inactive_browser->tab_strip_model()->GetWebContentsAt(1))); 2111 inactive_browser->tab_strip_model()->GetWebContentsAt(1)));
2109 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( 2112 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab(
2110 active_browser->tab_strip_model()->GetWebContentsAt(1))); 2113 active_browser->tab_strip_model()->GetWebContentsAt(1)));
2111 EXPECT_EQ(0, NumLoadingTabs()); 2114 EXPECT_EQ(0, NumLoadingTabs());
2112 2115
2113 // Check captive portal test results. 2116 // Check captive portal test results.
2114 portal_observer.WaitForResults(1); 2117 portal_observer.WaitForResults(1);
2115 ASSERT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, 2118 ASSERT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
2116 portal_observer.captive_portal_result()); 2119 portal_observer.captive_portal_result());
2117 EXPECT_EQ(1, portal_observer.num_results_received()); 2120 EXPECT_EQ(1, portal_observer.num_results_received());
2118 2121
2119 // Check the inactive browser. 2122 // Check the inactive browser.
2120 EXPECT_EQ(2, inactive_browser->tab_strip_model()->count()); 2123 EXPECT_EQ(2, inactive_browser->tab_strip_model()->count());
2121 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 2124 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
2122 GetStateOfTabReloaderAt(inactive_browser, 0)); 2125 GetStateOfTabReloaderAt(inactive_browser, 0));
2123 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, 2126 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
2124 GetStateOfTabReloaderAt(inactive_browser, 1)); 2127 GetStateOfTabReloaderAt(inactive_browser, 1));
2125 2128
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2191 content::BrowserThread::PostTask( 2194 content::BrowserThread::PostTask(
2192 content::BrowserThread::IO, FROM_HERE, 2195 content::BrowserThread::IO, FROM_HERE,
2193 base::Bind(&AddHstsHost, 2196 base::Bind(&AddHstsHost,
2194 make_scoped_refptr(browser()->profile()->GetRequestContext()), 2197 make_scoped_refptr(browser()->profile()->GetRequestContext()),
2195 http_timeout_url.host())); 2198 http_timeout_url.host()));
2196 2199
2197 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); 2200 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1);
2198 Login(browser(), 1, 0); 2201 Login(browser(), 1, 0);
2199 FailLoadsAfterLogin(browser(), 1); 2202 FailLoadsAfterLogin(browser(), 1);
2200 } 2203 }
2201
2202 } // namespace captive_portal
OLDNEW
« no previous file with comments | « chrome/browser/captive_portal/DEPS ('k') | chrome/browser/captive_portal/captive_portal_detector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698