| 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 #import "ios/web/public/test/js_test_util.h" | 13 #import "ios/web/public/test/js_test_util.h" |
| 14 #include "ios/web/public/test/test_browser_state.h" | 14 #include "ios/web/public/test/test_browser_state.h" |
| 15 #import "ios/web/public/test/test_web_client.h" | 15 #import "ios/web/public/test/test_web_client.h" |
| 16 #include "ios/web/public/test/web_test.h" |
| 16 #import "ios/web/public/web_view_creation_util.h" | 17 #import "ios/web/public/web_view_creation_util.h" |
| 17 #import "ios/web/test/web_test.h" | |
| 18 #include "testing/gtest_mac.h" | 18 #include "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 base::scoped_nsobject<WKWebView> web_view( | 29 base::scoped_nsobject<WKWebView> web_view( |
| 30 CreateWKWebView(CGRectZero, GetBrowserState())); | 30 CreateWKWebView(CGRectZero, GetBrowserState())); |
| 31 EvaluateJavaScript(web_view, GetEarlyPageScript()); | 31 EvaluateJavaScript(web_view, GetEarlyPageScript()); |
| 32 EXPECT_NSEQ(@"object", EvaluateJavaScript(web_view, @"typeof __gCrWeb")); | 32 EXPECT_NSEQ(@"object", EvaluateJavaScript(web_view, @"typeof __gCrWeb")); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Tests that embedder's WKWebView script is included into early script. | 35 // Tests that embedder's WKWebView script is included into early script. |
| 36 TEST_F(PageScriptUtilTest, WKEmbedderScript) { | 36 TEST_F(PageScriptUtilTest, WKEmbedderScript) { |
| 37 GetWebClient()->SetEarlyPageScript(@"__gCrEmbedder = {};"); | 37 GetWebClient()->SetEarlyPageScript(@"__gCrEmbedder = {};"); |
| 38 base::scoped_nsobject<WKWebView> web_view( | 38 base::scoped_nsobject<WKWebView> web_view( |
| 39 CreateWKWebView(CGRectZero, GetBrowserState())); | 39 CreateWKWebView(CGRectZero, GetBrowserState())); |
| 40 EvaluateJavaScript(web_view, GetEarlyPageScript()); | 40 EvaluateJavaScript(web_view, GetEarlyPageScript()); |
| 41 EXPECT_NSEQ(@"object", EvaluateJavaScript(web_view, @"typeof __gCrEmbedder")); | 41 EXPECT_NSEQ(@"object", EvaluateJavaScript(web_view, @"typeof __gCrEmbedder")); |
| 42 } | 42 } |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 } // namespace web | 45 } // namespace web |
| OLD | NEW |