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> |
11 | 11 |
12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 20 #include "base/scoped_observer.h" |
20 #include "base/sequence_checker.h" | 21 #include "base/sequence_checker.h" |
21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
24 #include "chrome/browser/captive_portal/captive_portal_service.h" | 25 #include "chrome/browser/captive_portal/captive_portal_service.h" |
25 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 26 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
26 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 27 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
27 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 28 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
28 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
29 #include "chrome/browser/net/url_request_mock_util.h" | 30 #include "chrome/browser/net/url_request_mock_util.h" |
30 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | 32 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
32 #include "chrome/browser/ssl/ssl_blocking_page.h" | 33 #include "chrome/browser/ssl/ssl_blocking_page.h" |
33 #include "chrome/browser/ssl/ssl_error_handler.h" | 34 #include "chrome/browser/ssl/ssl_error_handler.h" |
34 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
35 #include "chrome/browser/ui/browser_commands.h" | 36 #include "chrome/browser/ui/browser_commands.h" |
36 #include "chrome/browser/ui/browser_finder.h" | 37 #include "chrome/browser/ui/browser_finder.h" |
37 #include "chrome/browser/ui/browser_navigator_params.h" | 38 #include "chrome/browser/ui/browser_navigator_params.h" |
38 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 39 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
39 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 40 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 41 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
40 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
41 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
42 #include "chrome/test/base/in_process_browser_test.h" | 44 #include "chrome/test/base/in_process_browser_test.h" |
43 #include "chrome/test/base/ui_test_utils.h" | 45 #include "chrome/test/base/ui_test_utils.h" |
44 #include "components/prefs/pref_service.h" | 46 #include "components/prefs/pref_service.h" |
45 #include "components/security_interstitials/content/security_interstitial_page.h
" | 47 #include "components/security_interstitials/content/security_interstitial_page.h
" |
46 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
47 #include "content/public/browser/interstitial_page.h" | 49 #include "content/public/browser/interstitial_page.h" |
48 #include "content/public/browser/interstitial_page_delegate.h" | 50 #include "content/public/browser/interstitial_page_delegate.h" |
49 #include "content/public/browser/navigation_controller.h" | 51 #include "content/public/browser/navigation_controller.h" |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 if (!transport_security_state) { | 888 if (!transport_security_state) { |
887 FAIL(); | 889 FAIL(); |
888 return; | 890 return; |
889 } | 891 } |
890 | 892 |
891 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); | 893 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); |
892 bool include_subdomains = false; | 894 bool include_subdomains = false; |
893 transport_security_state->AddHSTS(host, expiry, include_subdomains); | 895 transport_security_state->AddHSTS(host, expiry, include_subdomains); |
894 } | 896 } |
895 | 897 |
| 898 // Helper for waiting for a change of the active tab. |
| 899 // Users can wait for the change via WaitForActiveTabChange method. |
| 900 // DCHECKs ensure that only one change happens during the lifetime of a |
| 901 // TabActivationWaiter instance. |
| 902 class TabActivationWaiter : public TabStripModelObserver { |
| 903 public: |
| 904 explicit TabActivationWaiter(TabStripModel* tab_strip_model) |
| 905 : number_of_unconsumed_active_tab_changes_(0), scoped_observer_(this) { |
| 906 scoped_observer_.Add(tab_strip_model); |
| 907 } |
| 908 |
| 909 void WaitForActiveTabChange() { |
| 910 if (number_of_unconsumed_active_tab_changes_ == 0) { |
| 911 // Wait until TabStripModelObserver::ActiveTabChanged will get called. |
| 912 message_loop_runner_ = new content::MessageLoopRunner; |
| 913 message_loop_runner_->Run(); |
| 914 } |
| 915 |
| 916 // "consume" one tab activation event. |
| 917 DCHECK_EQ(1, number_of_unconsumed_active_tab_changes_); |
| 918 number_of_unconsumed_active_tab_changes_--; |
| 919 } |
| 920 |
| 921 // TabStripModelObserver overrides. |
| 922 void ActiveTabChanged(content::WebContents* old_contents, |
| 923 content::WebContents* new_contents, |
| 924 int index, |
| 925 int reason) override { |
| 926 number_of_unconsumed_active_tab_changes_++; |
| 927 DCHECK_EQ(1, number_of_unconsumed_active_tab_changes_); |
| 928 if (message_loop_runner_) |
| 929 message_loop_runner_->Quit(); |
| 930 } |
| 931 |
| 932 private: |
| 933 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 934 int number_of_unconsumed_active_tab_changes_; |
| 935 ScopedObserver<TabStripModel, TabActivationWaiter> scoped_observer_; |
| 936 |
| 937 DISALLOW_COPY_AND_ASSIGN(TabActivationWaiter); |
| 938 }; |
| 939 |
896 } // namespace | 940 } // namespace |
897 | 941 |
898 class CaptivePortalBrowserTest : public InProcessBrowserTest { | 942 class CaptivePortalBrowserTest : public InProcessBrowserTest { |
899 public: | 943 public: |
900 CaptivePortalBrowserTest(); | 944 CaptivePortalBrowserTest(); |
901 | 945 |
902 // InProcessBrowserTest: | 946 // InProcessBrowserTest: |
903 void SetUpOnMainThread() override; | 947 void SetUpOnMainThread() override; |
904 void TearDownOnMainThread() override; | 948 void TearDownOnMainThread() override; |
905 void SetUpCommandLine(base::CommandLine* command_line) override; | 949 void SetUpCommandLine(base::CommandLine* command_line) override; |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 int initial_tab_count = tab_strip_model->count(); | 1573 int initial_tab_count = tab_strip_model->count(); |
1530 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); | 1574 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); |
1531 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); | 1575 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); |
1532 | 1576 |
1533 int login_tab_index = tab_strip_model->active_index(); | 1577 int login_tab_index = tab_strip_model->active_index(); |
1534 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1578 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1535 GetStateOfTabReloader(tab_strip_model->GetActiveWebContents())); | 1579 GetStateOfTabReloader(tab_strip_model->GetActiveWebContents())); |
1536 ASSERT_TRUE(IsLoginTab(browser->tab_strip_model()->GetActiveWebContents())); | 1580 ASSERT_TRUE(IsLoginTab(browser->tab_strip_model()->GetActiveWebContents())); |
1537 | 1581 |
1538 // Do the navigation. | 1582 // Do the navigation. |
1539 EXPECT_TRUE(content::ExecuteScript(tab_strip_model->GetActiveWebContents(), | 1583 content::ExecuteScriptAsync(tab_strip_model->GetActiveWebContents(), |
1540 "submitForm()")); | 1584 "submitForm()"); |
1541 | 1585 |
1542 portal_observer.WaitForResults(1); | 1586 portal_observer.WaitForResults(1); |
1543 navigation_observer.WaitForNavigations(1); | 1587 navigation_observer.WaitForNavigations(1); |
1544 | 1588 |
1545 // Check the captive portal result. | 1589 // Check the captive portal result. |
1546 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | 1590 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
1547 portal_observer.captive_portal_result()); | 1591 portal_observer.captive_portal_result()); |
1548 EXPECT_EQ(1, portal_observer.num_results_received()); | 1592 EXPECT_EQ(1, portal_observer.num_results_received()); |
1549 EXPECT_FALSE(CheckPending(browser)); | 1593 EXPECT_FALSE(CheckPending(browser)); |
1550 | 1594 |
(...skipping 24 matching lines...) Expand all Loading... |
1575 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); | 1619 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); |
1576 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); | 1620 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); |
1577 | 1621 |
1578 // Verify that the login page is on top. | 1622 // Verify that the login page is on top. |
1579 int login_tab_index = tab_strip_model->active_index(); | 1623 int login_tab_index = tab_strip_model->active_index(); |
1580 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1624 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1581 GetStateOfTabReloaderAt(browser, login_tab_index)); | 1625 GetStateOfTabReloaderAt(browser, login_tab_index)); |
1582 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); | 1626 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); |
1583 | 1627 |
1584 // Trigger a navigation. | 1628 // Trigger a navigation. |
1585 EXPECT_TRUE(content::ExecuteScript(tab_strip_model->GetActiveWebContents(), | 1629 content::ExecuteScriptAsync(tab_strip_model->GetActiveWebContents(), |
1586 "submitForm()")); | 1630 "submitForm()"); |
1587 | 1631 |
1588 portal_observer.WaitForResults(1); | 1632 portal_observer.WaitForResults(1); |
1589 | 1633 |
1590 // Wait for all the timed out tabs to reload. | 1634 // Wait for all the timed out tabs to reload. |
1591 navigation_observer.WaitForNavigations(1 + num_timed_out_tabs); | 1635 navigation_observer.WaitForNavigations(1 + num_timed_out_tabs); |
1592 EXPECT_EQ(1, portal_observer.num_results_received()); | 1636 EXPECT_EQ(1, portal_observer.num_results_received()); |
1593 | 1637 |
1594 // The tabs that were loading before should still be loading, and now be in | 1638 // The tabs that were loading before should still be loading, and now be in |
1595 // STATE_NEEDS_RELOAD. | 1639 // STATE_NEEDS_RELOAD. |
1596 EXPECT_EQ(0, NumBrokenTabs()); | 1640 EXPECT_EQ(0, NumBrokenTabs()); |
(...skipping 20 matching lines...) Expand all Loading... |
1617 | 1661 |
1618 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 1662 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
1619 | 1663 |
1620 // Verify that the login page is on top. | 1664 // Verify that the login page is on top. |
1621 int login_tab_index = tab_strip_model->active_index(); | 1665 int login_tab_index = tab_strip_model->active_index(); |
1622 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1666 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1623 GetStateOfTabReloaderAt(browser, login_tab_index)); | 1667 GetStateOfTabReloaderAt(browser, login_tab_index)); |
1624 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); | 1668 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); |
1625 | 1669 |
1626 // Trigger a navigation. | 1670 // Trigger a navigation. |
1627 EXPECT_TRUE(content::ExecuteScript(tab_strip_model->GetActiveWebContents(), | 1671 content::ExecuteScriptAsync(tab_strip_model->GetActiveWebContents(), |
1628 "submitForm()")); | 1672 "submitForm()"); |
1629 | 1673 |
1630 // The captive portal tab navigation will trigger a captive portal check, | 1674 // The captive portal tab navigation will trigger a captive portal check, |
1631 // and reloading the original tab will bring up the interstitial page again, | 1675 // and reloading the original tab will bring up the interstitial page again, |
1632 // triggering a second captive portal check. | 1676 // triggering a second captive portal check. |
1633 portal_observer.WaitForResults(2); | 1677 portal_observer.WaitForResults(2); |
1634 | 1678 |
1635 // Wait for both tabs to finish loading. | 1679 // Wait for both tabs to finish loading. |
1636 navigation_observer.WaitForNavigations(2); | 1680 navigation_observer.WaitForNavigations(2); |
1637 EXPECT_EQ(2, portal_observer.num_results_received()); | 1681 EXPECT_EQ(2, portal_observer.num_results_received()); |
1638 EXPECT_FALSE(CheckPending(browser)); | 1682 EXPECT_FALSE(CheckPending(browser)); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1970 // active tab to the captive portal landing page. | 2014 // active tab to the captive portal landing page. |
1971 int login_tab_index = tab_strip_model->active_index(); | 2015 int login_tab_index = tab_strip_model->active_index(); |
1972 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); | 2016 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); |
1973 // Wait for the interstitial to load all the JavaScript code. Otherwise, | 2017 // Wait for the interstitial to load all the JavaScript code. Otherwise, |
1974 // trying to click on a button will fail. | 2018 // trying to click on a button will fail. |
1975 content::RenderFrameHost* rfh = | 2019 content::RenderFrameHost* rfh = |
1976 broken_tab_contents->GetInterstitialPage()->GetMainFrame(); | 2020 broken_tab_contents->GetInterstitialPage()->GetMainFrame(); |
1977 EXPECT_TRUE(WaitForRenderFrameReady(rfh)); | 2021 EXPECT_TRUE(WaitForRenderFrameReady(rfh)); |
1978 const char kClickConnectButtonJS[] = | 2022 const char kClickConnectButtonJS[] = |
1979 "document.getElementById('primary-button').click();"; | 2023 "document.getElementById('primary-button').click();"; |
1980 EXPECT_TRUE( | 2024 { |
1981 content::ExecuteScript(rfh, kClickConnectButtonJS)); | 2025 TabActivationWaiter tab_activation_waiter(tab_strip_model); |
| 2026 content::ExecuteScriptAsync(rfh, kClickConnectButtonJS); |
| 2027 tab_activation_waiter.WaitForActiveTabChange(); |
| 2028 } |
1982 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); | 2029 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); |
1983 | 2030 |
1984 // For completeness, close the login tab and try clicking |Connect| again. | 2031 // For completeness, close the login tab and try clicking |Connect| again. |
1985 // A new login tab should open. | 2032 // A new login tab should open. |
1986 EXPECT_EQ(1, login_tab_index); | 2033 EXPECT_EQ(1, login_tab_index); |
1987 content::WebContentsDestroyedWatcher destroyed_watcher( | 2034 content::WebContentsDestroyedWatcher destroyed_watcher( |
1988 tab_strip_model->GetActiveWebContents()); | 2035 tab_strip_model->GetActiveWebContents()); |
1989 EXPECT_TRUE( | 2036 EXPECT_TRUE( |
1990 tab_strip_model->CloseWebContentsAt(tab_strip_model->active_index(), 0)); | 2037 tab_strip_model->CloseWebContentsAt(tab_strip_model->active_index(), 0)); |
1991 destroyed_watcher.Wait(); | 2038 destroyed_watcher.Wait(); |
1992 MultiNavigationObserver navigation_observer; | 2039 MultiNavigationObserver navigation_observer; |
1993 EXPECT_TRUE( | 2040 content::ExecuteScriptAsync(rfh, kClickConnectButtonJS); |
1994 content::ExecuteScript(rfh, kClickConnectButtonJS)); | |
1995 navigation_observer.WaitForNavigations(1); | 2041 navigation_observer.WaitForNavigations(1); |
1996 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); | 2042 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); |
1997 | 2043 |
1998 LoginCertError(browser()); | 2044 LoginCertError(browser()); |
1999 | 2045 |
2000 // Once logged in, broken tab should reload and display the SSL interstitial. | 2046 // Once logged in, broken tab should reload and display the SSL interstitial. |
2001 WaitForInterstitialAttach(broken_tab_contents); | 2047 WaitForInterstitialAttach(broken_tab_contents); |
2002 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); | 2048 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); |
2003 | 2049 |
2004 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | 2050 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2830 | 2876 |
2831 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 2877 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
2832 GetStateOfTabReloaderAt(browser(), broken_tab_index)); | 2878 GetStateOfTabReloaderAt(browser(), broken_tab_index)); |
2833 | 2879 |
2834 WaitForInterstitialAttach(broken_tab_contents); | 2880 WaitForInterstitialAttach(broken_tab_contents); |
2835 portal_observer.WaitForResults(1); | 2881 portal_observer.WaitForResults(1); |
2836 | 2882 |
2837 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | 2883 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
2838 GetInterstitialType(broken_tab_contents)); | 2884 GetInterstitialType(broken_tab_contents)); |
2839 } | 2885 } |
OLD | NEW |