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

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: Rebase Created 9 years, 4 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
« no previous file with comments | « chrome/browser/autofill/form_structure.cc ('k') | chrome/common/autofill_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 field.label = ASCIIToUTF16("Fax"); 1497 field.label = ASCIIToUTF16("Fax");
1498 field.name = ASCIIToUTF16("fax"); 1498 field.name = ASCIIToUTF16("fax");
1499 field.form_control_type = ASCIIToUTF16("tel"); 1499 field.form_control_type = ASCIIToUTF16("tel");
1500 form.fields.push_back(field); 1500 form.fields.push_back(field);
1501 possible_field_types.push_back(FieldTypeSet()); 1501 possible_field_types.push_back(FieldTypeSet());
1502 possible_field_types.back().insert(PHONE_FAX_WHOLE_NUMBER); 1502 possible_field_types.back().insert(PHONE_FAX_WHOLE_NUMBER);
1503 form_structure.reset(new FormStructure(form)); 1503 form_structure.reset(new FormStructure(form));
1504 1504
1505 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1505 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1506 for (size_t i = 0; i < form_structure->field_count(); ++i) 1506 for (size_t i = 0; i < form_structure->field_count(); ++i)
1507 form_structure->set_possible_types(i, possible_field_types[i]); 1507 form_structure->field(i)->set_possible_types(possible_field_types[i]);
1508 1508
1509 FieldTypeSet available_field_types; 1509 FieldTypeSet available_field_types;
1510 available_field_types.insert(NAME_FIRST); 1510 available_field_types.insert(NAME_FIRST);
1511 available_field_types.insert(NAME_LAST); 1511 available_field_types.insert(NAME_LAST);
1512 available_field_types.insert(ADDRESS_HOME_LINE1); 1512 available_field_types.insert(ADDRESS_HOME_LINE1);
1513 available_field_types.insert(ADDRESS_HOME_LINE2); 1513 available_field_types.insert(ADDRESS_HOME_LINE2);
1514 available_field_types.insert(ADDRESS_HOME_COUNTRY); 1514 available_field_types.insert(ADDRESS_HOME_COUNTRY);
1515 available_field_types.insert(ADDRESS_BILLING_LINE1); 1515 available_field_types.insert(ADDRESS_BILLING_LINE1);
1516 available_field_types.insert(ADDRESS_BILLING_LINE2); 1516 available_field_types.insert(ADDRESS_BILLING_LINE2);
1517 available_field_types.insert(EMAIL_ADDRESS); 1517 available_field_types.insert(EMAIL_ADDRESS);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 1563
1564 form_structure.reset(new FormStructure(form)); 1564 form_structure.reset(new FormStructure(form));
1565 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1565 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1566 for (size_t i = 0; i < form_structure->field_count(); ++i) 1566 for (size_t i = 0; i < form_structure->field_count(); ++i)
1567 form_structure->set_possible_types(i, possible_field_types[i]); 1567 form_structure->field(i)->set_possible_types(possible_field_types[i]);
1568 1568
1569 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1569 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1570 &encoded_xml)); 1570 &encoded_xml));
1571 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1571 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1572 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " 1572 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" "
1573 "formsignature=\"12226592129574322128\" autofillused=\"false\" " 1573 "formsignature=\"12226592129574322128\" autofillused=\"false\" "
1574 "datapresent=\"144200830e\">" 1574 "datapresent=\"144200830e\">"
1575 "<field signature=\"3763331450\" autofilltype=\"3\"/>" 1575 "<field signature=\"3763331450\" autofilltype=\"3\"/>"
1576 "<field signature=\"3494530716\" autofilltype=\"5\"/>" 1576 "<field signature=\"3494530716\" autofilltype=\"5\"/>"
1577 "<field signature=\"1029417091\" autofilltype=\"9\"/>" 1577 "<field signature=\"1029417091\" autofilltype=\"9\"/>"
(...skipping 19 matching lines...) Expand all
1597 form.fields.push_back(field); 1597 form.fields.push_back(field);
1598 possible_field_types.push_back(FieldTypeSet()); 1598 possible_field_types.push_back(FieldTypeSet());
1599 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1599 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1600 possible_field_types.back().insert(ADDRESS_HOME_LINE2); 1600 possible_field_types.back().insert(ADDRESS_HOME_LINE2);
1601 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); 1601 possible_field_types.back().insert(ADDRESS_BILLING_LINE1);
1602 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); 1602 possible_field_types.back().insert(ADDRESS_BILLING_LINE2);
1603 } 1603 }
1604 form_structure.reset(new FormStructure(form)); 1604 form_structure.reset(new FormStructure(form));
1605 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); 1605 ASSERT_EQ(form_structure->field_count(), possible_field_types.size());
1606 for (size_t i = 0; i < form_structure->field_count(); ++i) 1606 for (size_t i = 0; i < form_structure->field_count(); ++i)
1607 form_structure->set_possible_types(i, possible_field_types[i]); 1607 form_structure->field(i)->set_possible_types(possible_field_types[i]);
1608 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, 1608 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false,
1609 &encoded_xml)); 1609 &encoded_xml));
1610 } 1610 }
1611 1611
1612 // Check that we compute the "datapresent" string correctly for the given 1612 // Check that we compute the "datapresent" string correctly for the given
1613 // |available_types|. 1613 // |available_types|.
1614 TEST(FormStructureTest, CheckDataPresence) { 1614 TEST(FormStructureTest, CheckDataPresence) {
1615 FormData form; 1615 FormData form;
1616 form.method = ASCIIToUTF16("post"); 1616 form.method = ASCIIToUTF16("post");
1617 1617
(...skipping 10 matching lines...) Expand all
1628 1628
1629 field.label = ASCIIToUTF16("Email"); 1629 field.label = ASCIIToUTF16("Email");
1630 field.name = ASCIIToUTF16("email"); 1630 field.name = ASCIIToUTF16("email");
1631 form.fields.push_back(field); 1631 form.fields.push_back(field);
1632 1632
1633 FormStructure form_structure(form); 1633 FormStructure form_structure(form);
1634 1634
1635 FieldTypeSet unknown_type; 1635 FieldTypeSet unknown_type;
1636 unknown_type.insert(UNKNOWN_TYPE); 1636 unknown_type.insert(UNKNOWN_TYPE);
1637 for (size_t i = 0; i < form_structure.field_count(); ++i) 1637 for (size_t i = 0; i < form_structure.field_count(); ++i)
1638 form_structure.set_possible_types(i, unknown_type); 1638 form_structure.field(i)->set_possible_types(unknown_type);
1639 1639
1640 // No available types. 1640 // No available types.
1641 // datapresent should be "" == trimmmed(0x0000000000000000) == 1641 // datapresent should be "" == trimmmed(0x0000000000000000) ==
1642 // 0b0000000000000000000000000000000000000000000000000000000000000000 1642 // 0b0000000000000000000000000000000000000000000000000000000000000000
1643 FieldTypeSet available_field_types; 1643 FieldTypeSet available_field_types;
1644 1644
1645 std::string encoded_xml; 1645 std::string encoded_xml;
1646 EXPECT_TRUE(form_structure.EncodeUploadRequest(available_field_types, false, 1646 EXPECT_TRUE(form_structure.EncodeUploadRequest(available_field_types, false,
1647 &encoded_xml)); 1647 &encoded_xml));
1648 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1648 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 1912
1913 field.label = ASCIIToUTF16("Address"); 1913 field.label = ASCIIToUTF16("Address");
1914 field.name = ASCIIToUTF16("address"); 1914 field.name = ASCIIToUTF16("address");
1915 form.fields.push_back(field); 1915 form.fields.push_back(field);
1916 possible_field_types.push_back(FieldTypeSet()); 1916 possible_field_types.push_back(FieldTypeSet());
1917 possible_field_types.back().insert(ADDRESS_HOME_LINE1); 1917 possible_field_types.back().insert(ADDRESS_HOME_LINE1);
1918 1918
1919 form_structure.reset(new FormStructure(form)); 1919 form_structure.reset(new FormStructure(form));
1920 1920
1921 for (size_t i = 0; i < form_structure->field_count(); ++i) 1921 for (size_t i = 0; i < form_structure->field_count(); ++i)
1922 form_structure->set_possible_types(i, possible_field_types[i]); 1922 form_structure->field(i)->set_possible_types(possible_field_types[i]);
1923 std::string encoded_xml; 1923 std::string encoded_xml;
1924 1924
1925 // Now we matched both fields singularly. 1925 // Now we matched both fields singularly.
1926 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1926 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1927 &encoded_xml)); 1927 &encoded_xml));
1928 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1928 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1929 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" 1929 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1930 " formsignature=\"18062476096658145866\" autofillused=\"false\"" 1930 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1931 " datapresent=\"1440000360000008\">" 1931 " datapresent=\"1440000360000008\">"
1932 "<field signature=\"420638584\" autofilltype=\"9\"/>" 1932 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1933 "<field signature=\"1089846351\" autofilltype=\"3\"/>" 1933 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1934 "<field signature=\"2404144663\" autofilltype=\"5\"/>" 1934 "<field signature=\"2404144663\" autofilltype=\"5\"/>"
1935 "<field signature=\"509334676\" autofilltype=\"30\"/>" 1935 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1936 "</autofillupload>", 1936 "</autofillupload>",
1937 encoded_xml); 1937 encoded_xml);
1938 // Match third field as both first and last. 1938 // Match third field as both first and last.
1939 possible_field_types[2].insert(NAME_FIRST); 1939 possible_field_types[2].insert(NAME_FIRST);
1940 form_structure->set_possible_types(2, possible_field_types[2]); 1940 form_structure->field(2)->set_possible_types(possible_field_types[2]);
1941 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1941 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1942 &encoded_xml)); 1942 &encoded_xml));
1943 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1943 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1944 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" 1944 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1945 " formsignature=\"18062476096658145866\" autofillused=\"false\"" 1945 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1946 " datapresent=\"1440000360000008\">" 1946 " datapresent=\"1440000360000008\">"
1947 "<field signature=\"420638584\" autofilltype=\"9\"/>" 1947 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1948 "<field signature=\"1089846351\" autofilltype=\"3\"/>" 1948 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1949 "<field signature=\"2404144663\" autofilltype=\"3\"/>" 1949 "<field signature=\"2404144663\" autofilltype=\"3\"/>"
1950 "<field signature=\"2404144663\" autofilltype=\"5\"/>" 1950 "<field signature=\"2404144663\" autofilltype=\"5\"/>"
1951 "<field signature=\"509334676\" autofilltype=\"30\"/>" 1951 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1952 "</autofillupload>", 1952 "</autofillupload>",
1953 encoded_xml); 1953 encoded_xml);
1954 possible_field_types[3].insert(ADDRESS_HOME_LINE2); 1954 possible_field_types[3].insert(ADDRESS_HOME_LINE2);
1955 form_structure->set_possible_types( 1955 form_structure->field(form_structure->field_count() - 1)->set_possible_types(
1956 form_structure->field_count() - 1,
1957 possible_field_types[form_structure->field_count() - 1]); 1956 possible_field_types[form_structure->field_count() - 1]);
1958 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1957 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1959 &encoded_xml)); 1958 &encoded_xml));
1960 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1959 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1961 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" 1960 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1962 " formsignature=\"18062476096658145866\" autofillused=\"false\"" 1961 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1963 " datapresent=\"1440000360000008\">" 1962 " datapresent=\"1440000360000008\">"
1964 "<field signature=\"420638584\" autofilltype=\"9\"/>" 1963 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1965 "<field signature=\"1089846351\" autofilltype=\"3\"/>" 1964 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1966 "<field signature=\"2404144663\" autofilltype=\"3\"/>" 1965 "<field signature=\"2404144663\" autofilltype=\"3\"/>"
1967 "<field signature=\"2404144663\" autofilltype=\"5\"/>" 1966 "<field signature=\"2404144663\" autofilltype=\"5\"/>"
1968 "<field signature=\"509334676\" autofilltype=\"30\"/>" 1967 "<field signature=\"509334676\" autofilltype=\"30\"/>"
1969 "<field signature=\"509334676\" autofilltype=\"31\"/>" 1968 "<field signature=\"509334676\" autofilltype=\"31\"/>"
1970 "</autofillupload>", 1969 "</autofillupload>",
1971 encoded_xml); 1970 encoded_xml);
1972 possible_field_types[3].clear(); 1971 possible_field_types[3].clear();
1973 possible_field_types[3].insert(ADDRESS_HOME_LINE1); 1972 possible_field_types[3].insert(ADDRESS_HOME_LINE1);
1974 possible_field_types[3].insert(COMPANY_NAME); 1973 possible_field_types[3].insert(COMPANY_NAME);
1975 form_structure->set_possible_types( 1974 form_structure->field(form_structure->field_count() - 1)->set_possible_types(
1976 form_structure->field_count() - 1,
1977 possible_field_types[form_structure->field_count() - 1]); 1975 possible_field_types[form_structure->field_count() - 1]);
1978 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, 1976 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false,
1979 &encoded_xml)); 1977 &encoded_xml));
1980 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" 1978 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>"
1981 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" 1979 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
1982 " formsignature=\"18062476096658145866\" autofillused=\"false\"" 1980 " formsignature=\"18062476096658145866\" autofillused=\"false\""
1983 " datapresent=\"1440000360000008\">" 1981 " datapresent=\"1440000360000008\">"
1984 "<field signature=\"420638584\" autofilltype=\"9\"/>" 1982 "<field signature=\"420638584\" autofilltype=\"9\"/>"
1985 "<field signature=\"1089846351\" autofilltype=\"3\"/>" 1983 "<field signature=\"1089846351\" autofilltype=\"3\"/>"
1986 "<field signature=\"2404144663\" autofilltype=\"3\"/>" 1984 "<field signature=\"2404144663\" autofilltype=\"3\"/>"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 EXPECT_EQ(FormStructureTest::Hash64Bit( 2023 EXPECT_EQ(FormStructureTest::Hash64Bit(
2026 std::string("https://login.facebook.com&&email&first")), 2024 std::string("https://login.facebook.com&&email&first")),
2027 form_structure->FormSignature()); 2025 form_structure->FormSignature());
2028 2026
2029 form.name = ASCIIToUTF16("login_form"); 2027 form.name = ASCIIToUTF16("login_form");
2030 form_structure.reset(new FormStructure(form)); 2028 form_structure.reset(new FormStructure(form));
2031 EXPECT_EQ(FormStructureTest::Hash64Bit( 2029 EXPECT_EQ(FormStructureTest::Hash64Bit(
2032 std::string("https://login.facebook.com&login_form&email&first")), 2030 std::string("https://login.facebook.com&login_form&email&first")),
2033 form_structure->FormSignature()); 2031 form_structure->FormSignature());
2034 } 2032 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/form_structure.cc ('k') | chrome/common/autofill_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698