Modified: trunk/Tools/ChangeLog (263013 => 263014)
--- trunk/Tools/ChangeLog 2020-06-14 20:27:48 UTC (rev 263013)
+++ trunk/Tools/ChangeLog 2020-06-14 23:06:11 UTC (rev 263014)
@@ -1,3 +1,45 @@
+2020-06-14 Wenson Hsieh <[email protected]>
+
+ [iOS] Two KeyboardInputTests are failing on recent iOS SDK versions
+ https://bugs.webkit.org/show_bug.cgi?id=213183
+ <rdar://problem/64273483>
+
+ Reviewed by Tim Horton.
+
+ On recent versions of the iOS SDK, iOS simulators that are not shown on-screen are treated as if the hardware
+ keyboard is not available (that is, `+[UIIKeyboard isInHardwareKeyboardMode]` returns `NO`). When running API
+ tests while `Simulator.app` is already launched, an iOS simulator is presented on-screen, whereas the simulator
+ is not visible when running API tests without launching `Simulator.app` beforehand.
+
+ This discrepancy causes two iOS API tests to fail (i.e. `CaretSelectionRectAfterRestoringFirstResponder` and
+ `RangedSelectionRectAfterRestoringFirstResponder`), due to the fact that `-[WKWebView becomeFirstResponder]` no
+ longer causes an input session to begin.
+
+ Interestingly, these tests already attempt to circumvent this by using `webViewWithAutofocusedInput()`, which
+ creates and loads a `WKWebView` with a single autofocusing input element, with a `_WKInputDelegate` that
+ unconditionally allows input sessions to begin. However, this doesn't work as intended in these tests, because
+ nothing keeps the delegate (a `TestInputDelegate`) alive past the scope of the call to
+ `webViewWithAutofocusedInput()`. Since `[WKWebView _inputDelegate]` is a weak property, the input delegate
+ simply disappears after we finish waiting for the load to finish (and the autofocused input element begins its
+ input session). This causes us to erroneously fall back to default behavior (i.e.
+ `_WKFocusStartsInputSessionPolicyAuto`) for subsequent calls to show the keyboard for the focused element, as is
+ the case when these two API tests call `-becomeFirstResponder`. The end result is that the keyboard doesn't
+ appear and text selection views are not created and laid out, but only when API tests are run without having
+ launched the Simulator app beforehand.
+
+ To fix this, refactor `webViewWithAutofocusedInput()` into `webViewAndInputDelegateWithAutofocusedInput()`,
+ which returns both the new `WKWebView` as well as the `TestInputDelegate` of the web view. The call site is then
+ responsible for keeping the input delegate around for as long as it needs.
+
+ * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
+ (webViewWithAutofocusedInput):
+
+ Drive-by fix: fix a potential stack smasher by using an Objective-C block when setting the input delegate's
+ policy handler, and by using `__block` for the `doneWaiting` boolean flag. This is now a problem becuase this
+ block may be invoked multiple times.
+
+ (webViewAndInputDelegateWithAutofocusedInput):
+
2020-06-13 Saam Barati <[email protected]>
compare-results should have an option to print a breakdown and to save the breakdown as csv file
Modified: trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm (263013 => 263014)
--- trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm 2020-06-14 20:27:48 UTC (rev 263013)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm 2020-06-14 23:06:11 UTC (rev 263014)
@@ -187,9 +187,9 @@
{
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
- bool doneWaiting = false;
- [inputDelegate setFocusStartsInputSessionPolicyHandler:[&] (WKWebView *, id <_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy {
- doneWaiting = true;
+ __block BOOL doneWaiting = NO;
+ [inputDelegate setFocusStartsInputSessionPolicyHandler:^_WKFocusStartsInputSessionPolicy(WKWebView *, id <_WKFocusedElementInfo>) {
+ doneWaiting = YES;
return _WKFocusStartsInputSessionPolicyAllow;
}];
[webView _setInputDelegate:inputDelegate.get()];
@@ -200,10 +200,10 @@
return webView;
}
-static RetainPtr<TestWKWebView> webViewWithAutofocusedInput()
+static std::pair<RetainPtr<TestWKWebView>, RetainPtr<TestInputDelegate>> webViewAndInputDelegateWithAutofocusedInput()
{
auto inputDelegate = adoptNS([TestInputDelegate new]);
- return webViewWithAutofocusedInput(inputDelegate);
+ return { webViewWithAutofocusedInput(inputDelegate), inputDelegate };
}
namespace TestWebKitAPI {
@@ -309,7 +309,7 @@
TEST(KeyboardInputTests, CanHandleKeyEventInCompletionHandler)
{
- auto webView = webViewWithAutofocusedInput();
+ auto [webView, inputDelegate] = webViewAndInputDelegateWithAutofocusedInput();
bool doneWaiting = false;
id <UITextInputPrivate> contentView = (id <UITextInputPrivate>)[webView firstResponder];
@@ -330,7 +330,7 @@
TEST(KeyboardInputTests, ResigningFirstResponderCancelsKeyEvents)
{
- auto webView = webViewWithAutofocusedInput();
+ auto [webView, inputDelegate] = webViewAndInputDelegateWithAutofocusedInput();
auto contentView = [webView textInputContentView];
auto keyDownEvent = adoptNS([[WebEvent alloc] initWithKeyEventType:WebEventKeyDown timeStamp:CFAbsoluteTimeGetCurrent() characters:@"a" charactersIgnoringModifiers:@"a" modifiers:0 isRepeating:NO withFlags:0 withInputManagerHint:nil keyCode:0 isTabKey:NO]);
@@ -372,7 +372,7 @@
{
// 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.
auto expectedCaretRect = CGRectMake(16, 13, UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad ? 3 : 2, 15);
- auto webView = webViewWithAutofocusedInput();
+ auto [webView, inputDelegate] = webViewAndInputDelegateWithAutofocusedInput();
EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
[webView waitForCaretViewFrameToBecome:expectedCaretRect];
@@ -389,7 +389,7 @@
{
NSArray *expectedSelectionRects = @[ [NSValue valueWithCGRect:CGRectMake(16, 13, 24, 15)] ];
- auto webView = webViewWithAutofocusedInput();
+ auto [webView, inputDelegate] = webViewAndInputDelegateWithAutofocusedInput();
[[webView textInputContentView] insertText:@"hello"];
[webView selectAll:nil];
EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
@@ -408,7 +408,7 @@
{
// 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.
auto expectedCaretRect = CGRectMake(16, 13, UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad ? 3 : 2, 15);
- auto webView = webViewWithAutofocusedInput();
+ auto [webView, inputDelegate] = webViewAndInputDelegateWithAutofocusedInput();
EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
[webView waitForCaretViewFrameToBecome:expectedCaretRect];
@@ -423,7 +423,7 @@
{
NSArray *expectedSelectionRects = @[ [NSValue valueWithCGRect:CGRectMake(16, 13, 24, 15)] ];
- auto webView = webViewWithAutofocusedInput();
+ auto [webView, inputDelegate] = webViewAndInputDelegateWithAutofocusedInput();
[[webView textInputContentView] insertText:@"hello"];
[webView selectAll:nil];
EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);