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/ui/wk_web_view_configuration_provider.h" | 5 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
6 | 6 |
7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
8 | 8 |
9 #import "base/ios/weak_nsobject.h" | 9 #import "base/ios/weak_nsobject.h" |
10 #include "ios/web/public/test/test_browser_state.h" | 10 #include "ios/web/public/test/test_browser_state.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 provider.GetWebViewConfiguration().processPool); | 61 provider.GetWebViewConfiguration().processPool); |
62 | 62 |
63 // Different WKProcessPools for different providers. | 63 // Different WKProcessPools for different providers. |
64 TestBrowserState other_browser_state; | 64 TestBrowserState other_browser_state; |
65 WKWebViewConfigurationProvider& other_provider = | 65 WKWebViewConfigurationProvider& other_provider = |
66 GetProvider(&other_browser_state); | 66 GetProvider(&other_browser_state); |
67 EXPECT_NE(provider.GetWebViewConfiguration().processPool, | 67 EXPECT_NE(provider.GetWebViewConfiguration().processPool, |
68 other_provider.GetWebViewConfiguration().processPool); | 68 other_provider.GetWebViewConfiguration().processPool); |
69 } | 69 } |
70 | 70 |
71 #if 0 | |
72 // TODO(shreyasv) Disabled for usaging of nil on latest Xcode beta. | |
sdefresne
2015/06/10 16:15:56
s/usaging/using/
justincohen
2015/06/10 16:33:36
Done.
| |
73 // crbug.com/498841 | |
71 // Tests that internal configuration object can not be changed by clients. | 74 // Tests that internal configuration object can not be changed by clients. |
72 TEST_F(WKWebViewConfigurationProviderTest, ConfigurationProtection) { | 75 TEST_F(WKWebViewConfigurationProviderTest, ConfigurationProtection) { |
73 CR_TEST_REQUIRES_WK_WEB_VIEW(); | 76 CR_TEST_REQUIRES_WK_WEB_VIEW(); |
74 | 77 |
75 WKWebViewConfigurationProvider& provider = GetProvider(&browser_state_); | 78 WKWebViewConfigurationProvider& provider = GetProvider(&browser_state_); |
76 WKWebViewConfiguration* config = provider.GetWebViewConfiguration(); | 79 WKWebViewConfiguration* config = provider.GetWebViewConfiguration(); |
77 base::scoped_nsobject<WKProcessPool> pool([[config processPool] retain]); | 80 base::scoped_nsobject<WKProcessPool> pool([[config processPool] retain]); |
78 base::scoped_nsobject<WKPreferences> prefs([[config preferences] retain]); | 81 base::scoped_nsobject<WKPreferences> prefs([[config preferences] retain]); |
79 base::scoped_nsobject<WKUserContentController> userContentController( | 82 base::scoped_nsobject<WKUserContentController> userContentController( |
80 [[config userContentController] retain]); | 83 [[config userContentController] retain]); |
81 | 84 |
82 // nil-out the properties of returned configuration object. | 85 // nil-out the properties of returned configuration object. |
83 config.processPool = nil; | 86 config.processPool = nil; |
84 config.preferences = nil; | 87 config.preferences = nil; |
85 config.userContentController = nil; | 88 config.userContentController = nil; |
86 | 89 |
87 // Make sure that the properties of internal configuration were not changed. | 90 // Make sure that the properties of internal configuration were not changed. |
88 EXPECT_TRUE(provider.GetWebViewConfiguration().processPool); | 91 EXPECT_TRUE(provider.GetWebViewConfiguration().processPool); |
89 EXPECT_EQ(pool.get(), provider.GetWebViewConfiguration().processPool); | 92 EXPECT_EQ(pool.get(), provider.GetWebViewConfiguration().processPool); |
90 EXPECT_TRUE(provider.GetWebViewConfiguration().preferences); | 93 EXPECT_TRUE(provider.GetWebViewConfiguration().preferences); |
91 EXPECT_EQ(prefs.get(), provider.GetWebViewConfiguration().preferences); | 94 EXPECT_EQ(prefs.get(), provider.GetWebViewConfiguration().preferences); |
92 EXPECT_TRUE(provider.GetWebViewConfiguration().userContentController); | 95 EXPECT_TRUE(provider.GetWebViewConfiguration().userContentController); |
93 EXPECT_EQ(userContentController.get(), | 96 EXPECT_EQ(userContentController.get(), |
94 provider.GetWebViewConfiguration().userContentController); | 97 provider.GetWebViewConfiguration().userContentController); |
95 } | 98 } |
99 #endif | |
96 | 100 |
97 // Tests that |HasWebViewConfiguration| returns false by default. | 101 // Tests that |HasWebViewConfiguration| returns false by default. |
98 TEST_F(WKWebViewConfigurationProviderTest, NoConfigurationByDefault) { | 102 TEST_F(WKWebViewConfigurationProviderTest, NoConfigurationByDefault) { |
99 CR_TEST_REQUIRES_WK_WEB_VIEW(); | 103 CR_TEST_REQUIRES_WK_WEB_VIEW(); |
100 | 104 |
101 EXPECT_FALSE(GetProvider().HasWebViewConfiguration()); | 105 EXPECT_FALSE(GetProvider().HasWebViewConfiguration()); |
102 } | 106 } |
103 | 107 |
104 // Tests that |HasWebViewConfiguration| returns true after | 108 // Tests that |HasWebViewConfiguration| returns true after |
105 // |GetWebViewConfiguration| call and false after |Purge| call. | 109 // |GetWebViewConfiguration| call and false after |Purge| call. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 NSArray* scripts = config.userContentController.userScripts; | 149 NSArray* scripts = config.userContentController.userScripts; |
146 EXPECT_EQ(1U, scripts.count); | 150 EXPECT_EQ(1U, scripts.count); |
147 NSString* early_script = GetEarlyPageScript(WK_WEB_VIEW_TYPE); | 151 NSString* early_script = GetEarlyPageScript(WK_WEB_VIEW_TYPE); |
148 // |earlyScript| is a substring of |userScripts|. The latter wraps the | 152 // |earlyScript| is a substring of |userScripts|. The latter wraps the |
149 // former with "if (!injected)" check to avoid double injections. | 153 // former with "if (!injected)" check to avoid double injections. |
150 EXPECT_LT(0U, [[scripts[0] source] rangeOfString:early_script].length); | 154 EXPECT_LT(0U, [[scripts[0] source] rangeOfString:early_script].length); |
151 } | 155 } |
152 | 156 |
153 } // namespace | 157 } // namespace |
154 } // namespace web | 158 } // namespace web |
OLD | NEW |