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