| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/form_structure.h" | 5 #include "components/autofill/core/browser/form_structure.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 FormData form; | 239 FormData form; |
| 240 | 240 |
| 241 // We need at least three text fields to be parseable. | 241 // We need at least three text fields to be parseable. |
| 242 FormFieldData field; | 242 FormFieldData field; |
| 243 field.label = ASCIIToUTF16("username"); | 243 field.label = ASCIIToUTF16("username"); |
| 244 field.name = ASCIIToUTF16("username"); | 244 field.name = ASCIIToUTF16("username"); |
| 245 field.form_control_type = "text"; | 245 field.form_control_type = "text"; |
| 246 form.fields.push_back(field); | 246 form.fields.push_back(field); |
| 247 | 247 |
| 248 FormFieldData checkable_field; | 248 FormFieldData checkable_field; |
| 249 checkable_field.is_checkable = true; | 249 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; |
| 250 checkable_field.name = ASCIIToUTF16("radiobtn"); | 250 checkable_field.name = ASCIIToUTF16("radiobtn"); |
| 251 checkable_field.form_control_type = "radio"; | 251 checkable_field.form_control_type = "radio"; |
| 252 form.fields.push_back(checkable_field); | 252 form.fields.push_back(checkable_field); |
| 253 | 253 |
| 254 checkable_field.name = ASCIIToUTF16("checkbox"); | 254 checkable_field.name = ASCIIToUTF16("checkbox"); |
| 255 checkable_field.form_control_type = "checkbox"; | 255 checkable_field.form_control_type = "checkbox"; |
| 256 form.fields.push_back(checkable_field); | 256 form.fields.push_back(checkable_field); |
| 257 | 257 |
| 258 // We have only one text field, should not be parsed. | 258 // We have only one text field, should not be parsed. |
| 259 form_structure.reset(new FormStructure(form)); | 259 form_structure.reset(new FormStructure(form)); |
| (...skipping 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1852 field.label = ASCIIToUTF16("Expiration Date"); | 1852 field.label = ASCIIToUTF16("Expiration Date"); |
| 1853 field.name = ASCIIToUTF16("expiration_month"); | 1853 field.name = ASCIIToUTF16("expiration_month"); |
| 1854 form.fields.push_back(field); | 1854 form.fields.push_back(field); |
| 1855 | 1855 |
| 1856 field.label = ASCIIToUTF16("Expiration Year"); | 1856 field.label = ASCIIToUTF16("Expiration Year"); |
| 1857 field.name = ASCIIToUTF16("expiration_year"); | 1857 field.name = ASCIIToUTF16("expiration_year"); |
| 1858 form.fields.push_back(field); | 1858 form.fields.push_back(field); |
| 1859 | 1859 |
| 1860 // Add checkable field. | 1860 // Add checkable field. |
| 1861 FormFieldData checkable_field; | 1861 FormFieldData checkable_field; |
| 1862 checkable_field.is_checkable = true; | 1862 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; |
| 1863 checkable_field.label = ASCIIToUTF16("Checkable1"); | 1863 checkable_field.label = ASCIIToUTF16("Checkable1"); |
| 1864 checkable_field.name = ASCIIToUTF16("Checkable1"); | 1864 checkable_field.name = ASCIIToUTF16("Checkable1"); |
| 1865 form.fields.push_back(checkable_field); | 1865 form.fields.push_back(checkable_field); |
| 1866 | 1866 |
| 1867 ScopedVector<FormStructure> forms; | 1867 ScopedVector<FormStructure> forms; |
| 1868 forms.push_back(new FormStructure(form)); | 1868 forms.push_back(new FormStructure(form)); |
| 1869 std::vector<std::string> encoded_signatures; | 1869 std::vector<std::string> encoded_signatures; |
| 1870 | 1870 |
| 1871 // Prepare the expected proto string. | 1871 // Prepare the expected proto string. |
| 1872 AutofillQueryContents query; | 1872 AutofillQueryContents query; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2020 | 2020 |
| 2021 field.label = ASCIIToUTF16("Country"); | 2021 field.label = ASCIIToUTF16("Country"); |
| 2022 field.name = ASCIIToUTF16("country"); | 2022 field.name = ASCIIToUTF16("country"); |
| 2023 field.form_control_type = "select-one"; | 2023 field.form_control_type = "select-one"; |
| 2024 form.fields.push_back(field); | 2024 form.fields.push_back(field); |
| 2025 possible_field_types.push_back(ServerFieldTypeSet()); | 2025 possible_field_types.push_back(ServerFieldTypeSet()); |
| 2026 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); | 2026 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); |
| 2027 | 2027 |
| 2028 // Add checkable field. | 2028 // Add checkable field. |
| 2029 FormFieldData checkable_field; | 2029 FormFieldData checkable_field; |
| 2030 checkable_field.is_checkable = true; | 2030 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; |
| 2031 checkable_field.label = ASCIIToUTF16("Checkable1"); | 2031 checkable_field.label = ASCIIToUTF16("Checkable1"); |
| 2032 checkable_field.name = ASCIIToUTF16("Checkable1"); | 2032 checkable_field.name = ASCIIToUTF16("Checkable1"); |
| 2033 form.fields.push_back(checkable_field); | 2033 form.fields.push_back(checkable_field); |
| 2034 possible_field_types.push_back(ServerFieldTypeSet()); | 2034 possible_field_types.push_back(ServerFieldTypeSet()); |
| 2035 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); | 2035 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); |
| 2036 | 2036 |
| 2037 form_structure.reset(new FormStructure(form)); | 2037 form_structure.reset(new FormStructure(form)); |
| 2038 | 2038 |
| 2039 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 2039 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
| 2040 for (size_t i = 0; i < form_structure->field_count(); ++i) | 2040 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3070 form.fields.push_back(field); | 3070 form.fields.push_back(field); |
| 3071 | 3071 |
| 3072 field.label = ASCIIToUTF16("First Name"); | 3072 field.label = ASCIIToUTF16("First Name"); |
| 3073 field.name = ASCIIToUTF16("first"); | 3073 field.name = ASCIIToUTF16("first"); |
| 3074 form.fields.push_back(field); | 3074 form.fields.push_back(field); |
| 3075 | 3075 |
| 3076 // Checkable fields shouldn't affect the signature. | 3076 // Checkable fields shouldn't affect the signature. |
| 3077 field.label = ASCIIToUTF16("Select"); | 3077 field.label = ASCIIToUTF16("Select"); |
| 3078 field.name = ASCIIToUTF16("Select"); | 3078 field.name = ASCIIToUTF16("Select"); |
| 3079 field.form_control_type = "checkbox"; | 3079 field.form_control_type = "checkbox"; |
| 3080 field.is_checkable = true; | 3080 field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; |
| 3081 form.fields.push_back(field); | 3081 form.fields.push_back(field); |
| 3082 | 3082 |
| 3083 form_structure.reset(new FormStructure(form)); | 3083 form_structure.reset(new FormStructure(form)); |
| 3084 | 3084 |
| 3085 EXPECT_EQ(FormStructureTest::Hash64Bit( | 3085 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 3086 std::string("://&&email&first")), | 3086 std::string("://&&email&first")), |
| 3087 form_structure->FormSignature()); | 3087 form_structure->FormSignature()); |
| 3088 | 3088 |
| 3089 form.origin = GURL(std::string("http://www.facebook.com")); | 3089 form.origin = GURL(std::string("http://www.facebook.com")); |
| 3090 form_structure.reset(new FormStructure(form)); | 3090 form_structure.reset(new FormStructure(form)); |
| 3091 EXPECT_EQ(FormStructureTest::Hash64Bit( | 3091 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 3092 std::string("http://www.facebook.com&&email&first")), | 3092 std::string("http://www.facebook.com&&email&first")), |
| 3093 form_structure->FormSignature()); | 3093 form_structure->FormSignature()); |
| 3094 | 3094 |
| 3095 form.action = GURL(std::string("https://login.facebook.com/path")); | 3095 form.action = GURL(std::string("https://login.facebook.com/path")); |
| 3096 form_structure.reset(new FormStructure(form)); | 3096 form_structure.reset(new FormStructure(form)); |
| 3097 EXPECT_EQ(FormStructureTest::Hash64Bit( | 3097 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 3098 std::string("https://login.facebook.com&&email&first")), | 3098 std::string("https://login.facebook.com&&email&first")), |
| 3099 form_structure->FormSignature()); | 3099 form_structure->FormSignature()); |
| 3100 | 3100 |
| 3101 form.name = ASCIIToUTF16("login_form"); | 3101 form.name = ASCIIToUTF16("login_form"); |
| 3102 form_structure.reset(new FormStructure(form)); | 3102 form_structure.reset(new FormStructure(form)); |
| 3103 EXPECT_EQ(FormStructureTest::Hash64Bit( | 3103 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 3104 std::string("https://login.facebook.com&login_form&email&first")), | 3104 std::string("https://login.facebook.com&login_form&email&first")), |
| 3105 form_structure->FormSignature()); | 3105 form_structure->FormSignature()); |
| 3106 | 3106 |
| 3107 field.is_checkable = false; | 3107 field.check_status = FormFieldData::NOT_CHECKABLE; |
| 3108 field.label = ASCIIToUTF16("Random Field label"); | 3108 field.label = ASCIIToUTF16("Random Field label"); |
| 3109 field.name = ASCIIToUTF16("random1234"); | 3109 field.name = ASCIIToUTF16("random1234"); |
| 3110 field.form_control_type = "text"; | 3110 field.form_control_type = "text"; |
| 3111 form.fields.push_back(field); | 3111 form.fields.push_back(field); |
| 3112 field.label = ASCIIToUTF16("Random Field label2"); | 3112 field.label = ASCIIToUTF16("Random Field label2"); |
| 3113 field.name = ASCIIToUTF16("random12345"); | 3113 field.name = ASCIIToUTF16("random12345"); |
| 3114 form.fields.push_back(field); | 3114 form.fields.push_back(field); |
| 3115 field.label = ASCIIToUTF16("Random Field label3"); | 3115 field.label = ASCIIToUTF16("Random Field label3"); |
| 3116 field.name = ASCIIToUTF16("1random12345678"); | 3116 field.name = ASCIIToUTF16("1random12345678"); |
| 3117 form.fields.push_back(field); | 3117 form.fields.push_back(field); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3158 | 3158 |
| 3159 FormFieldData field; | 3159 FormFieldData field; |
| 3160 field.label = ASCIIToUTF16("username"); | 3160 field.label = ASCIIToUTF16("username"); |
| 3161 field.name = ASCIIToUTF16("username"); | 3161 field.name = ASCIIToUTF16("username"); |
| 3162 field.form_control_type = "text"; | 3162 field.form_control_type = "text"; |
| 3163 form.fields.push_back(field); | 3163 form.fields.push_back(field); |
| 3164 | 3164 |
| 3165 field.label = ASCIIToUTF16("select"); | 3165 field.label = ASCIIToUTF16("select"); |
| 3166 field.name = ASCIIToUTF16("select"); | 3166 field.name = ASCIIToUTF16("select"); |
| 3167 field.form_control_type = "checkbox"; | 3167 field.form_control_type = "checkbox"; |
| 3168 field.is_checkable = true; | 3168 field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; |
| 3169 form.fields.push_back(field); | 3169 form.fields.push_back(field); |
| 3170 | 3170 |
| 3171 field.label = base::string16(); | 3171 field.label = base::string16(); |
| 3172 field.name = ASCIIToUTF16("email"); | 3172 field.name = ASCIIToUTF16("email"); |
| 3173 field.form_control_type = "text"; | 3173 field.form_control_type = "text"; |
| 3174 field.is_checkable = false; | 3174 field.check_status = FormFieldData::NOT_CHECKABLE; |
| 3175 form.fields.push_back(field); | 3175 form.fields.push_back(field); |
| 3176 | 3176 |
| 3177 ScopedVector<FormStructure> forms; | 3177 ScopedVector<FormStructure> forms; |
| 3178 forms.push_back(new FormStructure(form)); | 3178 forms.push_back(new FormStructure(form)); |
| 3179 std::vector<std::string> encoded_signatures; | 3179 std::vector<std::string> encoded_signatures; |
| 3180 AutofillQueryContents encoded_query; | 3180 AutofillQueryContents encoded_query; |
| 3181 | 3181 |
| 3182 // Create the expected query and serialize it to a string. | 3182 // Create the expected query and serialize it to a string. |
| 3183 AutofillQueryContents query; | 3183 AutofillQueryContents query; |
| 3184 query.set_client_version("6.1.1715.1442/en (GGLL)"); | 3184 query.set_client_version("6.1.1715.1442/en (GGLL)"); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3326 FormFieldData field; | 3326 FormFieldData field; |
| 3327 field.label = ASCIIToUTF16("username"); | 3327 field.label = ASCIIToUTF16("username"); |
| 3328 field.name = ASCIIToUTF16("username"); | 3328 field.name = ASCIIToUTF16("username"); |
| 3329 field.form_control_type = "text"; | 3329 field.form_control_type = "text"; |
| 3330 form.fields.push_back(field); | 3330 form.fields.push_back(field); |
| 3331 | 3331 |
| 3332 field.label = base::string16(); | 3332 field.label = base::string16(); |
| 3333 // No name set for this field. | 3333 // No name set for this field. |
| 3334 field.name = ASCIIToUTF16(""); | 3334 field.name = ASCIIToUTF16(""); |
| 3335 field.form_control_type = "text"; | 3335 field.form_control_type = "text"; |
| 3336 field.is_checkable = false; | 3336 field.check_status = FormFieldData::NOT_CHECKABLE; |
| 3337 form.fields.push_back(field); | 3337 form.fields.push_back(field); |
| 3338 | 3338 |
| 3339 ScopedVector<FormStructure> forms; | 3339 ScopedVector<FormStructure> forms; |
| 3340 forms.push_back(new FormStructure(form)); | 3340 forms.push_back(new FormStructure(form)); |
| 3341 std::vector<std::string> encoded_signatures; | 3341 std::vector<std::string> encoded_signatures; |
| 3342 AutofillQueryContents encoded_query; | 3342 AutofillQueryContents encoded_query; |
| 3343 | 3343 |
| 3344 // Create the expected query and serialize it to a string. | 3344 // Create the expected query and serialize it to a string. |
| 3345 AutofillQueryContents query; | 3345 AutofillQueryContents query; |
| 3346 query.set_client_version("6.1.1715.1442/en (GGLL)"); | 3346 query.set_client_version("6.1.1715.1442/en (GGLL)"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3378 | 3378 |
| 3379 FormFieldData field; | 3379 FormFieldData field; |
| 3380 field.label = ASCIIToUTF16("username"); | 3380 field.label = ASCIIToUTF16("username"); |
| 3381 field.name = ASCIIToUTF16("username"); | 3381 field.name = ASCIIToUTF16("username"); |
| 3382 field.form_control_type = "text"; | 3382 field.form_control_type = "text"; |
| 3383 form.fields.push_back(field); | 3383 form.fields.push_back(field); |
| 3384 | 3384 |
| 3385 field.label = base::string16(); | 3385 field.label = base::string16(); |
| 3386 field.name = ASCIIToUTF16("country"); | 3386 field.name = ASCIIToUTF16("country"); |
| 3387 field.form_control_type = "text"; | 3387 field.form_control_type = "text"; |
| 3388 field.is_checkable = false; | 3388 field.check_status = FormFieldData::NOT_CHECKABLE; |
| 3389 form.fields.push_back(field); | 3389 form.fields.push_back(field); |
| 3390 | 3390 |
| 3391 ScopedVector<FormStructure> forms; | 3391 ScopedVector<FormStructure> forms; |
| 3392 forms.push_back(new FormStructure(form)); | 3392 forms.push_back(new FormStructure(form)); |
| 3393 std::vector<std::string> encoded_signatures; | 3393 std::vector<std::string> encoded_signatures; |
| 3394 AutofillQueryContents encoded_query; | 3394 AutofillQueryContents encoded_query; |
| 3395 | 3395 |
| 3396 // Create the expected query and serialize it to a string. | 3396 // Create the expected query and serialize it to a string. |
| 3397 AutofillQueryContents query; | 3397 AutofillQueryContents query; |
| 3398 query.set_client_version("6.1.1715.1442/en (GGLL)"); | 3398 query.set_client_version("6.1.1715.1442/en (GGLL)"); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3471 form.fields.push_back(field); | 3471 form.fields.push_back(field); |
| 3472 | 3472 |
| 3473 field.label = ASCIIToUTF16("address"); | 3473 field.label = ASCIIToUTF16("address"); |
| 3474 field.name = ASCIIToUTF16("address"); | 3474 field.name = ASCIIToUTF16("address"); |
| 3475 form.fields.push_back(field); | 3475 form.fields.push_back(field); |
| 3476 | 3476 |
| 3477 // Checkable fields should be ignored in parsing | 3477 // Checkable fields should be ignored in parsing |
| 3478 FormFieldData checkable_field; | 3478 FormFieldData checkable_field; |
| 3479 checkable_field.label = ASCIIToUTF16("radio_button"); | 3479 checkable_field.label = ASCIIToUTF16("radio_button"); |
| 3480 checkable_field.form_control_type = "radio"; | 3480 checkable_field.form_control_type = "radio"; |
| 3481 checkable_field.is_checkable = true; | 3481 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; |
| 3482 form.fields.push_back(checkable_field); | 3482 form.fields.push_back(checkable_field); |
| 3483 | 3483 |
| 3484 ScopedVector<FormStructure> forms; | 3484 ScopedVector<FormStructure> forms; |
| 3485 forms.push_back(new FormStructure(form)); | 3485 forms.push_back(new FormStructure(form)); |
| 3486 | 3486 |
| 3487 field.label = ASCIIToUTF16("email"); | 3487 field.label = ASCIIToUTF16("email"); |
| 3488 field.name = ASCIIToUTF16("email"); | 3488 field.name = ASCIIToUTF16("email"); |
| 3489 form.fields.push_back(field); | 3489 form.fields.push_back(field); |
| 3490 | 3490 |
| 3491 field.label = ASCIIToUTF16("password"); | 3491 field.label = ASCIIToUTF16("password"); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3586 prefix = FormStructure::FindLongestCommonPrefix(strings); | 3586 prefix = FormStructure::FindLongestCommonPrefix(strings); |
| 3587 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix); | 3587 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix); |
| 3588 | 3588 |
| 3589 // Empty vector. | 3589 // Empty vector. |
| 3590 strings.clear(); | 3590 strings.clear(); |
| 3591 prefix = FormStructure::FindLongestCommonPrefix(strings); | 3591 prefix = FormStructure::FindLongestCommonPrefix(strings); |
| 3592 EXPECT_EQ(ASCIIToUTF16(""), prefix); | 3592 EXPECT_EQ(ASCIIToUTF16(""), prefix); |
| 3593 } | 3593 } |
| 3594 | 3594 |
| 3595 } // namespace autofill | 3595 } // namespace autofill |
| OLD | NEW |