Chromium Code Reviews| Index: chrome/browser/autofill/form_structure_unittest.cc |
| =================================================================== |
| --- chrome/browser/autofill/form_structure_unittest.cc (revision 72012) |
| +++ chrome/browser/autofill/form_structure_unittest.cc (working copy) |
| @@ -1675,8 +1675,8 @@ |
| EXPECT_EQ(encoded_xml, |
| "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " |
| "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" |
| - "8269229441054798720\" autofillused=\"false\" datapresent=\"\"><field " |
| - "signature=\"3763331450\" autofilltype=\"3\"/><field signature=\"" |
| + "8269229441054798720\" autofillused=\"false\" datapresent=\"1442008208\">" |
| + "<field signature=\"3763331450\" autofilltype=\"3\"/><field signature=\"" |
| "3494530716\" autofilltype=\"5\"/><field signature=\"1029417091\" " |
| "autofilltype=\"9\"/><field signature=\"466116101\" autofilltype=" |
| "\"14\"/><field signature=\"2799270304\" autofilltype=\"36\"/><field " |
| @@ -1686,8 +1686,8 @@ |
| EXPECT_EQ(encoded_xml, |
| "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " |
| "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" |
| - "8269229441054798720\" autofillused=\"true\" datapresent=\"\"><field " |
| - "signature=\"3763331450\" autofilltype=\"3\"/><field signature=\"" |
| + "8269229441054798720\" autofillused=\"true\" datapresent=\"1442008208\">" |
| + "<field signature=\"3763331450\" autofilltype=\"3\"/><field signature=\"" |
| "3494530716\" autofilltype=\"5\"/><field signature=\"1029417091\" " |
| "autofilltype=\"9\"/><field signature=\"466116101\" autofilltype=" |
| "\"14\"/><field signature=\"2799270304\" autofilltype=\"36\"/><field " |
| @@ -1715,29 +1715,17 @@ |
| EXPECT_EQ(encoded_xml, |
| "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " |
| "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" |
| - "2027360543766157144\" autofillused=\"false\" datapresent=\"\"><field " |
| - "signature=\"3763331450\" autofilltype=\"3\"/><field signature=\"" |
| + "2027360543766157144\" autofillused=\"false\" datapresent=\"5442008208\">" |
| + "<field signature=\"3763331450\" autofilltype=\"3\"/><field signature=\"" |
| "3494530716\" autofilltype=\"5\"/><field signature=\"1029417091\" " |
| "autofilltype=\"9\"/><field signature=\"466116101\" autofilltype=\"14\"/>" |
| "<field signature=\"2799270304\" autofilltype=\"36\"/><field signature=\"" |
| "1876771436\" autofilltype=\"24\"/><field signature=\"263446779\" " |
| - "autofilltype=\"30\"/><field signature=\"509334676\" autofilltype=" |
| - "\"30\"/><field signature=\"509334676\" autofilltype=\"31\"/><field " |
| - "signature=\"509334676\" autofilltype=\"37\"/><field signature=" |
| - "\"509334676\" autofilltype=\"38\"/><field signature=\"509334676\" " |
| - "autofilltype=\"30\"/><field signature=\"509334676\" autofilltype=" |
| - "\"31\"/><field signature=\"509334676\" autofilltype=\"37\"/><field " |
| - "signature=\"509334676\" autofilltype=\"38\"/><field signature=\"" |
| - "509334676\" autofilltype=\"30\"/><field signature=\"509334676\" " |
| - "autofilltype=\"31\"/><field signature=\"509334676\" " |
| - "autofilltype=\"37\"/><field signature=\"509334676\" autofilltype=" |
| - "\"38\"/><field signature=\"509334676\" autofilltype=\"30\"/><field " |
| - "signature=\"509334676\" autofilltype=\"31\"/><field signature=" |
| - "\"509334676\" autofilltype=\"37\"/><field signature=\"509334676\" " |
| - "autofilltype=\"38\"/><field signature=\"509334676\" autofilltype=" |
| - "\"30\"/><field signature=\"509334676\" autofilltype=\"31\"/><field " |
| - "signature=\"509334676\" autofilltype=\"37\"/><field signature=" |
| - "\"509334676\" autofilltype=\"38\"/></autofillupload>"); |
| + "autofilltype=\"30\"/><field signature=\"509334676\" autofilltype=\"1\"/>" |
| + "<field signature=\"509334676\" autofilltype=\"1\"/><field signature=\"" |
| + "509334676\" autofilltype=\"1\"/><field signature=\"509334676\" " |
| + "autofilltype=\"1\"/><field signature=\"509334676\" autofilltype=\"1\"/>" |
| + "</autofillupload>"); |
| // Add 50 address fields - now the form is invalid. |
| for (size_t i = 0; i < 50; ++i) { |
| form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), |
| @@ -1760,4 +1748,200 @@ |
| EXPECT_EQ(encoded_xml, ""); |
| } |
| +TEST(FormStructureTest, CheckDataPresence) { |
|
Ilya Sherman
2011/01/22 01:12:35
nit: Please include a quick comment describing thi
Ilya Sherman
2011/01/22 01:12:35
Might be good to test EmptyType as well.
GeorgeY
2011/01/22 01:40:40
Done.
|
| + scoped_ptr<FormStructure> form_structure; |
| + std::vector<FieldTypeSet> possible_field_types; |
| + FormData form; |
| + form.method = ASCIIToUTF16("post"); |
| + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), |
| + ASCIIToUTF16("first"), |
| + string16(), |
| + ASCIIToUTF16("text"), |
| + 0, |
| + false)); |
| + possible_field_types.push_back(FieldTypeSet()); |
| + possible_field_types.back().insert(NAME_FIRST); |
| + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), |
| + ASCIIToUTF16("last"), |
| + string16(), |
| + ASCIIToUTF16("text"), |
| + 0, |
| + false)); |
| + possible_field_types.push_back(FieldTypeSet()); |
| + possible_field_types.back().insert(NAME_LAST); |
| + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), |
| + ASCIIToUTF16("email"), |
| + string16(), |
| + ASCIIToUTF16("text"), |
| + 0, |
| + false)); |
| + possible_field_types.push_back(FieldTypeSet()); |
| + possible_field_types.back().insert(EMAIL_ADDRESS); |
| + form_structure.reset(new FormStructure(form)); |
| + for (size_t i = 0; i < form_structure->field_count(); ++i) |
| + form_structure->set_possible_types(i, possible_field_types[i]); |
| + std::string encoded_xml; |
| + EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); |
| + EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " |
| + "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" |
| + "6402244543831589061\" autofillused=\"false\" " |
| + "datapresent=\"1440\"><field signature=\"1089846351\" ", |
| + encoded_xml.substr(0, 200)); |
| + |
| + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), |
| + ASCIIToUTF16("address"), |
| + string16(), |
| + ASCIIToUTF16("text"), |
| + 0, |
| + false)); |
| + possible_field_types.push_back(FieldTypeSet()); |
| + possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
| + form_structure.reset(new FormStructure(form)); |
| + for (size_t i = 0; i < form_structure->field_count(); ++i) |
| + form_structure->set_possible_types(i, possible_field_types[i]); |
| + EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); |
| + EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " |
| + "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" |
| + "11817937699000629499\" autofillused=\"false\" " |
| + "datapresent=\"14400002\"><field signature=\"1089846", |
| + encoded_xml.substr(0, 200)); |
| + |
| + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("F4"), |
| + ASCIIToUTF16("f4"), |
| + string16(), |
| + ASCIIToUTF16("text"), |
| + 0, |
| + false)); |
| + possible_field_types.push_back(FieldTypeSet()); |
| + possible_field_types.back().insert(CREDIT_CARD_TYPE); |
| + form_structure.reset(new FormStructure(form)); |
| + for (size_t i = 0; i < form_structure->field_count(); ++i) |
| + form_structure->set_possible_types(i, possible_field_types[i]); |
| + EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); |
| + EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " |
| + "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" |
| + "15126663683491865216\" autofillused=\"false\" " |
| + "datapresent=\"1440000200000020\"><field signature=", |
| + encoded_xml.substr(0, 200)); |
| +} |
| + |
| +TEST(FormStructureTest, CheckMultipleTypes) { |
|
Ilya Sherman
2011/01/22 01:12:35
nit: Ditto.
GeorgeY
2011/01/22 01:40:40
Changed comment in next 4 lines
|
| + // Let's imagine user entered 'George' 'Washington' in first and second fields |
| + // and there are two profiles: for George Washington and Washington Irving. |
| + // As Washington will match both first and last name in two profiles we are |
| + // not sure which one it is, so we will not poison crowd sourced data. |
| + scoped_ptr<FormStructure> form_structure; |
| + std::vector<FieldTypeSet> possible_field_types; |
| + FormData form; |
| + form.method = ASCIIToUTF16("post"); |
| + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), |
| + ASCIIToUTF16("email"), |
| + string16(), |
| + ASCIIToUTF16("text"), |
| + 0, |
| + false)); |
| + possible_field_types.push_back(FieldTypeSet()); |
| + possible_field_types.back().insert(EMAIL_ADDRESS); |
| + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), |
| + ASCIIToUTF16("first"), |
| + string16(), |
| + ASCIIToUTF16("text"), |
| + 0, |
| + false)); |
| + possible_field_types.push_back(FieldTypeSet()); |
| + possible_field_types.back().insert(NAME_FIRST); |
| + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), |
| + ASCIIToUTF16("last"), |
| + string16(), |
| + ASCIIToUTF16("text"), |
| + 0, |
| + false)); |
| + possible_field_types.push_back(FieldTypeSet()); |
| + possible_field_types.back().insert(NAME_LAST); |
| + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), |
| + ASCIIToUTF16("address"), |
| + string16(), |
| + ASCIIToUTF16("text"), |
| + 0, |
| + false)); |
| + possible_field_types.push_back(FieldTypeSet()); |
| + possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
| + form_structure.reset(new FormStructure(form)); |
| + for (size_t i = 0; i < form_structure->field_count(); ++i) |
| + form_structure->set_possible_types(i, possible_field_types[i]); |
| + std::string encoded_xml; |
| + // Now we matched both fields singularly. |
| + EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); |
| + // datapresent==14400002==00010100010000000000000000000010b set bits are: |
| + // #3 == NAME_FIRST |
| + // #5 == NAME_LAST |
| + // #9 == EMAIL_ADDRESS |
| + // #30 == ADDRESS_HOME_LINE1 |
| + EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " |
| + "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" |
| + "18062476096658145866\" autofillused=\"false\" datapresent=" |
| + "\"14400002\"><field signature=\"420638584\" autofilltype=" |
| + "\"9\"/><field signature=\"1089846351\" autofilltype=\"3\"/><field " |
| + "signature=\"2404144663\" autofilltype=\"5\"/><field signature=" |
| + "\"509334676\" autofilltype=\"30\"/></autofillupload>", |
| + encoded_xml); |
| + // Match third field as both first and last. |
| + possible_field_types[2].insert(NAME_FIRST); |
| + form_structure->set_possible_types(2, possible_field_types[2]); |
| + EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); |
| + // datapresent==50400002==01010100010000000000000000000010b set bits are: |
| + // #1 == UNKNOWN_TYPE |
| + // #3 == NAME_FIRST |
| + // #9 == EMAIL_ADDRESS |
| + // #30 == ADDRESS_HOME_LINE1 |
| + EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " |
| + "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" |
| + "18062476096658145866\" autofillused=\"false\" datapresent=" |
| + "\"50400002\"><field signature=\"420638584\" autofilltype=" |
| + "\"9\"/><field signature=\"1089846351\" autofilltype=\"3\"/><field " |
| + "signature=\"2404144663\" autofilltype=\"1\"/><field signature=" |
| + "\"509334676\" autofilltype=\"30\"/></autofillupload>", |
| + encoded_xml); |
| + possible_field_types[3].insert(ADDRESS_BILLING_LINE1); |
| + form_structure->set_possible_types( |
| + form_structure->field_count() - 1, |
| + possible_field_types[form_structure->field_count() - 1]); |
| + EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); |
| + // datapresent==5040000204==0101010001000000000000000000001000000100b set bits |
| + // are: |
| + // #1 == UNKNOWN_TYPE |
| + // #3 == NAME_FIRST |
| + // #9 == EMAIL_ADDRESS |
| + // #30 == ADDRESS_HOME_LINE1 |
| + // #37 == ADDRESS_BILLING_LINE1 |
| + EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " |
| + "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" |
| + "18062476096658145866\" autofillused=\"false\" datapresent=" |
| + "\"5040000204\"><field signature=\"420638584\" autofilltype=" |
| + "\"9\"/><field signature=\"1089846351\" autofilltype=\"3\"/><field " |
| + "signature=\"2404144663\" autofilltype=\"1\"/><field signature=" |
| + "\"509334676\" autofilltype=\"30\"/><field signature=\"509334676\" " |
| + "autofilltype=\"37\"/></autofillupload>", |
| + encoded_xml); |
| + possible_field_types[3].clear(); |
| + possible_field_types[3].insert(ADDRESS_HOME_LINE1); |
| + possible_field_types[3].insert(ADDRESS_BILLING_LINE2); |
| + form_structure->set_possible_types( |
| + form_structure->field_count() - 1, |
| + possible_field_types[form_structure->field_count() - 1]); |
| + EXPECT_TRUE(form_structure->EncodeUploadRequest(false, &encoded_xml)); |
| + // datapresent==5040==0101010001000000b set bits are: |
| + // #1 == UNKNOWN_TYPE |
| + // #3 == NAME_FIRST |
| + // #9 == EMAIL_ADDRESS |
| + EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillupload " |
| + "clientversion=\"6.1.1715.1442/en (GGLL)\" formsignature=\"" |
| + "18062476096658145866\" autofillused=\"false\" " |
| + "datapresent=\"5040\"><field signature=\"420638584\" autofilltype=" |
| + "\"9\"/><field signature=\"1089846351\" autofilltype=\"3\"/><field " |
| + "signature=\"2404144663\" autofilltype=\"1\"/><field signature=" |
| + "\"509334676\" autofilltype=\"1\"/></autofillupload>", |
| + encoded_xml); |
| +} |
| + |
| } // namespace |