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

Side by Side Diff: ios/chrome/browser/web/chrome_web_client_unittest.mm

Issue 2949583002: [Payment Request] window.PaymentRequest must be undefined if PR is disabled (Closed)
Patch Set: Addressed comment Created 3 years, 6 months 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 (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 "ios/chrome/browser/web/chrome_web_client.h" 5 #include "ios/chrome/browser/web/chrome_web_client.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/command_line.h"
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
13 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "ios/chrome/browser/chrome_switches.h"
16 #include "ios/chrome/browser/experimental_flags.h"
14 #include "ios/web/public/test/fakes/test_browser_state.h" 17 #include "ios/web/public/test/fakes/test_browser_state.h"
15 #import "ios/web/public/test/js_test_util.h" 18 #import "ios/web/public/test/js_test_util.h"
16 #include "ios/web/public/test/scoped_testing_web_client.h" 19 #include "ios/web/public/test/scoped_testing_web_client.h"
17 #include "ios/web/public/test/web_test.h" 20 #include "ios/web/public/test/web_test.h"
18 #import "ios/web/public/web_view_creation_util.h" 21 #import "ios/web/public/web_view_creation_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
20 #include "testing/gtest_mac.h" 23 #include "testing/gtest_mac.h"
21 24
22 #if !defined(__has_feature) || !__has_feature(objc_arc) 25 #if !defined(__has_feature) || !__has_feature(objc_arc)
23 #error "This file requires ARC support." 26 #error "This file requires ARC support."
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Not sure what can be done to better check the OS string, since it's highly 66 // Not sure what can be done to better check the OS string, since it's highly
64 // platform-dependent. 67 // platform-dependent.
65 EXPECT_FALSE(os_str.empty()); 68 EXPECT_FALSE(os_str.empty());
66 69
67 EXPECT_FALSE(webkit_version_str.empty()); 70 EXPECT_FALSE(webkit_version_str.empty());
68 EXPECT_FALSE(safari_version_str.empty()); 71 EXPECT_FALSE(safari_version_str.empty());
69 72
70 EXPECT_EQ(0u, product_str.find("CriOS/")); 73 EXPECT_EQ(0u, product_str.find("CriOS/"));
71 } 74 }
72 75
73 // Tests that ChromeWebClient provides print script and does not provide 76 // Tests that ChromeWebClient provides print script for WKWebView.
74 // windowOpenFix script for WKWebView. 77 TEST_F(ChromeWebClientTest, WKWebViewEarlyPageScriptPrint) {
75 TEST_F(ChromeWebClientTest, WKWebViewEarlyPageScript) {
76 // Chrome scripts rely on __gCrWeb object presence. 78 // Chrome scripts rely on __gCrWeb object presence.
77 web::TestBrowserState browser_state; 79 web::TestBrowserState browser_state;
78 WKWebView* web_view = web::BuildWKWebView(CGRectZero, &browser_state); 80 WKWebView* web_view = web::BuildWKWebView(CGRectZero, &browser_state);
79 web::ExecuteJavaScript(web_view, @"__gCrWeb = {};"); 81 web::ExecuteJavaScript(web_view, @"__gCrWeb = {};");
80 82
81 web::ScopedTestingWebClient web_client(base::MakeUnique<ChromeWebClient>()); 83 web::ScopedTestingWebClient web_client(base::MakeUnique<ChromeWebClient>());
82 NSString* script = web_client.Get()->GetEarlyPageScript(&browser_state); 84 NSString* script = web_client.Get()->GetEarlyPageScript(&browser_state);
83 web::ExecuteJavaScript(web_view, script); 85 web::ExecuteJavaScript(web_view, script);
84 EXPECT_NSEQ(@"object", 86 EXPECT_NSEQ(@"object",
85 web::ExecuteJavaScript(web_view, @"typeof __gCrWeb.print")); 87 web::ExecuteJavaScript(web_view, @"typeof __gCrWeb.print"));
88 }
89
90 // Tests that ChromeWebClient does not provide payment request script for
91 // WKWebView unless the feature is enabled.
92 TEST_F(ChromeWebClientTest, WKWebViewEarlyPageScriptPaymentRequest) {
93 // Chrome scripts rely on __gCrWeb object presence.
94 web::TestBrowserState browser_state;
95 WKWebView* web_view = web::BuildWKWebView(CGRectZero, &browser_state);
96 web::ExecuteJavaScript(web_view, @"__gCrWeb = {};");
97
98 web::ScopedTestingWebClient web_client(base::MakeUnique<ChromeWebClient>());
99 NSString* script = web_client.Get()->GetEarlyPageScript(&browser_state);
100 web::ExecuteJavaScript(web_view, script);
101 EXPECT_NSEQ(@"undefined", web::ExecuteJavaScript(
102 web_view, @"typeof window.PaymentRequest"));
103
104 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
105 switches::kEnablePaymentRequest, std::string());
106 script = web_client.Get()->GetEarlyPageScript(&browser_state);
107 web::ExecuteJavaScript(web_view, script);
86 EXPECT_NSEQ(@"function", web::ExecuteJavaScript( 108 EXPECT_NSEQ(@"function", web::ExecuteJavaScript(
87 web_view, @"typeof window.PaymentRequest")); 109 web_view, @"typeof window.PaymentRequest"));
88 } 110 }
89 111
90 } // namespace 112 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/chrome_web_client.mm ('k') | ios/chrome/browser/web/resources/chrome_bundle.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698