OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 3484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3495 expected.max_length = WebInputElement::defaultMaxLength(); | 3495 expected.max_length = WebInputElement::defaultMaxLength(); |
3496 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3496 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
3497 | 3497 |
3498 expected.name = ASCIIToUTF16("country"); | 3498 expected.name = ASCIIToUTF16("country"); |
3499 expected.value = ASCIIToUTF16("AL"); | 3499 expected.value = ASCIIToUTF16("AL"); |
3500 expected.form_control_type = "select-one"; | 3500 expected.form_control_type = "select-one"; |
3501 expected.max_length = 0; | 3501 expected.max_length = 0; |
3502 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3502 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3503 } | 3503 } |
3504 | 3504 |
3505 // Autofill's "Clear Form" should clear only autofilled fields | |
3506 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { | |
3507 // Load the form. | |
3508 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | |
3509 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | |
3510 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>" | |
3511 " <INPUT type=\"email\" id=\"email\" value=\"wyatt@earp.com\"/>" | |
3512 " <INPUT type=\"tel\" id=\"phone\" value=\"650-777-9999\"/>" | |
3513 " <INPUT type=\"submit\" value=\"Send\"/>" | |
3514 "</FORM>"); | |
3515 | |
3516 WebFrame* web_frame = GetMainFrame(); | |
3517 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | |
3518 | |
3519 FormCache form_cache; | |
3520 std::vector<FormData> forms; | |
3521 form_cache.ExtractNewForms(*web_frame, &forms); | |
3522 ASSERT_EQ(1U, forms.size()); | |
3523 | |
3524 // Set the autofilled attribute. | |
3525 WebInputElement firstname = | |
3526 web_frame->document().getElementById("firstname").to<WebInputElement>(); | |
3527 firstname.setAutofilled(false); | |
3528 WebInputElement lastname = | |
3529 web_frame->document().getElementById("lastname").to<WebInputElement>(); | |
3530 lastname.setAutofilled(true); | |
3531 WebInputElement email = | |
3532 web_frame->document().getElementById("email").to<WebInputElement>(); | |
3533 email.setAutofilled(true); | |
3534 WebInputElement phone = | |
3535 web_frame->document().getElementById("phone").to<WebInputElement>(); | |
3536 phone.setAutofilled(true); | |
3537 | |
3538 // Clear the fields. | |
3539 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | |
3540 EXPECT_TRUE(form_cache.ClearFormWithElement(lastname)); | |
3541 EXPECT_TRUE(form_cache.ClearFormWithElement(email)); | |
3542 EXPECT_TRUE(form_cache.ClearFormWithElement(phone)); | |
Ilya Sherman
2014/06/13 20:55:29
Hmm, ClearFormWithElement clears the entire form,
Nikhil
2014/06/16 13:54:28
Done.
| |
3543 | |
3544 // Verify only autofilled fields are cleared. | |
3545 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); | |
3546 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | |
3547 EXPECT_FALSE(firstname.isAutofilled()); | |
3548 EXPECT_TRUE(lastname.value().isEmpty()); | |
3549 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); | |
3550 EXPECT_FALSE(lastname.isAutofilled()); | |
3551 EXPECT_TRUE(email.value().isEmpty()); | |
3552 EXPECT_TRUE(email.suggestedValue().isEmpty()); | |
3553 EXPECT_FALSE(email.isAutofilled()); | |
3554 EXPECT_TRUE(phone.value().isEmpty()); | |
3555 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | |
3556 EXPECT_FALSE(phone.isAutofilled()); | |
3557 } | |
Ilya Sherman
2014/06/13 20:55:29
Please move this so that it is adjacent to the oth
Nikhil
2014/06/16 13:54:28
Done.
| |
3505 } // namespace autofill | 3558 } // namespace autofill |
OLD | NEW |