|
Lines 37-42
a/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm_sec1
|
| 37 |
static bool isDone; |
37 |
static bool isDone; |
| 38 |
static RetainPtr<WKNavigation> currentNavigation; |
38 |
static RetainPtr<WKNavigation> currentNavigation; |
| 39 |
static RetainPtr<NSURL> redirectURL; |
39 |
static RetainPtr<NSURL> redirectURL; |
|
|
40 |
static NSTimeInterval redirectDelay; |
| 41 |
static bool didCancelRedirect; |
| 40 |
|
42 |
|
| 41 |
@interface NavigationDelegate : NSObject <WKNavigationDelegate> |
43 |
@interface NavigationDelegate : NSObject <WKNavigationDelegate> |
| 42 |
@end |
44 |
@end |
|
Lines 188-227
TEST(WKNavigation, DecidePolicyForPageCacheNavigation)
a/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm_sec2
|
| 188 |
ASSERT_TRUE([delegate decidedPolicyForBackForwardNavigation]); |
190 |
ASSERT_TRUE([delegate decidedPolicyForBackForwardNavigation]); |
| 189 |
} |
191 |
} |
| 190 |
|
192 |
|
| 191 |
@interface DidPerformClientRedirectNavigationDelegate : NSObject<WKNavigationDelegatePrivate> |
193 |
@interface ClientRedirectNavigationDelegate : NSObject<WKNavigationDelegatePrivate> |
| 192 |
@end |
194 |
@end |
| 193 |
|
195 |
|
| 194 |
@implementation DidPerformClientRedirectNavigationDelegate |
196 |
@implementation ClientRedirectNavigationDelegate |
| 195 |
- (void)_webView:(WKWebView *)webView didPerformClientRedirectForNavigation:(WKNavigation *)navigation |
197 |
- (void)_webView:(WKWebView *)webView didScheduleClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)delay |
|
|
198 |
{ |
| 199 |
redirectURL = URL; |
| 200 |
redirectDelay = delay; |
| 201 |
} |
| 202 |
- (void)_webViewDidCancelClientRedirect:(WKWebView *)webView |
| 203 |
{ |
| 204 |
didCancelRedirect = true; |
| 205 |
} |
| 206 |
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation |
| 196 |
{ |
207 |
{ |
| 197 |
isDone = true; |
208 |
isDone = true; |
| 198 |
redirectURL = webView.URL; |
|
|
| 199 |
} |
209 |
} |
| 200 |
@end |
210 |
@end |
| 201 |
|
211 |
|
| 202 |
TEST(WKNavigation, DidPerformClientRedirect) |
212 |
TEST(WKNavigation, WebViewDidScheduleClientRedirect) |
| 203 |
{ |
213 |
{ |
| 204 |
RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); |
214 |
auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); |
| 205 |
|
215 |
|
| 206 |
RetainPtr<DidPerformClientRedirectNavigationDelegate> delegate = adoptNS([[DidPerformClientRedirectNavigationDelegate alloc] init]); |
216 |
auto delegate = adoptNS([[ClientRedirectNavigationDelegate alloc] init]); |
| 207 |
[webView setNavigationDelegate:delegate.get()]; |
217 |
[webView setNavigationDelegate:delegate.get()]; |
| 208 |
|
218 |
|
| 209 |
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%220;URL=data:text/html,Page1%22%3E"]]; |
219 |
auto request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%22123;URL=data:text/html,Page1%22%3E"]]; |
| 210 |
|
220 |
|
| 211 |
isDone = false; |
221 |
isDone = false; |
| 212 |
redirectURL = nil; |
222 |
redirectURL = nil; |
|
|
223 |
redirectDelay = 0; |
| 213 |
[webView loadRequest:request]; |
224 |
[webView loadRequest:request]; |
| 214 |
TestWebKitAPI::Util::run(&isDone); |
225 |
TestWebKitAPI::Util::run(&isDone); |
| 215 |
|
226 |
|
|
|
227 |
ASSERT_DOUBLE_EQ(redirectDelay, 123); |
| 216 |
ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page1"); |
228 |
ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page1"); |
| 217 |
|
229 |
|
| 218 |
request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cscript%3Ewindow.location=%22data:text/html,Page2%22;%3C/script%3E"]]; |
230 |
request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cscript%3Ewindow.location=%22data:text/html,Page2%22;%3C/script%3E"]]; |
| 219 |
isDone = false; |
231 |
isDone = false; |
| 220 |
redirectURL = nil; |
232 |
redirectURL = nil; |
|
|
233 |
redirectDelay = NSTimeIntervalSince1970; // Use any non-zero value, we will test that the delegate receives a delay of 0. |
| 221 |
[webView loadRequest:request]; |
234 |
[webView loadRequest:request]; |
| 222 |
TestWebKitAPI::Util::run(&isDone); |
235 |
TestWebKitAPI::Util::run(&isDone); |
| 223 |
|
236 |
|
|
|
237 |
ASSERT_DOUBLE_EQ(redirectDelay, 0); |
| 224 |
ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page2"); |
238 |
ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page2"); |
| 225 |
} |
239 |
} |
| 226 |
|
240 |
|
|
|
241 |
TEST(WKNavigation, WebViewDidCancelClientRedirect) |
| 242 |
{ |
| 243 |
auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); |
| 244 |
|
| 245 |
auto delegate = adoptNS([[ClientRedirectNavigationDelegate alloc] init]); |
| 246 |
[webView setNavigationDelegate:delegate.get()]; |
| 247 |
|
| 248 |
// Test 1: During a navigation that is not a client redirect, -_webViewDidCancelClientRedirect: should not be called. |
| 249 |
|
| 250 |
auto request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,Page1"]]; |
| 251 |
|
| 252 |
isDone = false; |
| 253 |
didCancelRedirect = false; |
| 254 |
[webView loadRequest:request]; |
| 255 |
TestWebKitAPI::Util::run(&isDone); |
| 256 |
|
| 257 |
ASSERT_FALSE(didCancelRedirect); |
| 258 |
|
| 259 |
// Test 2: When a client redirect does happen, -_webViewDidCancelClientRedirect: should still be called. It essentially |
| 260 |
// is called whenever the web view transitions from "expecting a redirect" to "not expecting a redirect". |
| 261 |
|
| 262 |
request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cscript%3Ewindow.location=%22data:text/html,Page2%22;%3C/script%3E"]]; |
| 263 |
isDone = false; |
| 264 |
didCancelRedirect = false; |
| 265 |
[webView loadRequest:request]; |
| 266 |
TestWebKitAPI::Util::run(&isDone); |
| 267 |
|
| 268 |
ASSERT_FALSE(didCancelRedirect); |
| 269 |
|
| 270 |
isDone = false; |
| 271 |
TestWebKitAPI::Util::run(&isDone); |
| 272 |
|
| 273 |
ASSERT_TRUE(didCancelRedirect); |
| 274 |
|
| 275 |
// Test 3: When another navigation begins while a client redirect is scheduled, -_webViewDidCancelClientRedirect: |
| 276 |
// should be called. |
| 277 |
|
| 278 |
request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%2210000;URL=data:text/html,Page3%22%3E"]]; |
| 279 |
|
| 280 |
isDone = false; |
| 281 |
didCancelRedirect = false; |
| 282 |
[webView loadRequest:request]; |
| 283 |
TestWebKitAPI::Util::run(&isDone); |
| 284 |
|
| 285 |
ASSERT_FALSE(didCancelRedirect); |
| 286 |
|
| 287 |
request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,Page4"]]; |
| 288 |
isDone = false; |
| 289 |
[webView loadRequest:request]; |
| 290 |
TestWebKitAPI::Util::run(&isDone); |
| 291 |
|
| 292 |
ASSERT_TRUE(didCancelRedirect); |
| 293 |
} |
| 294 |
|
| 227 |
#endif |
295 |
#endif |