| OLD | NEW |
| 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 #import "ios/web/web_state/js/page_script_util.h" | 5 #import "ios/web/web_state/js/page_script_util.h" |
| 6 | 6 |
| 7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 #import <WebKit/WebKit.h> | 8 #import <WebKit/WebKit.h> |
| 9 | 9 |
| 10 #import "base/mac/scoped_nsobject.h" | |
| 11 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 12 #import "base/test/ios/wait_util.h" | 11 #import "base/test/ios/wait_util.h" |
| 13 #include "ios/web/public/test/fakes/test_browser_state.h" | 12 #include "ios/web/public/test/fakes/test_browser_state.h" |
| 14 #import "ios/web/public/test/fakes/test_web_client.h" | 13 #import "ios/web/public/test/fakes/test_web_client.h" |
| 15 #import "ios/web/public/test/js_test_util.h" | 14 #import "ios/web/public/test/js_test_util.h" |
| 16 #include "ios/web/public/test/web_test.h" | 15 #include "ios/web/public/test/web_test.h" |
| 17 #import "ios/web/public/web_view_creation_util.h" | 16 #import "ios/web/public/web_view_creation_util.h" |
| 18 #import "testing/gtest_mac.h" | 17 #import "testing/gtest_mac.h" |
| 19 | 18 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." |
| 21 #endif |
| 22 |
| 20 namespace web { | 23 namespace web { |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 // A test fixture for testing the page_script_util methods. | 26 // A test fixture for testing the page_script_util methods. |
| 24 typedef WebTest PageScriptUtilTest; | 27 typedef WebTest PageScriptUtilTest; |
| 25 | 28 |
| 26 // Tests that WKWebView early page script is a valid script that injects global | 29 // Tests that WKWebView early page script is a valid script that injects global |
| 27 // __gCrWeb object. | 30 // __gCrWeb object. |
| 28 TEST_F(PageScriptUtilTest, WKWebViewEarlyPageScript) { | 31 TEST_F(PageScriptUtilTest, WKWebViewEarlyPageScript) { |
| 29 WKWebView* web_view = BuildWKWebView(CGRectZero, GetBrowserState()); | 32 WKWebView* web_view = BuildWKWebView(CGRectZero, GetBrowserState()); |
| 30 ExecuteJavaScript(web_view, GetEarlyPageScript(GetBrowserState())); | 33 ExecuteJavaScript(web_view, GetEarlyPageScript(GetBrowserState())); |
| 31 EXPECT_NSEQ(@"object", ExecuteJavaScript(web_view, @"typeof __gCrWeb")); | 34 EXPECT_NSEQ(@"object", ExecuteJavaScript(web_view, @"typeof __gCrWeb")); |
| 32 } | 35 } |
| 33 | 36 |
| 34 // Tests that embedder's WKWebView script is included into early script. | 37 // Tests that embedder's WKWebView script is included into early script. |
| 35 TEST_F(PageScriptUtilTest, WKEmbedderScript) { | 38 TEST_F(PageScriptUtilTest, WKEmbedderScript) { |
| 36 GetWebClient()->SetEarlyPageScript(@"__gCrEmbedder = {};"); | 39 GetWebClient()->SetEarlyPageScript(@"__gCrEmbedder = {};"); |
| 37 WKWebView* web_view = BuildWKWebView(CGRectZero, GetBrowserState()); | 40 WKWebView* web_view = BuildWKWebView(CGRectZero, GetBrowserState()); |
| 38 ExecuteJavaScript(web_view, GetEarlyPageScript(GetBrowserState())); | 41 ExecuteJavaScript(web_view, GetEarlyPageScript(GetBrowserState())); |
| 39 EXPECT_NSEQ(@"object", ExecuteJavaScript(web_view, @"typeof __gCrEmbedder")); | 42 EXPECT_NSEQ(@"object", ExecuteJavaScript(web_view, @"typeof __gCrEmbedder")); |
| 40 } | 43 } |
| 41 | 44 |
| 42 } // namespace | 45 } // namespace |
| 43 } // namespace web | 46 } // namespace web |
| OLD | NEW |