| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/browser/interstitials/security_interstitial_page.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/common/pref_names.h" |
| 16 #include "content/public/browser/interstitial_page.h" |
| 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/test/browser_test_utils.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "url/gurl.h" |
| 21 |
| 22 namespace chrome_browser_interstitials { |
| 23 |
| 24 bool IsInterstitialDisplayingText(content::InterstitialPage* interstitial, |
| 25 const std::string& text) { |
| 26 // It's valid for |text| to contain "\'", but simply look for "'" instead |
| 27 // since this function is used for searching host names and a predefined |
| 28 // string. |
| 29 DCHECK(text.find("\'") == std::string::npos); |
| 30 std::string command = base::StringPrintf( |
| 31 "var hasText = document.body.textContent.indexOf('%s') >= 0;" |
| 32 "window.domAutomationController.send(hasText ? 1 : 0);", |
| 33 text.c_str()); |
| 34 int result = 0; |
| 35 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(interstitial->GetMainFrame(), |
| 36 command, &result)); |
| 37 return result == 1; |
| 38 } |
| 39 |
| 40 void SecurityInterstitialIDNTest::SetUpOnMainThread() { |
| 41 // Clear AcceptLanguages to force punycode decoding. |
| 42 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages, |
| 43 std::string()); |
| 44 } |
| 45 |
| 46 void SecurityInterstitialIDNTest::TestIDN() { |
| 47 const char kHostname[] = "xn--d1abbgf6aiiy.xn--p1ai"; |
| 48 const char kHostnameJSUnicode[] = |
| 49 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442." |
| 50 "\\u0440\\u0444"; |
| 51 std::string request_url_spec = base::StringPrintf("https://%s/", kHostname); |
| 52 GURL request_url(request_url_spec); |
| 53 |
| 54 content::WebContents* contents = |
| 55 browser()->tab_strip_model()->GetActiveWebContents(); |
| 56 DCHECK(contents); |
| 57 SecurityInterstitialPage* blocking_page = |
| 58 CreateInterstitial(contents, request_url); |
| 59 blocking_page->Show(); |
| 60 |
| 61 WaitForInterstitialAttach(contents); |
| 62 EXPECT_TRUE( |
| 63 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 64 EXPECT_TRUE(IsInterstitialDisplayingText(contents->GetInterstitialPage(), |
| 65 kHostnameJSUnicode)); |
| 66 } |
| 67 } // namespace chrome_browser_interstitials |
| OLD | NEW |