Skip to content

Commit

Permalink
Expose password text to DocumentContext
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=250491
rdar://101610334

Reviewed by Wenson Hsieh and Tim Horton.

* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestDocumentEditingContext):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
(TEST):

Canonical link: https://commits.webkit.org/258859@main
  • Loading branch information
megangardner committed Jan 13, 2023
1 parent 33d4b1c commit e1c274e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4585,7 +4585,7 @@ static VisiblePositionRange constrainRangeToSelection(const VisiblePositionRange
if (!range || range->collapsed())
return { };
// FIXME: This should return editing-offset-compatible attributed strings if that option is requested.
return { adoptNS([[NSAttributedString alloc] initWithString:WebCore::plainTextReplacingNoBreakSpace(*range)]), nil };
return { adoptNS([[NSAttributedString alloc] initWithString:WebCore::plainTextReplacingNoBreakSpace(*range, TextIteratorBehavior::EmitsOriginalText)]), nil };
};

DocumentEditingContext context;
Expand Down
13 changes: 13 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,19 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue)
}
}

TEST(DocumentEditingContext, PasswordFieldRequest)
{
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);

[webView synchronouslyLoadHTMLString:applyAhemStyle(@"<input id='passwordField' type='password' value='testPassword'>")];
[webView stringByEvaluatingJavaScript:@"passwordField.focus(); passwordField.select();"];

UIWKDocumentContext *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityWord, 1)];
EXPECT_NOT_NULL(context);
EXPECT_NULL(context.contextBefore);
EXPECT_NSSTRING_EQ("testPassword", context.selectedText);
EXPECT_NULL(context.contextAfter);
}

TEST(DocumentEditingContext, SpatialRequest_RectEncompassingInput)
{
Expand Down

0 comments on commit e1c274e

Please sign in to comment.