diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-24 01:14:06 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-24 01:14:06 +0000 |
commit | d77ddc80612ad43982c6f7da0de0c9e299f049c4 (patch) | |
tree | 5f87cdb5038bf919a6285274cfba6b33f489ef4c /chrome/renderer/form_manager_browsertest.cc | |
parent | 8c619149607580303c4050ee908f22c08fcb697c (diff) | |
download | chromium_src-d77ddc80612ad43982c6f7da0de0c9e299f049c4.zip chromium_src-d77ddc80612ad43982c6f7da0de0c9e299f049c4.tar.gz chromium_src-d77ddc80612ad43982c6f7da0de0c9e299f049c4.tar.bz2 |
Always include nonzero unique ID with autofill suggestions.
In particular, include the ID when correcting a form field.
BUG=62416
TEST=unit_tests --gtest_filter=AutoFillManagerTest.*
Review URL: http://codereview.chromium.org/5265002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67192 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/form_manager_browsertest.cc')
-rw-r--r-- | chrome/renderer/form_manager_browsertest.cc | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/chrome/renderer/form_manager_browsertest.cc b/chrome/renderer/form_manager_browsertest.cc index ffcfc53..c1d421c 100644 --- a/chrome/renderer/form_manager_browsertest.cc +++ b/chrome/renderer/form_manager_browsertest.cc @@ -2710,7 +2710,7 @@ TEST_F(FormManagerTest, ClearPreviewedFormWithNode) { email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); // Clear the previewed fields. - EXPECT_TRUE(form_manager.ClearPreviewedFormWithNode(lastname)); + EXPECT_TRUE(form_manager.ClearPreviewedFormWithNode(lastname, false)); // Fields with empty suggestions suggestions are not modified. EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); @@ -2766,7 +2766,7 @@ TEST_F(FormManagerTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); // Clear the previewed fields. - EXPECT_TRUE(form_manager.ClearPreviewedFormWithNode(firstname)); + EXPECT_TRUE(form_manager.ClearPreviewedFormWithNode(firstname, false)); // Fields with non-empty values are restored. EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); @@ -2784,6 +2784,60 @@ TEST_F(FormManagerTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { EXPECT_FALSE(email.isAutofilled()); } +TEST_F(FormManagerTest, ClearPreviewedFormWithAutofilledInitiatingNode) { + LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" + " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>" + " <INPUT type=\"text\" id=\"lastname\"/>" + " <INPUT type=\"text\" id=\"email\"/>" + " <INPUT type=\"submit\" value=\"Send\"/>" + "</FORM>"); + + WebFrame* web_frame = GetMainFrame(); + ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); + + FormManager form_manager; + form_manager.ExtractForms(web_frame); + + // Verify that we have the form. + std::vector<FormData> forms; + form_manager.GetFormsInFrame(web_frame, FormManager::REQUIRE_NONE, &forms); + ASSERT_EQ(1U, forms.size()); + + // Set the auto-filled attribute. + WebInputElement firstname = + web_frame->document().getElementById("firstname").to<WebInputElement>(); + firstname.setAutofilled(true); + WebInputElement lastname = + web_frame->document().getElementById("lastname").to<WebInputElement>(); + lastname.setAutofilled(true); + WebInputElement email = + web_frame->document().getElementById("email").to<WebInputElement>(); + email.setAutofilled(true); + + // Set the suggested values on all of the elements. + firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); + lastname.setSuggestedValue(ASCIIToUTF16("Earp")); + email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); + + // Clear the previewed fields. + EXPECT_TRUE(form_manager.ClearPreviewedFormWithNode(firstname, true)); + + // Fields with non-empty values are restored. + EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); + EXPECT_TRUE(firstname.suggestedValue().isEmpty()); + EXPECT_TRUE(firstname.isAutofilled()); + EXPECT_EQ(1, firstname.selectionStart()); + EXPECT_EQ(1, firstname.selectionEnd()); + + // Verify the previewed fields are cleared. + EXPECT_TRUE(lastname.value().isEmpty()); + EXPECT_TRUE(lastname.suggestedValue().isEmpty()); + EXPECT_FALSE(lastname.isAutofilled()); + EXPECT_TRUE(email.value().isEmpty()); + EXPECT_TRUE(email.suggestedValue().isEmpty()); + EXPECT_FALSE(email.isAutofilled()); +} + TEST_F(FormManagerTest, FormWithNodeIsAutoFilled) { LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |