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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 field.form_control_type = "submit"; | 104 field.form_control_type = "submit"; |
105 form.fields.push_back(field); | 105 form.fields.push_back(field); |
106 | 106 |
107 // Only text and select fields that are heuristically matched are counted. | 107 // Only text and select fields that are heuristically matched are counted. |
108 form_structure.reset(new FormStructure(form)); | 108 form_structure.reset(new FormStructure(form)); |
109 form_structure->DetermineHeuristicTypes(); | 109 form_structure->DetermineHeuristicTypes(); |
110 EXPECT_EQ(1U, form_structure->autofill_count()); | 110 EXPECT_EQ(1U, form_structure->autofill_count()); |
111 | 111 |
112 // Add a field with should_autocomplete=false. This should not be considered a | 112 // Add a field with should_autocomplete=false. This should not be considered a |
113 // fillable field. | 113 // fillable field. |
114 field.label = ASCIIToUTF16("address1"); | 114 field.label = ASCIIToUTF16("city"); |
115 field.name = ASCIIToUTF16("address1"); | 115 field.name = ASCIIToUTF16("city"); |
116 field.form_control_type = "text"; | 116 field.form_control_type = "text"; |
117 field.should_autocomplete = false; | 117 field.should_autocomplete = false; |
118 form.fields.push_back(field); | 118 form.fields.push_back(field); |
119 | 119 |
120 form_structure.reset(new FormStructure(form)); | 120 form_structure.reset(new FormStructure(form)); |
121 form_structure->DetermineHeuristicTypes(); | 121 form_structure->DetermineHeuristicTypes(); |
122 EXPECT_EQ(2U, form_structure->autofill_count()); | 122 EXPECT_EQ(2U, form_structure->autofill_count()); |
123 | 123 |
124 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 124 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
125 switches::kRespectAutocompleteOffForAutofill); | 125 switches::kRespectAutocompleteOffForAutofill); |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 form.fields.push_back(field); | 1061 form.fields.push_back(field); |
1062 | 1062 |
1063 field.label = ASCIIToUTF16("Address Line3"); | 1063 field.label = ASCIIToUTF16("Address Line3"); |
1064 field.name = ASCIIToUTF16("billing.address.addressLine3"); | 1064 field.name = ASCIIToUTF16("billing.address.addressLine3"); |
1065 form.fields.push_back(field); | 1065 form.fields.push_back(field); |
1066 | 1066 |
1067 field.label = ASCIIToUTF16("Address Line4"); | 1067 field.label = ASCIIToUTF16("Address Line4"); |
1068 field.name = ASCIIToUTF16("billing.address.addressLine4"); | 1068 field.name = ASCIIToUTF16("billing.address.addressLine4"); |
1069 form.fields.push_back(field); | 1069 form.fields.push_back(field); |
1070 | 1070 |
| 1071 field.label = ASCIIToUTF16("City"); |
| 1072 field.name = ASCIIToUTF16("billing.address.city"); |
| 1073 form.fields.push_back(field); |
| 1074 |
1071 form_structure.reset(new FormStructure(form)); | 1075 form_structure.reset(new FormStructure(form)); |
1072 form_structure->DetermineHeuristicTypes(); | 1076 form_structure->DetermineHeuristicTypes(); |
1073 ASSERT_EQ(4U, form_structure->field_count()); | 1077 ASSERT_EQ(5U, form_structure->field_count()); |
1074 ASSERT_EQ(3U, form_structure->autofill_count()); | 1078 EXPECT_EQ(4U, form_structure->autofill_count()); |
1075 | 1079 |
1076 // Address Line 1. | 1080 // Address Line 1. |
1077 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1081 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
1078 // Address Line 2. | 1082 // Address Line 2. |
1079 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1083 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
1080 // Address Line 3. | 1084 // Address Line 3. |
1081 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); | 1085 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); |
1082 // Address Line 4 (ignored). | 1086 // Address Line 4 (ignored). |
1083 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); | 1087 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); |
1084 } | 1088 } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 field.form_control_type = "text"; | 1327 field.form_control_type = "text"; |
1324 | 1328 |
1325 field.label = ASCIIToUTF16("Name on Card"); | 1329 field.label = ASCIIToUTF16("Name on Card"); |
1326 field.name = ASCIIToUTF16("name_on_card"); | 1330 field.name = ASCIIToUTF16("name_on_card"); |
1327 form.fields.push_back(field); | 1331 form.fields.push_back(field); |
1328 | 1332 |
1329 field.label = ASCIIToUTF16("Address"); | 1333 field.label = ASCIIToUTF16("Address"); |
1330 field.name = ASCIIToUTF16("billing_address"); | 1334 field.name = ASCIIToUTF16("billing_address"); |
1331 form.fields.push_back(field); | 1335 form.fields.push_back(field); |
1332 | 1336 |
| 1337 field.label = ASCIIToUTF16("City"); |
| 1338 field.name = ASCIIToUTF16("city"); |
| 1339 form.fields.push_back(field); |
| 1340 |
1333 field.label = ASCIIToUTF16("Card Number"); | 1341 field.label = ASCIIToUTF16("Card Number"); |
1334 field.name = ASCIIToUTF16("card_number"); | 1342 field.name = ASCIIToUTF16("card_number"); |
1335 form.fields.push_back(field); | 1343 form.fields.push_back(field); |
1336 | 1344 |
1337 field.label = ASCIIToUTF16("Expiration Date"); | 1345 field.label = ASCIIToUTF16("Expiration Date"); |
1338 field.name = ASCIIToUTF16("expiration_month"); | 1346 field.name = ASCIIToUTF16("expiration_month"); |
1339 form.fields.push_back(field); | 1347 form.fields.push_back(field); |
1340 | 1348 |
1341 field.label = ASCIIToUTF16("Expiration Year"); | 1349 field.label = ASCIIToUTF16("Expiration Year"); |
1342 field.name = ASCIIToUTF16("expiration_year"); | 1350 field.name = ASCIIToUTF16("expiration_year"); |
1343 form.fields.push_back(field); | 1351 form.fields.push_back(field); |
1344 | 1352 |
1345 form_structure.reset(new FormStructure(form)); | 1353 form_structure.reset(new FormStructure(form)); |
1346 form_structure->DetermineHeuristicTypes(); | 1354 form_structure->DetermineHeuristicTypes(); |
1347 EXPECT_TRUE(form_structure->IsAutofillable()); | 1355 EXPECT_TRUE(form_structure->IsAutofillable()); |
1348 | 1356 |
1349 // Expect the correct number of fields. | 1357 // Expect the correct number of fields. |
1350 ASSERT_EQ(5U, form_structure->field_count()); | 1358 ASSERT_EQ(6U, form_structure->field_count()); |
1351 EXPECT_EQ(5U, form_structure->autofill_count()); | 1359 EXPECT_EQ(6U, form_structure->autofill_count()); |
1352 | 1360 |
1353 // Name on Card. | 1361 // Name on Card. |
1354 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); | 1362 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); |
1355 // Address. | 1363 // Address. |
1356 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(1)->heuristic_type()); | 1364 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(1)->heuristic_type()); |
| 1365 // City. |
| 1366 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type()); |
1357 // Card Number. | 1367 // Card Number. |
1358 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type()); | 1368 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(3)->heuristic_type()); |
1359 // Expiration Date. | 1369 // Expiration Date. |
1360 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); | 1370 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(4)->heuristic_type()); |
1361 // Expiration Year. | 1371 // Expiration Year. |
1362 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 1372 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
1363 form_structure->field(4)->heuristic_type()); | 1373 form_structure->field(5)->heuristic_type()); |
1364 } | 1374 } |
1365 | 1375 |
1366 TEST(FormStructureTest, CVCCodeClash) { | 1376 TEST(FormStructureTest, CVCCodeClash) { |
1367 scoped_ptr<FormStructure> form_structure; | 1377 scoped_ptr<FormStructure> form_structure; |
1368 FormData form; | 1378 FormData form; |
1369 | 1379 |
1370 FormFieldData field; | 1380 FormFieldData field; |
1371 field.form_control_type = "text"; | 1381 field.form_control_type = "text"; |
1372 | 1382 |
1373 field.label = ASCIIToUTF16("Card number"); | 1383 field.label = ASCIIToUTF16("Card number"); |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2413 std::string response = | 2423 std::string response = |
2414 "<autofillqueryresponse>" | 2424 "<autofillqueryresponse>" |
2415 "<field autofilltype=\"7\" />" | 2425 "<field autofilltype=\"7\" />" |
2416 "<field autofilltype=\"30\" />" | 2426 "<field autofilltype=\"30\" />" |
2417 "<field autofilltype=\"9\" />" | 2427 "<field autofilltype=\"9\" />" |
2418 "<field autofilltype=\"0\" />" | 2428 "<field autofilltype=\"0\" />" |
2419 "</autofillqueryresponse>"; | 2429 "</autofillqueryresponse>"; |
2420 | 2430 |
2421 FormStructure::ParseQueryResponse(response, forms.get()); | 2431 FormStructure::ParseQueryResponse(response, forms.get()); |
2422 | 2432 |
| 2433 ASSERT_GE(forms[0]->field_count(), 2U); |
| 2434 ASSERT_GE(forms[1]->field_count(), 2U); |
2423 EXPECT_EQ(7, forms[0]->field(0)->server_type()); | 2435 EXPECT_EQ(7, forms[0]->field(0)->server_type()); |
2424 EXPECT_EQ(30, forms[0]->field(1)->server_type()); | 2436 EXPECT_EQ(30, forms[0]->field(1)->server_type()); |
2425 EXPECT_EQ(9, forms[1]->field(0)->server_type()); | 2437 EXPECT_EQ(9, forms[1]->field(0)->server_type()); |
2426 EXPECT_EQ(0, forms[1]->field(1)->server_type()); | 2438 EXPECT_EQ(0, forms[1]->field(1)->server_type()); |
2427 } | 2439 } |
2428 | 2440 |
2429 // If user defined types are present, only parse password fields. | 2441 // If user defined types are present, only parse password fields. |
2430 TEST(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) { | 2442 TEST(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) { |
2431 FormData form; | 2443 FormData form; |
2432 FormFieldData field; | 2444 FormFieldData field; |
(...skipping 15 matching lines...) Expand all Loading... |
2448 forms.front()->DetermineHeuristicTypes(); | 2460 forms.front()->DetermineHeuristicTypes(); |
2449 | 2461 |
2450 std::string response = | 2462 std::string response = |
2451 "<autofillqueryresponse>" | 2463 "<autofillqueryresponse>" |
2452 "<field autofilltype=\"9\" />" | 2464 "<field autofilltype=\"9\" />" |
2453 "<field autofilltype=\"76\" />" | 2465 "<field autofilltype=\"76\" />" |
2454 "</autofillqueryresponse>"; | 2466 "</autofillqueryresponse>"; |
2455 | 2467 |
2456 FormStructure::ParseQueryResponse(response, forms.get()); | 2468 FormStructure::ParseQueryResponse(response, forms.get()); |
2457 | 2469 |
| 2470 ASSERT_GE(forms[0]->field_count(), 2U); |
2458 EXPECT_EQ(NO_SERVER_DATA, forms[0]->field(0)->server_type()); | 2471 EXPECT_EQ(NO_SERVER_DATA, forms[0]->field(0)->server_type()); |
2459 EXPECT_EQ(76, forms[0]->field(1)->server_type()); | 2472 EXPECT_EQ(76, forms[0]->field(1)->server_type()); |
2460 } | 2473 } |
2461 | 2474 |
2462 } // namespace autofill | 2475 } // namespace autofill |
OLD | NEW |