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

Side by Side Diff: chrome/browser/ssl/captive_portal_blocking_page_browsertest.cc

Issue 1000333003: Properly decode IDN in interstitials (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move test commands to negative values, and control flow nit Created 5 years, 9 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 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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
19 #include "components/captive_portal/captive_portal_detector.h" 20 #include "components/captive_portal/captive_portal_detector.h"
20 #include "content/public/browser/interstitial_page.h" 21 #include "content/public/browser/interstitial_page.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/browser_test_utils.h" 23 #include "content/public/test/browser_test_utils.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
27 using chrome_browser_interstitials::IsInterstitialDisplayingText;
28 using chrome_browser_interstitials::SecurityInterstitialIDNTest;
29
26 namespace { 30 namespace {
27 // Partial text in the captive portal interstitial's main paragraph when the 31 // Partial text in the captive portal interstitial's main paragraph when the
28 // login domain isn't displayed. 32 // login domain isn't displayed.
29 const char kGenericLoginURLText[] = "its login page"; 33 const char kGenericLoginURLText[] = "its login page";
30 const char kBrokenSSL[] = "https://broken.ssl"; 34 const char kBrokenSSL[] = "https://broken.ssl";
31 const char kWiFiSSID[] = "WiFiSSID"; 35 const char kWiFiSSID[] = "WiFiSSID";
32 36
33 // Returns true if the interstitial contains |text| in its body.
34 bool IsInterstitialDisplayingText(content::InterstitialPage* interstitial,
35 const std::string& text) {
36 // It's valid for |text| to contain "\'", but simply look for "'" instead
37 // since this function is used for searching host names and a predefined
38 // string.
39 DCHECK(text.find("\'") == std::string::npos);
40 std::string command = base::StringPrintf(
41 "var hasText = document.body.textContent.indexOf('%s') >= 0;"
42 "window.domAutomationController.send(hasText ? 1 : 0);",
43 text.c_str());
44 int result = 0;
45 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
46 interstitial->GetMainFrame(), command, &result));
47 return result == 1;
48 }
49
50 enum ExpectWiFi { 37 enum ExpectWiFi {
51 EXPECT_WIFI_NO, 38 EXPECT_WIFI_NO,
52 EXPECT_WIFI_YES 39 EXPECT_WIFI_YES
53 }; 40 };
54 41
55 enum ExpectWiFiSSID { 42 enum ExpectWiFiSSID {
56 EXPECT_WIFI_SSID_NO, 43 EXPECT_WIFI_SSID_NO,
57 EXPECT_WIFI_SSID_YES 44 EXPECT_WIFI_SSID_YES
58 }; 45 };
59 46
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 200 }
214 201
215 // Same as above, with no SSID and no login URL. 202 // Same as above, with no SSID and no login URL.
216 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, 203 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
217 WiFi_NoSSID_NoLoginURL) { 204 WiFi_NoSSID_NoLoginURL) {
218 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL); 205 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL);
219 TestInterstitial(true, "", kLandingUrl, 206 TestInterstitial(true, "", kLandingUrl,
220 EXPECT_WIFI_YES, EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_NO); 207 EXPECT_WIFI_YES, EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_NO);
221 } 208 }
222 209
223 class CaptivePortalBlockingPageIDNTest : public CaptivePortalBlockingPageTest { 210 class CaptivePortalBlockingPageIDNTest : public SecurityInterstitialIDNTest {
224 public: 211 protected:
225 // InProcessBrowserTest: 212 // SecurityInterstitialIDNTest implementation
226 void SetUpOnMainThread() override { 213 SecurityInterstitialPage* CreateInterstitial(
227 // Clear AcceptLanguages to force punycode decoding. 214 content::WebContents* contents,
228 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages, 215 const GURL& request_url) const override {
229 std::string()); 216 // Delegate is owned by the blocking page.
217 FakeConnectionInfoDelegate* delegate =
218 new FakeConnectionInfoDelegate(false, "");
219 // Blocking page is owned by the interstitial.
220 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage(
221 contents, GURL(kBrokenSSL), request_url, base::Callback<void(bool)>());
222 blocking_page->SetDelegateForTesting(delegate);
223 return blocking_page;
230 } 224 }
231 }; 225 };
232 226
233 // Same as CaptivePortalBlockingPageTest.WiredNetwork_LoginURL, except the login 227 // Test that an IDN login domain is decoded properly.
234 // domain is an IDN.
235 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageIDNTest, 228 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageIDNTest,
236 ShowLoginIDNIfPortalRedirectsDetectionURL) { 229 ShowLoginIDNIfPortalRedirectsDetectionURL) {
237 const char kHostname[] = 230 EXPECT_TRUE(VerifyIDNDecoded());
238 "xn--d1abbgf6aiiy.xn--p1ai";
239 const char kHostnameJSUnicode[] =
240 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442."
241 "\\u0440\\u0444";
242 std::string landing_url_spec =
243 base::StringPrintf("http://%s/landing_url", kHostname);
244 GURL landing_url(landing_url_spec);
245
246 TestInterstitial(false, "", landing_url, EXPECT_WIFI_NO, EXPECT_WIFI_SSID_NO,
247 EXPECT_LOGIN_URL_YES, kHostnameJSUnicode);
248 } 231 }
OLDNEW
« no previous file with comments | « chrome/browser/interstitials/security_interstitial_page_test_utils.cc ('k') | chrome/browser/ssl/ssl_blocking_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698