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

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

Issue 7747009: Add metrics to track Autofill "user happiness" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 field.label = ASCIIToUTF16("Fax"); 1456 field.label = ASCIIToUTF16("Fax");
1457 field.name = ASCIIToUTF16("fax"); 1457 field.name = ASCIIToUTF16("fax");
1458 field.form_control_type = ASCIIToUTF16("tel"); 1458 field.form_control_type = ASCIIToUTF16("tel");
1459 form.fields.push_back(field); 1459 form.fields.push_back(field);
1460 possible_field_types.push_back(FieldTypeSet()); 1460 possible_field_types.push_back(FieldTypeSet());
1461 possible_field_types.back().insert(PHONE_FAX_WHOLE_NUMBER); 1461 possible_field_types.back().insert(PHONE_FAX_WHOLE_NUMBER);
1462 form_structure.reset(new FormStructure(form)); 1462 form_structure.reset(new FormStructure(form));
1463 1463
1464 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1464 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1465 for (size_t i = 0; i < form_structure->field_count(); ++i) 1465 for (size_t i = 0; i < form_structure->field_count(); ++i)
1466 form_structure->set_possible_types(i, possible_field_types[i]); 1466 form_structure->field(i)->set_possible_types(possible_field_types[i]);
1467 1467
1468 FieldTypeSet available_field_types; 1468 FieldTypeSet available_field_types;
1469 available_field_types.insert(NAME_FIRST); 1469 available_field_types.insert(NAME_FIRST);
1470 available_field_types.insert(NAME_LAST); 1470 available_field_types.insert(NAME_LAST);
1471 available_field_types.insert(ADDRESS_HOME_LINE1); 1471 available_field_types.insert(ADDRESS_HOME_LINE1);
1472 available_field_types.insert(ADDRESS_HOME_LINE2); 1472 available_field_types.insert(ADDRESS_HOME_LINE2);
1473 available_field_types.insert(ADDRESS_HOME_COUNTRY); 1473 available_field_types.insert(ADDRESS_HOME_COUNTRY);
1474 available_field_types.insert(ADDRESS_BILLING_LINE1); 1474 available_field_types.insert(ADDRESS_BILLING_LINE1);
1475 available_field_types.insert(ADDRESS_BILLING_LINE2); 1475 available_field_types.insert(ADDRESS_BILLING_LINE2);
1476 available_field_types.insert(EMAIL_ADDRESS); 1476 available_field_types.insert(EMAIL_ADDRESS);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 possible_field_types.push_back(FieldTypeSet()); 1516 possible_field_types.push_back(FieldTypeSet());
1517 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1517 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1518 possible_field_types.back().insert(ADDRESS_HOME_LINE2); 1518 possible_field_types.back().insert(ADDRESS_HOME_LINE2);
1519 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); 1519 possible_field_types.back().insert(ADDRESS_BILLING_LINE1);
1520 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); 1520 possible_field_types.back().insert(ADDRESS_BILLING_LINE2);
1521 } 1521 }
1522 1522
1523 form_structure.reset(new FormStructure(form)); 1523 form_structure.reset(new FormStructure(form));
1524 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1524 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1525 for (size_t i = 0; i < form_structure->field_count(); ++i) 1525 for (size_t i = 0; i < form_structure->field_count(); ++i)
1526 form_structure->set_possible_types(i, possible_field_types[i]); 1526 form_structure->field(i)->set_possible_types(possible_field_types[i]);
1527 1527
1528 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1528 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1529 &encoded_xml)); 1529 &encoded_xml));
1530 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1530 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1531 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " 1531 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" "
1532 "formsignature=\"12226592129574322128\" autofillused=\"false\" " 1532 "formsignature=\"12226592129574322128\" autofillused=\"false\" "
1533 "datapresent=\"144200830e\">" 1533 "datapresent=\"144200830e\">"
1534 "<field signature=\"3763331450\" autofilltype=\"3\"/>" 1534 "<field signature=\"3763331450\" autofilltype=\"3\"/>"
1535 "<field signature=\"3494530716\" autofilltype=\"5\"/>" 1535 "<field signature=\"3494530716\" autofilltype=\"5\"/>"
1536 "<field signature=\"1029417091\" autofilltype=\"9\"/>" 1536 "<field signature=\"1029417091\" autofilltype=\"9\"/>"
(...skipping 19 matching lines...) Expand all
1556 form.fields.push_back(field); 1556 form.fields.push_back(field);
1557 possible_field_types.push_back(FieldTypeSet()); 1557 possible_field_types.push_back(FieldTypeSet());
1558 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1558 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1559 possible_field_types.back().insert(ADDRESS_HOME_LINE2); 1559 possible_field_types.back().insert(ADDRESS_HOME_LINE2);
1560 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); 1560 possible_field_types.back().insert(ADDRESS_BILLING_LINE1);
1561 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); 1561 possible_field_types.back().insert(ADDRESS_BILLING_LINE2);
1562 } 1562 }
1563 form_structure.reset(new FormStructure(form)); 1563 form_structure.reset(new FormStructure(form));
1564 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1564 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1565 for (size_t i = 0; i < form_structure->field_count(); ++i) 1565 for (size_t i = 0; i < form_structure->field_count(); ++i)
1566 form_structure->set_possible_types(i, possible_field_types[i]); 1566 form_structure->field(i)->set_possible_types(possible_field_types[i]);
1567 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, 1567 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false,
1568 &encoded_xml)); 1568 &encoded_xml));
1569 } 1569 }
1570 1570
1571 // Check that we compute the "datapresent" string correctly for the given 1571 // Check that we compute the "datapresent" string correctly for the given
1572 // |available_types|. 1572 // |available_types|.
1573 TEST(FormStructureTest, CheckDataPresence) { 1573 TEST(FormStructureTest, CheckDataPresence) {
1574 FormData form; 1574 FormData form;
1575 form.method = ASCIIToUTF16("post"); 1575 form.method = ASCIIToUTF16("post");
1576 1576
(...skipping 10 matching lines...) Expand all
1587 1587
1588 field.label = ASCIIToUTF16("Email"); 1588 field.label = ASCIIToUTF16("Email");
1589 field.name = ASCIIToUTF16("email"); 1589 field.name = ASCIIToUTF16("email");
1590 form.fields.push_back(field); 1590 form.fields.push_back(field);
1591 1591
1592 FormStructure form_structure(form); 1592 FormStructure form_structure(form);
1593 1593
1594 FieldTypeSet unknown_type; 1594 FieldTypeSet unknown_type;
1595 unknown_type.insert(UNKNOWN_TYPE); 1595 unknown_type.insert(UNKNOWN_TYPE);
1596 for (size_t i = 0; i < form_structure.field_count(); ++i) 1596 for (size_t i = 0; i < form_structure.field_count(); ++i)
1597 form_structure.set_possible_types(i, unknown_type); 1597 form_structure.field(i)->set_possible_types(unknown_type);
1598 1598
1599 // No available types. 1599 // No available types.
1600 // datapresent should be "" == trimmmed(0x0000000000000000) == 1600 // datapresent should be "" == trimmmed(0x0000000000000000) ==
1601 // 0b0000000000000000000000000000000000000000000000000000000000000000 1601 // 0b0000000000000000000000000000000000000000000000000000000000000000
1602 FieldTypeSet available_field_types; 1602 FieldTypeSet available_field_types;
1603 1603
1604 std::string encoded_xml; 1604 std::string encoded_xml;
1605 EXPECT_TRUE(form_structure.EncodeUploadRequest(available_field_types, false, 1605 EXPECT_TRUE(form_structure.EncodeUploadRequest(available_field_types, false,
1606 &encoded_xml)); 1606 &encoded_xml));
1607 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1607 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 1871
1872 field.label = ASCIIToUTF16("Address"); 1872 field.label = ASCIIToUTF16("Address");
1873 field.name = ASCIIToUTF16("address"); 1873 field.name = ASCIIToUTF16("address");
1874 form.fields.push_back(field); 1874 form.fields.push_back(field);
1875 possible_field_types.push_back(FieldTypeSet()); 1875 possible_field_types.push_back(FieldTypeSet());
1876 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1876 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1877 1877
1878 form_structure.reset(new FormStructure(form)); 1878 form_structure.reset(new FormStructure(form));
1879 1879
1880 for (size_t i = 0; i < form_structure->field_count(); ++i) 1880 for (size_t i = 0; i < form_structure->field_count(); ++i)
1881 form_structure->set_possible_types(i, possible_field_types[i]); 1881 form_structure->field(i)->set_possible_types(possible_field_types[i]);
1882 std::string encoded_xml; 1882 std::string encoded_xml;
1883 1883
1884 // Now we matched both fields singularly. 1884 // Now we matched both fields singularly.
1885 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1885 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1886 &encoded_xml)); 1886 &encoded_xml));
1887 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1887 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1888 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" 1888 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1889 " formsignature=\"18062476096658145866\" autofillused=\"false\"" 1889 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1890 " datapresent=\"1440000360000008\">" 1890 " datapresent=\"1440000360000008\">"
1891 "<field signature=\"420638584\" autofilltype=\"9\"/>" 1891 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1892 "<field signature=\"1089846351\" autofilltype=\"3\"/>" 1892 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1893 "<field signature=\"2404144663\" autofilltype=\"5\"/>" 1893 "<field signature=\"2404144663\" autofilltype=\"5\"/>"
1894 "<field signature=\"509334676\" autofilltype=\"30\"/>" 1894 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1895 "</autofillupload>", 1895 "</autofillupload>",
1896 encoded_xml); 1896 encoded_xml);
1897 // Match third field as both first and last. 1897 // Match third field as both first and last.
1898 possible_field_types[2].insert(NAME_FIRST); 1898 possible_field_types[2].insert(NAME_FIRST);
1899 form_structure->set_possible_types(2, possible_field_types[2]); 1899 form_structure->field(2)->set_possible_types(possible_field_types[2]);
1900 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1900 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1901 &encoded_xml)); 1901 &encoded_xml));
1902 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1902 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1903 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" 1903 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1904 " formsignature=\"18062476096658145866\" autofillused=\"false\"" 1904 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1905 " datapresent=\"1440000360000008\">" 1905 " datapresent=\"1440000360000008\">"
1906 "<field signature=\"420638584\" autofilltype=\"9\"/>" 1906 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1907 "<field signature=\"1089846351\" autofilltype=\"3\"/>" 1907 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1908 "<field signature=\"2404144663\" autofilltype=\"3\"/>" 1908 "<field signature=\"2404144663\" autofilltype=\"3\"/>"
1909 "<field signature=\"2404144663\" autofilltype=\"5\"/>" 1909 "<field signature=\"2404144663\" autofilltype=\"5\"/>"
1910 "<field signature=\"509334676\" autofilltype=\"30\"/>" 1910 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1911 "</autofillupload>", 1911 "</autofillupload>",
1912 encoded_xml); 1912 encoded_xml);
1913 possible_field_types[3].insert(ADDRESS_HOME_LINE2); 1913 possible_field_types[3].insert(ADDRESS_HOME_LINE2);
1914 form_structure->set_possible_types( 1914 form_structure->field(field_count() - 1)->set_possible_types(
1915 form_structure->field_count() - 1,
1916 possible_field_types[form_structure->field_count() - 1]); 1915 possible_field_types[form_structure->field_count() - 1]);
1917 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1916 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1918 &encoded_xml)); 1917 &encoded_xml));
1919 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1918 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1920 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" 1919 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1921 " formsignature=\"18062476096658145866\" autofillused=\"false\"" 1920 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1922 " datapresent=\"1440000360000008\">" 1921 " datapresent=\"1440000360000008\">"
1923 "<field signature=\"420638584\" autofilltype=\"9\"/>" 1922 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1924 "<field signature=\"1089846351\" autofilltype=\"3\"/>" 1923 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1925 "<field signature=\"2404144663\" autofilltype=\"3\"/>" 1924 "<field signature=\"2404144663\" autofilltype=\"3\"/>"
1926 "<field signature=\"2404144663\" autofilltype=\"5\"/>" 1925 "<field signature=\"2404144663\" autofilltype=\"5\"/>"
1927 "<field signature=\"509334676\" autofilltype=\"30\"/>" 1926 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1928 "<field signature=\"509334676\" autofilltype=\"31\"/>" 1927 "<field signature=\"509334676\" autofilltype=\"31\"/>"
1929 "</autofillupload>", 1928 "</autofillupload>",
1930 encoded_xml); 1929 encoded_xml);
1931 possible_field_types[3].clear(); 1930 possible_field_types[3].clear();
1932 possible_field_types[3].insert(ADDRESS_HOME_LINE1); 1931 possible_field_types[3].insert(ADDRESS_HOME_LINE1);
1933 possible_field_types[3].insert(COMPANY_NAME); 1932 possible_field_types[3].insert(COMPANY_NAME);
1934 form_structure->set_possible_types( 1933 form_structure->field(field_count() - 1)->set_possible_types(
1935 form_structure->field_count() - 1,
1936 possible_field_types[form_structure->field_count() - 1]); 1934 possible_field_types[form_structure->field_count() - 1]);
1937 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1935 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1938 &encoded_xml)); 1936 &encoded_xml));
1939 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1937 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1940 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" 1938 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1941 " formsignature=\"18062476096658145866\" autofillused=\"false\"" 1939 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1942 " datapresent=\"1440000360000008\">" 1940 " datapresent=\"1440000360000008\">"
1943 "<field signature=\"420638584\" autofilltype=\"9\"/>" 1941 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1944 "<field signature=\"1089846351\" autofilltype=\"3\"/>" 1942 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1945 "<field signature=\"2404144663\" autofilltype=\"3\"/>" 1943 "<field signature=\"2404144663\" autofilltype=\"3\"/>"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 form_structure->FormSignature()); 1984 form_structure->FormSignature());
1987 1985
1988 form.name = ASCIIToUTF16("login_form"); 1986 form.name = ASCIIToUTF16("login_form");
1989 form_structure.reset(new FormStructure(form)); 1987 form_structure.reset(new FormStructure(form));
1990 EXPECT_EQ(FormStructureTest::Hash64Bit( 1988 EXPECT_EQ(FormStructureTest::Hash64Bit(
1991 std::string("https://login.facebook.com&login_form&email&first")), 1989 std::string("https://login.facebook.com&login_form&email&first")),
1992 form_structure->FormSignature()); 1990 form_structure->FormSignature());
1993 } 1991 }
1994 1992
1995 } // namespace 1993 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698