LEFT | RIGHT |
1 /* | 1 /* |
2 * Copyright (C) 2018 Google LLC. All rights reserved. | 2 * Copyright (C) 2018 Google LLC. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 | 27 |
28 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IO
S) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) | 28 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300 |
29 | 29 |
30 #import "PlatformUtilities.h" | 30 #import "PlatformUtilities.h" |
31 #import "TestProtocol.h" | 31 #import "TestProtocol.h" |
32 #import <WebKit/WKNavigationActionPrivate.h> | 32 #import <WebKit/WKNavigationActionPrivate.h> |
33 #import <WebKit/WKWebViewConfiguration.h> | 33 #import <WebKit/WKWebViewConfiguration.h> |
34 #import <WebKit/WKWebViewPrivate.h> | 34 #import <WebKit/WKWebViewPrivate.h> |
35 #import <wtf/RetainPtr.h> | 35 #import <wtf/RetainPtr.h> |
36 | 36 |
37 #if WK_API_ENABLED | 37 #if WK_API_ENABLED |
38 | 38 |
39 static bool shouldCancelNavigation; | 39 static bool shouldCancelNavigation; |
40 static bool shouldCancelForSafeBrowsing; | |
41 static bool shouldShowSafeBrowsingWarning; | |
42 static bool decidedNavigationPolicy; | 40 static bool decidedNavigationPolicy; |
43 static bool decidedSafeBrowsingPolicy; | |
44 static bool finishedNavigation; | 41 static bool finishedNavigation; |
45 static bool finishedRedirectNavigation; | 42 static bool finishedRedirectNavigation; |
46 | 43 |
47 static NSString *firstURL = @"data:text/html,First"; | 44 static NSString *firstURL = @"sb://host/good.html"; |
48 static NSString *secondURL = @"data:text/html,Second"; | 45 static NSString *secondURL = @"sb://host/good2.html"; |
49 static NSString *unsafeURL = @"sb://host/phishing.html"; | 46 static NSString *unsafeURL = @"sb://host/phishing.html"; |
50 static NSString *warningURL = @"file:///SafeBrowsing"; | 47 static NSString *warningURL = @"file:///SafeBrowsing"; |
51 | 48 |
52 @interface SBScheme : NSObject <WKURLSchemeHandler> | 49 @interface SBScheme : NSObject <WKURLSchemeHandler> |
53 @end | 50 @end |
54 | 51 |
55 @implementation SBScheme | 52 @implementation SBScheme |
56 | 53 |
57 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)ur
lSchemeTask | 54 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)ur
lSchemeTask |
58 { | 55 { |
(...skipping 16 matching lines...) Expand all Loading... |
75 | 72 |
76 - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
onAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))
decisionHandler | 73 - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
onAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))
decisionHandler |
77 { | 74 { |
78 if (shouldCancelNavigation) | 75 if (shouldCancelNavigation) |
79 decisionHandler(WKNavigationActionPolicyCancel); | 76 decisionHandler(WKNavigationActionPolicyCancel); |
80 else | 77 else |
81 decisionHandler(WKNavigationActionPolicyAllow); | 78 decisionHandler(WKNavigationActionPolicyAllow); |
82 decidedNavigationPolicy = true; | 79 decidedNavigationPolicy = true; |
83 } | 80 } |
84 | 81 |
85 - (void)webView:(WKWebView*)webView decidePolicyForSafeBrowsingResultForNavigati
onAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKSafe
BrowsingResultPolicy))decisionHandler | |
86 { | |
87 if (shouldCancelForSafeBrowsing) | |
88 decisionHandler(WKSafeBrowsingResultPolicyCancel); | |
89 else if (shouldShowSafeBrowsingWarning) | |
90 decisionHandler(WKSafeBrowsingResultPolicyCancelAndShowWarning); | |
91 else | |
92 decisionHandler(WKSafeBrowsingResultPolicyAllow); | |
93 decidedSafeBrowsingPolicy = true; | |
94 } | |
95 | |
96 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat
ion | 82 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat
ion |
97 { | 83 { |
98 if (finishedNavigation) | 84 if (finishedNavigation) |
99 finishedRedirectNavigation = true; | 85 finishedRedirectNavigation = true; |
100 else | 86 else |
101 finishedNavigation = true; | 87 finishedNavigation = true; |
102 } | 88 } |
103 | 89 |
104 | 90 |
105 @end | 91 @end |
106 | 92 |
107 TEST(WebKit, SafeBrowsingForSafePage) | 93 TEST(WebKit, SafeBrowsingForSafePage) |
108 { | 94 { |
109 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); | 95 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); |
110 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); | 96 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); |
111 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; | 97 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; |
112 [configuration preferences].safeBrowsingEnabled = YES; | 98 [configuration preferences].safeBrowsingEnabled = YES; |
113 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); | 99 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); |
114 [webView _setUseTestSafeBrowsingContext:YES]; | 100 [webView _setUseTestSafeBrowsingContext:YES]; |
115 | 101 |
116 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; | 102 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; |
117 [[window contentView] addSubview:webView.get()]; | 103 [[window contentView] addSubview:webView.get()]; |
118 | 104 |
119 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); | 105 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); |
120 [webView setNavigationDelegate:controller.get()]; | 106 [webView setNavigationDelegate:controller.get()]; |
121 [webView setUIDelegate:controller.get()]; | 107 [webView setUIDelegate:controller.get()]; |
122 | 108 |
123 finishedNavigation = false; | 109 finishedNavigation = false; |
124 decidedNavigationPolicy = false; | 110 decidedNavigationPolicy = false; |
125 decidedSafeBrowsingPolicy = false; | 111 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; |
126 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; | 112 TestWebKitAPI::Util::run(&finishedNavigation); |
127 TestWebKitAPI::Util::run(&finishedNavigation); | 113 |
128 | 114 EXPECT_TRUE(decidedNavigationPolicy); |
129 EXPECT_TRUE(decidedNavigationPolicy); | 115 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], firstURL); |
130 EXPECT_FALSE(decidedSafeBrowsingPolicy); | 116 EXPECT_WK_STREQ([[webView URL] absoluteString], firstURL); |
131 } | 117 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], firstURL); |
132 | 118 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], ""); |
133 TEST(WebKit, SafeBrowsingForUnsafePageAllow) | 119 } |
134 { | 120 |
135 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); | 121 TEST(WebKit, SafeBrowsingForUnsafePage) |
136 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); | 122 { |
137 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; | 123 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); |
138 [configuration preferences].safeBrowsingEnabled = YES; | 124 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); |
139 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); | 125 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; |
140 [webView _setUseTestSafeBrowsingContext:YES]; | 126 [configuration preferences].safeBrowsingEnabled = YES; |
141 | 127 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); |
142 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; | 128 [webView _setUseTestSafeBrowsingContext:YES]; |
143 [[window contentView] addSubview:webView.get()]; | 129 |
144 | 130 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; |
145 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); | 131 [[window contentView] addSubview:webView.get()]; |
146 [webView setNavigationDelegate:controller.get()]; | 132 |
147 [webView setUIDelegate:controller.get()]; | 133 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); |
148 | 134 [webView setNavigationDelegate:controller.get()]; |
149 finishedNavigation = false; | 135 [webView setUIDelegate:controller.get()]; |
150 decidedNavigationPolicy = false; | 136 |
151 decidedSafeBrowsingPolicy = false; | 137 finishedNavigation = false; |
| 138 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; |
| 139 TestWebKitAPI::Util::run(&finishedNavigation); |
| 140 |
| 141 finishedNavigation = false; |
| 142 decidedNavigationPolicy = false; |
152 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:unsaf
eURL]]]; | 143 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:unsaf
eURL]]]; |
153 TestWebKitAPI::Util::run(&finishedNavigation); | 144 TestWebKitAPI::Util::run(&finishedNavigation); |
154 | 145 |
155 EXPECT_TRUE(decidedNavigationPolicy); | 146 EXPECT_TRUE(decidedNavigationPolicy); |
156 EXPECT_TRUE(decidedSafeBrowsingPolicy); | 147 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); |
157 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); | 148 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); |
| 149 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); |
| 150 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); |
| 151 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], unsafeURL); |
| 152 |
| 153 finishedNavigation = false; |
| 154 decidedNavigationPolicy = false; |
| 155 [webView evaluateJavaScript:@"var evt = document.createEvent('MouseEvent');
evt.initMouseEvent('click'); document.getElementById('visitAnyway').dispatchEven
t(evt);" completionHandler:nil]; |
| 156 TestWebKitAPI::Util::run(&finishedNavigation); |
| 157 EXPECT_TRUE(decidedNavigationPolicy); |
| 158 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); |
| 159 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); |
158 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); | 160 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); |
159 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], unsafeURL); | 161 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], unsafeURL); |
160 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], ""); | 162 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], ""); |
161 } | 163 } |
162 | 164 |
163 TEST(WebKit, SafeBrowsingForUnsafePageShowWarning) | 165 |
164 { | 166 TEST(WebKit, SafeBrowsingForUnsafePageBackForward) |
165 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); | 167 { |
166 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); | 168 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); |
167 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; | 169 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); |
168 [configuration preferences].safeBrowsingEnabled = YES; | 170 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; |
169 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); | 171 [configuration preferences].safeBrowsingEnabled = YES; |
170 [webView _setUseTestSafeBrowsingContext:YES]; | 172 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); |
171 | 173 [webView _setUseTestSafeBrowsingContext:YES]; |
172 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; | 174 |
173 [[window contentView] addSubview:webView.get()]; | 175 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; |
174 | 176 [[window contentView] addSubview:webView.get()]; |
175 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); | 177 |
176 [webView setNavigationDelegate:controller.get()]; | 178 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); |
177 [webView setUIDelegate:controller.get()]; | 179 [webView setNavigationDelegate:controller.get()]; |
178 | 180 [webView setUIDelegate:controller.get()]; |
179 finishedNavigation = false; | 181 |
180 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; | 182 finishedNavigation = false; |
181 TestWebKitAPI::Util::run(&finishedNavigation); | 183 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; |
182 | 184 TestWebKitAPI::Util::run(&finishedNavigation); |
183 finishedNavigation = false; | 185 |
184 decidedNavigationPolicy = false; | 186 finishedNavigation = false; |
185 decidedSafeBrowsingPolicy = false; | 187 decidedNavigationPolicy = false; |
186 shouldShowSafeBrowsingWarning = true; | |
187 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:unsaf
eURL]]]; | 188 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:unsaf
eURL]]]; |
188 TestWebKitAPI::Util::run(&finishedNavigation); | 189 TestWebKitAPI::Util::run(&finishedNavigation); |
189 shouldShowSafeBrowsingWarning = false; | 190 |
190 | 191 EXPECT_TRUE(decidedNavigationPolicy); |
191 EXPECT_TRUE(decidedNavigationPolicy); | |
192 EXPECT_TRUE(decidedSafeBrowsingPolicy); | |
193 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); | 192 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); |
194 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); | 193 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); |
195 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); | |
196 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); | |
197 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], unsafeURL); | |
198 | |
199 finishedNavigation = false; | |
200 decidedNavigationPolicy = false; | |
201 decidedSafeBrowsingPolicy = false; | |
202 [webView evaluateJavaScript:@"var evt = document.createEvent('MouseEvent');
evt.initMouseEvent('click'); document.getElementById('visitAnyway').dispatchEven
t(evt);" completionHandler:nil]; | |
203 TestWebKitAPI::Util::run(&finishedNavigation); | |
204 EXPECT_TRUE(decidedNavigationPolicy); | |
205 EXPECT_FALSE(decidedSafeBrowsingPolicy); | |
206 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); | |
207 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); | |
208 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); | |
209 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], unsafeURL); | |
210 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], ""); | |
211 } | |
212 | |
213 TEST(WebKit, SafeBrowsingForUnsafePageShowWarningBackForward) | |
214 { | |
215 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); | |
216 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); | |
217 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; | |
218 [configuration preferences].safeBrowsingEnabled = YES; | |
219 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); | |
220 [webView _setUseTestSafeBrowsingContext:YES]; | |
221 | |
222 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; | |
223 [[window contentView] addSubview:webView.get()]; | |
224 | |
225 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); | |
226 [webView setNavigationDelegate:controller.get()]; | |
227 [webView setUIDelegate:controller.get()]; | |
228 | |
229 finishedNavigation = false; | |
230 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; | |
231 TestWebKitAPI::Util::run(&finishedNavigation); | |
232 | |
233 finishedNavigation = false; | |
234 decidedNavigationPolicy = false; | |
235 decidedSafeBrowsingPolicy = false; | |
236 shouldShowSafeBrowsingWarning = true; | |
237 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:unsaf
eURL]]]; | |
238 TestWebKitAPI::Util::run(&finishedNavigation); | |
239 shouldShowSafeBrowsingWarning = false; | |
240 | |
241 EXPECT_TRUE(decidedNavigationPolicy); | |
242 EXPECT_TRUE(decidedSafeBrowsingPolicy); | |
243 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); | |
244 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); | |
245 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); | |
246 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); | |
247 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], unsafeURL); | |
248 | |
249 finishedNavigation = false; | |
250 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:secon
dURL]]]; | |
251 TestWebKitAPI::Util::run(&finishedNavigation); | |
252 | |
253 finishedNavigation = false; | |
254 decidedNavigationPolicy = false; | |
255 decidedSafeBrowsingPolicy = false; | |
256 shouldShowSafeBrowsingWarning = true; | |
257 [webView goBack]; | |
258 TestWebKitAPI::Util::run(&finishedNavigation); | |
259 shouldShowSafeBrowsingWarning = false; | |
260 | |
261 EXPECT_TRUE(decidedNavigationPolicy); | |
262 EXPECT_TRUE(decidedSafeBrowsingPolicy); | |
263 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); | |
264 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); | |
265 EXPECT_WK_STREQ([[[[webView backForwardList] forwardItem] URL] absoluteStrin
g], secondURL); | |
266 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); | 194 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); |
267 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); | 195 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); |
268 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], unsafeURL); | 196 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], unsafeURL); |
269 | 197 |
270 finishedNavigation = false; | 198 finishedNavigation = false; |
271 [webView goBack]; | 199 [webView goBack]; |
272 TestWebKitAPI::Util::run(&finishedNavigation); | 200 TestWebKitAPI::Util::run(&finishedNavigation); |
273 | 201 |
274 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], firstURL); | 202 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], firstURL); |
275 EXPECT_WK_STREQ([[[[webView backForwardList] forwardItem] URL] absoluteStrin
g], unsafeURL); | 203 EXPECT_WK_STREQ([[[[webView backForwardList] forwardItem] URL] absoluteStrin
g], unsafeURL); |
276 EXPECT_WK_STREQ([[webView URL] absoluteString], firstURL); | 204 EXPECT_WK_STREQ([[webView URL] absoluteString], firstURL); |
277 | 205 |
278 finishedNavigation = false; | 206 finishedNavigation = false; |
279 decidedNavigationPolicy = false; | 207 decidedNavigationPolicy = false; |
280 decidedSafeBrowsingPolicy = false; | |
281 shouldShowSafeBrowsingWarning = true; | |
282 [webView goForward]; | 208 [webView goForward]; |
283 TestWebKitAPI::Util::run(&finishedNavigation); | 209 TestWebKitAPI::Util::run(&finishedNavigation); |
284 shouldShowSafeBrowsingWarning = false; | 210 |
285 | 211 EXPECT_TRUE(decidedNavigationPolicy); |
286 EXPECT_TRUE(decidedNavigationPolicy); | |
287 EXPECT_TRUE(decidedSafeBrowsingPolicy); | |
288 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); | 212 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); |
289 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); | 213 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); |
290 EXPECT_WK_STREQ([[[[webView backForwardList] forwardItem] URL] absoluteStrin
g], secondURL); | 214 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); |
291 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); | 215 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); |
292 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); | 216 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], unsafeURL); |
293 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], unsafeURL); | 217 |
294 | 218 finishedNavigation = false; |
295 finishedNavigation = false; | 219 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:secon
dURL]]]; |
296 [webView goForward]; | 220 TestWebKitAPI::Util::run(&finishedNavigation); |
297 TestWebKitAPI::Util::run(&finishedNavigation); | 221 |
298 | 222 finishedNavigation = false; |
299 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], secondURL); | 223 decidedNavigationPolicy = false; |
300 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
unsafeURL); | 224 [webView goBack]; |
301 EXPECT_WK_STREQ([[webView URL] absoluteString], secondURL); | 225 TestWebKitAPI::Util::run(&finishedNavigation); |
302 } | 226 |
303 | 227 EXPECT_TRUE(decidedNavigationPolicy); |
304 TEST(WebKit, SafeBrowsingForUnsafePageCancelForSafeBrowsing) | 228 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); |
305 { | 229 // FIXME: Also check backItem and forwardItem, once those are updated correc
tly. |
306 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); | 230 |
307 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); | 231 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); |
308 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; | 232 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); |
309 [configuration preferences].safeBrowsingEnabled = YES; | 233 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], unsafeURL); |
310 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); | 234 } |
311 [webView _setUseTestSafeBrowsingContext:YES]; | 235 |
312 | 236 |
313 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; | 237 TEST(WebKit, SafeBrowsingForUnsafePageCancelNavigation) |
314 [[window contentView] addSubview:webView.get()]; | 238 { |
315 | 239 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); |
316 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); | 240 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); |
317 [webView setNavigationDelegate:controller.get()]; | 241 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; |
318 [webView setUIDelegate:controller.get()]; | 242 [configuration preferences].safeBrowsingEnabled = YES; |
319 | 243 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); |
320 finishedNavigation = false; | 244 [webView _setUseTestSafeBrowsingContext:YES]; |
321 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; | 245 |
322 TestWebKitAPI::Util::run(&finishedNavigation); | 246 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; |
323 | 247 [[window contentView] addSubview:webView.get()]; |
324 finishedNavigation = false; | 248 |
325 decidedNavigationPolicy = false; | 249 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); |
326 decidedSafeBrowsingPolicy = false; | 250 [webView setNavigationDelegate:controller.get()]; |
327 shouldCancelForSafeBrowsing = true; | 251 [webView setUIDelegate:controller.get()]; |
| 252 |
| 253 finishedNavigation = false; |
| 254 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; |
| 255 TestWebKitAPI::Util::run(&finishedNavigation); |
| 256 |
| 257 finishedNavigation = false; |
| 258 decidedNavigationPolicy = false; |
| 259 shouldCancelNavigation = true; |
328 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:unsaf
eURL]]]; | 260 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:unsaf
eURL]]]; |
329 TestWebKitAPI::Util::run(&decidedSafeBrowsingPolicy); | 261 TestWebKitAPI::Util::run(&decidedNavigationPolicy); |
330 shouldCancelForSafeBrowsing = false; | 262 shouldCancelNavigation = false; |
331 | 263 |
332 EXPECT_TRUE(decidedNavigationPolicy); | |
333 EXPECT_FALSE(finishedNavigation); | 264 EXPECT_FALSE(finishedNavigation); |
334 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], firstURL); | 265 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], firstURL); |
335 EXPECT_WK_STREQ([[webView URL] absoluteString], firstURL); | 266 EXPECT_WK_STREQ([[webView URL] absoluteString], firstURL); |
336 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], firstURL); | 267 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], firstURL); |
337 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], ""); | 268 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], ""); |
338 } | 269 } |
339 | 270 |
340 TEST(WebKit, SafeBrowsingForUnsafePageCancelNavigation) | 271 TEST(WebKit, SafeBrowsingForUnsafePageRedirect) |
341 { | |
342 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); | |
343 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); | |
344 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; | |
345 [configuration preferences].safeBrowsingEnabled = YES; | |
346 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); | |
347 [webView _setUseTestSafeBrowsingContext:YES]; | |
348 | |
349 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; | |
350 [[window contentView] addSubview:webView.get()]; | |
351 | |
352 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); | |
353 [webView setNavigationDelegate:controller.get()]; | |
354 [webView setUIDelegate:controller.get()]; | |
355 | |
356 finishedNavigation = false; | |
357 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; | |
358 TestWebKitAPI::Util::run(&finishedNavigation); | |
359 | |
360 finishedNavigation = false; | |
361 decidedNavigationPolicy = false; | |
362 decidedSafeBrowsingPolicy = false; | |
363 shouldCancelNavigation = true; | |
364 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:unsaf
eURL]]]; | |
365 TestWebKitAPI::Util::run(&decidedNavigationPolicy); | |
366 shouldCancelNavigation = false; | |
367 | |
368 EXPECT_FALSE(decidedSafeBrowsingPolicy); | |
369 EXPECT_FALSE(finishedNavigation); | |
370 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], firstURL); | |
371 EXPECT_WK_STREQ([[webView URL] absoluteString], firstURL); | |
372 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], firstURL); | |
373 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], ""); | |
374 } | |
375 | |
376 TEST(WebKit, SafeBrowsingForUnsafePageRedirectShowWarning) | |
377 { | 272 { |
378 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); | 273 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); |
379 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); | 274 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); |
380 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; | 275 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; |
381 [configuration preferences].safeBrowsingEnabled = YES; | 276 [configuration preferences].safeBrowsingEnabled = YES; |
382 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); | 277 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); |
383 [webView _setUseTestSafeBrowsingContext:YES]; | 278 [webView _setUseTestSafeBrowsingContext:YES]; |
384 | 279 |
385 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; | 280 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; |
386 [[window contentView] addSubview:webView.get()]; | 281 [[window contentView] addSubview:webView.get()]; |
387 | 282 |
388 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); | 283 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); |
389 [webView setNavigationDelegate:controller.get()]; | 284 [webView setNavigationDelegate:controller.get()]; |
390 [webView setUIDelegate:controller.get()]; | 285 [webView setUIDelegate:controller.get()]; |
391 | 286 |
392 finishedNavigation = false; | 287 finishedNavigation = false; |
393 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; | 288 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; |
394 TestWebKitAPI::Util::run(&finishedNavigation); | 289 TestWebKitAPI::Util::run(&finishedNavigation); |
395 | 290 |
396 finishedNavigation = false; | 291 finishedNavigation = false; |
397 finishedRedirectNavigation = false; | 292 finishedRedirectNavigation = false; |
398 decidedNavigationPolicy = false; | 293 decidedNavigationPolicy = false; |
399 decidedSafeBrowsingPolicy = false; | |
400 shouldShowSafeBrowsingWarning = true; | |
401 [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URL
ForResource:@"redirect-to-unsafe" withExtension:@"html" subdirectory:@"TestWebKi
tAPI.resources"]]]; | 294 [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URL
ForResource:@"redirect-to-unsafe" withExtension:@"html" subdirectory:@"TestWebKi
tAPI.resources"]]]; |
402 TestWebKitAPI::Util::run(&finishedRedirectNavigation); | 295 TestWebKitAPI::Util::run(&finishedRedirectNavigation); |
403 shouldShowSafeBrowsingWarning = false; | 296 |
404 | 297 EXPECT_TRUE(decidedNavigationPolicy); |
405 EXPECT_TRUE(decidedNavigationPolicy); | 298 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); |
406 EXPECT_TRUE(decidedSafeBrowsingPolicy); | 299 // FIXME: Also check that backItem is firstURL, once that backItem is update
d correctly. |
407 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); | 300 |
408 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); | 301 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); |
409 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); | 302 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); |
410 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); | 303 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], unsafeURL); |
411 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], unsafeURL); | 304 } |
412 } | 305 |
413 | 306 TEST(WebKit, SafeBrowsingForUnsafeSubframe) |
414 TEST(WebKit, SafeBrowsingForUnsafePageRedirectAllow) | |
415 { | 307 { |
416 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); | 308 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); |
417 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); | 309 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); |
418 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; | 310 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; |
419 [configuration preferences].safeBrowsingEnabled = YES; | 311 [configuration preferences].safeBrowsingEnabled = YES; |
420 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); | 312 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); |
421 [webView _setUseTestSafeBrowsingContext:YES]; | 313 [webView _setUseTestSafeBrowsingContext:YES]; |
422 | 314 |
423 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; | 315 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; |
424 [[window contentView] addSubview:webView.get()]; | 316 [[window contentView] addSubview:webView.get()]; |
425 | 317 |
426 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); | 318 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); |
427 [webView setNavigationDelegate:controller.get()]; | 319 [webView setNavigationDelegate:controller.get()]; |
428 [webView setUIDelegate:controller.get()]; | 320 [webView setUIDelegate:controller.get()]; |
429 | 321 |
430 finishedNavigation = false; | 322 finishedNavigation = false; |
431 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; | 323 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; |
432 TestWebKitAPI::Util::run(&finishedNavigation); | 324 TestWebKitAPI::Util::run(&finishedNavigation); |
433 | 325 |
434 finishedNavigation = false; | 326 finishedNavigation = false; |
435 finishedRedirectNavigation = false; | 327 finishedRedirectNavigation = false; |
436 decidedNavigationPolicy = false; | 328 decidedNavigationPolicy = false; |
437 decidedSafeBrowsingPolicy = false; | |
438 [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URL
ForResource:@"redirect-to-unsafe" withExtension:@"html" subdirectory:@"TestWebKi
tAPI.resources"]]]; | |
439 TestWebKitAPI::Util::run(&finishedRedirectNavigation); | |
440 | |
441 EXPECT_TRUE(decidedNavigationPolicy); | |
442 EXPECT_TRUE(decidedSafeBrowsingPolicy); | |
443 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], unsafeURL); | |
444 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); | |
445 EXPECT_WK_STREQ([[webView URL] absoluteString], unsafeURL); | |
446 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], unsafeURL); | |
447 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], ""); | |
448 } | |
449 | |
450 TEST(WebKit, SafeBrowsingForUnsafePageRedirectCancel) | |
451 { | |
452 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); | |
453 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); | |
454 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; | |
455 [configuration preferences].safeBrowsingEnabled = YES; | |
456 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); | |
457 [webView _setUseTestSafeBrowsingContext:YES]; | |
458 | |
459 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; | |
460 [[window contentView] addSubview:webView.get()]; | |
461 | |
462 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); | |
463 [webView setNavigationDelegate:controller.get()]; | |
464 [webView setUIDelegate:controller.get()]; | |
465 | |
466 finishedNavigation = false; | |
467 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; | |
468 TestWebKitAPI::Util::run(&finishedNavigation); | |
469 | |
470 finishedNavigation = false; | |
471 finishedRedirectNavigation = false; | |
472 decidedNavigationPolicy = false; | |
473 decidedSafeBrowsingPolicy = false; | |
474 shouldCancelForSafeBrowsing = true; | |
475 NSURLRequest* request = [NSURLRequest requestWithURL:[[NSBundle mainBundle]
URLForResource:@"redirect-to-unsafe" withExtension:@"html" subdirectory:@"TestWe
bKitAPI.resources"]]; | |
476 [webView loadRequest:request]; | |
477 TestWebKitAPI::Util::run(&decidedSafeBrowsingPolicy); | |
478 shouldCancelForSafeBrowsing = false; | |
479 | |
480 EXPECT_TRUE(decidedNavigationPolicy); | |
481 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], [[request URL] absoluteString]); | |
482 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); | |
483 EXPECT_WK_STREQ([[webView URL] absoluteString], [[request URL] absoluteStrin
g]); | |
484 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], [[request URL] abs
oluteString]); | |
485 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], ""); | |
486 } | |
487 | |
488 TEST(WebKit, SafeBrowsingForUnsafeSubframeShowWarning) | |
489 { | |
490 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfigu
ration alloc] init]); | |
491 RetainPtr<SBScheme> handler = adoptNS([[SBScheme alloc] init]); | |
492 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SB"]; | |
493 [configuration preferences].safeBrowsingEnabled = YES; | |
494 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800
, 600) configuration:configuration.get()]); | |
495 [webView _setUseTestSafeBrowsingContext:YES]; | |
496 | |
497 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame]
styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES])
; | |
498 [[window contentView] addSubview:webView.get()]; | |
499 | |
500 auto controller = adoptNS([[SafeBrowsingTestController alloc] init]); | |
501 [webView setNavigationDelegate:controller.get()]; | |
502 [webView setUIDelegate:controller.get()]; | |
503 | |
504 finishedNavigation = false; | |
505 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first
URL]]]; | |
506 TestWebKitAPI::Util::run(&finishedNavigation); | |
507 | |
508 finishedNavigation = false; | |
509 finishedRedirectNavigation = false; | |
510 decidedNavigationPolicy = false; | |
511 decidedSafeBrowsingPolicy = false; | |
512 shouldShowSafeBrowsingWarning = true; | |
513 NSURLRequest* request = [NSURLRequest requestWithURL:[[NSBundle mainBundle]
URLForResource:@"unsafe-iframe" withExtension:@"html" subdirectory:@"TestWebKitA
PI.resources"]]; | 329 NSURLRequest* request = [NSURLRequest requestWithURL:[[NSBundle mainBundle]
URLForResource:@"unsafe-iframe" withExtension:@"html" subdirectory:@"TestWebKitA
PI.resources"]]; |
514 [webView loadRequest:request]; | 330 [webView loadRequest:request]; |
515 TestWebKitAPI::Util::run(&finishedRedirectNavigation); | 331 TestWebKitAPI::Util::run(&finishedRedirectNavigation); |
516 shouldShowSafeBrowsingWarning = false; | 332 |
517 | 333 EXPECT_TRUE(decidedNavigationPolicy); |
518 EXPECT_TRUE(decidedNavigationPolicy); | |
519 EXPECT_TRUE(decidedSafeBrowsingPolicy); | |
520 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], [[request URL] absoluteString]); | 334 EXPECT_WK_STREQ([[[[webView backForwardList] currentItem] URL] absoluteStrin
g], [[request URL] absoluteString]); |
521 EXPECT_WK_STREQ([[[[webView backForwardList] backItem] URL] absoluteString],
firstURL); | 335 // FIXME: Also check that backItem is firstURL, once that backItem is update
d correctly. |
| 336 |
522 EXPECT_WK_STREQ([[webView URL] absoluteString], [[request URL] absoluteStrin
g]); | 337 EXPECT_WK_STREQ([[webView URL] absoluteString], [[request URL] absoluteStrin
g]); |
523 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); | 338 EXPECT_WK_STREQ([[webView _committedURL] absoluteString], warningURL); |
524 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], [[request URL] a
bsoluteString]); | 339 EXPECT_WK_STREQ([[webView _unreachableURL] absoluteString], [[request URL] a
bsoluteString]); |
525 } | 340 } |
526 | 341 |
527 #endif | 342 #endif |
528 | 343 |
529 #endif | 344 #endif |
LEFT | RIGHT |