Skip to content

[iOS 17.4] ~11 layout tests debug assert in -handleKeyEntry:withCompletionHandler:#25836

Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
whsieh:eng/270928
Mar 14, 2024
Merged

[iOS 17.4] ~11 layout tests debug assert in -handleKeyEntry:withCompletionHandler:#25836
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
whsieh:eng/270928

Conversation

@whsieh
Copy link
Member

@whsieh whsieh commented Mar 13, 2024

a477452

[iOS 17.4] ~11 layout tests debug assert in `-handleKeyEntry:withCompletionHandler:`
https://bugs.webkit.org/show_bug.cgi?id=270928
rdar://123028621

Reviewed by Abrar Rahman Protyasha.

The new debug assertion in `-handleKeyEntry:withCompletionHandler:` (which sanity checks that the
key event completion handler for an incoming event `e` is invoked with `e`) is sometimes hit when
running layout tests that send synthetic key events. This reveals an existing bug, wherein
`WKContentView`'s `_keyWebEventHandler` is replaced with another incoming ObjC block in the case
when async key events are invoked back-to-back, before the preceding key event's completion handler
has been called. This causes the latter key event handler to be called with the previous key event,
and also means that the previous key event handler won't ever be called.

In practice, this is not an issue because UIKit's `UIKeyboardTaskQueue` doesn't attempt to send the
next key event until the previous one has finished processing (i.e., WebKit has called the
completion block associated with the event); this is likely an artifact of how HID key events are
synthesized and dispatched in WebKitTestRunner.

However, the `BETextInput` protocol doesn't inherently require or enforce this invariant, so it
probably makes more sense for `WKContentView` to be robust for this scenario and call all incoming
key event handler completion blocks with their corresponding appropriate events. To ensure this, we
replace the current `_keyWebEventHandler` instance variable with a vector of events and completion
blocks. This allows us to store multiple completion blocks if needed (for each key event that's
currently in-flight), and invoke the correct event handler in response.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:

Replace `_keyWebEventHandler` with `_keyWebEventHandlers`, a `Vector` of `WebEvent`s and completion
handler blocks. See above for more details.

(-[WKContentView cleanUpInteraction]):
(-[WKContentView _cancelPendingKeyEventHandlers:]):
(-[WKContentView resignFirstResponderForWebView]):
(-[WKContentView _internalHandleKeyWebEvent:withCompletionHandler:]):
(-[WKContentView _didHandleKeyEvent:eventWasHandled:]):
(-[WKContentView _cancelPendingKeyEventHandler]): Deleted.

Canonical link: https://commits.webkit.org/276062@main

7abc100

Misc iOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
🛠 ios-sim ✅ 🛠 mac-AS-debug 🧪 wpe-wk2
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
❌ 🧪 ios-wk2-wpt ✅ 🛠 wpe-skia
loading 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 tv 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
loading 🛠 tv-sim ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 watch
✅ 🛠 watch-sim

@whsieh whsieh requested a review from cdumez as a code owner March 13, 2024 21:02
@whsieh whsieh self-assigned this Mar 13, 2024
@whsieh whsieh added the Platform Portability improvements and other general platform improvements not driven directly by site bugs. label Mar 13, 2024
@whsieh
Copy link
Member Author

whsieh commented Mar 13, 2024

Thanks for the review!

TestWebKitAPI.KeyboardInputTests.ResigningFirstResponderCancelsKeyEvents

This API test failure is legit (and pretty subtle) — we should be defaulting to handled=YES when canceling key event handlers due to resigning first responder.

@whsieh whsieh added the merge-queue Applied to send a pull request to merge-queue label Mar 14, 2024
…letionHandler:`

https://bugs.webkit.org/show_bug.cgi?id=270928
rdar://123028621

Reviewed by Abrar Rahman Protyasha.

The new debug assertion in `-handleKeyEntry:withCompletionHandler:` (which sanity checks that the
key event completion handler for an incoming event `e` is invoked with `e`) is sometimes hit when
running layout tests that send synthetic key events. This reveals an existing bug, wherein
`WKContentView`'s `_keyWebEventHandler` is replaced with another incoming ObjC block in the case
when async key events are invoked back-to-back, before the preceding key event's completion handler
has been called. This causes the latter key event handler to be called with the previous key event,
and also means that the previous key event handler won't ever be called.

In practice, this is not an issue because UIKit's `UIKeyboardTaskQueue` doesn't attempt to send the
next key event until the previous one has finished processing (i.e., WebKit has called the
completion block associated with the event); this is likely an artifact of how HID key events are
synthesized and dispatched in WebKitTestRunner.

However, the `BETextInput` protocol doesn't inherently require or enforce this invariant, so it
probably makes more sense for `WKContentView` to be robust for this scenario and call all incoming
key event handler completion blocks with their corresponding appropriate events. To ensure this, we
replace the current `_keyWebEventHandler` instance variable with a vector of events and completion
blocks. This allows us to store multiple completion blocks if needed (for each key event that's
currently in-flight), and invoke the correct event handler in response.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:

Replace `_keyWebEventHandler` with `_keyWebEventHandlers`, a `Vector` of `WebEvent`s and completion
handler blocks. See above for more details.

(-[WKContentView cleanUpInteraction]):
(-[WKContentView _cancelPendingKeyEventHandlers:]):
(-[WKContentView resignFirstResponderForWebView]):
(-[WKContentView _internalHandleKeyWebEvent:withCompletionHandler:]):
(-[WKContentView _didHandleKeyEvent:eventWasHandled:]):
(-[WKContentView _cancelPendingKeyEventHandler]): Deleted.

Canonical link: https://commits.webkit.org/276062@main
@webkit-commit-queue
Copy link
Collaborator

Committed 276062@main (a477452): https://commits.webkit.org/276062@main

Reviewed commits have been landed. Closing PR #25836 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit a477452 into WebKit:main Mar 14, 2024
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Mar 14, 2024
@whsieh whsieh deleted the eng/270928 branch March 14, 2024 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Platform Portability improvements and other general platform improvements not driven directly by site bugs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants