OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ssl/captive_portal_blocking_page.h" | 5 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } | 46 } |
47 | 47 |
48 class CaptivePortalBlockingPageTest : public InProcessBrowserTest { | 48 class CaptivePortalBlockingPageTest : public InProcessBrowserTest { |
49 public: | 49 public: |
50 CaptivePortalBlockingPageTest() {} | 50 CaptivePortalBlockingPageTest() {} |
51 | 51 |
52 private: | 52 private: |
53 DISALLOW_COPY_AND_ASSIGN(CaptivePortalBlockingPageTest); | 53 DISALLOW_COPY_AND_ASSIGN(CaptivePortalBlockingPageTest); |
54 }; | 54 }; |
55 | 55 |
| 56 // If the connection is not a Wi-Fi connection, the wired network version of the |
| 57 // captive portal interstitial should be displayed. |
| 58 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, |
| 59 ShowWiredNetworkInterstitial) { |
| 60 const GURL kLandingUrl("http://captive.portal/landing_url"); |
| 61 content::WebContents* contents = |
| 62 browser()->tab_strip_model()->GetActiveWebContents(); |
| 63 DCHECK(contents); |
| 64 // Blocking page is owned by the interstitial. |
| 65 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( |
| 66 contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>()); |
| 67 blocking_page->SetWiFiConnectionForTesting(false); |
| 68 blocking_page->Show(); |
| 69 |
| 70 WaitForInterstitialAttach(contents); |
| 71 EXPECT_TRUE( |
| 72 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 73 EXPECT_FALSE( |
| 74 IsInterstitialDisplayingText(contents->GetInterstitialPage(), "Wi-Fi")); |
| 75 } |
| 76 |
| 77 // If the connection is a Wi-Fi connection, the Wi-Fi version of the captive |
| 78 // portal interstitial should be displayed. |
| 79 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, |
| 80 ShowWiFiInterstitial) { |
| 81 const GURL kLandingUrl("http://captive.portal/landing_url"); |
| 82 content::WebContents* contents = |
| 83 browser()->tab_strip_model()->GetActiveWebContents(); |
| 84 DCHECK(contents); |
| 85 // Blocking page is owned by the interstitial. |
| 86 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( |
| 87 contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>()); |
| 88 blocking_page->SetWiFiConnectionForTesting(true); |
| 89 blocking_page->Show(); |
| 90 |
| 91 WaitForInterstitialAttach(contents); |
| 92 EXPECT_TRUE( |
| 93 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 94 EXPECT_TRUE( |
| 95 IsInterstitialDisplayingText(contents->GetInterstitialPage(), "Wi-Fi")); |
| 96 } |
| 97 |
56 // The captive portal interstitial should show the login url if the login url | 98 // The captive portal interstitial should show the login url if the login url |
57 // is different than the captive portal ping url (i.e. the portal intercepts | 99 // is different than the captive portal ping url (i.e. the portal intercepts |
58 // requests via HTTP redirects). | 100 // requests via HTTP redirects). |
59 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, | 101 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, |
60 ShowLoginDomainIfPortalRedirectsDetectionURL) { | 102 ShowLoginDomainIfPortalRedirectsDetectionURL) { |
61 const GURL kLandingUrl("http://captive.portal/landing_url"); | 103 const GURL kLandingUrl("http://captive.portal/landing_url"); |
62 content::WebContents* contents = | 104 content::WebContents* contents = |
63 browser()->tab_strip_model()->GetActiveWebContents(); | 105 browser()->tab_strip_model()->GetActiveWebContents(); |
64 DCHECK(contents); | 106 DCHECK(contents); |
65 // Blocking page is owned by the interstitial. | 107 // Blocking page is owned by the interstitial. |
66 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( | 108 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( |
67 contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>()); | 109 contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>()); |
| 110 blocking_page->SetWiFiConnectionForTesting(false); |
68 blocking_page->Show(); | 111 blocking_page->Show(); |
69 | 112 |
70 WaitForInterstitialAttach(contents); | 113 WaitForInterstitialAttach(contents); |
71 EXPECT_TRUE( | 114 EXPECT_TRUE( |
72 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | 115 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
73 | 116 |
74 EXPECT_TRUE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), | 117 EXPECT_TRUE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), |
75 kLandingUrl.host())); | 118 kLandingUrl.host())); |
76 EXPECT_FALSE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), | 119 EXPECT_FALSE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), |
77 kGenericLoginURLText)); | 120 kGenericLoginURLText)); |
78 } | 121 } |
79 | 122 |
80 // The captive portal interstitial should show a generic text if the login url | 123 // The captive portal interstitial should show a generic text if the login url |
81 // is the same as the captive portal ping url (i.e. the portal intercepts | 124 // is the same as the captive portal ping url (i.e. the portal intercepts |
82 // requests without using HTTP redirects). | 125 // requests without using HTTP redirects). |
83 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, | 126 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, |
84 DontShowLoginDomainIfPortalDoesntRedirectDetectionURL) { | 127 DontShowLoginDomainIfPortalDoesntRedirectDetectionURL) { |
85 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL); | 128 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL); |
86 content::WebContents* contents = | 129 content::WebContents* contents = |
87 browser()->tab_strip_model()->GetActiveWebContents(); | 130 browser()->tab_strip_model()->GetActiveWebContents(); |
88 DCHECK(contents); | 131 DCHECK(contents); |
89 // Blocking page is owned by the interstitial. | 132 // Blocking page is owned by the interstitial. |
90 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( | 133 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( |
91 contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>()); | 134 contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>()); |
| 135 blocking_page->SetWiFiConnectionForTesting(false); |
92 blocking_page->Show(); | 136 blocking_page->Show(); |
93 | 137 |
94 WaitForInterstitialAttach(contents); | 138 WaitForInterstitialAttach(contents); |
95 EXPECT_TRUE( | 139 EXPECT_TRUE( |
96 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | 140 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
97 | 141 |
98 EXPECT_FALSE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), | 142 EXPECT_FALSE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), |
99 kLandingUrl.host())); | 143 kLandingUrl.host())); |
100 EXPECT_TRUE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), | 144 EXPECT_TRUE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), |
101 kGenericLoginURLText)); | 145 kGenericLoginURLText)); |
(...skipping 21 matching lines...) Expand all Loading... |
123 std::string landing_url_spec = | 167 std::string landing_url_spec = |
124 base::StringPrintf("http://%s/landing_url", kHostname); | 168 base::StringPrintf("http://%s/landing_url", kHostname); |
125 GURL landing_url(landing_url_spec); | 169 GURL landing_url(landing_url_spec); |
126 | 170 |
127 content::WebContents* contents = | 171 content::WebContents* contents = |
128 browser()->tab_strip_model()->GetActiveWebContents(); | 172 browser()->tab_strip_model()->GetActiveWebContents(); |
129 DCHECK(contents); | 173 DCHECK(contents); |
130 // Blocking page is owned by the interstitial. | 174 // Blocking page is owned by the interstitial. |
131 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( | 175 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( |
132 contents, GURL(kBrokenSSL), landing_url, base::Callback<void(bool)>()); | 176 contents, GURL(kBrokenSSL), landing_url, base::Callback<void(bool)>()); |
| 177 blocking_page->SetWiFiConnectionForTesting(false); |
133 blocking_page->Show(); | 178 blocking_page->Show(); |
134 | 179 |
135 WaitForInterstitialAttach(contents); | 180 WaitForInterstitialAttach(contents); |
136 EXPECT_TRUE( | 181 EXPECT_TRUE( |
137 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | 182 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
138 | 183 |
139 EXPECT_TRUE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), | 184 EXPECT_TRUE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), |
140 kHostnameJSUnicode)); | 185 kHostnameJSUnicode)); |
141 EXPECT_FALSE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), | 186 EXPECT_FALSE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), |
142 kGenericLoginURLText)); | 187 kGenericLoginURLText)); |
143 } | 188 } |
OLD | NEW |