|
30 | 30 | #import "PlatformUtilities.h" |
31 | 31 | #import "TestCocoa.h" |
32 | 32 | #import "TestInputDelegate.h" |
| 33 | +#import "TestNavigationDelegate.h" |
| 34 | +#import "TestProtocol.h" |
33 | 35 | #import "TestWKWebView.h" |
34 | 36 | #import "UIKitSPI.h" |
35 | 37 | #import "UserInterfaceSwizzler.h" |
| 38 | +#import <WebKit/WKProcessPoolPrivate.h> |
36 | 39 | #import <WebKit/WKWebViewPrivate.h> |
| 40 | +#import <WebKit/_WKProcessPoolConfiguration.h> |
37 | 41 | #import <WebKitLegacy/WebEvent.h> |
38 | 42 | #import <cmath> |
39 | 43 |
|
@@ -368,6 +372,69 @@ - (UIView *)inputAccessoryView |
368 | 372 | TestWebKitAPI::Util::run(&doneWaiting); |
369 | 373 | } |
370 | 374 |
|
| 375 | +TEST(KeyboardInputTests, HandleKeyEventsInCrashedOrUninitializedWebProcess) |
| 376 | +{ |
| 377 | + auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); |
| 378 | + auto contentView = [webView textInputContentView]; |
| 379 | + { |
| 380 | + auto keyDownEvent = adoptNS([[WebEvent alloc] initWithKeyEventType:WebEventKeyDown timeStamp:CFAbsoluteTimeGetCurrent() characters:@"a" charactersIgnoringModifiers:@"a" modifiers:0 isRepeating:NO withFlags:0 withInputManagerHint:nil keyCode:65 isTabKey:NO]); |
| 381 | + bool doneWaiting = false; |
| 382 | + [webView synchronouslyLoadHTMLString:@"<body></body>"]; |
| 383 | + [webView evaluateJavaScript:@"while (1);" completionHandler:nil]; |
| 384 | + [contentView handleKeyWebEvent:keyDownEvent.get() withCompletionHandler:[&](WebEvent *event, BOOL handled) { |
| 385 | + EXPECT_TRUE([event isEqual:keyDownEvent.get()]); |
| 386 | + EXPECT_FALSE(handled); |
| 387 | + doneWaiting = true; |
| 388 | + }]; |
| 389 | + [webView _killWebContentProcessAndResetState]; |
| 390 | + TestWebKitAPI::Util::run(&doneWaiting); |
| 391 | + } |
| 392 | + { |
| 393 | + auto keyUpEvent = adoptNS([[WebEvent alloc] initWithKeyEventType:WebEventKeyUp timeStamp:CFAbsoluteTimeGetCurrent() characters:@"a" charactersIgnoringModifiers:@"a" modifiers:0 isRepeating:NO withFlags:0 withInputManagerHint:nil keyCode:65 isTabKey:NO]); |
| 394 | + bool doneWaiting = false; |
| 395 | + [webView _close]; |
| 396 | + [contentView handleKeyWebEvent:keyUpEvent.get() withCompletionHandler:[&](WebEvent *event, BOOL handled) { |
| 397 | + EXPECT_TRUE([event isEqual:keyUpEvent.get()]); |
| 398 | + EXPECT_FALSE(handled); |
| 399 | + doneWaiting = true; |
| 400 | + }]; |
| 401 | + TestWebKitAPI::Util::run(&doneWaiting); |
| 402 | + } |
| 403 | +} |
| 404 | + |
| 405 | +TEST(KeyboardInputTests, HandleKeyEventsWhileSwappingWebProcess) |
| 406 | +{ |
| 407 | + [TestProtocol registerWithScheme:@"https"]; |
| 408 | + |
| 409 | + auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]); |
| 410 | + [processPoolConfiguration setProcessSwapsOnNavigation:YES]; |
| 411 | + auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]); |
| 412 | + auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); |
| 413 | + [configuration setProcessPool:processPool.get()]; |
| 414 | + |
| 415 | + auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]); |
| 416 | + auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); |
| 417 | + [webView setNavigationDelegate:navigationDelegate.get()]; |
| 418 | + [webView loadHTMLString:@"<body>webkit.org</body>" baseURL:[NSURL URLWithString:@"https://webkit.org"]]; |
| 419 | + [navigationDelegate waitForDidFinishNavigation]; |
| 420 | + |
| 421 | + [webView loadHTMLString:@"<body>apple.com</body>" baseURL:[NSURL URLWithString:@"https://apple.com"]]; |
| 422 | + [navigationDelegate waitForDidStartProvisionalNavigation]; |
| 423 | + |
| 424 | + bool done = false; |
| 425 | + auto keyEvent = adoptNS([[WebEvent alloc] initWithKeyEventType:WebEventKeyDown timeStamp:CFAbsoluteTimeGetCurrent() characters:@"a" charactersIgnoringModifiers:@"a" modifiers:0 isRepeating:NO withFlags:0 withInputManagerHint:nil keyCode:65 isTabKey:NO]); |
| 426 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), [keyEvent, webView, &done] { |
| 427 | + [[webView textInputContentView] handleKeyWebEvent:keyEvent.get() withCompletionHandler:[keyEvent, &done](WebEvent *event, BOOL handled) { |
| 428 | + EXPECT_TRUE([event isEqual:keyEvent.get()]); |
| 429 | + EXPECT_FALSE(handled); |
| 430 | + done = true; |
| 431 | + }]; |
| 432 | + }); |
| 433 | + |
| 434 | + [navigationDelegate waitForDidFinishNavigation]; |
| 435 | + TestWebKitAPI::Util::run(&done); |
| 436 | +} |
| 437 | + |
371 | 438 | TEST(KeyboardInputTests, CaretSelectionRectAfterRestoringFirstResponderWithRetainActiveFocusedState) |
372 | 439 | { |
373 | 440 | // This difference in caret width is due to the fact that we don't zoom in to the input field on iPad, but do on iPhone. |
|
0 commit comments