Commit 8af98307 authored by Maria Kazinova's avatar Maria Kazinova Committed by Commit Bot

Added password credential suggestions filtering by username prefix.

Implementing the behaviour that already exists on other platforms:
when user starts typing the username into username field, it makes sense
to show only credentials with the same username prefix.
When user types something into password field, no suggestions should
be shown.

Bug: 831564
Change-Id: I9eeffd808e441ff598d26a1af88994150d8682a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2073761Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Maria Kazinova <kazinova@google.com>
Cr-Commit-Position: refs/heads/master@{#745120}
parent aa4f7b3f
...@@ -424,7 +424,17 @@ NSString* const kSuggestionSuffix = @" ••••••••"; ...@@ -424,7 +424,17 @@ NSString* const kSuggestionSuffix = @" ••••••••";
fieldType:fieldType]; fieldType:fieldType];
NSMutableArray<FormSuggestion*>* suggestions = [NSMutableArray array]; NSMutableArray<FormSuggestion*>* suggestions = [NSMutableArray array];
bool isPasswordField = [fieldType isEqual:@"password"];
for (FormSuggestion* rawSuggestion in rawSuggestions) { for (FormSuggestion* rawSuggestion in rawSuggestions) {
// 1) If this is a focus event or the field is empty show all suggestions.
// Otherwise:
// 2) If this is a username field then show only credentials with matching
// prefixes. 3) If this is a password field then show suggestions only if
// the field is empty.
if (![type isEqual:@"focus"] && typedValue.length > 0 &&
(isPasswordField || ![rawSuggestion.value hasPrefix:typedValue])) {
continue;
}
[suggestions [suggestions
addObject:[FormSuggestion addObject:[FormSuggestion
suggestionWithValue: suggestionWithValue:
......
...@@ -876,7 +876,9 @@ static NSString* kHtmlWithPasswordForm = ...@@ -876,7 +876,9 @@ static NSString* kHtmlWithPasswordForm =
"<input id='un' type='text' name=\"u'\"" "<input id='un' type='text' name=\"u'\""
" onkeyup='window.onKeyUpCalled_=true'" " onkeyup='window.onKeyUpCalled_=true'"
" onchange='window.onChangeCalled_=true'>" " onchange='window.onChangeCalled_=true'>"
"<input id='pw' type='password' name=\"p'\">" "<input id='pw' type='password' name=\"p'\""
" onkeyup='window.onKeyUpCalled_=true'"
" onchange='window.onChangeCalled_=true'>"
"</form>"; "</form>";
static NSString* kHtmlWithNewPasswordForm = static NSString* kHtmlWithNewPasswordForm =
...@@ -1007,6 +1009,29 @@ TEST_F(PasswordControllerTest, SuggestionUpdateTests) { ...@@ -1007,6 +1009,29 @@ TEST_F(PasswordControllerTest, SuggestionUpdateTests) {
@[@"user0 ••••••••", @"abc ••••••••"], @[@"user0 ••••••••", @"abc ••••••••"],
@"ab[]=, onkeyup=false, onchange=false" @"ab[]=, onkeyup=false, onchange=false"
}, },
{
"Should filter suggestions when typing into a username field",
@[(@"username_.value='ab';"
"username_.focus();"
// Keyup event is dispatched to simulate typing
"var ev = new KeyboardEvent('keyup', {bubbles:true});"
"username_.dispatchEvent(ev);"),
@""],
@[@"abc ••••••••"],
@"ab[]=, onkeyup=true, onchange=false"
},
{
"Should not show suggestions when typing into a password field",
@[(@"username_.value='abc';"
"password_.value='••';"
"password_.focus();"
// Keyup event is dispatched to simulate typing.
"var ev = new KeyboardEvent('keyup', {bubbles:true});"
"password_.dispatchEvent(ev);"),
@""],
@[],
@"abc[]=••, onkeyup=true, onchange=false"
},
}; };
// clang-format on // clang-format on
...@@ -1028,7 +1053,7 @@ TEST_F(PasswordControllerTest, SuggestionUpdateTests) { ...@@ -1028,7 +1053,7 @@ TEST_F(PasswordControllerTest, SuggestionUpdateTests) {
} }
// Wait until suggestions are received. // Wait until suggestions are received.
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{ EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return [GetSuggestionValues() count] > 0; return [GetSuggestionValues() count] == [data.expected_suggestions count];
})); }));
EXPECT_NSEQ(data.expected_suggestions, GetSuggestionValues()); EXPECT_NSEQ(data.expected_suggestions, GetSuggestionValues());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment