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 <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" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "chrome/browser/captive_portal/captive_portal_service.h" | 17 #include "chrome/browser/captive_portal/captive_portal_service.h" |
18 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 18 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
19 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 19 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
20 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 20 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/interstitials/security_interstitial_page.h" | |
22 #include "chrome/browser/net/url_request_mock_util.h" | 23 #include "chrome/browser/net/url_request_mock_util.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_commands.h" | 26 #include "chrome/browser/ui/browser_commands.h" |
26 #include "chrome/browser/ui/browser_finder.h" | 27 #include "chrome/browser/ui/browser_finder.h" |
27 #include "chrome/browser/ui/browser_navigator.h" | 28 #include "chrome/browser/ui/browser_navigator.h" |
28 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 29 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
30 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
33 #include "chrome/test/base/in_process_browser_test.h" | 34 #include "chrome/test/base/in_process_browser_test.h" |
34 #include "chrome/test/base/ui_test_utils.h" | 35 #include "chrome/test/base/ui_test_utils.h" |
35 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
37 #include "content/public/browser/interstitial_page.h" | |
38 #include "content/public/browser/interstitial_page_delegate.h" | |
36 #include "content/public/browser/navigation_controller.h" | 39 #include "content/public/browser/navigation_controller.h" |
40 #include "content/public/browser/navigation_entry.h" | |
37 #include "content/public/browser/notification_observer.h" | 41 #include "content/public/browser/notification_observer.h" |
38 #include "content/public/browser/notification_registrar.h" | 42 #include "content/public/browser/notification_registrar.h" |
39 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
40 #include "content/public/browser/notification_types.h" | 44 #include "content/public/browser/notification_types.h" |
41 #include "content/public/browser/render_frame_host.h" | 45 #include "content/public/browser/render_frame_host.h" |
42 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
43 #include "content/public/common/url_constants.h" | 47 #include "content/public/common/url_constants.h" |
44 #include "net/base/net_errors.h" | 48 #include "net/base/net_errors.h" |
45 #include "net/http/transport_security_state.h" | 49 #include "net/http/transport_security_state.h" |
46 #include "net/test/url_request/url_request_failed_job.h" | 50 #include "net/test/url_request/url_request_failed_job.h" |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 } | 687 } |
684 } | 688 } |
685 | 689 |
686 // An observer for watching the CaptivePortalService. It tracks the last | 690 // An observer for watching the CaptivePortalService. It tracks the last |
687 // received result and the total number of received results. | 691 // received result and the total number of received results. |
688 class CaptivePortalObserver : public content::NotificationObserver { | 692 class CaptivePortalObserver : public content::NotificationObserver { |
689 public: | 693 public: |
690 explicit CaptivePortalObserver(Profile* profile); | 694 explicit CaptivePortalObserver(Profile* profile); |
691 | 695 |
692 // Runs the message loop until until at exactly |update_count| capitive portal | 696 // Runs the message loop until until at exactly |update_count| capitive portal |
693 // results have been received, since this creation of |this|. Expects no | 697 // results have been received, since the creation of |this|. Expects no |
694 // additional captive portal results. | 698 // additional captive portal results. |
695 void WaitForResults(int num_results_to_wait_for); | 699 void WaitForResults(int num_results_to_wait_for); |
696 | 700 |
697 int num_results_received() const { return num_results_received_; } | 701 int num_results_received() const { return num_results_received_; } |
698 | 702 |
699 CaptivePortalResult captive_portal_result() const { | 703 CaptivePortalResult captive_portal_result() const { |
700 return captive_portal_result_; | 704 return captive_portal_result_; |
701 } | 705 } |
702 | 706 |
703 private: | 707 private: |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 void EnableCaptivePortalDetection(Profile* profile, bool enabled); | 813 void EnableCaptivePortalDetection(Profile* profile, bool enabled); |
810 | 814 |
811 // Sets up the captive portal service for the given profile so that | 815 // Sets up the captive portal service for the given profile so that |
812 // all checks go to |test_url|. Also disables all timers. | 816 // all checks go to |test_url|. Also disables all timers. |
813 void SetUpCaptivePortalService(Profile* profile, const GURL& test_url); | 817 void SetUpCaptivePortalService(Profile* profile, const GURL& test_url); |
814 | 818 |
815 // Returns true if |browser|'s profile is currently running a captive portal | 819 // Returns true if |browser|'s profile is currently running a captive portal |
816 // check. | 820 // check. |
817 bool CheckPending(Browser* browser); | 821 bool CheckPending(Browser* browser); |
818 | 822 |
823 // Returns the type of the interstitial being shown. | |
824 SecurityInterstitialPage::Type GetInterstitialType( | |
825 WebContents* contents) const; | |
826 | |
819 // Returns the CaptivePortalTabReloader::State of |web_contents|. | 827 // Returns the CaptivePortalTabReloader::State of |web_contents|. |
820 CaptivePortalTabReloader::State GetStateOfTabReloader( | 828 CaptivePortalTabReloader::State GetStateOfTabReloader( |
821 WebContents* web_contents) const; | 829 WebContents* web_contents) const; |
822 | 830 |
823 // Returns the CaptivePortalTabReloader::State of the indicated tab. | 831 // Returns the CaptivePortalTabReloader::State of the indicated tab. |
824 CaptivePortalTabReloader::State GetStateOfTabReloaderAt(Browser* browser, | 832 CaptivePortalTabReloader::State GetStateOfTabReloaderAt(Browser* browser, |
825 int index) const; | 833 int index) const; |
826 | 834 |
827 // Returns the number of tabs with the given state, across all profiles. | 835 // Returns the number of tabs with the given state, across all profiles. |
828 int NumTabsWithState(CaptivePortalTabReloader::State state) const; | 836 int NumTabsWithState(CaptivePortalTabReloader::State state) const; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
942 void RunNavigateLoadingTabToTimeoutTest(Browser* browser, | 950 void RunNavigateLoadingTabToTimeoutTest(Browser* browser, |
943 const GURL& starting_url, | 951 const GURL& starting_url, |
944 const GURL& interrupted_url, | 952 const GURL& interrupted_url, |
945 const GURL& timeout_url); | 953 const GURL& timeout_url); |
946 | 954 |
947 // Sets the timeout used by a CaptivePortalTabReloader on slow SSL loads | 955 // Sets the timeout used by a CaptivePortalTabReloader on slow SSL loads |
948 // before a captive portal check. | 956 // before a captive portal check. |
949 void SetSlowSSLLoadTime(CaptivePortalTabReloader* tab_reloader, | 957 void SetSlowSSLLoadTime(CaptivePortalTabReloader* tab_reloader, |
950 base::TimeDelta slow_ssl_load_time); | 958 base::TimeDelta slow_ssl_load_time); |
951 | 959 |
960 void SetSSLErrorDisplayDelay(CaptivePortalTabHelper* tab_helper, | |
961 base::TimeDelta ssl_error_delay); | |
962 | |
952 CaptivePortalTabReloader* GetTabReloader(WebContents* web_contents) const; | 963 CaptivePortalTabReloader* GetTabReloader(WebContents* web_contents) const; |
953 | 964 |
954 private: | 965 private: |
955 DISALLOW_COPY_AND_ASSIGN(CaptivePortalBrowserTest); | 966 DISALLOW_COPY_AND_ASSIGN(CaptivePortalBrowserTest); |
956 }; | 967 }; |
957 | 968 |
958 CaptivePortalBrowserTest::CaptivePortalBrowserTest() { | 969 CaptivePortalBrowserTest::CaptivePortalBrowserTest() { |
959 } | 970 } |
960 | 971 |
961 void CaptivePortalBrowserTest::SetUpOnMainThread() { | 972 void CaptivePortalBrowserTest::SetUpOnMainThread() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1005 } | 1016 } |
1006 | 1017 |
1007 bool CaptivePortalBrowserTest::CheckPending(Browser* browser) { | 1018 bool CaptivePortalBrowserTest::CheckPending(Browser* browser) { |
1008 CaptivePortalService* captive_portal_service = | 1019 CaptivePortalService* captive_portal_service = |
1009 CaptivePortalServiceFactory::GetForProfile(browser->profile()); | 1020 CaptivePortalServiceFactory::GetForProfile(browser->profile()); |
1010 | 1021 |
1011 return captive_portal_service->DetectionInProgress() || | 1022 return captive_portal_service->DetectionInProgress() || |
1012 captive_portal_service->TimerRunning(); | 1023 captive_portal_service->TimerRunning(); |
1013 } | 1024 } |
1014 | 1025 |
1026 SecurityInterstitialPage::Type CaptivePortalBrowserTest::GetInterstitialType( | |
1027 WebContents* contents) const { | |
1028 DCHECK(contents->ShowingInterstitialPage()); | |
1029 SecurityInterstitialPage* blocking_page = | |
1030 static_cast<SecurityInterstitialPage*>( | |
1031 contents->GetInterstitialPage()->GetDelegateForTesting()); | |
1032 DCHECK(blocking_page); | |
1033 return blocking_page->GetTypeForTesting(); | |
1034 } | |
1035 | |
1015 CaptivePortalTabReloader::State CaptivePortalBrowserTest::GetStateOfTabReloader( | 1036 CaptivePortalTabReloader::State CaptivePortalBrowserTest::GetStateOfTabReloader( |
1016 WebContents* web_contents) const { | 1037 WebContents* web_contents) const { |
1017 return GetTabReloader(web_contents)->state(); | 1038 return GetTabReloader(web_contents)->state(); |
1018 } | 1039 } |
1019 | 1040 |
1020 CaptivePortalTabReloader::State | 1041 CaptivePortalTabReloader::State |
1021 CaptivePortalBrowserTest::GetStateOfTabReloaderAt(Browser* browser, | 1042 CaptivePortalBrowserTest::GetStateOfTabReloaderAt(Browser* browser, |
1022 int index) const { | 1043 int index) const { |
1023 return GetStateOfTabReloader( | 1044 return GetStateOfTabReloader( |
1024 browser->tab_strip_model()->GetWebContentsAt(index)); | 1045 browser->tab_strip_model()->GetWebContentsAt(index)); |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1539 // Timeout occurs, and page is automatically reloaded. | 1560 // Timeout occurs, and page is automatically reloaded. |
1540 FailLoadsAfterLogin(browser, 1); | 1561 FailLoadsAfterLogin(browser, 1); |
1541 } | 1562 } |
1542 | 1563 |
1543 void CaptivePortalBrowserTest::SetSlowSSLLoadTime( | 1564 void CaptivePortalBrowserTest::SetSlowSSLLoadTime( |
1544 CaptivePortalTabReloader* tab_reloader, | 1565 CaptivePortalTabReloader* tab_reloader, |
1545 base::TimeDelta slow_ssl_load_time) { | 1566 base::TimeDelta slow_ssl_load_time) { |
1546 tab_reloader->set_slow_ssl_load_time(slow_ssl_load_time); | 1567 tab_reloader->set_slow_ssl_load_time(slow_ssl_load_time); |
1547 } | 1568 } |
1548 | 1569 |
1570 void CaptivePortalBrowserTest::SetSSLErrorDisplayDelay( | |
1571 CaptivePortalTabHelper* tab_helper, | |
1572 base::TimeDelta ssl_error_delay) { | |
1573 tab_helper->SetSSLErrorDelayForTest(ssl_error_delay); | |
1574 } | |
1575 | |
1549 CaptivePortalTabReloader* CaptivePortalBrowserTest::GetTabReloader( | 1576 CaptivePortalTabReloader* CaptivePortalBrowserTest::GetTabReloader( |
1550 WebContents* web_contents) const { | 1577 WebContents* web_contents) const { |
1551 return CaptivePortalTabHelper::FromWebContents(web_contents)-> | 1578 return CaptivePortalTabHelper::FromWebContents(web_contents)-> |
1552 GetTabReloaderForTest(); | 1579 GetTabReloaderForTest(); |
1553 } | 1580 } |
1554 | 1581 |
1555 // Make sure there's no test for a captive portal on HTTP timeouts. This will | 1582 // Make sure there's no test for a captive portal on HTTP timeouts. This will |
1556 // also trigger the link doctor page, which results in the load of a second | 1583 // also trigger the link doctor page, which results in the load of a second |
1557 // error page. | 1584 // error page. |
1558 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HttpTimeout) { | 1585 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HttpTimeout) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1711 ASSERT_TRUE(test_server()->Start()); | 1738 ASSERT_TRUE(test_server()->Start()); |
1712 | 1739 |
1713 net::SpawnedTestServer::SSLOptions https_options; | 1740 net::SpawnedTestServer::SSLOptions https_options; |
1714 https_options.server_certificate = | 1741 https_options.server_certificate = |
1715 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 1742 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; |
1716 net::SpawnedTestServer https_server( | 1743 net::SpawnedTestServer https_server( |
1717 net::SpawnedTestServer::TYPE_HTTPS, https_options, | 1744 net::SpawnedTestServer::TYPE_HTTPS, https_options, |
1718 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 1745 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
1719 ASSERT_TRUE(https_server.Start()); | 1746 ASSERT_TRUE(https_server.Start()); |
1720 | 1747 |
1748 // Set SSL interstitial delay to zero so that a captive portal result can not | |
1749 // arrive during this window, so an SSL interstitial is displayed instead | |
1750 // of a captive portal error page. | |
1751 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
1752 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
1753 SetSSLErrorDisplayDelay( | |
1754 CaptivePortalTabHelper::FromWebContents(broken_tab_contents), | |
1755 base::TimeDelta()); | |
1756 | |
1721 // The path does not matter. | 1757 // The path does not matter. |
1722 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | 1758 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); |
1723 // The interstitial should trigger a captive portal check when it opens, just | 1759 // The interstitial should trigger a captive portal check when it opens, just |
1724 // like navigating to kMockHttpsQuickTimeoutUrl. | 1760 // like navigating to kMockHttpsQuickTimeoutUrl. |
1725 FastErrorBehindCaptivePortal(browser(), true, cert_error_url); | 1761 FastErrorBehindCaptivePortal(browser(), true, cert_error_url); |
1726 | 1762 |
1763 EXPECT_EQ(SecurityInterstitialPage::SSL, | |
1764 GetInterstitialType(broken_tab_contents)); | |
1765 | |
1727 // Simulate logging in. Can't use Login() because the interstitial tab looks | 1766 // Simulate logging in. Can't use Login() because the interstitial tab looks |
1728 // like a cross between a hung tab (Load was never committed) and a tab at an | 1767 // like a cross between a hung tab (Load was never committed) and a tab at an |
1729 // error page (The load was stopped). | 1768 // error page (The load was stopped). |
1730 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); | 1769 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); |
1731 MultiNavigationObserver navigation_observer; | 1770 MultiNavigationObserver navigation_observer; |
1732 CaptivePortalObserver portal_observer(browser()->profile()); | 1771 CaptivePortalObserver portal_observer(browser()->profile()); |
1733 | 1772 |
1734 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
1735 content::RenderFrameHost* render_frame_host = | 1773 content::RenderFrameHost* render_frame_host = |
1736 tab_strip_model->GetActiveWebContents()->GetMainFrame(); | 1774 tab_strip_model->GetActiveWebContents()->GetMainFrame(); |
1737 render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("submitForm()")); | 1775 render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("submitForm()")); |
1738 | 1776 |
1739 // The captive portal tab navigation will trigger a captive portal check, | 1777 // The captive portal tab navigation will trigger a captive portal check, |
1740 // and reloading the original tab will bring up the interstitial page again, | 1778 // and reloading the original tab will bring up the interstitial page again, |
1741 // triggering a second captive portal check. | 1779 // triggering a second captive portal check. |
1742 portal_observer.WaitForResults(2); | 1780 portal_observer.WaitForResults(2); |
1743 | 1781 |
1744 // Wait for both tabs to finish loading. | 1782 // Wait for both tabs to finish loading. |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2206 content::BrowserThread::PostTask( | 2244 content::BrowserThread::PostTask( |
2207 content::BrowserThread::IO, FROM_HERE, | 2245 content::BrowserThread::IO, FROM_HERE, |
2208 base::Bind(&AddHstsHost, | 2246 base::Bind(&AddHstsHost, |
2209 make_scoped_refptr(browser()->profile()->GetRequestContext()), | 2247 make_scoped_refptr(browser()->profile()->GetRequestContext()), |
2210 http_timeout_url.host())); | 2248 http_timeout_url.host())); |
2211 | 2249 |
2212 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); | 2250 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); |
2213 Login(browser(), 1, 0); | 2251 Login(browser(), 1, 0); |
2214 FailLoadsAfterLogin(browser(), 1); | 2252 FailLoadsAfterLogin(browser(), 1); |
2215 } | 2253 } |
2254 | |
2255 // A cert error triggers a captive portal check and results in opening a login | |
2256 // tab. The user then logs in and the page with the error is reloaded. | |
mmenke
2014/10/30 19:28:01
The last sentence is false.
mmenke
2014/10/30 19:28:01
I suggest putting more basic tests before ones tha
meacer
2014/11/06 21:21:55
Done.
| |
2257 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | |
2258 ShowCaptivePortalInterstitialOnCertError) { | |
2259 net::SpawnedTestServer::SSLOptions https_options; | |
2260 https_options.server_certificate = | |
2261 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | |
2262 net::SpawnedTestServer https_server( | |
2263 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
2264 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
2265 ASSERT_TRUE(https_server.Start()); | |
2266 | |
2267 // Set SSL interstitial delay long enough so that a captive portal result | |
2268 // is guaranteed to arrive during this window, and a captive portal | |
2269 // error page is displayed instead of an SSL interstitial. | |
2270 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2271 SetSSLErrorDisplayDelay( | |
2272 CaptivePortalTabHelper::FromWebContents( | |
2273 tab_strip_model->GetActiveWebContents()), | |
2274 base::TimeDelta::FromHours(1)); | |
2275 | |
2276 content::WebContents* web_contents = tab_strip_model->GetActiveWebContents(); | |
2277 // The path does not matter. | |
2278 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
2279 // The interstitial should trigger a captive portal check when it opens, just | |
2280 // like navigating to kMockHttpsQuickTimeoutUrl. | |
2281 FastErrorBehindCaptivePortal(browser(), true, cert_error_url); | |
2282 | |
2283 EXPECT_EQ(SecurityInterstitialPage::CAPTIVE_PORTAL, | |
2284 GetInterstitialType(web_contents)); | |
2285 } | |
OLD | NEW |