Chromium Code Reviews| 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 2942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2953 "</FORM>"); | 2953 "</FORM>"); |
| 2954 | 2954 |
| 2955 WebFrame* web_frame = GetMainFrame(); | 2955 WebFrame* web_frame = GetMainFrame(); |
| 2956 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 2956 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 2957 | 2957 |
| 2958 FormCache form_cache; | 2958 FormCache form_cache; |
| 2959 std::vector<FormData> forms; | 2959 std::vector<FormData> forms; |
| 2960 form_cache.ExtractNewForms(*web_frame, &forms); | 2960 form_cache.ExtractNewForms(*web_frame, &forms); |
| 2961 ASSERT_EQ(1U, forms.size()); | 2961 ASSERT_EQ(1U, forms.size()); |
| 2962 | 2962 |
| 2963 // Set the auto-filled attribute on the firstname element. | 2963 // Set the auto-filled attribute. |
| 2964 WebInputElement firstname = | 2964 WebInputElement firstname = |
| 2965 web_frame->document().getElementById("firstname").to<WebInputElement>(); | 2965 web_frame->document().getElementById("firstname").to<WebInputElement>(); |
| 2966 firstname.setAutofilled(true); | 2966 firstname.setAutofilled(true); |
| 2967 | 2967 |
|
Ilya Sherman
2014/06/16 21:19:37
nit: I'd avoid these blank lines for the various e
Nikhil
2014/06/17 08:59:43
Done.
| |
| 2968 WebInputElement lastname = | |
| 2969 web_frame->document().getElementById("lastname").to<WebInputElement>(); | |
| 2970 lastname.setAutofilled(true); | |
| 2971 | |
| 2972 WebInputElement no_autocomplete = | |
| 2973 web_frame->document().getElementById("noAC").to<WebInputElement>(); | |
| 2974 no_autocomplete.setAutofilled(true); | |
|
Ilya Sherman
2014/06/16 21:19:37
It doesn't really make sense to set autofilled to
Nikhil
2014/06/17 08:59:43
Right! I've updated the behavior. Since these fiel
| |
| 2975 | |
| 2976 WebInputElement month = | |
| 2977 web_frame->document().getElementById("month").to<WebInputElement>(); | |
| 2978 month.setAutofilled(true); | |
| 2979 | |
| 2980 WebInputElement textarea = | |
| 2981 web_frame->document().getElementById("textarea").to<WebInputElement>(); | |
| 2982 textarea.setAutofilled(true); | |
| 2983 | |
| 2984 WebInputElement textarea_no_autocomplete = | |
| 2985 web_frame->document() | |
| 2986 .getElementById("textarea-noAC") | |
| 2987 .to<WebInputElement>(); | |
| 2988 textarea_no_autocomplete.setAutofilled(true); | |
| 2989 | |
| 2968 // Set the value of the disabled text input element. | 2990 // Set the value of the disabled text input element. |
| 2969 WebInputElement notenabled = | 2991 WebInputElement notenabled = |
| 2970 web_frame->document().getElementById("notenabled").to<WebInputElement>(); | 2992 web_frame->document().getElementById("notenabled").to<WebInputElement>(); |
| 2971 notenabled.setValue(WebString::fromUTF8("no clear")); | 2993 notenabled.setValue(WebString::fromUTF8("no clear")); |
| 2972 | 2994 |
| 2973 // Clear the form. | 2995 // Clear the form. |
| 2974 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 2996 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| 2975 | 2997 |
| 2976 // Verify that the auto-filled attribute has been turned off. | 2998 // Verify that the auto-filled attribute has been turned off. |
| 2977 EXPECT_FALSE(firstname.isAutofilled()); | 2999 EXPECT_FALSE(firstname.isAutofilled()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3057 "</FORM>"); | 3079 "</FORM>"); |
| 3058 | 3080 |
| 3059 WebFrame* web_frame = GetMainFrame(); | 3081 WebFrame* web_frame = GetMainFrame(); |
| 3060 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 3082 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 3061 | 3083 |
| 3062 FormCache form_cache; | 3084 FormCache form_cache; |
| 3063 std::vector<FormData> forms; | 3085 std::vector<FormData> forms; |
| 3064 form_cache.ExtractNewForms(*web_frame, &forms); | 3086 form_cache.ExtractNewForms(*web_frame, &forms); |
| 3065 ASSERT_EQ(1U, forms.size()); | 3087 ASSERT_EQ(1U, forms.size()); |
| 3066 | 3088 |
| 3067 // Set the auto-filled attribute on the firstname element. | 3089 // Set the auto-filled attribute. |
| 3068 WebInputElement firstname = | 3090 WebInputElement firstname = |
| 3069 web_frame->document().getElementById("firstname").to<WebInputElement>(); | 3091 web_frame->document().getElementById("firstname").to<WebInputElement>(); |
| 3070 firstname.setAutofilled(true); | 3092 firstname.setAutofilled(true); |
| 3071 | 3093 |
| 3094 WebInputElement lastname = | |
| 3095 web_frame->document().getElementById("lastname").to<WebInputElement>(); | |
| 3096 lastname.setAutofilled(true); | |
| 3097 | |
| 3098 WebInputElement state = | |
| 3099 web_frame->document().getElementById("state").to<WebInputElement>(); | |
| 3100 state.setAutofilled(true); | |
| 3101 | |
| 3072 // Set the value of the select-one. | 3102 // Set the value of the select-one. |
| 3073 WebSelectElement select_element = | 3103 WebSelectElement select_element = |
| 3074 web_frame->document().getElementById("state").to<WebSelectElement>(); | 3104 web_frame->document().getElementById("state").to<WebSelectElement>(); |
| 3075 select_element.setValue(WebString::fromUTF8("AK")); | 3105 select_element.setValue(WebString::fromUTF8("AK")); |
| 3076 | 3106 |
| 3077 // Clear the form. | 3107 // Clear the form. |
| 3078 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 3108 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| 3079 | 3109 |
| 3080 // Verify that the auto-filled attribute has been turned off. | 3110 // Verify that the auto-filled attribute has been turned off. |
| 3081 EXPECT_FALSE(firstname.isAutofilled()); | 3111 EXPECT_FALSE(firstname.isAutofilled()); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3315 EXPECT_TRUE(email.suggestedValue().isEmpty()); | 3345 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| 3316 EXPECT_FALSE(email.isAutofilled()); | 3346 EXPECT_FALSE(email.isAutofilled()); |
| 3317 EXPECT_TRUE(email2.value().isEmpty()); | 3347 EXPECT_TRUE(email2.value().isEmpty()); |
| 3318 EXPECT_TRUE(email2.suggestedValue().isEmpty()); | 3348 EXPECT_TRUE(email2.suggestedValue().isEmpty()); |
| 3319 EXPECT_FALSE(email2.isAutofilled()); | 3349 EXPECT_FALSE(email2.isAutofilled()); |
| 3320 EXPECT_TRUE(phone.value().isEmpty()); | 3350 EXPECT_TRUE(phone.value().isEmpty()); |
| 3321 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | 3351 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 3322 EXPECT_FALSE(phone.isAutofilled()); | 3352 EXPECT_FALSE(phone.isAutofilled()); |
| 3323 } | 3353 } |
| 3324 | 3354 |
| 3355 // Autofill's "Clear Form" should clear only autofilled fields | |
| 3356 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { | |
| 3357 // Load the form. | |
| 3358 LoadHTML( | |
| 3359 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | |
| 3360 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | |
| 3361 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>" | |
| 3362 " <INPUT type=\"email\" id=\"email\" value=\"wyatt@earp.com\"/>" | |
| 3363 " <INPUT type=\"tel\" id=\"phone\" value=\"650-777-9999\"/>" | |
| 3364 " <INPUT type=\"submit\" value=\"Send\"/>" | |
| 3365 "</FORM>"); | |
| 3366 | |
| 3367 WebFrame* web_frame = GetMainFrame(); | |
| 3368 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | |
| 3369 | |
| 3370 FormCache form_cache; | |
| 3371 std::vector<FormData> forms; | |
| 3372 form_cache.ExtractNewForms(*web_frame, &forms); | |
| 3373 ASSERT_EQ(1U, forms.size()); | |
| 3374 | |
| 3375 // Set the autofilled attribute. | |
| 3376 WebInputElement firstname = | |
| 3377 web_frame->document().getElementById("firstname").to<WebInputElement>(); | |
| 3378 firstname.setAutofilled(false); | |
| 3379 WebInputElement lastname = | |
| 3380 web_frame->document().getElementById("lastname").to<WebInputElement>(); | |
| 3381 lastname.setAutofilled(true); | |
| 3382 WebInputElement email = | |
| 3383 web_frame->document().getElementById("email").to<WebInputElement>(); | |
| 3384 email.setAutofilled(true); | |
| 3385 WebInputElement phone = | |
| 3386 web_frame->document().getElementById("phone").to<WebInputElement>(); | |
| 3387 phone.setAutofilled(true); | |
| 3388 | |
| 3389 // Clear the fields. | |
| 3390 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | |
| 3391 | |
| 3392 // Verify only autofilled fields are cleared. | |
| 3393 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); | |
| 3394 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | |
| 3395 EXPECT_FALSE(firstname.isAutofilled()); | |
| 3396 EXPECT_TRUE(lastname.value().isEmpty()); | |
| 3397 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); | |
| 3398 EXPECT_FALSE(lastname.isAutofilled()); | |
| 3399 EXPECT_TRUE(email.value().isEmpty()); | |
| 3400 EXPECT_TRUE(email.suggestedValue().isEmpty()); | |
| 3401 EXPECT_FALSE(email.isAutofilled()); | |
| 3402 EXPECT_TRUE(phone.value().isEmpty()); | |
| 3403 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | |
| 3404 EXPECT_FALSE(phone.isAutofilled()); | |
| 3405 } | |
| 3406 | |
| 3325 TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) { | 3407 TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) { |
| 3326 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 3408 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 3327 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 3409 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| 3328 " <INPUT type=\"text\" id=\"lastname\"/>" | 3410 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 3329 " <INPUT type=\"text\" id=\"email\"/>" | 3411 " <INPUT type=\"text\" id=\"email\"/>" |
| 3330 " <INPUT type=\"email\" id=\"email2\"/>" | 3412 " <INPUT type=\"email\" id=\"email2\"/>" |
| 3331 " <INPUT type=\"tel\" id=\"phone\"/>" | 3413 " <INPUT type=\"tel\" id=\"phone\"/>" |
| 3332 " <INPUT type=\"submit\" value=\"Send\"/>" | 3414 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 3333 "</FORM>"); | 3415 "</FORM>"); |
| 3334 | 3416 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3494 expected.form_control_type = "text"; | 3576 expected.form_control_type = "text"; |
| 3495 expected.max_length = WebInputElement::defaultMaxLength(); | 3577 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3496 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3578 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 3497 | 3579 |
| 3498 expected.name = ASCIIToUTF16("country"); | 3580 expected.name = ASCIIToUTF16("country"); |
| 3499 expected.value = ASCIIToUTF16("AL"); | 3581 expected.value = ASCIIToUTF16("AL"); |
| 3500 expected.form_control_type = "select-one"; | 3582 expected.form_control_type = "select-one"; |
| 3501 expected.max_length = 0; | 3583 expected.max_length = 0; |
| 3502 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3584 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 3503 } | 3585 } |
| 3504 | |
| 3505 } // namespace autofill | 3586 } // namespace autofill |
| OLD | NEW |