| 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 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1418 // Expiration Year. | 1418 // Expiration Year. |
| 1419 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 1419 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 1420 form_structure->field(4)->heuristic_type()); | 1420 form_structure->field(4)->heuristic_type()); |
| 1421 // CVC code. | 1421 // CVC code. |
| 1422 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, | 1422 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, |
| 1423 form_structure->field(5)->heuristic_type()); | 1423 form_structure->field(5)->heuristic_type()); |
| 1424 } | 1424 } |
| 1425 | 1425 |
| 1426 TEST(FormStructureTest, EncodeQueryRequest) { | 1426 TEST(FormStructureTest, EncodeQueryRequest) { |
| 1427 FormData form; | 1427 FormData form; |
| 1428 form.name = ASCIIToUTF16("shipping-form"); | |
| 1429 | 1428 |
| 1430 FormFieldData field; | 1429 FormFieldData field; |
| 1431 field.form_control_type = "text"; | 1430 field.form_control_type = "text"; |
| 1432 | 1431 |
| 1433 field.label = ASCIIToUTF16("Name on Card"); | 1432 field.label = ASCIIToUTF16("Name on Card"); |
| 1434 field.name = ASCIIToUTF16("name_on_card"); | 1433 field.name = ASCIIToUTF16("name_on_card"); |
| 1435 form.fields.push_back(field); | 1434 form.fields.push_back(field); |
| 1436 | 1435 |
| 1437 field.label = ASCIIToUTF16("Address"); | 1436 field.label = ASCIIToUTF16("Address"); |
| 1438 field.name = ASCIIToUTF16("billing_address"); | 1437 field.name = ASCIIToUTF16("billing_address"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1454 FormFieldData checkable_field; | 1453 FormFieldData checkable_field; |
| 1455 checkable_field.is_checkable = true; | 1454 checkable_field.is_checkable = true; |
| 1456 checkable_field.label = ASCIIToUTF16("Checkable1"); | 1455 checkable_field.label = ASCIIToUTF16("Checkable1"); |
| 1457 checkable_field.name = ASCIIToUTF16("Checkable1"); | 1456 checkable_field.name = ASCIIToUTF16("Checkable1"); |
| 1458 form.fields.push_back(checkable_field); | 1457 form.fields.push_back(checkable_field); |
| 1459 | 1458 |
| 1460 ScopedVector<FormStructure> forms; | 1459 ScopedVector<FormStructure> forms; |
| 1461 forms.push_back(new FormStructure(form)); | 1460 forms.push_back(new FormStructure(form)); |
| 1462 std::vector<std::string> encoded_signatures; | 1461 std::vector<std::string> encoded_signatures; |
| 1463 std::string encoded_xml; | 1462 std::string encoded_xml; |
| 1464 const char kSignature1[] = "18299433261292307089"; | 1463 const char kSignature1[] = "11337937696949187602"; |
| 1465 const char kResponse1[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 1464 const char kResponse1[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 1466 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 1465 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
| 1467 "<form signature=\"18299433261292307089\" name=\"shipping-form\">" | 1466 "<form signature=\"11337937696949187602\">" |
| 1468 "<field signature=\"412125936\" name=\"name_on_card\" type=\"text\"/>" | 1467 "<field signature=\"412125936\" name=\"name_on_card\" type=\"text\"/>" |
| 1469 "<field signature=\"1917667676\" name=\"billing_address\" type=\"text\"/>" | 1468 "<field signature=\"1917667676\" name=\"billing_address\" type=\"text\"/>" |
| 1470 "<field signature=\"2226358947\" name=\"card_number\" type=\"text\"/>" | 1469 "<field signature=\"2226358947\" name=\"card_number\" type=\"text\"/>" |
| 1471 "<field signature=\"747221617\" name=\"expiration_month\" type=\"text\"/>" | 1470 "<field signature=\"747221617\" name=\"expiration_month\" type=\"text\"/>" |
| 1472 "<field signature=\"4108155786\" name=\"expiration_year\" type=\"text\"/>" | 1471 "<field signature=\"4108155786\" name=\"expiration_year\" type=\"text\"/>" |
| 1473 "</form></autofillquery>"; | 1472 "</form></autofillquery>"; |
| 1474 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1473 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 1475 &encoded_signatures, | 1474 &encoded_signatures, |
| 1476 &encoded_xml)); | 1475 &encoded_xml)); |
| 1477 ASSERT_EQ(1U, encoded_signatures.size()); | 1476 ASSERT_EQ(1U, encoded_signatures.size()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1493 field.name = ASCIIToUTF16("address"); | 1492 field.name = ASCIIToUTF16("address"); |
| 1494 form.fields.push_back(field); | 1493 form.fields.push_back(field); |
| 1495 } | 1494 } |
| 1496 | 1495 |
| 1497 forms.push_back(new FormStructure(form)); | 1496 forms.push_back(new FormStructure(form)); |
| 1498 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1497 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 1499 &encoded_signatures, | 1498 &encoded_signatures, |
| 1500 &encoded_xml)); | 1499 &encoded_xml)); |
| 1501 ASSERT_EQ(2U, encoded_signatures.size()); | 1500 ASSERT_EQ(2U, encoded_signatures.size()); |
| 1502 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1501 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
| 1503 const char kSignature2[] = "12765336621163642783"; | 1502 const char kSignature2[] = "8308881815906226214"; |
| 1504 EXPECT_EQ(kSignature2, encoded_signatures[1]); | 1503 EXPECT_EQ(kSignature2, encoded_signatures[1]); |
| 1505 const char kResponse2[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 1504 const char kResponse2[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 1506 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 1505 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
| 1507 "<form signature=\"18299433261292307089\" name=\"shipping-form\">" | 1506 "<form signature=\"11337937696949187602\">" |
| 1508 "<field signature=\"412125936\" name=\"name_on_card\" type=\"text\"/>" | 1507 "<field signature=\"412125936\" name=\"name_on_card\" type=\"text\"/>" |
| 1509 "<field signature=\"1917667676\" name=\"billing_address\" type=\"text\"/>" | 1508 "<field signature=\"1917667676\" name=\"billing_address\" type=\"text\"/>" |
| 1510 "<field signature=\"2226358947\" name=\"card_number\" type=\"text\"/>" | 1509 "<field signature=\"2226358947\" name=\"card_number\" type=\"text\"/>" |
| 1511 "<field signature=\"747221617\" name=\"expiration_month\" type=\"text\"/>" | 1510 "<field signature=\"747221617\" name=\"expiration_month\" type=\"text\"/>" |
| 1512 "<field signature=\"4108155786\" name=\"expiration_year\" type=\"text\"/>" | 1511 "<field signature=\"4108155786\" name=\"expiration_year\" type=\"text\"/>" |
| 1513 "</form><form signature=\"12765336621163642783\" name=\"shipping-form\">" | 1512 "</form><form signature=\"8308881815906226214\">" |
| 1514 "<field signature=\"412125936\" name=\"name_on_card\" type=\"text\"/>" | 1513 "<field signature=\"412125936\" name=\"name_on_card\" type=\"text\"/>" |
| 1515 "<field signature=\"1917667676\" name=\"billing_address\" type=\"text\"/>" | 1514 "<field signature=\"1917667676\" name=\"billing_address\" type=\"text\"/>" |
| 1516 "<field signature=\"2226358947\" name=\"card_number\" type=\"text\"/>" | 1515 "<field signature=\"2226358947\" name=\"card_number\" type=\"text\"/>" |
| 1517 "<field signature=\"747221617\" name=\"expiration_month\" type=\"text\"/>" | 1516 "<field signature=\"747221617\" name=\"expiration_month\" type=\"text\"/>" |
| 1518 "<field signature=\"4108155786\" name=\"expiration_year\" type=\"text\"/>" | 1517 "<field signature=\"4108155786\" name=\"expiration_year\" type=\"text\"/>" |
| 1519 "<field signature=\"509334676\" name=\"address\" type=\"text\"/>" | 1518 "<field signature=\"509334676\" name=\"address\" type=\"text\"/>" |
| 1520 "<field signature=\"509334676\" name=\"address\" type=\"text\"/>" | 1519 "<field signature=\"509334676\" name=\"address\" type=\"text\"/>" |
| 1521 "<field signature=\"509334676\" name=\"address\" type=\"text\"/>" | 1520 "<field signature=\"509334676\" name=\"address\" type=\"text\"/>" |
| 1522 "<field signature=\"509334676\" name=\"address\" type=\"text\"/>" | 1521 "<field signature=\"509334676\" name=\"address\" type=\"text\"/>" |
| 1523 "<field signature=\"509334676\" name=\"address\" type=\"text\"/></form>" | 1522 "<field signature=\"509334676\" name=\"address\" type=\"text\"/>" |
| 1524 "</autofillquery>"; | 1523 "</form></autofillquery>"; |
| 1525 EXPECT_EQ(kResponse2, encoded_xml); | 1524 EXPECT_EQ(kResponse2, encoded_xml); |
| 1526 | 1525 |
| 1527 FormData malformed_form(form); | 1526 FormData malformed_form(form); |
| 1528 // Add 50 address fields - the form is not valid anymore, but previous ones | 1527 // Add 50 address fields - the form is not valid anymore, but previous ones |
| 1529 // are. The result should be the same as in previous test. | 1528 // are. The result should be the same as in previous test. |
| 1530 for (size_t i = 0; i < 50; ++i) { | 1529 for (size_t i = 0; i < 50; ++i) { |
| 1531 field.label = ASCIIToUTF16("Address"); | 1530 field.label = ASCIIToUTF16("Address"); |
| 1532 field.name = ASCIIToUTF16("address"); | 1531 field.name = ASCIIToUTF16("address"); |
| 1533 malformed_form.fields.push_back(field); | 1532 malformed_form.fields.push_back(field); |
| 1534 } | 1533 } |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2476 form.fields.push_back(field); | 2475 form.fields.push_back(field); |
| 2477 | 2476 |
| 2478 ScopedVector<FormStructure> forms; | 2477 ScopedVector<FormStructure> forms; |
| 2479 forms.push_back(new FormStructure(form)); | 2478 forms.push_back(new FormStructure(form)); |
| 2480 std::vector<std::string> encoded_signatures; | 2479 std::vector<std::string> encoded_signatures; |
| 2481 std::string encoded_xml; | 2480 std::string encoded_xml; |
| 2482 | 2481 |
| 2483 const char kSignature[] = "18006745212084723782"; | 2482 const char kSignature[] = "18006745212084723782"; |
| 2484 const char kResponse[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 2483 const char kResponse[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 2485 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 2484 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
| 2486 "<form signature=\"18006745212084723782\" name=\"the-name\">" | 2485 "<form signature=\"18006745212084723782\">" |
| 2487 "<field signature=\"239111655\" name=\"username\" type=\"text\"/>" | 2486 "<field signature=\"239111655\" name=\"username\" type=\"text\"/>" |
| 2488 "<field signature=\"420638584\" name=\"email\" type=\"text\"/></form>" | 2487 "<field signature=\"420638584\" name=\"email\" type=\"text\"/></form>" |
| 2489 "</autofillquery>"; | 2488 "</autofillquery>"; |
| 2490 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 2489 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 2491 &encoded_signatures, | 2490 &encoded_signatures, |
| 2492 &encoded_xml)); | 2491 &encoded_xml)); |
| 2493 ASSERT_EQ(1U, encoded_signatures.size()); | 2492 ASSERT_EQ(1U, encoded_signatures.size()); |
| 2494 EXPECT_EQ(kSignature, encoded_signatures[0]); | 2493 EXPECT_EQ(kSignature, encoded_signatures[0]); |
| 2495 EXPECT_EQ(kResponse, encoded_xml); | 2494 EXPECT_EQ(kResponse, encoded_xml); |
| 2496 } | 2495 } |
| 2497 | 2496 |
| 2498 // Some of the names are missing from the form and one field. | 2497 // One name is missing from one field. |
| 2499 TEST(FormStructureTest, EncodeQueryRequest_MissingNames) { | 2498 TEST(FormStructureTest, EncodeQueryRequest_MissingNames) { |
| 2500 FormData form; | 2499 FormData form; |
| 2501 // No name set for the form. | 2500 // No name set for the form. |
| 2502 form.origin = GURL("http://cool.com"); | 2501 form.origin = GURL("http://cool.com"); |
| 2503 form.action = form.origin.Resolve("/login"); | 2502 form.action = form.origin.Resolve("/login"); |
| 2504 | 2503 |
| 2505 FormFieldData field; | 2504 FormFieldData field; |
| 2506 field.label = ASCIIToUTF16("username"); | 2505 field.label = ASCIIToUTF16("username"); |
| 2507 field.name = ASCIIToUTF16("username"); | 2506 field.name = ASCIIToUTF16("username"); |
| 2508 field.form_control_type = "text"; | 2507 field.form_control_type = "text"; |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2810 "</autofillqueryresponse>"; | 2809 "</autofillqueryresponse>"; |
| 2811 | 2810 |
| 2812 FormStructure::ParseQueryResponse(response, forms.get(), &rappor_service); | 2811 FormStructure::ParseQueryResponse(response, forms.get(), &rappor_service); |
| 2813 | 2812 |
| 2814 // No RAPPOR metrics are logged in the case there is at least some server data | 2813 // No RAPPOR metrics are logged in the case there is at least some server data |
| 2815 // available for all forms. | 2814 // available for all forms. |
| 2816 EXPECT_EQ(0, rappor_service.GetReportsCount()); | 2815 EXPECT_EQ(0, rappor_service.GetReportsCount()); |
| 2817 } | 2816 } |
| 2818 | 2817 |
| 2819 } // namespace autofill | 2818 } // namespace autofill |
| OLD | NEW |