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 ? %d : %d);", |
| 33 text.c_str(), SecurityInterstitialPage::CMD_TEXT_FOUND, |
| 34 SecurityInterstitialPage::CMD_TEXT_NOT_FOUND); |
| 35 int result = 0; |
| 36 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(interstitial->GetMainFrame(), |
| 37 command, &result)); |
| 38 return result == SecurityInterstitialPage::CMD_TEXT_FOUND; |
| 39 } |
| 40 |
| 41 void SecurityInterstitialIDNTest::SetUpOnMainThread() { |
| 42 // Clear AcceptLanguages to force punycode decoding. |
| 43 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages, |
| 44 std::string()); |
| 45 } |
| 46 |
| 47 testing::AssertionResult SecurityInterstitialIDNTest::VerifyIDNDecoded() const { |
| 48 const char kHostname[] = "xn--d1abbgf6aiiy.xn--p1ai"; |
| 49 const char kHostnameJSUnicode[] = |
| 50 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442." |
| 51 "\\u0440\\u0444"; |
| 52 std::string request_url_spec = base::StringPrintf("https://%s/", kHostname); |
| 53 GURL request_url(request_url_spec); |
| 54 |
| 55 content::WebContents* contents = |
| 56 browser()->tab_strip_model()->GetActiveWebContents(); |
| 57 DCHECK(contents); |
| 58 SecurityInterstitialPage* blocking_page = |
| 59 CreateInterstitial(contents, request_url); |
| 60 blocking_page->Show(); |
| 61 |
| 62 WaitForInterstitialAttach(contents); |
| 63 if (!WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())) |
| 64 return testing::AssertionFailure() << "Render frame not ready"; |
| 65 |
| 66 if (IsInterstitialDisplayingText(contents->GetInterstitialPage(), |
| 67 kHostnameJSUnicode)) { |
| 68 return testing::AssertionSuccess(); |
| 69 } |
| 70 return testing::AssertionFailure() << "Interstitial not displaying text"; |
| 71 } |
| 72 } // namespace chrome_browser_interstitials |
OLD | NEW |