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

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

Issue 2478803003: Remove DOMAutomationController::automation_id_ (Closed)
Patch Set: More of: Fixing issues caught by extra |expected_response| checks in ExecuteScript function. Created 3 years, 5 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 <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
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 class TabActivationWaiter : public TabStripModelObserver {
899 public:
900 explicit TabActivationWaiter(TabStripModel* tab_strip_model)
901 : number_of_unconsumed_active_tab_changes_(0), scoped_observer_(this) {
902 scoped_observer_.Add(tab_strip_model);
903 }
904
905 void WaitUntilActiveTabChanges() {
mmenke 2017/07/06 16:10:34 Suggestion: Wait for a single change, and fail if
Łukasz Anforowicz 2017/07/06 16:46:56 Good point. Done.
906 if (number_of_unconsumed_active_tab_changes_ == 0) {
907 // Wait until TabStripModelObserver::ActiveTabChanged will get called.
908 message_loop_runner_ = new content::MessageLoopRunner;
909 message_loop_runner_->Run();
910 }
911
912 // "consume" one tab activation event.
913 DCHECK_LT(0, number_of_unconsumed_active_tab_changes_);
914 number_of_unconsumed_active_tab_changes_--;
915 }
916
917 // TabStripModelObserver overrides.
918 void ActiveTabChanged(content::WebContents* old_contents,
919 content::WebContents* new_contents,
920 int index,
921 int reason) override {
922 number_of_unconsumed_active_tab_changes_++;
923 if (message_loop_runner_)
924 message_loop_runner_->Quit();
925 }
926
927 private:
928 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
929 int number_of_unconsumed_active_tab_changes_;
930 ScopedObserver<TabStripModel, TabActivationWaiter> scoped_observer_;
931
932 DISALLOW_COPY_AND_ASSIGN(TabActivationWaiter);
933 };
934
896 } // namespace 935 } // namespace
897 936
898 class CaptivePortalBrowserTest : public InProcessBrowserTest { 937 class CaptivePortalBrowserTest : public InProcessBrowserTest {
899 public: 938 public:
900 CaptivePortalBrowserTest(); 939 CaptivePortalBrowserTest();
901 940
902 // InProcessBrowserTest: 941 // InProcessBrowserTest:
903 void SetUpOnMainThread() override; 942 void SetUpOnMainThread() override;
904 void TearDownOnMainThread() override; 943 void TearDownOnMainThread() override;
905 void SetUpCommandLine(base::CommandLine* command_line) override; 944 void SetUpCommandLine(base::CommandLine* command_line) override;
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 int initial_tab_count = tab_strip_model->count(); 1568 int initial_tab_count = tab_strip_model->count();
1530 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); 1569 EXPECT_EQ(num_loading_tabs, NumLoadingTabs());
1531 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); 1570 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs());
1532 1571
1533 int login_tab_index = tab_strip_model->active_index(); 1572 int login_tab_index = tab_strip_model->active_index();
1534 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 1573 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
1535 GetStateOfTabReloader(tab_strip_model->GetActiveWebContents())); 1574 GetStateOfTabReloader(tab_strip_model->GetActiveWebContents()));
1536 ASSERT_TRUE(IsLoginTab(browser->tab_strip_model()->GetActiveWebContents())); 1575 ASSERT_TRUE(IsLoginTab(browser->tab_strip_model()->GetActiveWebContents()));
1537 1576
1538 // Do the navigation. 1577 // Do the navigation.
1539 EXPECT_TRUE(content::ExecuteScript(tab_strip_model->GetActiveWebContents(), 1578 content::ExecuteUnmodifiedScript(tab_strip_model->GetActiveWebContents(),
1540 "submitForm()")); 1579 "submitForm()");
1541 1580
1542 portal_observer.WaitForResults(1); 1581 portal_observer.WaitForResults(1);
1543 navigation_observer.WaitForNavigations(1); 1582 navigation_observer.WaitForNavigations(1);
1544 1583
1545 // Check the captive portal result. 1584 // Check the captive portal result.
1546 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, 1585 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL,
1547 portal_observer.captive_portal_result()); 1586 portal_observer.captive_portal_result());
1548 EXPECT_EQ(1, portal_observer.num_results_received()); 1587 EXPECT_EQ(1, portal_observer.num_results_received());
1549 EXPECT_FALSE(CheckPending(browser)); 1588 EXPECT_FALSE(CheckPending(browser));
1550 1589
(...skipping 24 matching lines...) Expand all
1575 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); 1614 ASSERT_EQ(num_loading_tabs, NumLoadingTabs());
1576 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); 1615 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs());
1577 1616
1578 // Verify that the login page is on top. 1617 // Verify that the login page is on top.
1579 int login_tab_index = tab_strip_model->active_index(); 1618 int login_tab_index = tab_strip_model->active_index();
1580 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 1619 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
1581 GetStateOfTabReloaderAt(browser, login_tab_index)); 1620 GetStateOfTabReloaderAt(browser, login_tab_index));
1582 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); 1621 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index)));
1583 1622
1584 // Trigger a navigation. 1623 // Trigger a navigation.
1585 EXPECT_TRUE(content::ExecuteScript(tab_strip_model->GetActiveWebContents(), 1624 content::ExecuteUnmodifiedScript(tab_strip_model->GetActiveWebContents(),
1586 "submitForm()")); 1625 "submitForm()");
1587 1626
1588 portal_observer.WaitForResults(1); 1627 portal_observer.WaitForResults(1);
1589 1628
1590 // Wait for all the timed out tabs to reload. 1629 // Wait for all the timed out tabs to reload.
1591 navigation_observer.WaitForNavigations(1 + num_timed_out_tabs); 1630 navigation_observer.WaitForNavigations(1 + num_timed_out_tabs);
1592 EXPECT_EQ(1, portal_observer.num_results_received()); 1631 EXPECT_EQ(1, portal_observer.num_results_received());
1593 1632
1594 // The tabs that were loading before should still be loading, and now be in 1633 // The tabs that were loading before should still be loading, and now be in
1595 // STATE_NEEDS_RELOAD. 1634 // STATE_NEEDS_RELOAD.
1596 EXPECT_EQ(0, NumBrokenTabs()); 1635 EXPECT_EQ(0, NumBrokenTabs());
(...skipping 20 matching lines...) Expand all
1617 1656
1618 TabStripModel* tab_strip_model = browser->tab_strip_model(); 1657 TabStripModel* tab_strip_model = browser->tab_strip_model();
1619 1658
1620 // Verify that the login page is on top. 1659 // Verify that the login page is on top.
1621 int login_tab_index = tab_strip_model->active_index(); 1660 int login_tab_index = tab_strip_model->active_index();
1622 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 1661 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
1623 GetStateOfTabReloaderAt(browser, login_tab_index)); 1662 GetStateOfTabReloaderAt(browser, login_tab_index));
1624 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); 1663 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index)));
1625 1664
1626 // Trigger a navigation. 1665 // Trigger a navigation.
1627 EXPECT_TRUE(content::ExecuteScript(tab_strip_model->GetActiveWebContents(), 1666 content::ExecuteUnmodifiedScript(tab_strip_model->GetActiveWebContents(),
1628 "submitForm()")); 1667 "submitForm()");
1629 1668
1630 // The captive portal tab navigation will trigger a captive portal check, 1669 // The captive portal tab navigation will trigger a captive portal check,
1631 // and reloading the original tab will bring up the interstitial page again, 1670 // and reloading the original tab will bring up the interstitial page again,
1632 // triggering a second captive portal check. 1671 // triggering a second captive portal check.
1633 portal_observer.WaitForResults(2); 1672 portal_observer.WaitForResults(2);
1634 1673
1635 // Wait for both tabs to finish loading. 1674 // Wait for both tabs to finish loading.
1636 navigation_observer.WaitForNavigations(2); 1675 navigation_observer.WaitForNavigations(2);
1637 EXPECT_EQ(2, portal_observer.num_results_received()); 1676 EXPECT_EQ(2, portal_observer.num_results_received());
1638 EXPECT_FALSE(CheckPending(browser)); 1677 EXPECT_FALSE(CheckPending(browser));
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 // active tab to the captive portal landing page. 2009 // active tab to the captive portal landing page.
1971 int login_tab_index = tab_strip_model->active_index(); 2010 int login_tab_index = tab_strip_model->active_index();
1972 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); 2011 tab_strip_model->ActivateTabAt(cert_error_tab_index, false);
1973 // Wait for the interstitial to load all the JavaScript code. Otherwise, 2012 // Wait for the interstitial to load all the JavaScript code. Otherwise,
1974 // trying to click on a button will fail. 2013 // trying to click on a button will fail.
1975 content::RenderFrameHost* rfh = 2014 content::RenderFrameHost* rfh =
1976 broken_tab_contents->GetInterstitialPage()->GetMainFrame(); 2015 broken_tab_contents->GetInterstitialPage()->GetMainFrame();
1977 EXPECT_TRUE(WaitForRenderFrameReady(rfh)); 2016 EXPECT_TRUE(WaitForRenderFrameReady(rfh));
1978 const char kClickConnectButtonJS[] = 2017 const char kClickConnectButtonJS[] =
1979 "document.getElementById('primary-button').click();"; 2018 "document.getElementById('primary-button').click();";
1980 EXPECT_TRUE( 2019 {
1981 content::ExecuteScript(rfh, kClickConnectButtonJS)); 2020 TabActivationWaiter tab_activation_waiter(tab_strip_model);
2021 content::ExecuteUnmodifiedScript(rfh, kClickConnectButtonJS);
2022 tab_activation_waiter.WaitUntilActiveTabChanges();
2023 }
1982 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); 2024 EXPECT_EQ(login_tab_index, tab_strip_model->active_index());
1983 2025
1984 // For completeness, close the login tab and try clicking |Connect| again. 2026 // For completeness, close the login tab and try clicking |Connect| again.
1985 // A new login tab should open. 2027 // A new login tab should open.
1986 EXPECT_EQ(1, login_tab_index); 2028 EXPECT_EQ(1, login_tab_index);
1987 content::WebContentsDestroyedWatcher destroyed_watcher( 2029 content::WebContentsDestroyedWatcher destroyed_watcher(
1988 tab_strip_model->GetActiveWebContents()); 2030 tab_strip_model->GetActiveWebContents());
1989 EXPECT_TRUE( 2031 EXPECT_TRUE(
1990 tab_strip_model->CloseWebContentsAt(tab_strip_model->active_index(), 0)); 2032 tab_strip_model->CloseWebContentsAt(tab_strip_model->active_index(), 0));
1991 destroyed_watcher.Wait(); 2033 destroyed_watcher.Wait();
1992 MultiNavigationObserver navigation_observer; 2034 MultiNavigationObserver navigation_observer;
1993 EXPECT_TRUE( 2035 content::ExecuteUnmodifiedScript(rfh, kClickConnectButtonJS);
1994 content::ExecuteScript(rfh, kClickConnectButtonJS));
1995 navigation_observer.WaitForNavigations(1); 2036 navigation_observer.WaitForNavigations(1);
1996 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); 2037 EXPECT_EQ(login_tab_index, tab_strip_model->active_index());
1997 2038
1998 LoginCertError(browser()); 2039 LoginCertError(browser());
1999 2040
2000 // Once logged in, broken tab should reload and display the SSL interstitial. 2041 // Once logged in, broken tab should reload and display the SSL interstitial.
2001 WaitForInterstitialAttach(broken_tab_contents); 2042 WaitForInterstitialAttach(broken_tab_contents);
2002 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); 2043 tab_strip_model->ActivateTabAt(cert_error_tab_index, false);
2003 2044
2004 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, 2045 EXPECT_EQ(SSLBlockingPage::kTypeForTesting,
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
2830 2871
2831 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, 2872 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
2832 GetStateOfTabReloaderAt(browser(), broken_tab_index)); 2873 GetStateOfTabReloaderAt(browser(), broken_tab_index));
2833 2874
2834 WaitForInterstitialAttach(broken_tab_contents); 2875 WaitForInterstitialAttach(broken_tab_contents);
2835 portal_observer.WaitForResults(1); 2876 portal_observer.WaitForResults(1);
2836 2877
2837 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, 2878 EXPECT_EQ(SSLBlockingPage::kTypeForTesting,
2838 GetInterstitialType(broken_tab_contents)); 2879 GetInterstitialType(broken_tab_contents));
2839 } 2880 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698