summaryrefslogtreecommitdiffstats
path: root/webkit/glue
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-09 01:41:27 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-09 01:41:27 +0000
commit1081e0c20e74dd08836274d409f92e7ff52e0299 (patch)
treebd94fa0dd2d9550b6e917990e800e7ca3c5613c7 /webkit/glue
parentf10d9e175f026c82990a7c9ce4a11cb079bae770 (diff)
downloadchromium_src-1081e0c20e74dd08836274d409f92e7ff52e0299.zip
chromium_src-1081e0c20e74dd08836274d409f92e7ff52e0299.tar.gz
chromium_src-1081e0c20e74dd08836274d409f92e7ff52e0299.tar.bz2
Password Autocomplete needs to check maximum field length when filling.
Changes input element |setValue()| call sites to respect the input element's maxlength attribute. BUG=56378, 45831 TEST=Manual test as per bug 45831, and PasswordManagerAutocompleteTests.TestValidValueConditions Review URL: http://codereview.chromium.org/3615008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62059 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r--webkit/glue/dom_operations.cc3
-rw-r--r--webkit/glue/webpasswordautocompletelistener_impl.cc30
-rw-r--r--webkit/glue/webpasswordautocompletelistener_impl.h1
-rw-r--r--webkit/glue/webpasswordautocompletelistener_unittest.cc51
4 files changed, 77 insertions, 8 deletions
diff --git a/webkit/glue/dom_operations.cc b/webkit/glue/dom_operations.cc
index 22e0e75..b459473 100644
--- a/webkit/glue/dom_operations.cc
+++ b/webkit/glue/dom_operations.cc
@@ -190,6 +190,9 @@ static bool FillFormImpl(FormElements* fe, const FormData& data) {
(!element.isEnabledFormControl() || element.hasAttribute("readonly"))) {
continue; // Don't fill uneditable password fields.
}
+ if (!element.isValidValue(data_map[it->first]))
+ continue;
+
element.setValue(data_map[it->first]);
element.setAutofilled(true);
element.dispatchFormControlChangeEvent();
diff --git a/webkit/glue/webpasswordautocompletelistener_impl.cc b/webkit/glue/webpasswordautocompletelistener_impl.cc
index 0c894fc..280ce43 100644
--- a/webkit/glue/webpasswordautocompletelistener_impl.cc
+++ b/webkit/glue/webpasswordautocompletelistener_impl.cc
@@ -33,6 +33,10 @@ bool WebInputElementDelegate::IsEditable() const {
return element_.isEnabledFormControl() && !element_.hasAttribute("readonly");
}
+bool WebInputElementDelegate::IsValidValue(const string16& value) {
+ return element_.isValidValue(value);
+}
+
void WebInputElementDelegate::SetValue(const string16& value) {
element_.setValue(value);
}
@@ -107,14 +111,19 @@ void WebPasswordAutocompleteListenerImpl::didBlurInputElement(
// If enabled, set the password field to match the current username.
if (data_.basic_data.fields[0].value() == user_input16) {
- // Preferred username/login is selected.
- password_delegate_->SetValue(data_.basic_data.fields[1].value());
- password_delegate_->SetAutofilled(true);
+ if (password_delegate_->IsValidValue(data_.basic_data.fields[1].value())) {
+ // Preferred username/login is selected.
+ password_delegate_->SetValue(data_.basic_data.fields[1].value());
+ password_delegate_->SetAutofilled(true);
+ }
} else if (data_.additional_logins.find(user_input16) !=
data_.additional_logins.end()) {
- // One of the extra username/logins is selected.
- password_delegate_->SetValue(data_.additional_logins[user_input16]);
- password_delegate_->SetAutofilled(true);
+ if (password_delegate_->IsValidValue(
+ data_.additional_logins[user_input16])) {
+ // One of the extra username/logins is selected.
+ password_delegate_->SetValue(data_.additional_logins[user_input16]);
+ password_delegate_->SetAutofilled(true);
+ }
}
}
@@ -183,13 +192,18 @@ bool WebPasswordAutocompleteListenerImpl::TryToMatch(const string16& input,
if (!StartsWith(username, input, false))
return false;
+ if (!username_delegate_->IsValidValue(username))
+ return false;
+
// Input matches the username, fill in required values.
username_delegate_->SetValue(username);
username_delegate_->SetSelectionRange(input.length(), username.length());
username_delegate_->SetAutofilled(true);
- if (password_delegate_->IsEditable())
+ if (password_delegate_->IsEditable() &&
+ password_delegate_->IsValidValue(password)) {
password_delegate_->SetValue(password);
- password_delegate_->SetAutofilled(true);
+ password_delegate_->SetAutofilled(true);
+ }
return true;
}
diff --git a/webkit/glue/webpasswordautocompletelistener_impl.h b/webkit/glue/webpasswordautocompletelistener_impl.h
index 4a3ed11..6badcb7 100644
--- a/webkit/glue/webpasswordautocompletelistener_impl.h
+++ b/webkit/glue/webpasswordautocompletelistener_impl.h
@@ -29,6 +29,7 @@ class WebInputElementDelegate {
// These are virtual to support unit testing.
virtual bool IsEditable() const;
+ virtual bool IsValidValue(const string16& value);
virtual void SetValue(const string16& value);
virtual bool IsAutofilled() const;
virtual void SetAutofilled(bool autofilled);
diff --git a/webkit/glue/webpasswordautocompletelistener_unittest.cc b/webkit/glue/webpasswordautocompletelistener_unittest.cc
index 0ce2916..5de593c 100644
--- a/webkit/glue/webpasswordautocompletelistener_unittest.cc
+++ b/webkit/glue/webpasswordautocompletelistener_unittest.cc
@@ -28,6 +28,7 @@ class TestWebInputElementDelegate : public WebInputElementDelegate {
selection_start_(0),
selection_end_(0),
is_editable_(true),
+ is_valid_(true),
is_autofilled_(false) {
}
@@ -36,6 +37,10 @@ class TestWebInputElementDelegate : public WebInputElementDelegate {
return is_editable_;
}
+ virtual bool IsValidValue(const string16& value) {
+ return is_valid_;
+ }
+
virtual void SetValue(const string16& value) {
value_ = value;
}
@@ -56,6 +61,10 @@ class TestWebInputElementDelegate : public WebInputElementDelegate {
is_editable_ = editable;
}
+ void set_is_valid(bool valid) {
+ is_valid_ = valid;
+ }
+
string16 value() const {
return value_;
}
@@ -73,6 +82,7 @@ class TestWebInputElementDelegate : public WebInputElementDelegate {
size_t selection_start_;
size_t selection_end_;
bool is_editable_;
+ bool is_valid_;
bool is_autofilled_;
};
@@ -289,4 +299,45 @@ TEST_F(PasswordManagerAutocompleteTests, TestPasswordClearOnEdit) {
EXPECT_TRUE(password_delegate_->value().empty());
}
+// Tests that filling with invalid value for input element does not fill.
+TEST_F(PasswordManagerAutocompleteTests, TestValidValueConditions) {
+ WebKit::WebPasswordAutocompleteListener* listener = CreateListener(false);
+
+ // User enters a known login that validates ok.
+ username_delegate_->set_is_valid(true);
+ password_delegate_->set_is_valid(true);
+ username_delegate_->SetValue(string16());
+ password_delegate_->SetValue(string16());
+ listener->performInlineAutocomplete(ASCIIToUTF16("alice"), false, false);
+ // We are autofilled.
+ EXPECT_EQ(username1_, username_delegate_->value());
+ EXPECT_TRUE(username_delegate_->IsAutofilled());
+ EXPECT_EQ(password1_, password_delegate_->value());
+ EXPECT_TRUE(password_delegate_->IsAutofilled());
+
+ // User enters a known login that does not validate.
+ username_delegate_->set_is_valid(false);
+ password_delegate_->set_is_valid(true);
+ username_delegate_->SetValue(string16());
+ password_delegate_->SetValue(string16());
+ listener->performInlineAutocomplete(ASCIIToUTF16("alice"), false, false);
+ // We are not autofilled.
+ EXPECT_EQ(string16(), username_delegate_->value());
+ EXPECT_FALSE(username_delegate_->IsAutofilled());
+ EXPECT_EQ(string16(), password_delegate_->value());
+ EXPECT_FALSE(password_delegate_->IsAutofilled());
+
+ // User enters a known login that validates ok, but password does not.
+ username_delegate_->set_is_valid(true);
+ password_delegate_->set_is_valid(false);
+ username_delegate_->SetValue(string16());
+ password_delegate_->SetValue(string16());
+ listener->performInlineAutocomplete(ASCIIToUTF16("alice"), false, false);
+ // We are autofilled.
+ EXPECT_EQ(username1_, username_delegate_->value());
+ EXPECT_TRUE(username_delegate_->IsAutofilled());
+ EXPECT_EQ(string16(), password_delegate_->value());
+ EXPECT_FALSE(password_delegate_->IsAutofilled());
+}
+
} // namespace