Commit 68035f6b authored by Maria Kazinova's avatar Maria Kazinova Committed by Commit Bot

[iOS] PasswordManager: FieldDataManager improvements.

Previously the FieldDataManager data was not cleaned in time, and it
was causing problems especially on interaction with pages retrieved
from cash.

Bug: 1109189
Change-Id: I8ec9707157d1fb90c38fd4cf931c6faff8d28513
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2322828Reviewed-by: default avatarVadym Doroshenko  <dvadym@chromium.org>
Commit-Queue: Maria Kazinova <kazinova@google.com>
Cr-Commit-Position: refs/heads/master@{#792363}
parent e480f825
...@@ -13,6 +13,7 @@ FieldDataManager::FieldDataManager() = default; ...@@ -13,6 +13,7 @@ FieldDataManager::FieldDataManager() = default;
void FieldDataManager::ClearData() { void FieldDataManager::ClearData() {
field_value_and_properties_map_.clear(); field_value_and_properties_map_.clear();
autofilled_values_map_.clear();
} }
bool FieldDataManager::HasFieldData(FieldRendererId id) const { bool FieldDataManager::HasFieldData(FieldRendererId id) const {
...@@ -94,6 +95,9 @@ void FieldDataManager::UpdateFieldDataWithAutofilledValue( ...@@ -94,6 +95,9 @@ void FieldDataManager::UpdateFieldDataWithAutofilledValue(
FieldRendererId id, FieldRendererId id,
const base::string16& value, const base::string16& value,
FieldPropertiesMask mask) { FieldPropertiesMask mask) {
// Typed value has no interest once it is rewritten with an autofilled value.
if (HasFieldData(id))
field_value_and_properties_map_.at(id).first.reset();
UpdateFieldDataMapWithNullValue(id, mask); UpdateFieldDataMapWithNullValue(id, mask);
autofilled_values_map_[id] = value; autofilled_values_map_[id] = value;
} }
......
...@@ -109,6 +109,9 @@ TEST_F(FieldDataManagerTest, UpdateFieldDataMapWithAutofilledValue) { ...@@ -109,6 +109,9 @@ TEST_F(FieldDataManagerTest, UpdateFieldDataMapWithAutofilledValue) {
const scoped_refptr<FieldDataManager> field_data_manager = const scoped_refptr<FieldDataManager> field_data_manager =
base::MakeRefCounted<FieldDataManager>(); base::MakeRefCounted<FieldDataManager>();
const FieldRendererId id(control_elements_[0].unique_renderer_id); const FieldRendererId id(control_elements_[0].unique_renderer_id);
// Add a typed value to make sure it will be cleared.
field_data_manager->UpdateFieldDataMap(id, ASCIIToUTF16("typedvalue"), 0);
field_data_manager->UpdateFieldDataWithAutofilledValue( field_data_manager->UpdateFieldDataWithAutofilledValue(
id, ASCIIToUTF16("autofilled"), id, ASCIIToUTF16("autofilled"),
FieldPropertiesFlags::kAutofilledOnPageLoad); FieldPropertiesFlags::kAutofilledOnPageLoad);
......
...@@ -152,6 +152,12 @@ constexpr char kCommandPrefix[] = "passwordForm"; ...@@ -152,6 +152,12 @@ constexpr char kCommandPrefix[] = "passwordForm";
_formActivityObserverBridge.reset(); _formActivityObserverBridge.reset();
} }
- (void)webState:(web::WebState*)webState
didFinishNavigation:(web::NavigationContext*)navigation {
// Delete collected field data.
_fieldDataManager->ClearData();
}
#pragma mark - FormActivityObserver #pragma mark - FormActivityObserver
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "components/autofill/core/common/password_form_fill_data.h" #include "components/autofill/core/common/password_form_fill_data.h"
#include "components/password_manager/ios/account_select_fill_data.h" #include "components/password_manager/ios/account_select_fill_data.h"
#include "components/password_manager/ios/test_helpers.h" #include "components/password_manager/ios/test_helpers.h"
#import "ios/web/public/test/fakes/fake_navigation_context.h"
#include "ios/web/public/test/fakes/test_web_client.h" #include "ios/web/public/test/fakes/test_web_client.h"
#import "ios/web/public/test/web_test_with_web_state.h" #import "ios/web/public/test/web_test_with_web_state.h"
#import "ios/web/public/web_state.h" #import "ios/web/public/web_state.h"
...@@ -344,12 +345,21 @@ TEST_F(PasswordFormHelperTest, RefillFormFilledOnUserTrigger) { ...@@ -344,12 +345,21 @@ TEST_F(PasswordFormHelperTest, RefillFormFilledOnUserTrigger) {
})); }));
// Try to autofill the form. // Try to autofill the form.
FormData form_data; PasswordFormFillData form_data;
SetFormData(base_url, 0, 1, "someacc@store.com", 2, "store!pw", &form_data); SetPasswordFormFillData(BaseUrl(), "", 0, "", 1, "someacc@store.com", "", 2,
"store!pw", "", "", NO, &form_data);
// Verify that the form has not been refilled. __block bool called = NO;
id result = ExecuteJavaScript(kInputFieldValueVerificationScript); __block bool success = NO;
EXPECT_NSEQ(@"u1=john.doe@gmail.com;p1=super!secret;", result); [helper_ fillPasswordForm:form_data
completionHandler:^(BOOL res) {
called = YES;
success = res;
}];
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return called;
}));
EXPECT_EQ(success, NO);
} }
// Tests that a form with credentials typed by user // Tests that a form with credentials typed by user
...@@ -371,12 +381,34 @@ TEST_F(PasswordFormHelperTest, RefillFormWithUserTypedInput) { ...@@ -371,12 +381,34 @@ TEST_F(PasswordFormHelperTest, RefillFormWithUserTypedInput) {
inputValue:@"super!secret"]; inputValue:@"super!secret"];
// Try to autofill the form. // Try to autofill the form.
FormData form_data; PasswordFormFillData form_data;
SetFormData(BaseUrl(), 0, 1, "someacc@store.com", 2, "store!pw", &form_data); SetPasswordFormFillData(BaseUrl(), "", 0, "", 1, "someacc@store.com", "", 2,
"store!pw", "", "", NO, &form_data);
// Verify that the form has not been refilled. __block bool called = NO;
id result = ExecuteJavaScript(kInputFieldValueVerificationScript); __block bool success = NO;
EXPECT_NSEQ(@"u1=john.doe@gmail.com;p1=super!secret;", result); [helper_ fillPasswordForm:form_data
completionHandler:^(BOOL res) {
called = YES;
success = res;
}];
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return called;
}));
EXPECT_EQ(success, NO);
// Make sure that this form can be filled again after a navigation.
web::FakeNavigationContext context;
[helper_ webState:web_state() didFinishNavigation:&context];
success = NO;
[helper_ fillPasswordForm:form_data
completionHandler:^(BOOL res) {
success = res;
}];
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return success;
}));
} }
} // namespace } // namespace
......
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