[Swift Testing] Make it easy to allow a WebPage to get and set selection, and to evaluate JS in general#63656
Merged
Conversation
Collaborator
|
EWS run on previous version of this PR (hash 7b3eedf) Details
|
7b3eedf to
7b15755
Compare
Collaborator
|
EWS run on previous version of this PR (hash 7b15755) Details |
djg
reviewed
Apr 27, 2026
| public func callJavaScript<Expression>( | ||
| _ expression: Expression | ||
| ) async throws where Expression: JavaScriptExpression, Expression.Output == Void { | ||
| let arguments = expression.encoded() as [String: Any] |
Contributor
There was a problem hiding this comment.
What happens when expression.encoded() returns ["foo": nil]?
Contributor
There was a problem hiding this comment.
@rr-codes pointed out on slack that:
2> let z: [String: Any?] = ["hi": nil]
z: [String : Any?] = 1 key/value pair {
[0] = {
key = "hi"
value = nil
}
}
3> let q: [String: Any] = z
q: [String : Any] = 1 key/value pair {
[0] = {
key = "hi"
value = nil
}
}
| } | ||
| } | ||
|
|
||
| extension JavaScriptSelection.Position: WebPage.JavaScriptDecodable { |
Contributor
There was a problem hiding this comment.
Why is this a separate extension to the one above?
Contributor
Author
There was a problem hiding this comment.
it's usually conventional to make each protocol conformance a separate extension since each extension is "about" a different thing
7b15755 to
d50ce15
Compare
Collaborator
|
EWS run on current version of this PR (hash d50ce15) Details |
…ion, and to evaluate JS in general https://bugs.webkit.org/show_bug.cgi?id=313383 rdar://175649972 Reviewed by Dan Glastonbury. Implement a generalized way to create semi-type-safe, re-usable JS expressions to be evaluated by a WebPage in TestWebKitAPI. Use this new mechanism and implement some basic expressions to get and set selections. * Tools/TestWebKitAPI/Helpers/cocoa/JavaScriptMessages.swift: Added. (SelectionBoundingClientRect.expression): (SelectionBoundingClientRect.encoded): (SetSelection.expression): (SetSelection.encoded): (GetSelection.expression): (GetSelection.encoded): * Tools/TestWebKitAPI/Helpers/cocoa/JavaScriptTypes.swift: Added. (JavaScriptSelection.encoded): * Tools/TestWebKitAPI/Helpers/cocoa/WebPage+JavaScriptExpression.swift: Added. (JavaScriptEncodable.encoded): (JavaScriptExpression.expression): * Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * Tools/TestWebKitAPI/Tests/WebKit/WebPage/AppKitGesturesTests.swift: (AppKitGesturesTests.clickingChangesSelection): * Tools/TestWebKitAPI/Tests/WebKit/WebPage/JavaScriptExpressionTests.swift: Added. (JavaScriptExpressionTests.setAndGetSelectionWithCollapsedPositionRoundTrip): (JavaScriptExpressionTests.setSelectionAppliesRangeSelection): (JavaScriptExpressionTests.getSelectionReturnsCollapsedAfterCollapsedIsSet): (JavaScriptExpressionTests.getSelectionReturnsRangeAfterRangeIsSet): (JavaScriptExpressionTests.setAndGetSelectionRangeRoundTrip): (JavaScriptExpressionTests.selectionBoundingClientRectReturnsNonEmptyRectForRangeSelection): (JavaScriptExpressionTests.selectionBoundingClientRectReturnsZeroWidthRectForCollapsedSelection): Canonical link: https://commits.webkit.org/312070@main
d50ce15 to
5c4b430
Compare
Collaborator
|
Committed 312070@main (5c4b430): https://commits.webkit.org/312070@main Reviewed commits have been landed. Closing PR #63656 and removing active labels. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠 ios-apple
5c4b430
d50ce15
🧪 win-tests🧪 ios-wk2-wpt🧪 api-mac-debug🧪 mac-AS-debug-wk2