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

Side by Side Diff: chrome/browser/interstitials/security_interstitial_page_test_utils.cc

Issue 1467063002: Introduce the ChromeControllerClient class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bugfix Created 5 years 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/interstitials/security_interstitial_page_test_utils.h" 5 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/interstitials/security_interstitial_page.h" 11 #include "chrome/browser/interstitials/security_interstitial_page.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "components/security_interstitials/core/controller_client.h"
16 #include "content/public/browser/interstitial_page.h" 17 #include "content/public/browser/interstitial_page.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/browser_test_utils.h" 19 #include "content/public/test/browser_test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 namespace chrome_browser_interstitials { 23 namespace chrome_browser_interstitials {
23 24
24 bool IsInterstitialDisplayingText( 25 bool IsInterstitialDisplayingText(
25 const content::InterstitialPage* const interstitial, 26 const content::InterstitialPage* const interstitial,
26 const std::string& text) { 27 const std::string& text) {
27 // It's valid for |text| to contain "\'", but simply look for "'" instead 28 // It's valid for |text| to contain "\'", but simply look for "'" instead
28 // since this function is used for searching host names and a predefined 29 // since this function is used for searching host names and a predefined
29 // string. 30 // string.
30 DCHECK(text.find("\'") == std::string::npos); 31 DCHECK(text.find("\'") == std::string::npos);
31 std::string command = base::StringPrintf( 32 std::string command = base::StringPrintf(
32 "var hasText = document.body.textContent.indexOf('%s') >= 0;" 33 "var hasText = document.body.textContent.indexOf('%s') >= 0;"
33 "window.domAutomationController.send(hasText ? %d : %d);", 34 "window.domAutomationController.send(hasText ? %d : %d);",
34 text.c_str(), SecurityInterstitialPage::CMD_TEXT_FOUND, 35 text.c_str(), security_interstitials::CMD_TEXT_FOUND,
35 SecurityInterstitialPage::CMD_TEXT_NOT_FOUND); 36 security_interstitials::CMD_TEXT_NOT_FOUND);
36 int result = 0; 37 int result = 0;
37 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(interstitial->GetMainFrame(), 38 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(interstitial->GetMainFrame(),
38 command, &result)); 39 command, &result));
39 return result == SecurityInterstitialPage::CMD_TEXT_FOUND; 40 return result == security_interstitials::CMD_TEXT_FOUND;
40 } 41 }
41 42
42 void SecurityInterstitialIDNTest::SetUpOnMainThread() { 43 void SecurityInterstitialIDNTest::SetUpOnMainThread() {
43 // Clear AcceptLanguages to force punycode decoding. 44 // Clear AcceptLanguages to force punycode decoding.
44 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages, 45 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages,
45 std::string()); 46 std::string());
46 } 47 }
47 48
48 testing::AssertionResult SecurityInterstitialIDNTest::VerifyIDNDecoded() const { 49 testing::AssertionResult SecurityInterstitialIDNTest::VerifyIDNDecoded() const {
49 const char kHostname[] = "xn--d1abbgf6aiiy.xn--p1ai"; 50 const char kHostname[] = "xn--d1abbgf6aiiy.xn--p1ai";
(...skipping 14 matching lines...) Expand all
64 if (!WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())) 65 if (!WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame()))
65 return testing::AssertionFailure() << "Render frame not ready"; 66 return testing::AssertionFailure() << "Render frame not ready";
66 67
67 if (IsInterstitialDisplayingText(contents->GetInterstitialPage(), 68 if (IsInterstitialDisplayingText(contents->GetInterstitialPage(),
68 kHostnameJSUnicode)) { 69 kHostnameJSUnicode)) {
69 return testing::AssertionSuccess(); 70 return testing::AssertionSuccess();
70 } 71 }
71 return testing::AssertionFailure() << "Interstitial not displaying text"; 72 return testing::AssertionFailure() << "Interstitial not displaying text";
72 } 73 }
73 } // namespace chrome_browser_interstitials 74 } // namespace chrome_browser_interstitials
OLDNEW
« no previous file with comments | « chrome/browser/interstitials/security_interstitial_page.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698