Skip to content

Commit

Permalink
TestWebKitAPI.SelectionTests.SelectedTextAfterSelectingWordForReplace…
Browse files Browse the repository at this point in the history
…ment times out on iPhone Simulator

https://bugs.webkit.org/show_bug.cgi?id=273736
rdar://127547635

Reviewed by Abrar Rahman Protyasha.

Augment the `SelectionChangeListener` helper class to be compatible with the case where WebKit uses
BrowserEngineKit's `BETextInput`. Instead of calling directly into `-selection(Will|Did)Change:`,
we now call into `-[BETextInputDelegate selection(Will|Did)ChangeForTextInput:]`.

* Tools/TestWebKitAPI/Tests/ios/SelectionByWord.mm:
(-[SelectionChangeListener selectionWillChangeForTextInput:]):
(-[SelectionChangeListener selectionDidChangeForTextInput:]):
(-[SelectionChangeListener shouldDeferEventHandlingToSystemForTextInput:context:]):
(-[SelectionChangeListener textInput:setCandidateSuggestions:]):
(-[SelectionChangeListener textInput:deferReplaceTextActionToSystem:]):
(-[SelectionChangeListener invalidateTextEntryContextForTextInput:]):
(TEST(SelectionTests, SelectedTextAfterSelectingWordForReplacement)):

Canonical link: https://commits.webkit.org/278428@main
  • Loading branch information
whsieh committed May 6, 2024
1 parent a03f439 commit c3c0e1a
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion Tools/TestWebKitAPI/Tests/ios/SelectionByWord.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@
EXPECT_WK_STREQ("foo bar", [webView selectedText]);
}

@interface SelectionChangeListener : NSObject <UITextInputDelegate>
@interface SelectionChangeListener : NSObject<
#if USE(BROWSERENGINEKIT)
BETextInputDelegate,
#endif
UITextInputDelegate>
@property (nonatomic) dispatch_block_t selectionWillChangeHandler;
@property (nonatomic) dispatch_block_t selectionDidChangeHandler;
@end
Expand Down Expand Up @@ -123,6 +127,43 @@ - (void)textDidChange:(id <UITextInput>)textInput
{
}

#if USE(BROWSERENGINEKIT)

#pragma mark - BETextInputDelegate

- (void)selectionWillChangeForTextInput:(id<BETextInput>)textInput
{
if (_selectionWillChangeHandler)
_selectionWillChangeHandler();
}

- (void)selectionDidChangeForTextInput:(id<BETextInput>)textInput
{
if (_selectionDidChangeHandler)
_selectionDidChangeHandler();
}

// Empty stubs for delegate protocol conformance.

- (BOOL)shouldDeferEventHandlingToSystemForTextInput:(id<BETextInput>)textInput context:(BEKeyEntryContext *)keyEventContext
{
return NO;
}

- (void)textInput:(id<BETextInput>)textInput setCandidateSuggestions:(NSArray<BETextSuggestion *> *)suggestions
{
}

- (void)textInput:(id<BETextInput>)textInput deferReplaceTextActionToSystem:(id)sender
{
}

- (void)invalidateTextEntryContextForTextInput:(id<BETextInput>)textInput
{
}

#endif // USE(BROWSERENGINEKIT)

@end

TEST(SelectionTests, SelectedTextAfterSelectingWordForReplacement)
Expand All @@ -134,6 +175,10 @@ - (void)textDidChange:(id <UITextInput>)textInput
auto contentView = [webView textInputContentView];
[contentView setInputDelegate:listener.get()];

#if USE(BROWSERENGINEKIT)
[webView asyncTextInput].asyncInputDelegate = listener.get();
#endif

__block bool selectionWillChange = false;
[listener setSelectionWillChangeHandler:^{
selectionWillChange = true;
Expand Down

0 comments on commit c3c0e1a

Please sign in to comment.