Skip to content

Commit

Permalink
Add API test coverage for 283722@main
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=281935
rdar://138440875

Reviewed by Abrar Rahman Protyasha and Richard Robinson.

283722@main landed without any test coverage. Add an API test to help avoid
future regressions.

Verified that the test passes on main, and fails (times out) when reverting
283722@main and 283725@main (which also fixed the same issue in a different way).

* Tools/TestWebKitAPI/Tests/WebKitCocoa/WritingTools.mm:
(TEST(WritingTools, CompositionWithRestart)):

Web content crashes were encountered when performing two successive rewrites.

Add a test that makes Writing Tools API calls to match the system behavior when
performing two successive rewrites. Allow time for the animations to run to
completion.

Canonical link: https://commits.webkit.org/285590@main
  • Loading branch information
pxlcoder committed Oct 23, 2024
1 parent feb66d3 commit a10ee6a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/WritingTools.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,44 @@ static void checkColor(WebCore::CocoaColor *color, std::optional<ColorExpectatio
TestWebKitAPI::Util::run(&finished);
}

TEST(WritingTools, CompositionWithRestart)
{
RetainPtr session = adoptNS([[WTSession alloc] initWithType:WTSessionTypeComposition textViewDelegate:nil]);

RetainPtr webView = adoptNS([[WritingToolsWKWebView alloc] initWithHTMLString:@"<body id='p' contenteditable><p id='first'>Hey do you wanna go see a movie this weekend - start</p></body>"]);
[webView focusDocumentBodyAndSelectAll];

__block bool finished = false;

[[webView writingToolsDelegate] willBeginWritingToolsSession:session.get() requestContexts:^(NSArray<WTContext *> *contexts) {
EXPECT_EQ(1UL, contexts.count);

EXPECT_WK_STREQ(@"Hey do you wanna go see a movie this weekend - start", contexts.firstObject.attributedText.string);

__auto_type rewrite = ^(NSString *rewrittenText) {
[[webView writingToolsDelegate] writingToolsSession:session.get() didReceiveAction:WTActionCompositionRestart];

RetainPtr attributedText = adoptNS([[NSAttributedString alloc] initWithString:rewrittenText]);

[[webView writingToolsDelegate] compositionSession:session.get() didReceiveText:attributedText.get() replacementRange:NSMakeRange(0, 52) inContext:contexts.firstObject finished:NO];
[[webView writingToolsDelegate] compositionSession:session.get() didReceiveText:attributedText.get() replacementRange:NSMakeRange(0, 52) inContext:contexts.firstObject finished:YES];

[webView waitForContentValue:rewrittenText];
EXPECT_WK_STREQ(rewrittenText, [webView contentsAsStringWithoutNBSP]);
};

rewrite(@"Would you like to see a movie? - first");

TestWebKitAPI::Util::runFor(0.5_s);

rewrite(@"I'm going to a film, would you like to join? - second");

finished = true;
}];

TestWebKitAPI::Util::run(&finished);
}

TEST(WritingTools, CompositionWithMultipleUndosAndRestarts)
{
auto session = adoptNS([[WTSession alloc] initWithType:WTSessionTypeComposition textViewDelegate:nil]);
Expand Down

0 comments on commit a10ee6a

Please sign in to comment.