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

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: Created 5 years, 1 month 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
23 using security_interstitials::ControllerClient;
24
22 namespace chrome_browser_interstitials { 25 namespace chrome_browser_interstitials {
23 26
24 bool IsInterstitialDisplayingText( 27 bool IsInterstitialDisplayingText(
25 const content::InterstitialPage* const interstitial, 28 const content::InterstitialPage* const interstitial,
26 const std::string& text) { 29 const std::string& text) {
27 // It's valid for |text| to contain "\'", but simply look for "'" instead 30 // 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 31 // since this function is used for searching host names and a predefined
29 // string. 32 // string.
30 DCHECK(text.find("\'") == std::string::npos); 33 DCHECK(text.find("\'") == std::string::npos);
31 std::string command = base::StringPrintf( 34 std::string command = base::StringPrintf(
32 "var hasText = document.body.textContent.indexOf('%s') >= 0;" 35 "var hasText = document.body.textContent.indexOf('%s') >= 0;"
33 "window.domAutomationController.send(hasText ? %d : %d);", 36 "window.domAutomationController.send(hasText ? %d : %d);",
34 text.c_str(), SecurityInterstitialPage::CMD_TEXT_FOUND, 37 text.c_str(), ControllerClient::CMD_TEXT_FOUND,
35 SecurityInterstitialPage::CMD_TEXT_NOT_FOUND); 38 ControllerClient::CMD_TEXT_NOT_FOUND);
36 int result = 0; 39 int result = 0;
37 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(interstitial->GetMainFrame(), 40 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(interstitial->GetMainFrame(),
38 command, &result)); 41 command, &result));
39 return result == SecurityInterstitialPage::CMD_TEXT_FOUND; 42 return result == ControllerClient::CMD_TEXT_FOUND;
40 } 43 }
41 44
42 void SecurityInterstitialIDNTest::SetUpOnMainThread() { 45 void SecurityInterstitialIDNTest::SetUpOnMainThread() {
43 // Clear AcceptLanguages to force punycode decoding. 46 // Clear AcceptLanguages to force punycode decoding.
44 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages, 47 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages,
45 std::string()); 48 std::string());
46 } 49 }
47 50
48 testing::AssertionResult SecurityInterstitialIDNTest::VerifyIDNDecoded() const { 51 testing::AssertionResult SecurityInterstitialIDNTest::VerifyIDNDecoded() const {
49 const char kHostname[] = "xn--d1abbgf6aiiy.xn--p1ai"; 52 const char kHostname[] = "xn--d1abbgf6aiiy.xn--p1ai";
(...skipping 14 matching lines...) Expand all
64 if (!WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())) 67 if (!WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame()))
65 return testing::AssertionFailure() << "Render frame not ready"; 68 return testing::AssertionFailure() << "Render frame not ready";
66 69
67 if (IsInterstitialDisplayingText(contents->GetInterstitialPage(), 70 if (IsInterstitialDisplayingText(contents->GetInterstitialPage(),
68 kHostnameJSUnicode)) { 71 kHostnameJSUnicode)) {
69 return testing::AssertionSuccess(); 72 return testing::AssertionSuccess();
70 } 73 }
71 return testing::AssertionFailure() << "Interstitial not displaying text"; 74 return testing::AssertionFailure() << "Interstitial not displaying text";
72 } 75 }
73 } // namespace chrome_browser_interstitials 76 } // namespace chrome_browser_interstitials
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698