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 2982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2993 expected.value = ASCIIToUTF16("?"); | 2993 expected.value = ASCIIToUTF16("?"); |
2994 expected.form_control_type = "select-one"; | 2994 expected.form_control_type = "select-one"; |
2995 expected.max_length = 0; | 2995 expected.max_length = 0; |
2996 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 2996 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
2997 | 2997 |
2998 // Verify that the cursor position has been updated. | 2998 // Verify that the cursor position has been updated. |
2999 EXPECT_EQ(0, firstname.selectionStart()); | 2999 EXPECT_EQ(0, firstname.selectionStart()); |
3000 EXPECT_EQ(0, firstname.selectionEnd()); | 3000 EXPECT_EQ(0, firstname.selectionEnd()); |
3001 } | 3001 } |
3002 | 3002 |
| 3003 TEST_F(FormAutofillTest, ClearPreviewedPasswordWithPasswordAutofilled) { |
| 3004 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 3005 " <INPUT type=\"text\" id=\"username\"/>" |
| 3006 " <INPUT type=\"password\" id=\"password\" value=\"s\"/>" |
| 3007 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 3008 "</FORM>"); |
| 3009 |
| 3010 WebFrame* web_frame = GetMainFrame(); |
| 3011 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 3012 |
| 3013 // Set the auto-filled attribute. |
| 3014 WebInputElement username = |
| 3015 web_frame->document().getElementById("username").to<WebInputElement>(); |
| 3016 username.setAutofilled(true); |
| 3017 WebInputElement password = |
| 3018 web_frame->document().getElementById("password").to<WebInputElement>(); |
| 3019 password.setAutofilled(true); |
| 3020 |
| 3021 username.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
| 3022 password.setSuggestedValue(ASCIIToUTF16("secret")); |
| 3023 |
| 3024 EXPECT_TRUE(ClearPreviewedFormWithElement(username, false, true)); |
| 3025 |
| 3026 EXPECT_TRUE(username.value().isEmpty()); |
| 3027 EXPECT_TRUE(username.suggestedValue().isEmpty()); |
| 3028 EXPECT_FALSE(username.isAutofilled()); |
| 3029 |
| 3030 EXPECT_EQ(ASCIIToUTF16("s"), password.value()); |
| 3031 EXPECT_TRUE(password.suggestedValue().isEmpty()); |
| 3032 EXPECT_TRUE(password.isAutofilled()); |
| 3033 } |
| 3034 |
| 3035 TEST_F(FormAutofillTest, ClearPreviewedPasswordWithUserNameAutofilled) { |
| 3036 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 3037 " <INPUT type=\"text\" id=\"username\" value=\"W\"/>" |
| 3038 " <INPUT type=\"password\" id=\"password\"/>" |
| 3039 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 3040 "</FORM>"); |
| 3041 |
| 3042 WebFrame* web_frame = GetMainFrame(); |
| 3043 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 3044 |
| 3045 WebInputElement username = |
| 3046 web_frame->document().getElementById("username").to<WebInputElement>(); |
| 3047 username.setAutofilled(true); |
| 3048 WebInputElement password = |
| 3049 web_frame->document().getElementById("password").to<WebInputElement>(); |
| 3050 password.setAutofilled(true); |
| 3051 |
| 3052 username.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
| 3053 password.setSuggestedValue(ASCIIToUTF16("secret")); |
| 3054 |
| 3055 EXPECT_TRUE(ClearPreviewedFormWithElement(username, true, false)); |
| 3056 |
| 3057 EXPECT_EQ(ASCIIToUTF16("W"), username.value()); |
| 3058 EXPECT_TRUE(username.suggestedValue().isEmpty()); |
| 3059 EXPECT_TRUE(username.isAutofilled()); |
| 3060 |
| 3061 EXPECT_TRUE(password.value().isEmpty()); |
| 3062 EXPECT_TRUE(password.suggestedValue().isEmpty()); |
| 3063 EXPECT_FALSE(password.isAutofilled()); |
| 3064 } |
| 3065 |
| 3066 TEST_F(FormAutofillTest, |
| 3067 ClearPreviewedPasswordWithAutofilledUserNameAndPassword) { |
| 3068 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 3069 " <INPUT type=\"text\" id=\"username\" value=\"W\"/>" |
| 3070 " <INPUT type=\"password\" id=\"password\" value=\"s\"/>" |
| 3071 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 3072 "</FORM>"); |
| 3073 |
| 3074 WebFrame* web_frame = GetMainFrame(); |
| 3075 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 3076 |
| 3077 WebInputElement username = |
| 3078 web_frame->document().getElementById("username").to<WebInputElement>(); |
| 3079 username.setAutofilled(true); |
| 3080 WebInputElement password = |
| 3081 web_frame->document().getElementById("password").to<WebInputElement>(); |
| 3082 password.setAutofilled(true); |
| 3083 |
| 3084 username.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
| 3085 password.setSuggestedValue(ASCIIToUTF16("secret")); |
| 3086 |
| 3087 EXPECT_TRUE(ClearPreviewedFormWithElement(username, true, true)); |
| 3088 |
| 3089 EXPECT_EQ(ASCIIToUTF16("W"), username.value()); |
| 3090 EXPECT_TRUE(username.suggestedValue().isEmpty()); |
| 3091 EXPECT_TRUE(username.isAutofilled()); |
| 3092 |
| 3093 EXPECT_EQ(ASCIIToUTF16("s"), password.value()); |
| 3094 EXPECT_TRUE(password.suggestedValue().isEmpty()); |
| 3095 EXPECT_TRUE(password.isAutofilled()); |
| 3096 } |
| 3097 |
| 3098 TEST_F(FormAutofillTest, |
| 3099 ClearPreviewedPasswordWithNotAutofilledUserNameAndPassword) { |
| 3100 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 3101 " <INPUT type=\"text\" id=\"username\"/>" |
| 3102 " <INPUT type=\"password\" id=\"password\"/>" |
| 3103 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 3104 "</FORM>"); |
| 3105 |
| 3106 WebFrame* web_frame = GetMainFrame(); |
| 3107 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 3108 |
| 3109 // Set the auto-filled attribute. |
| 3110 WebInputElement username = |
| 3111 web_frame->document().getElementById("username").to<WebInputElement>(); |
| 3112 username.setAutofilled(true); |
| 3113 WebInputElement password = |
| 3114 web_frame->document().getElementById("password").to<WebInputElement>(); |
| 3115 password.setAutofilled(true); |
| 3116 |
| 3117 username.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
| 3118 password.setSuggestedValue(ASCIIToUTF16("secret")); |
| 3119 |
| 3120 // Clear the previewed fields. |
| 3121 EXPECT_TRUE(ClearPreviewedFormWithElement(username, false, false)); |
| 3122 |
| 3123 EXPECT_TRUE(username.value().isEmpty()); |
| 3124 EXPECT_TRUE(username.suggestedValue().isEmpty()); |
| 3125 EXPECT_FALSE(username.isAutofilled()); |
| 3126 |
| 3127 EXPECT_TRUE(password.value().isEmpty()); |
| 3128 EXPECT_TRUE(password.suggestedValue().isEmpty()); |
| 3129 EXPECT_FALSE(password.isAutofilled()); |
| 3130 } |
| 3131 |
| 3132 TEST_F(FormAutofillTest, |
| 3133 ClearPreviewedPasswordWithEmptyUserNameSuggestion) { |
| 3134 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 3135 " <INPUT type=\"text\" id=\"username\"/>" |
| 3136 " <INPUT type=\"password\" id=\"password\"/>" |
| 3137 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 3138 "</FORM>"); |
| 3139 |
| 3140 WebFrame* web_frame = GetMainFrame(); |
| 3141 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 3142 |
| 3143 WebInputElement username = |
| 3144 web_frame->document().getElementById("username").to<WebInputElement>(); |
| 3145 username.setAutofilled(true); |
| 3146 WebInputElement password = |
| 3147 web_frame->document().getElementById("password").to<WebInputElement>(); |
| 3148 password.setAutofilled(true); |
| 3149 |
| 3150 username.setSuggestedValue(base::string16()); |
| 3151 |
| 3152 EXPECT_TRUE(ClearPreviewedFormWithElement(username, false, false)); |
| 3153 EXPECT_TRUE(username.value().isEmpty()); |
| 3154 EXPECT_TRUE(username.suggestedValue().isEmpty()); |
| 3155 EXPECT_TRUE(username.isAutofilled()); |
| 3156 |
| 3157 EXPECT_TRUE(password.value().isEmpty()); |
| 3158 EXPECT_TRUE(password.suggestedValue().isEmpty()); |
| 3159 EXPECT_TRUE(password.isAutofilled()); |
| 3160 } |
| 3161 |
3003 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { | 3162 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { |
3004 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 3163 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
3005 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 3164 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
3006 " <INPUT type=\"text\" id=\"lastname\"/>" | 3165 " <INPUT type=\"text\" id=\"lastname\"/>" |
3007 " <INPUT type=\"text\" id=\"email\"/>" | 3166 " <INPUT type=\"text\" id=\"email\"/>" |
3008 " <INPUT type=\"email\" id=\"email2\"/>" | 3167 " <INPUT type=\"email\" id=\"email2\"/>" |
3009 " <INPUT type=\"tel\" id=\"phone\"/>" | 3168 " <INPUT type=\"tel\" id=\"phone\"/>" |
3010 " <INPUT type=\"submit\" value=\"Send\"/>" | 3169 " <INPUT type=\"submit\" value=\"Send\"/>" |
3011 "</FORM>"); | 3170 "</FORM>"); |
3012 | 3171 |
(...skipping 22 matching lines...) Expand all Loading... |
3035 web_frame->document().getElementById("phone").to<WebInputElement>(); | 3194 web_frame->document().getElementById("phone").to<WebInputElement>(); |
3036 phone.setAutofilled(true); | 3195 phone.setAutofilled(true); |
3037 | 3196 |
3038 // Set the suggested values on two of the elements. | 3197 // Set the suggested values on two of the elements. |
3039 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | 3198 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
3040 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3199 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3041 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3200 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3042 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | 3201 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
3043 | 3202 |
3044 // Clear the previewed fields. | 3203 // Clear the previewed fields. |
3045 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, false)); | 3204 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, false, false)); |
3046 | 3205 |
3047 // Fields with empty suggestions suggestions are not modified. | 3206 // Fields with empty suggestions suggestions are not modified. |
3048 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); | 3207 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); |
3049 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | 3208 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
3050 EXPECT_TRUE(firstname.isAutofilled()); | 3209 EXPECT_TRUE(firstname.isAutofilled()); |
3051 | 3210 |
3052 // Verify the previewed fields are cleared. | 3211 // Verify the previewed fields are cleared. |
3053 EXPECT_TRUE(lastname.value().isEmpty()); | 3212 EXPECT_TRUE(lastname.value().isEmpty()); |
3054 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); | 3213 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); |
3055 EXPECT_FALSE(lastname.isAutofilled()); | 3214 EXPECT_FALSE(lastname.isAutofilled()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3105 | 3264 |
3106 | 3265 |
3107 // Set the suggested values on all of the elements. | 3266 // Set the suggested values on all of the elements. |
3108 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); | 3267 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
3109 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | 3268 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
3110 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3269 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3111 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3270 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3112 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | 3271 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
3113 | 3272 |
3114 // Clear the previewed fields. | 3273 // Clear the previewed fields. |
3115 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, false)); | 3274 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, false, false)); |
3116 | 3275 |
3117 // Fields with non-empty values are restored. | 3276 // Fields with non-empty values are restored. |
3118 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); | 3277 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); |
3119 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | 3278 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
3120 EXPECT_FALSE(firstname.isAutofilled()); | 3279 EXPECT_FALSE(firstname.isAutofilled()); |
3121 EXPECT_EQ(1, firstname.selectionStart()); | 3280 EXPECT_EQ(1, firstname.selectionStart()); |
3122 EXPECT_EQ(1, firstname.selectionEnd()); | 3281 EXPECT_EQ(1, firstname.selectionEnd()); |
3123 | 3282 |
3124 // Verify the previewed fields are cleared. | 3283 // Verify the previewed fields are cleared. |
3125 EXPECT_TRUE(lastname.value().isEmpty()); | 3284 EXPECT_TRUE(lastname.value().isEmpty()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3172 phone.setAutofilled(true); | 3331 phone.setAutofilled(true); |
3173 | 3332 |
3174 // Set the suggested values on all of the elements. | 3333 // Set the suggested values on all of the elements. |
3175 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); | 3334 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
3176 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | 3335 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
3177 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3336 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3178 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3337 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3179 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | 3338 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
3180 | 3339 |
3181 // Clear the previewed fields. | 3340 // Clear the previewed fields. |
3182 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, true)); | 3341 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, true, false)); |
3183 | 3342 |
3184 // Fields with non-empty values are restored. | 3343 // Fields with non-empty values are restored. |
3185 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); | 3344 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); |
3186 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | 3345 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
3187 EXPECT_TRUE(firstname.isAutofilled()); | 3346 EXPECT_TRUE(firstname.isAutofilled()); |
3188 EXPECT_EQ(1, firstname.selectionStart()); | 3347 EXPECT_EQ(1, firstname.selectionStart()); |
3189 EXPECT_EQ(1, firstname.selectionEnd()); | 3348 EXPECT_EQ(1, firstname.selectionEnd()); |
3190 | 3349 |
3191 // Verify the previewed fields are cleared. | 3350 // Verify the previewed fields are cleared. |
3192 EXPECT_TRUE(lastname.value().isEmpty()); | 3351 EXPECT_TRUE(lastname.value().isEmpty()); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3377 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3536 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
3378 | 3537 |
3379 expected.name = ASCIIToUTF16("country"); | 3538 expected.name = ASCIIToUTF16("country"); |
3380 expected.value = ASCIIToUTF16("AL"); | 3539 expected.value = ASCIIToUTF16("AL"); |
3381 expected.form_control_type = "select-one"; | 3540 expected.form_control_type = "select-one"; |
3382 expected.max_length = 0; | 3541 expected.max_length = 0; |
3383 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3542 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3384 } | 3543 } |
3385 | 3544 |
3386 } // namespace autofill | 3545 } // namespace autofill |
OLD | NEW |