Chromium Code Reviews| 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.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "base/prefs/pref_service.h" | |
| 9 #include "base/strings/stringprintf.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/ui/browser.h" | |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 14 #include "chrome/common/pref_names.h" | |
| 15 #include "chrome/test/base/in_process_browser_test.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 { | |
| 23 | |
| 24 class SecurityInterstitialPageIDNTest : public InProcessBrowserTest { | |
| 25 public: | |
| 26 SecurityInterstitialPageIDNTest() {} | |
| 27 // InProcessBrowserTest: | |
| 28 void SetUpOnMainThread() override { | |
| 29 // Clear AcceptLanguages to force punycode decoding. | |
| 30 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages, | |
| 31 std::string()); | |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 DISALLOW_COPY_AND_ASSIGN(SecurityInterstitialPageIDNTest); | |
| 36 }; | |
| 37 | |
| 38 // A fake interstitial page for testing the output of | |
| 39 // |GetFormattedHostName|. | |
| 40 class TestSecurityInterstitialPage : public SecurityInterstitialPage { | |
| 41 public: | |
| 42 TestSecurityInterstitialPage(content::WebContents* web_contents, | |
| 43 const GURL& url) | |
| 44 : SecurityInterstitialPage(web_contents, url) {} | |
| 45 ~TestSecurityInterstitialPage() override {} | |
| 46 | |
| 47 void ExpectHostname(const std::string& expected_hostname) { | |
| 48 EXPECT_EQ(expected_hostname, base::UTF16ToUTF8(GetFormattedHostName())); | |
| 49 } | |
| 50 | |
| 51 protected: | |
| 52 // SecurityInterstitialPage implementation | |
| 53 bool ShouldCreateNewNavigation() const override { return true; } | |
| 54 void PopulateInterstitialStrings( | |
| 55 base::DictionaryValue* load_time_data) override {} | |
| 56 }; | |
| 57 | |
| 58 // Test that |GetFormattedHostname| properly decodes IDN. | |
| 59 IN_PROC_BROWSER_TEST_F(SecurityInterstitialPageIDNTest, | |
|
estark
2015/03/24 19:10:13
This is really a unit test for |GetFormattedHostNa
meacer
2015/03/24 20:22:24
I agree, it looks like this is testing |GetFormatt
estark
2015/03/24 22:35:47
Done.
| |
| 60 DecodeIDNInInterstitials) { | |
| 61 const char kHostname[] = "xn--d1abbgf6aiiy.xn--p1ai"; | |
| 62 const char kHostnameUnicode[] = | |
| 63 "\u043f\u0440\u0435\u0437\u0438\u0434\u0435\u043d\u0442." | |
| 64 "\u0440\u0444"; | |
| 65 | |
| 66 content::WebContents* contents = | |
| 67 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 68 DCHECK(contents); | |
| 69 | |
| 70 std::string url_spec = base::StringPrintf("https://%s", kHostname); | |
| 71 GURL url(url_spec); | |
| 72 | |
| 73 TestSecurityInterstitialPage* interstitial = | |
| 74 new TestSecurityInterstitialPage(contents, url); | |
| 75 interstitial->ExpectHostname(kHostnameUnicode); | |
| 76 } | |
| 77 | |
| 78 } // namespace | |
| OLD | NEW |