| 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 WebInputElement lastname = |
| 2968 web_frame->document().getElementById("lastname").to<WebInputElement>(); |
| 2969 lastname.setAutofilled(true); |
| 2970 WebInputElement month = |
| 2971 web_frame->document().getElementById("month").to<WebInputElement>(); |
| 2972 month.setAutofilled(true); |
| 2973 WebInputElement textarea = |
| 2974 web_frame->document().getElementById("textarea").to<WebInputElement>(); |
| 2975 textarea.setAutofilled(true); |
| 2967 | 2976 |
| 2968 // Set the value of the disabled text input element. | 2977 // Set the value of the disabled text input element. |
| 2969 WebInputElement notenabled = | 2978 WebInputElement notenabled = |
| 2970 web_frame->document().getElementById("notenabled").to<WebInputElement>(); | 2979 web_frame->document().getElementById("notenabled").to<WebInputElement>(); |
| 2971 notenabled.setValue(WebString::fromUTF8("no clear")); | 2980 notenabled.setValue(WebString::fromUTF8("no clear")); |
| 2972 | 2981 |
| 2973 // Clear the form. | 2982 // Clear the form. |
| 2974 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 2983 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| 2975 | 2984 |
| 2976 // Verify that the auto-filled attribute has been turned off. | 2985 // Verify that the auto-filled attribute has been turned off. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2996 | 3005 |
| 2997 expected.name = ASCIIToUTF16("firstname"); | 3006 expected.name = ASCIIToUTF16("firstname"); |
| 2998 expected.value = base::string16(); | 3007 expected.value = base::string16(); |
| 2999 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | 3008 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 3000 | 3009 |
| 3001 expected.name = ASCIIToUTF16("lastname"); | 3010 expected.name = ASCIIToUTF16("lastname"); |
| 3002 expected.value = base::string16(); | 3011 expected.value = base::string16(); |
| 3003 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | 3012 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 3004 | 3013 |
| 3005 expected.name = ASCIIToUTF16("noAC"); | 3014 expected.name = ASCIIToUTF16("noAC"); |
| 3006 expected.value = base::string16(); | 3015 expected.value = ASCIIToUTF16("one"); |
| 3007 expected.autocomplete_attribute = "off"; | 3016 expected.autocomplete_attribute = "off"; |
| 3008 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 3017 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 3009 expected.autocomplete_attribute = std::string(); // reset | 3018 expected.autocomplete_attribute = std::string(); // reset |
| 3010 | 3019 |
| 3011 expected.name = ASCIIToUTF16("notenabled"); | 3020 expected.name = ASCIIToUTF16("notenabled"); |
| 3012 expected.value = ASCIIToUTF16("no clear"); | 3021 expected.value = ASCIIToUTF16("no clear"); |
| 3013 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[3]); | 3022 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[3]); |
| 3014 | 3023 |
| 3015 expected.form_control_type = "month"; | 3024 expected.form_control_type = "month"; |
| 3016 expected.max_length = 0; | 3025 expected.max_length = 0; |
| 3017 expected.name = ASCIIToUTF16("month"); | 3026 expected.name = ASCIIToUTF16("month"); |
| 3018 expected.value = base::string16(); | 3027 expected.value = base::string16(); |
| 3019 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[4]); | 3028 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[4]); |
| 3020 | 3029 |
| 3021 expected.name = ASCIIToUTF16("month-disabled"); | 3030 expected.name = ASCIIToUTF16("month-disabled"); |
| 3022 expected.value = ASCIIToUTF16("2012-11"); | 3031 expected.value = ASCIIToUTF16("2012-11"); |
| 3023 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[5]); | 3032 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[5]); |
| 3024 | 3033 |
| 3025 expected.form_control_type = "textarea"; | 3034 expected.form_control_type = "textarea"; |
| 3026 expected.name = ASCIIToUTF16("textarea"); | 3035 expected.name = ASCIIToUTF16("textarea"); |
| 3027 expected.value = base::string16(); | 3036 expected.value = base::string16(); |
| 3028 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[6]); | 3037 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[6]); |
| 3029 | 3038 |
| 3030 expected.name = ASCIIToUTF16("textarea-disabled"); | 3039 expected.name = ASCIIToUTF16("textarea-disabled"); |
| 3031 expected.value = ASCIIToUTF16(" Banana! "); | 3040 expected.value = ASCIIToUTF16(" Banana! "); |
| 3032 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[7]); | 3041 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[7]); |
| 3033 | 3042 |
| 3034 expected.name = ASCIIToUTF16("textarea-noAC"); | 3043 expected.name = ASCIIToUTF16("textarea-noAC"); |
| 3035 expected.value = base::string16(); | 3044 expected.value = ASCIIToUTF16("Carrot?"); |
| 3036 expected.autocomplete_attribute = "off"; | 3045 expected.autocomplete_attribute = "off"; |
| 3037 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[8]); | 3046 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[8]); |
| 3038 expected.autocomplete_attribute = std::string(); // reset | 3047 expected.autocomplete_attribute = std::string(); // reset |
| 3039 | 3048 |
| 3040 // Verify that the cursor position has been updated. | 3049 // Verify that the cursor position has been updated. |
| 3041 EXPECT_EQ(0, firstname.selectionStart()); | 3050 EXPECT_EQ(0, firstname.selectionStart()); |
| 3042 EXPECT_EQ(0, firstname.selectionEnd()); | 3051 EXPECT_EQ(0, firstname.selectionEnd()); |
| 3043 } | 3052 } |
| 3044 | 3053 |
| 3045 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { | 3054 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3057 "</FORM>"); | 3066 "</FORM>"); |
| 3058 | 3067 |
| 3059 WebFrame* web_frame = GetMainFrame(); | 3068 WebFrame* web_frame = GetMainFrame(); |
| 3060 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 3069 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 3061 | 3070 |
| 3062 FormCache form_cache; | 3071 FormCache form_cache; |
| 3063 std::vector<FormData> forms; | 3072 std::vector<FormData> forms; |
| 3064 form_cache.ExtractNewForms(*web_frame, &forms); | 3073 form_cache.ExtractNewForms(*web_frame, &forms); |
| 3065 ASSERT_EQ(1U, forms.size()); | 3074 ASSERT_EQ(1U, forms.size()); |
| 3066 | 3075 |
| 3067 // Set the auto-filled attribute on the firstname element. | 3076 // Set the auto-filled attribute. |
| 3068 WebInputElement firstname = | 3077 WebInputElement firstname = |
| 3069 web_frame->document().getElementById("firstname").to<WebInputElement>(); | 3078 web_frame->document().getElementById("firstname").to<WebInputElement>(); |
| 3070 firstname.setAutofilled(true); | 3079 firstname.setAutofilled(true); |
| 3080 WebInputElement lastname = |
| 3081 web_frame->document().getElementById("lastname").to<WebInputElement>(); |
| 3082 lastname.setAutofilled(true); |
| 3083 WebInputElement state = |
| 3084 web_frame->document().getElementById("state").to<WebInputElement>(); |
| 3085 state.setAutofilled(true); |
| 3071 | 3086 |
| 3072 // Set the value of the select-one. | 3087 // Set the value of the select-one. |
| 3073 WebSelectElement select_element = | 3088 WebSelectElement select_element = |
| 3074 web_frame->document().getElementById("state").to<WebSelectElement>(); | 3089 web_frame->document().getElementById("state").to<WebSelectElement>(); |
| 3075 select_element.setValue(WebString::fromUTF8("AK")); | 3090 select_element.setValue(WebString::fromUTF8("AK")); |
| 3076 | 3091 |
| 3077 // Clear the form. | 3092 // Clear the form. |
| 3078 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 3093 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| 3079 | 3094 |
| 3080 // Verify that the auto-filled attribute has been turned off. | 3095 // Verify that the auto-filled attribute has been turned off. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3315 EXPECT_TRUE(email.suggestedValue().isEmpty()); | 3330 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| 3316 EXPECT_FALSE(email.isAutofilled()); | 3331 EXPECT_FALSE(email.isAutofilled()); |
| 3317 EXPECT_TRUE(email2.value().isEmpty()); | 3332 EXPECT_TRUE(email2.value().isEmpty()); |
| 3318 EXPECT_TRUE(email2.suggestedValue().isEmpty()); | 3333 EXPECT_TRUE(email2.suggestedValue().isEmpty()); |
| 3319 EXPECT_FALSE(email2.isAutofilled()); | 3334 EXPECT_FALSE(email2.isAutofilled()); |
| 3320 EXPECT_TRUE(phone.value().isEmpty()); | 3335 EXPECT_TRUE(phone.value().isEmpty()); |
| 3321 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | 3336 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 3322 EXPECT_FALSE(phone.isAutofilled()); | 3337 EXPECT_FALSE(phone.isAutofilled()); |
| 3323 } | 3338 } |
| 3324 | 3339 |
| 3340 // Autofill's "Clear Form" should clear only autofilled fields |
| 3341 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { |
| 3342 // Load the form. |
| 3343 LoadHTML( |
| 3344 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 3345 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| 3346 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>" |
| 3347 " <INPUT type=\"email\" id=\"email\" value=\"wyatt@earp.com\"/>" |
| 3348 " <INPUT type=\"tel\" id=\"phone\" value=\"650-777-9999\"/>" |
| 3349 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 3350 "</FORM>"); |
| 3351 |
| 3352 WebFrame* web_frame = GetMainFrame(); |
| 3353 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 3354 |
| 3355 FormCache form_cache; |
| 3356 std::vector<FormData> forms; |
| 3357 form_cache.ExtractNewForms(*web_frame, &forms); |
| 3358 ASSERT_EQ(1U, forms.size()); |
| 3359 |
| 3360 // Set the autofilled attribute. |
| 3361 WebInputElement firstname = |
| 3362 web_frame->document().getElementById("firstname").to<WebInputElement>(); |
| 3363 firstname.setAutofilled(false); |
| 3364 WebInputElement lastname = |
| 3365 web_frame->document().getElementById("lastname").to<WebInputElement>(); |
| 3366 lastname.setAutofilled(true); |
| 3367 WebInputElement email = |
| 3368 web_frame->document().getElementById("email").to<WebInputElement>(); |
| 3369 email.setAutofilled(true); |
| 3370 WebInputElement phone = |
| 3371 web_frame->document().getElementById("phone").to<WebInputElement>(); |
| 3372 phone.setAutofilled(true); |
| 3373 |
| 3374 // Clear the fields. |
| 3375 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| 3376 |
| 3377 // Verify only autofilled fields are cleared. |
| 3378 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); |
| 3379 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
| 3380 EXPECT_FALSE(firstname.isAutofilled()); |
| 3381 EXPECT_TRUE(lastname.value().isEmpty()); |
| 3382 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); |
| 3383 EXPECT_FALSE(lastname.isAutofilled()); |
| 3384 EXPECT_TRUE(email.value().isEmpty()); |
| 3385 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| 3386 EXPECT_FALSE(email.isAutofilled()); |
| 3387 EXPECT_TRUE(phone.value().isEmpty()); |
| 3388 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 3389 EXPECT_FALSE(phone.isAutofilled()); |
| 3390 } |
| 3391 |
| 3325 TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) { | 3392 TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) { |
| 3326 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 3393 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 3327 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 3394 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| 3328 " <INPUT type=\"text\" id=\"lastname\"/>" | 3395 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 3329 " <INPUT type=\"text\" id=\"email\"/>" | 3396 " <INPUT type=\"text\" id=\"email\"/>" |
| 3330 " <INPUT type=\"email\" id=\"email2\"/>" | 3397 " <INPUT type=\"email\" id=\"email2\"/>" |
| 3331 " <INPUT type=\"tel\" id=\"phone\"/>" | 3398 " <INPUT type=\"tel\" id=\"phone\"/>" |
| 3332 " <INPUT type=\"submit\" value=\"Send\"/>" | 3399 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 3333 "</FORM>"); | 3400 "</FORM>"); |
| 3334 | 3401 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3494 expected.form_control_type = "text"; | 3561 expected.form_control_type = "text"; |
| 3495 expected.max_length = WebInputElement::defaultMaxLength(); | 3562 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3496 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3563 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 3497 | 3564 |
| 3498 expected.name = ASCIIToUTF16("country"); | 3565 expected.name = ASCIIToUTF16("country"); |
| 3499 expected.value = ASCIIToUTF16("AL"); | 3566 expected.value = ASCIIToUTF16("AL"); |
| 3500 expected.form_control_type = "select-one"; | 3567 expected.form_control_type = "select-one"; |
| 3501 expected.max_length = 0; | 3568 expected.max_length = 0; |
| 3502 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3569 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 3503 } | 3570 } |
| 3504 | |
| 3505 } // namespace autofill | 3571 } // namespace autofill |
| OLD | NEW |