Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: chrome/browser/autofill/form_structure_unittest.cc

Issue 6931029: Set datapresent string to contain precisely those field types available in stored Autofill data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't SetInfo() for read-only fields Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/autofill/form_structure.h" 8 #include "chrome/browser/autofill/form_structure.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 0, 1377 0,
1378 false)); 1378 false));
1379 possible_field_types.push_back(FieldTypeSet()); 1379 possible_field_types.push_back(FieldTypeSet());
1380 possible_field_types.back().insert(PHONE_FAX_WHOLE_NUMBER); 1380 possible_field_types.back().insert(PHONE_FAX_WHOLE_NUMBER);
1381 form_structure.reset(new FormStructure(form)); 1381 form_structure.reset(new FormStructure(form));
1382 1382
1383 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1383 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1384 for (size_t i = 0; i < form_structure->field_count(); ++i) 1384 for (size_t i = 0; i < form_structure->field_count(); ++i)
1385 form_structure->set_possible_types(i, possible_field_types[i]); 1385 form_structure->set_possible_types(i, possible_field_types[i]);
1386 1386
1387 // TODO(isherman):
dhollowa 2011/05/06 03:06:20 TODO?
Ilya Sherman 2011/05/06 03:33:07 Oops, to-done. =)
1388 FieldTypeSet available_field_types;
1389 available_field_types.insert(NAME_FIRST);
1390 available_field_types.insert(NAME_LAST);
1391 available_field_types.insert(ADDRESS_HOME_LINE1);
1392 available_field_types.insert(ADDRESS_HOME_LINE2);
1393 available_field_types.insert(ADDRESS_HOME_COUNTRY);
1394 available_field_types.insert(ADDRESS_BILLING_LINE1);
1395 available_field_types.insert(ADDRESS_BILLING_LINE2);
1396 available_field_types.insert(EMAIL_ADDRESS);
1397 available_field_types.insert(PHONE_HOME_WHOLE_NUMBER);
1398 available_field_types.insert(PHONE_FAX_WHOLE_NUMBER);
1399
1387 std::string encoded_xml; 1400 std::string encoded_xml;
1388 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1401 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1402 &encoded_xml));
1389 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1403 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1390 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " 1404 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" "
1391 "formsignature=\"7641728017676399335\" autofillused=\"false\" " 1405 "formsignature=\"7641728017676399335\" autofillused=\"false\" "
1392 "datapresent=\"1442008008\">" 1406 "datapresent=\"144200830e\">"
1393 "<field signature=\"3763331450\" autofilltype=\"3\"/>" 1407 "<field signature=\"3763331450\" autofilltype=\"3\"/>"
1394 "<field signature=\"3494530716\" autofilltype=\"5\"/>" 1408 "<field signature=\"3494530716\" autofilltype=\"5\"/>"
1395 "<field signature=\"1029417091\" autofilltype=\"9\"/>" 1409 "<field signature=\"1029417091\" autofilltype=\"9\"/>"
1396 "<field signature=\"466116101\" autofilltype=\"14\"/>" 1410 "<field signature=\"466116101\" autofilltype=\"14\"/>"
1397 "<field signature=\"2799270304\" autofilltype=\"36\"/>" 1411 "<field signature=\"2799270304\" autofilltype=\"36\"/>"
1398 "<field signature=\"1876771436\" autofilltype=\"24\"/>" 1412 "<field signature=\"1876771436\" autofilltype=\"24\"/>"
1399 "</autofillupload>", 1413 "</autofillupload>",
1400 encoded_xml); 1414 encoded_xml);
1401 EXPECT_TRUE(form_structure->EncodeUploadRequest(true, &encoded_xml)); 1415 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, true,
1416 &encoded_xml));
1402 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1417 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1403 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " 1418 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" "
1404 "formsignature=\"7641728017676399335\" autofillused=\"true\" " 1419 "formsignature=\"7641728017676399335\" autofillused=\"true\" "
1405 "datapresent=\"1442008008\">" 1420 "datapresent=\"144200830e\">"
1406 "<field signature=\"3763331450\" autofilltype=\"3\"/>" 1421 "<field signature=\"3763331450\" autofilltype=\"3\"/>"
1407 "<field signature=\"3494530716\" autofilltype=\"5\"/>" 1422 "<field signature=\"3494530716\" autofilltype=\"5\"/>"
1408 "<field signature=\"1029417091\" autofilltype=\"9\"/>" 1423 "<field signature=\"1029417091\" autofilltype=\"9\"/>"
1409 "<field signature=\"466116101\" autofilltype=\"14\"/>" 1424 "<field signature=\"466116101\" autofilltype=\"14\"/>"
1410 "<field signature=\"2799270304\" autofilltype=\"36\"/>" 1425 "<field signature=\"2799270304\" autofilltype=\"36\"/>"
1411 "<field signature=\"1876771436\" autofilltype=\"24\"/>" 1426 "<field signature=\"1876771436\" autofilltype=\"24\"/>"
1412 "</autofillupload>", 1427 "</autofillupload>",
1413 encoded_xml); 1428 encoded_xml);
1414 1429
1415 // Add 2 address fields - this should be still a valid form. 1430 // Add 2 address fields - this should be still a valid form.
1416 for (size_t i = 0; i < 2; ++i) { 1431 for (size_t i = 0; i < 2; ++i) {
1417 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 1432 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"),
1418 ASCIIToUTF16("address"), 1433 ASCIIToUTF16("address"),
1419 string16(), 1434 string16(),
1420 ASCIIToUTF16("text"), 1435 ASCIIToUTF16("text"),
1421 0, 1436 0,
1422 false)); 1437 false));
1423 possible_field_types.push_back(FieldTypeSet()); 1438 possible_field_types.push_back(FieldTypeSet());
1424 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1439 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1425 possible_field_types.back().insert(ADDRESS_HOME_LINE2); 1440 possible_field_types.back().insert(ADDRESS_HOME_LINE2);
1426 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); 1441 possible_field_types.back().insert(ADDRESS_BILLING_LINE1);
1427 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); 1442 possible_field_types.back().insert(ADDRESS_BILLING_LINE2);
1428 } 1443 }
1444
1429 form_structure.reset(new FormStructure(form)); 1445 form_structure.reset(new FormStructure(form));
1430 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1446 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1431 for (size_t i = 0; i < form_structure->field_count(); ++i) 1447 for (size_t i = 0; i < form_structure->field_count(); ++i)
1432 form_structure->set_possible_types(i, possible_field_types[i]); 1448 form_structure->set_possible_types(i, possible_field_types[i]);
1433 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1449
1450 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1451 &encoded_xml));
1434 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1452 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1435 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " 1453 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" "
1436 "formsignature=\"12226592129574322128\" autofillused=\"false\" " 1454 "formsignature=\"12226592129574322128\" autofillused=\"false\" "
1437 "datapresent=\"144200830e\">" 1455 "datapresent=\"144200830e\">"
1438 "<field signature=\"3763331450\" autofilltype=\"3\"/>" 1456 "<field signature=\"3763331450\" autofilltype=\"3\"/>"
1439 "<field signature=\"3494530716\" autofilltype=\"5\"/>" 1457 "<field signature=\"3494530716\" autofilltype=\"5\"/>"
1440 "<field signature=\"1029417091\" autofilltype=\"9\"/>" 1458 "<field signature=\"1029417091\" autofilltype=\"9\"/>"
1441 "<field signature=\"466116101\" autofilltype=\"14\"/>" 1459 "<field signature=\"466116101\" autofilltype=\"14\"/>"
1442 "<field signature=\"2799270304\" autofilltype=\"36\"/>" 1460 "<field signature=\"2799270304\" autofilltype=\"36\"/>"
1443 "<field signature=\"1876771436\" autofilltype=\"24\"/>" 1461 "<field signature=\"1876771436\" autofilltype=\"24\"/>"
(...skipping 19 matching lines...) Expand all
1463 possible_field_types.push_back(FieldTypeSet()); 1481 possible_field_types.push_back(FieldTypeSet());
1464 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1482 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1465 possible_field_types.back().insert(ADDRESS_HOME_LINE2); 1483 possible_field_types.back().insert(ADDRESS_HOME_LINE2);
1466 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); 1484 possible_field_types.back().insert(ADDRESS_BILLING_LINE1);
1467 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); 1485 possible_field_types.back().insert(ADDRESS_BILLING_LINE2);
1468 } 1486 }
1469 form_structure.reset(new FormStructure(form)); 1487 form_structure.reset(new FormStructure(form));
1470 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1488 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1471 for (size_t i = 0; i < form_structure->field_count(); ++i) 1489 for (size_t i = 0; i < form_structure->field_count(); ++i)
1472 form_structure->set_possible_types(i, possible_field_types[i]); 1490 form_structure->set_possible_types(i, possible_field_types[i]);
1473 EXPECT_FALSE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1491 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false,
1474 EXPECT_EQ("", encoded_xml); 1492 &encoded_xml));
1475 } 1493 }
1476 1494
1495 // Check that we computer the "datapresent" string correctly for the given
1496 // |available_types|.
1477 TEST(FormStructureTest, CheckDataPresence) { 1497 TEST(FormStructureTest, CheckDataPresence) {
1478 // Checks bits set in the datapresence field: for each type in the form
1479 // relevant bit in datapresence has to be set.
1480 scoped_ptr<FormStructure> form_structure;
1481 std::vector<FieldTypeSet> possible_field_types;
1482 FormData form; 1498 FormData form;
1483 form.method = ASCIIToUTF16("post"); 1499 form.method = ASCIIToUTF16("post");
1484 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), 1500 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"),
1485 ASCIIToUTF16("first"), 1501 ASCIIToUTF16("first"),
1486 string16(), 1502 string16(),
1487 ASCIIToUTF16("text"), 1503 ASCIIToUTF16("text"),
1488 0, 1504 0,
1489 false)); 1505 false));
1490 possible_field_types.push_back(FieldTypeSet());
1491 possible_field_types.back().insert(NAME_FIRST);
1492 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), 1506 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"),
1493 ASCIIToUTF16("last"), 1507 ASCIIToUTF16("last"),
1494 string16(), 1508 string16(),
1495 ASCIIToUTF16("text"), 1509 ASCIIToUTF16("text"),
1496 0, 1510 0,
1497 false)); 1511 false));
1498 possible_field_types.push_back(FieldTypeSet());
1499 possible_field_types.back().insert(NAME_LAST);
1500 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), 1512 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"),
1501 ASCIIToUTF16("email"), 1513 ASCIIToUTF16("email"),
1502 string16(), 1514 string16(),
1503 ASCIIToUTF16("text"), 1515 ASCIIToUTF16("text"),
1504 0, 1516 0,
1505 false)); 1517 false));
1506 possible_field_types.push_back(FieldTypeSet()); 1518
1507 possible_field_types.back().insert(EMAIL_ADDRESS); 1519 FormStructure form_structure(form);
1508 form_structure.reset(new FormStructure(form)); 1520
1509 for (size_t i = 0; i < form_structure->field_count(); ++i) 1521 FieldTypeSet unknown_type;
1510 form_structure->set_possible_types(i, possible_field_types[i]); 1522 unknown_type.insert(UNKNOWN_TYPE);
1523 for (size_t i = 0; i < form_structure.field_count(); ++i)
1524 form_structure.set_possible_types(i, unknown_type);
1525
1526 // No available types.
1527 // datapresent should be "" == trimmmed(0x0000000000000000) ==
1528 // 0b0000000000000000000000000000000000000000000000000000000000000000
1529 FieldTypeSet available_field_types;
1530
1511 std::string encoded_xml; 1531 std::string encoded_xml;
1512 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1532 EXPECT_TRUE(form_structure.EncodeUploadRequest(available_field_types, false,
1513 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " 1533 &encoded_xml));
1514 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" 1534 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1515 "6402244543831589061\" autofillused=\"false\" " 1535 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1516 "datapresent=\"1440\"><field signature=\"1089846351\" ", 1536 " formsignature=\"6402244543831589061\" autofillused=\"false\""
1517 encoded_xml.substr(0, 200)); 1537 " datapresent=\"\">"
1518 1538 "<field signature=\"1089846351\" autofilltype=\"1\"/>"
1519 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 1539 "<field signature=\"2404144663\" autofilltype=\"1\"/>"
1520 ASCIIToUTF16("address"), 1540 "<field signature=\"420638584\" autofilltype=\"1\"/>"
1521 string16(), 1541 "</autofillupload>",
1522 ASCIIToUTF16("text"), 1542 encoded_xml);
1523 0, 1543
1524 false)); 1544 // Only a few types available.
1525 possible_field_types.push_back(FieldTypeSet()); 1545 // datapresent should be "1540000240" == trimmmed(0x1540000240000000) ==
1526 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1546 // 0b0001010101000000000000000000001001000000000000000000000000000000
1527 form_structure.reset(new FormStructure(form)); 1547 // The set bits are:
1528 for (size_t i = 0; i < form_structure->field_count(); ++i) 1548 // 3 == NAME_FIRST
1529 form_structure->set_possible_types(i, possible_field_types[i]); 1549 // 5 == NAME_LAST
1530 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1550 // 7 == NAME_FULL
1531 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " 1551 // 9 == EMAIL_ADDRESS
1532 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" 1552 // 30 == ADDRESS_HOME_LINE1
1533 "11817937699000629499\" autofillused=\"false\" " 1553 // 33 == ADDRESS_HOME_CITY
1534 "datapresent=\"14400002\"><field signature=\"1089846", 1554 available_field_types.clear();
1535 encoded_xml.substr(0, 200)); 1555 available_field_types.insert(NAME_FIRST);
1536 1556 available_field_types.insert(NAME_LAST);
1537 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("F4"), 1557 available_field_types.insert(NAME_FULL);
1538 ASCIIToUTF16("f4"), 1558 available_field_types.insert(EMAIL_ADDRESS);
1539 string16(), 1559 available_field_types.insert(ADDRESS_HOME_LINE1);
1540 ASCIIToUTF16("text"), 1560 available_field_types.insert(ADDRESS_HOME_CITY);
1541 0, 1561
1542 false)); 1562 EXPECT_TRUE(form_structure.EncodeUploadRequest(available_field_types, false,
1543 possible_field_types.push_back(FieldTypeSet()); 1563 &encoded_xml));
1544 possible_field_types.back().insert(CREDIT_CARD_TYPE); 1564 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1545 form_structure.reset(new FormStructure(form)); 1565 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1546 for (size_t i = 0; i < form_structure->field_count(); ++i) 1566 " formsignature=\"6402244543831589061\" autofillused=\"false\""
1547 form_structure->set_possible_types(i, possible_field_types[i]); 1567 " datapresent=\"1540000240\">"
1548 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1568 "<field signature=\"1089846351\" autofilltype=\"1\"/>"
1549 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " 1569 "<field signature=\"2404144663\" autofilltype=\"1\"/>"
1550 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" 1570 "<field signature=\"420638584\" autofilltype=\"1\"/>"
1551 "15126663683491865216\" autofillused=\"false\" " 1571 "</autofillupload>",
1552 "datapresent=\"1440000200000020\"><field signature=", 1572 encoded_xml);
1553 encoded_xml.substr(0, 200)); 1573
1574 // All supported non-credit card types available.
1575 // datapresent should be "1f7e0f8378000008" == trimmmed(0x1f7e0f8378000008) ==
1576 // 0b0001111101111110000011111000001101111000000000000000000000001000
1577 // The set bits are:
1578 // 3 == NAME_FIRST
1579 // 4 == NAME_MIDDLE
1580 // 5 == NAME_LAST
1581 // 6 == NAME_MIDDLE_INITIAL
1582 // 7 == NAME_FULL
1583 // 9 == EMAIL_ADDRESS
1584 // 10 == PHONE_HOME_NUMBER,
1585 // 11 == PHONE_HOME_CITY_CODE,
1586 // 12 == PHONE_HOME_COUNTRY_CODE,
1587 // 13 == PHONE_HOME_CITY_AND_NUMBER,
1588 // 14 == PHONE_HOME_WHOLE_NUMBER,
1589 // 20 == PHONE_FAX_NUMBER,
1590 // 21 == PHONE_FAX_CITY_CODE,
1591 // 22 == PHONE_FAX_COUNTRY_CODE,
1592 // 23 == PHONE_FAX_CITY_AND_NUMBER,
1593 // 24 == PHONE_FAX_WHOLE_NUMBER,
1594 // 30 == ADDRESS_HOME_LINE1
1595 // 31 == ADDRESS_HOME_LINE2
1596 // 33 == ADDRESS_HOME_CITY
1597 // 34 == ADDRESS_HOME_STATE
1598 // 35 == ADDRESS_HOME_ZIP
1599 // 36 == ADDRESS_HOME_COUNTRY
1600 // 60 == COMPANY_NAME
1601 available_field_types.clear();
1602 available_field_types.insert(NAME_FIRST);
1603 available_field_types.insert(NAME_MIDDLE);
1604 available_field_types.insert(NAME_LAST);
1605 available_field_types.insert(NAME_MIDDLE_INITIAL);
1606 available_field_types.insert(NAME_FULL);
1607 available_field_types.insert(EMAIL_ADDRESS);
1608 available_field_types.insert(PHONE_HOME_NUMBER);
1609 available_field_types.insert(PHONE_HOME_CITY_CODE);
1610 available_field_types.insert(PHONE_HOME_COUNTRY_CODE);
1611 available_field_types.insert(PHONE_HOME_CITY_AND_NUMBER);
1612 available_field_types.insert(PHONE_HOME_WHOLE_NUMBER);
1613 available_field_types.insert(PHONE_FAX_NUMBER);
1614 available_field_types.insert(PHONE_FAX_CITY_CODE);
1615 available_field_types.insert(PHONE_FAX_COUNTRY_CODE);
1616 available_field_types.insert(PHONE_FAX_CITY_AND_NUMBER);
1617 available_field_types.insert(PHONE_FAX_WHOLE_NUMBER);
1618 available_field_types.insert(ADDRESS_HOME_LINE1);
1619 available_field_types.insert(ADDRESS_HOME_LINE2);
1620 available_field_types.insert(ADDRESS_HOME_CITY);
1621 available_field_types.insert(ADDRESS_HOME_STATE);
1622 available_field_types.insert(ADDRESS_HOME_ZIP);
1623 available_field_types.insert(ADDRESS_HOME_COUNTRY);
1624 available_field_types.insert(COMPANY_NAME);
1625
1626 EXPECT_TRUE(form_structure.EncodeUploadRequest(available_field_types, false,
1627 &encoded_xml));
1628 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1629 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1630 " formsignature=\"6402244543831589061\" autofillused=\"false\""
1631 " datapresent=\"1f7e0f8378000008\">"
1632 "<field signature=\"1089846351\" autofilltype=\"1\"/>"
1633 "<field signature=\"2404144663\" autofilltype=\"1\"/>"
1634 "<field signature=\"420638584\" autofilltype=\"1\"/>"
1635 "</autofillupload>",
1636 encoded_xml);
1637
1638 // All supported credit card types available.
1639 // datapresent should be "0000000000001fc0" == trimmmed(0x0000000000001fc0) ==
1640 // 0b0000000000000000000000000000000000000000000000000001111111000000
1641 // The set bits are:
1642 // 51 == CREDIT_CARD_NAME
1643 // 52 == CREDIT_CARD_NUMBER
1644 // 53 == CREDIT_CARD_EXP_MONTH
1645 // 54 == CREDIT_CARD_EXP_2_DIGIT_YEAR
1646 // 55 == CREDIT_CARD_EXP_4_DIGIT_YEAR
1647 // 56 == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR
1648 // 57 == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR
1649 available_field_types.clear();
1650 available_field_types.insert(CREDIT_CARD_NAME);
1651 available_field_types.insert(CREDIT_CARD_NUMBER);
1652 available_field_types.insert(CREDIT_CARD_EXP_MONTH);
1653 available_field_types.insert(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1654 available_field_types.insert(CREDIT_CARD_EXP_4_DIGIT_YEAR);
1655 available_field_types.insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR);
1656 available_field_types.insert(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR);
1657
1658 EXPECT_TRUE(form_structure.EncodeUploadRequest(available_field_types, false,
1659 &encoded_xml));
1660 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1661 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1662 " formsignature=\"6402244543831589061\" autofillused=\"false\""
1663 " datapresent=\"0000000000001fc0\">"
1664 "<field signature=\"1089846351\" autofilltype=\"1\"/>"
1665 "<field signature=\"2404144663\" autofilltype=\"1\"/>"
1666 "<field signature=\"420638584\" autofilltype=\"1\"/>"
1667 "</autofillupload>",
1668 encoded_xml);
1669
1670 // All supported types available.
1671 // datapresent should be "1f7e0f8378001fc8" == trimmmed(0x1f7e0f8378001fc8) ==
1672 // 0b0001111101111110000011111000001101111000000000000001111111001000
1673 // The set bits are:
1674 // 3 == NAME_FIRST
1675 // 4 == NAME_MIDDLE
1676 // 5 == NAME_LAST
1677 // 6 == NAME_MIDDLE_INITIAL
1678 // 7 == NAME_FULL
1679 // 9 == EMAIL_ADDRESS
1680 // 10 == PHONE_HOME_NUMBER,
1681 // 11 == PHONE_HOME_CITY_CODE,
1682 // 12 == PHONE_HOME_COUNTRY_CODE,
1683 // 13 == PHONE_HOME_CITY_AND_NUMBER,
1684 // 14 == PHONE_HOME_WHOLE_NUMBER,
1685 // 20 == PHONE_FAX_NUMBER,
1686 // 21 == PHONE_FAX_CITY_CODE,
1687 // 22 == PHONE_FAX_COUNTRY_CODE,
1688 // 23 == PHONE_FAX_CITY_AND_NUMBER,
1689 // 24 == PHONE_FAX_WHOLE_NUMBER,
1690 // 30 == ADDRESS_HOME_LINE1
1691 // 31 == ADDRESS_HOME_LINE2
1692 // 33 == ADDRESS_HOME_CITY
1693 // 34 == ADDRESS_HOME_STATE
1694 // 35 == ADDRESS_HOME_ZIP
1695 // 36 == ADDRESS_HOME_COUNTRY
1696 // 51 == CREDIT_CARD_NAME
1697 // 52 == CREDIT_CARD_NUMBER
1698 // 53 == CREDIT_CARD_EXP_MONTH
1699 // 54 == CREDIT_CARD_EXP_2_DIGIT_YEAR
1700 // 55 == CREDIT_CARD_EXP_4_DIGIT_YEAR
1701 // 56 == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR
1702 // 57 == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR
1703 // 60 == COMPANY_NAME
1704 available_field_types.clear();
1705 available_field_types.insert(NAME_FIRST);
1706 available_field_types.insert(NAME_MIDDLE);
1707 available_field_types.insert(NAME_LAST);
1708 available_field_types.insert(NAME_MIDDLE_INITIAL);
1709 available_field_types.insert(NAME_FULL);
1710 available_field_types.insert(EMAIL_ADDRESS);
1711 available_field_types.insert(PHONE_HOME_NUMBER);
1712 available_field_types.insert(PHONE_HOME_CITY_CODE);
1713 available_field_types.insert(PHONE_HOME_COUNTRY_CODE);
1714 available_field_types.insert(PHONE_HOME_CITY_AND_NUMBER);
1715 available_field_types.insert(PHONE_HOME_WHOLE_NUMBER);
1716 available_field_types.insert(PHONE_FAX_NUMBER);
1717 available_field_types.insert(PHONE_FAX_CITY_CODE);
1718 available_field_types.insert(PHONE_FAX_COUNTRY_CODE);
1719 available_field_types.insert(PHONE_FAX_CITY_AND_NUMBER);
1720 available_field_types.insert(PHONE_FAX_WHOLE_NUMBER);
1721 available_field_types.insert(ADDRESS_HOME_LINE1);
1722 available_field_types.insert(ADDRESS_HOME_LINE2);
1723 available_field_types.insert(ADDRESS_HOME_CITY);
1724 available_field_types.insert(ADDRESS_HOME_STATE);
1725 available_field_types.insert(ADDRESS_HOME_ZIP);
1726 available_field_types.insert(ADDRESS_HOME_COUNTRY);
1727 available_field_types.insert(CREDIT_CARD_NAME);
1728 available_field_types.insert(CREDIT_CARD_NUMBER);
1729 available_field_types.insert(CREDIT_CARD_EXP_MONTH);
1730 available_field_types.insert(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1731 available_field_types.insert(CREDIT_CARD_EXP_4_DIGIT_YEAR);
1732 available_field_types.insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR);
1733 available_field_types.insert(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR);
1734 available_field_types.insert(COMPANY_NAME);
1735
1736 EXPECT_TRUE(form_structure.EncodeUploadRequest(available_field_types, false,
1737 &encoded_xml));
1738 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1739 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1740 " formsignature=\"6402244543831589061\" autofillused=\"false\""
1741 " datapresent=\"1f7e0f8378001fc8\">"
1742 "<field signature=\"1089846351\" autofilltype=\"1\"/>"
1743 "<field signature=\"2404144663\" autofilltype=\"1\"/>"
1744 "<field signature=\"420638584\" autofilltype=\"1\"/>"
1745 "</autofillupload>",
1746 encoded_xml);
1554 } 1747 }
1555 1748
1556 TEST(FormStructureTest, CheckMultipleTypes) { 1749 TEST(FormStructureTest, CheckMultipleTypes) {
1557 // Check that multiple types for the field are processed correctly, both in 1750 // Throughout this test, datapresent should be
1558 // datapresence and in actual field data. 1751 // 0x1440000360000008 ==
1752 // 0b0001010001000000000000000000001101100000000000000000000000001000
1753 // The set bits are:
1754 // 3 == NAME_FIRST
1755 // 5 == NAME_LAST
1756 // 9 == EMAIL_ADDRESS
1757 // 30 == ADDRESS_HOME_LINE1
1758 // 31 == ADDRESS_HOME_LINE2
1759 // 33 == ADDRESS_HOME_CITY
1760 // 34 == ADDRESS_HOME_STATE
1761 // 60 == COMPANY_NAME
1762 FieldTypeSet available_field_types;
1763 available_field_types.insert(NAME_FIRST);
1764 available_field_types.insert(NAME_LAST);
1765 available_field_types.insert(EMAIL_ADDRESS);
1766 available_field_types.insert(ADDRESS_HOME_LINE1);
1767 available_field_types.insert(ADDRESS_HOME_LINE2);
1768 available_field_types.insert(ADDRESS_HOME_CITY);
1769 available_field_types.insert(ADDRESS_HOME_STATE);
1770 available_field_types.insert(COMPANY_NAME);
1771
1772 // Check that multiple types for the field are processed correctly.
1559 scoped_ptr<FormStructure> form_structure; 1773 scoped_ptr<FormStructure> form_structure;
1560 std::vector<FieldTypeSet> possible_field_types; 1774 std::vector<FieldTypeSet> possible_field_types;
1561 FormData form; 1775 FormData form;
1562 form.method = ASCIIToUTF16("post"); 1776 form.method = ASCIIToUTF16("post");
1563 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), 1777 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"),
1564 ASCIIToUTF16("email"), 1778 ASCIIToUTF16("email"),
1565 string16(), 1779 string16(),
1566 ASCIIToUTF16("text"), 1780 ASCIIToUTF16("text"),
1567 0, 1781 0,
1568 false)); 1782 false));
(...skipping 17 matching lines...) Expand all
1586 possible_field_types.back().insert(NAME_LAST); 1800 possible_field_types.back().insert(NAME_LAST);
1587 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), 1801 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"),
1588 ASCIIToUTF16("address"), 1802 ASCIIToUTF16("address"),
1589 string16(), 1803 string16(),
1590 ASCIIToUTF16("text"), 1804 ASCIIToUTF16("text"),
1591 0, 1805 0,
1592 false)); 1806 false));
1593 possible_field_types.push_back(FieldTypeSet()); 1807 possible_field_types.push_back(FieldTypeSet());
1594 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1808 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1595 form_structure.reset(new FormStructure(form)); 1809 form_structure.reset(new FormStructure(form));
1810
1596 for (size_t i = 0; i < form_structure->field_count(); ++i) 1811 for (size_t i = 0; i < form_structure->field_count(); ++i)
1597 form_structure->set_possible_types(i, possible_field_types[i]); 1812 form_structure->set_possible_types(i, possible_field_types[i]);
1598 std::string encoded_xml; 1813 std::string encoded_xml;
1814
1599 // Now we matched both fields singularly. 1815 // Now we matched both fields singularly.
1600 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1816 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1601 // datapresent==14400002==00010100010000000000000000000010b set bits are: 1817 &encoded_xml));
1602 // #3 == NAME_FIRST 1818 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1603 // #5 == NAME_LAST 1819 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1604 // #9 == EMAIL_ADDRESS 1820 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1605 // #30 == ADDRESS_HOME_LINE1 1821 " datapresent=\"1440000360000008\">"
1606 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " 1822 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1607 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" 1823 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1608 "18062476096658145866\" autofillused=\"false\" datapresent=" 1824 "<field signature=\"2404144663\" autofilltype=\"5\"/>"
1609 "\"14400002\"><field signature=\"420638584\" autofilltype=" 1825 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1610 "\"9\"/><field signature=\"1089846351\" autofilltype=\"3\"/><field " 1826 "</autofillupload>",
1611 "signature=\"2404144663\" autofilltype=\"5\"/><field signature="
1612 "\"509334676\" autofilltype=\"30\"/></autofillupload>",
1613 encoded_xml); 1827 encoded_xml);
1614 // Match third field as both first and last. 1828 // Match third field as both first and last.
1615 possible_field_types[2].insert(NAME_FIRST); 1829 possible_field_types[2].insert(NAME_FIRST);
1616 form_structure->set_possible_types(2, possible_field_types[2]); 1830 form_structure->set_possible_types(2, possible_field_types[2]);
1617 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1831 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1618 // datapresent==14400002==00010100010000000000000000000010b set bits are: 1832 &encoded_xml));
1619 // #3 == NAME_FIRST 1833 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1620 // #5 == NAME_LAST 1834 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1621 // #9 == EMAIL_ADDRESS 1835 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1622 // #30 == ADDRESS_HOME_LINE1 1836 " datapresent=\"1440000360000008\">"
1623 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " 1837 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1624 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" 1838 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1625 "18062476096658145866\" autofillused=\"false\" datapresent=" 1839 "<field signature=\"2404144663\" autofilltype=\"3\"/>"
1626 "\"14400002\"><field signature=\"420638584\" autofilltype=" 1840 "<field signature=\"2404144663\" autofilltype=\"5\"/>"
1627 "\"9\"/><field signature=\"1089846351\" autofilltype=\"3\"/><field " 1841 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1628 "signature=\"2404144663\" autofilltype=\"3\"/><field " 1842 "</autofillupload>",
1629 "signature=\"2404144663\" autofilltype=\"5\"/><field signature="
1630 "\"509334676\" autofilltype=\"30\"/></autofillupload>",
1631 encoded_xml); 1843 encoded_xml);
1632 possible_field_types[3].insert(ADDRESS_BILLING_LINE1); 1844 possible_field_types[3].insert(ADDRESS_HOME_LINE2);
1633 form_structure->set_possible_types( 1845 form_structure->set_possible_types(
1634 form_structure->field_count() - 1, 1846 form_structure->field_count() - 1,
1635 possible_field_types[form_structure->field_count() - 1]); 1847 possible_field_types[form_structure->field_count() - 1]);
1636 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1848 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1637 // datapresent==1440000204==0001010001000000000000000000001000000100b set bits 1849 &encoded_xml));
1638 // are: 1850 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1639 // #3 == NAME_FIRST 1851 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1640 // #5 == NAME_LAST 1852 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1641 // #9 == EMAIL_ADDRESS 1853 " datapresent=\"1440000360000008\">"
1642 // #30 == ADDRESS_HOME_LINE1 1854 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1643 // #37 == ADDRESS_BILLING_LINE1 1855 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1644 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " 1856 "<field signature=\"2404144663\" autofilltype=\"3\"/>"
1645 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" 1857 "<field signature=\"2404144663\" autofilltype=\"5\"/>"
1646 "18062476096658145866\" autofillused=\"false\" datapresent=" 1858 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1647 "\"1440000204\"><field signature=\"420638584\" autofilltype=" 1859 "<field signature=\"509334676\" autofilltype=\"31\"/>"
1648 "\"9\"/><field signature=\"1089846351\" autofilltype=\"3\"/><field " 1860 "</autofillupload>",
1649 "signature=\"2404144663\" autofilltype=\"3\"/><field "
1650 "signature=\"2404144663\" autofilltype=\"5\"/><field signature="
1651 "\"509334676\" autofilltype=\"30\"/><field signature=\"509334676\" "
1652 "autofilltype=\"37\"/></autofillupload>",
1653 encoded_xml); 1861 encoded_xml);
1654 possible_field_types[3].clear(); 1862 possible_field_types[3].clear();
1655 possible_field_types[3].insert(ADDRESS_HOME_LINE1); 1863 possible_field_types[3].insert(ADDRESS_HOME_LINE1);
1656 possible_field_types[3].insert(ADDRESS_BILLING_LINE2); 1864 possible_field_types[3].insert(COMPANY_NAME);
1657 form_structure->set_possible_types( 1865 form_structure->set_possible_types(
1658 form_structure->field_count() - 1, 1866 form_structure->field_count() - 1,
1659 possible_field_types[form_structure->field_count() - 1]); 1867 possible_field_types[form_structure->field_count() - 1]);
1660 EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); 1868 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1661 // datapresent==1440000202==0001010001000000000000000000001000000010b set bits 1869 &encoded_xml));
1662 // are: 1870 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1663 // #3 == NAME_FIRST 1871 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1664 // #5 == NAME_LAST 1872 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1665 // #9 == EMAIL_ADDRESS 1873 " datapresent=\"1440000360000008\">"
1666 // #30 == ADDRESS_HOME_LINE1 1874 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1667 // #38 == ADDRESS_BILLING_LINE2 1875 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1668 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " 1876 "<field signature=\"2404144663\" autofilltype=\"3\"/>"
1669 "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" 1877 "<field signature=\"2404144663\" autofilltype=\"5\"/>"
1670 "18062476096658145866\" autofillused=\"false\" datapresent=" 1878 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1671 "\"1440000202\"><field signature=\"420638584\" autofilltype=" 1879 "<field signature=\"509334676\" autofilltype=\"60\"/>"
1672 "\"9\"/><field signature=\"1089846351\" autofilltype=\"3\"/><field " 1880 "</autofillupload>",
1673 "signature=\"2404144663\" autofilltype=\"3\"/><field "
1674 "signature=\"2404144663\" autofilltype=\"5\"/><field signature="
1675 "\"509334676\" autofilltype=\"30\"/><field signature=\"509334676\" "
1676 "autofilltype=\"38\"/></autofillupload>",
1677 encoded_xml); 1881 encoded_xml);
1678 } 1882 }
1679 1883
1680 TEST(FormStructureTest, CheckFormSignature) { 1884 TEST(FormStructureTest, CheckFormSignature) {
1681 // Check that form signature is created correctly. 1885 // Check that form signature is created correctly.
1682 scoped_ptr<FormStructure> form_structure; 1886 scoped_ptr<FormStructure> form_structure;
1683 FormData form; 1887 FormData form;
1684 form.method = ASCIIToUTF16("post"); 1888 form.method = ASCIIToUTF16("post");
1685 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), 1889 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"),
1686 ASCIIToUTF16("email"), 1890 ASCIIToUTF16("email"),
(...skipping 26 matching lines...) Expand all
1713 form_structure->FormSignature()); 1917 form_structure->FormSignature());
1714 1918
1715 form.name = ASCIIToUTF16("login_form"); 1919 form.name = ASCIIToUTF16("login_form");
1716 form_structure.reset(new FormStructure(form)); 1920 form_structure.reset(new FormStructure(form));
1717 EXPECT_EQ(FormStructureTest::Hash64Bit( 1921 EXPECT_EQ(FormStructureTest::Hash64Bit(
1718 std::string("https://login.facebook.com&login_form&email&first")), 1922 std::string("https://login.facebook.com&login_form&email&first")),
1719 form_structure->FormSignature()); 1923 form_structure->FormSignature());
1720 } 1924 }
1721 1925
1722 } // namespace 1926 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698