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

Side by Side Diff: components/autofill/core/browser/form_structure_unittest.cc

Issue 2403773002: Remove stl_util's STLDeleteContainerPointers from autofill. (Closed)
Patch Set: rebase Created 4 years, 2 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
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 field.label = ASCIIToUTF16("Expiration Year"); 1982 field.label = ASCIIToUTF16("Expiration Year");
1983 field.name = ASCIIToUTF16("expiration_year"); 1983 field.name = ASCIIToUTF16("expiration_year");
1984 form.fields.push_back(field); 1984 form.fields.push_back(field);
1985 1985
1986 // Add checkable field. 1986 // Add checkable field.
1987 FormFieldData checkable_field; 1987 FormFieldData checkable_field;
1988 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; 1988 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED;
1989 checkable_field.label = ASCIIToUTF16("Checkable1"); 1989 checkable_field.label = ASCIIToUTF16("Checkable1");
1990 checkable_field.name = ASCIIToUTF16("Checkable1"); 1990 checkable_field.name = ASCIIToUTF16("Checkable1");
1991 form.fields.push_back(checkable_field); 1991 form.fields.push_back(checkable_field);
1992 FormStructure form_structure(form);
1992 1993
1993 ScopedVector<FormStructure> forms; 1994 std::vector<FormStructure*> forms;
1994 forms.push_back(new FormStructure(form)); 1995 forms.push_back(&form_structure);
1995 std::vector<std::string> encoded_signatures; 1996 std::vector<std::string> encoded_signatures;
1996 1997
1997 // Prepare the expected proto string. 1998 // Prepare the expected proto string.
1998 AutofillQueryContents query; 1999 AutofillQueryContents query;
1999 query.set_client_version("6.1.1715.1442/en (GGLL)"); 2000 query.set_client_version("6.1.1715.1442/en (GGLL)");
2000 AutofillQueryContents::Form* query_form = query.add_form(); 2001 AutofillQueryContents::Form* query_form = query.add_form();
2001 query_form->set_signature(11337937696949187602U); 2002 query_form->set_signature(11337937696949187602U);
2002 2003
2003 test::FillQueryField(query_form->add_field(), 412125936U, "name_on_card", 2004 test::FillQueryField(query_form->add_field(), 412125936U, "name_on_card",
2004 "text"); 2005 "text");
2005 test::FillQueryField(query_form->add_field(), 1917667676U, "billing_address", 2006 test::FillQueryField(query_form->add_field(), 1917667676U, "billing_address",
2006 "text"); 2007 "text");
2007 test::FillQueryField(query_form->add_field(), 2226358947U, "card_number", 2008 test::FillQueryField(query_form->add_field(), 2226358947U, "card_number",
2008 "text"); 2009 "text");
2009 test::FillQueryField(query_form->add_field(), 747221617U, "expiration_month", 2010 test::FillQueryField(query_form->add_field(), 747221617U, "expiration_month",
2010 "text"); 2011 "text");
2011 test::FillQueryField(query_form->add_field(), 4108155786U, "expiration_year", 2012 test::FillQueryField(query_form->add_field(), 4108155786U, "expiration_year",
2012 "text"); 2013 "text");
2013 2014
2014 std::string expected_query_string; 2015 std::string expected_query_string;
2015 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); 2016 ASSERT_TRUE(query.SerializeToString(&expected_query_string));
2016 2017
2017 const char kSignature1[] = "11337937696949187602"; 2018 const char kSignature1[] = "11337937696949187602";
2018 2019
2019 AutofillQueryContents encoded_query; 2020 AutofillQueryContents encoded_query;
2020 ASSERT_TRUE(FormStructure::EncodeQueryRequest( 2021 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
2021 forms.get(), &encoded_signatures, &encoded_query)); 2022 &encoded_query));
2022 ASSERT_EQ(1U, encoded_signatures.size()); 2023 ASSERT_EQ(1U, encoded_signatures.size());
2023 EXPECT_EQ(kSignature1, encoded_signatures[0]); 2024 EXPECT_EQ(kSignature1, encoded_signatures[0]);
2024 2025
2025 std::string encoded_query_string; 2026 std::string encoded_query_string;
2026 encoded_query.SerializeToString(&encoded_query_string); 2027 encoded_query.SerializeToString(&encoded_query_string);
2027 EXPECT_EQ(expected_query_string, encoded_query_string); 2028 EXPECT_EQ(expected_query_string, encoded_query_string);
2028 2029
2029 // Add the same form, only one will be encoded, so EncodeQueryRequest() should 2030 // Add the same form, only one will be encoded, so EncodeQueryRequest() should
2030 // return the same data. 2031 // return the same data.
2031 forms.push_back(new FormStructure(form)); 2032 FormStructure form_structure2(form);
2033 forms.push_back(&form_structure2);
2032 2034
2033 AutofillQueryContents encoded_query2; 2035 AutofillQueryContents encoded_query2;
2034 ASSERT_TRUE(FormStructure::EncodeQueryRequest( 2036 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
2035 forms.get(), &encoded_signatures, &encoded_query2)); 2037 &encoded_query2));
2036 ASSERT_EQ(1U, encoded_signatures.size()); 2038 ASSERT_EQ(1U, encoded_signatures.size());
2037 EXPECT_EQ(kSignature1, encoded_signatures[0]); 2039 EXPECT_EQ(kSignature1, encoded_signatures[0]);
2038 2040
2039 encoded_query2.SerializeToString(&encoded_query_string); 2041 encoded_query2.SerializeToString(&encoded_query_string);
2040 EXPECT_EQ(expected_query_string, encoded_query_string); 2042 EXPECT_EQ(expected_query_string, encoded_query_string);
2041 2043
2042 // Add 5 address fields - this should be still a valid form. 2044 // Add 5 address fields - this should be still a valid form.
2043 for (size_t i = 0; i < 5; ++i) { 2045 for (size_t i = 0; i < 5; ++i) {
2044 field.label = ASCIIToUTF16("Address"); 2046 field.label = ASCIIToUTF16("Address");
2045 field.name = ASCIIToUTF16("address"); 2047 field.name = ASCIIToUTF16("address");
2046 form.fields.push_back(field); 2048 form.fields.push_back(field);
2047 } 2049 }
2048 2050
2049 forms.push_back(new FormStructure(form)); 2051 FormStructure form_structure3(form);
2052 forms.push_back(&form_structure3);
2050 2053
2051 // Add the second form to the expected proto. 2054 // Add the second form to the expected proto.
2052 query_form = query.add_form(); 2055 query_form = query.add_form();
2053 query_form->set_signature(8308881815906226214U); 2056 query_form->set_signature(8308881815906226214U);
2054 2057
2055 test::FillQueryField(query_form->add_field(), 412125936U, "name_on_card", 2058 test::FillQueryField(query_form->add_field(), 412125936U, "name_on_card",
2056 "text"); 2059 "text");
2057 test::FillQueryField(query_form->add_field(), 1917667676U, "billing_address", 2060 test::FillQueryField(query_form->add_field(), 1917667676U, "billing_address",
2058 "text"); 2061 "text");
2059 test::FillQueryField(query_form->add_field(), 2226358947U, "card_number", 2062 test::FillQueryField(query_form->add_field(), 2226358947U, "card_number",
2060 "text"); 2063 "text");
2061 test::FillQueryField(query_form->add_field(), 747221617U, "expiration_month", 2064 test::FillQueryField(query_form->add_field(), 747221617U, "expiration_month",
2062 "text"); 2065 "text");
2063 test::FillQueryField(query_form->add_field(), 4108155786U, "expiration_year", 2066 test::FillQueryField(query_form->add_field(), 4108155786U, "expiration_year",
2064 "text"); 2067 "text");
2065 for (int i = 0; i < 5; ++i) { 2068 for (int i = 0; i < 5; ++i) {
2066 test::FillQueryField(query_form->add_field(), 509334676U, "address", 2069 test::FillQueryField(query_form->add_field(), 509334676U, "address",
2067 "text"); 2070 "text");
2068 } 2071 }
2069 2072
2070 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); 2073 ASSERT_TRUE(query.SerializeToString(&expected_query_string));
2071 2074
2072 AutofillQueryContents encoded_query3; 2075 AutofillQueryContents encoded_query3;
2073 ASSERT_TRUE(FormStructure::EncodeQueryRequest( 2076 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
2074 forms.get(), &encoded_signatures, &encoded_query3)); 2077 &encoded_query3));
2075 ASSERT_EQ(2U, encoded_signatures.size()); 2078 ASSERT_EQ(2U, encoded_signatures.size());
2076 EXPECT_EQ(kSignature1, encoded_signatures[0]); 2079 EXPECT_EQ(kSignature1, encoded_signatures[0]);
2077 const char kSignature2[] = "8308881815906226214"; 2080 const char kSignature2[] = "8308881815906226214";
2078 EXPECT_EQ(kSignature2, encoded_signatures[1]); 2081 EXPECT_EQ(kSignature2, encoded_signatures[1]);
2079 2082
2080 encoded_query3.SerializeToString(&encoded_query_string); 2083 encoded_query3.SerializeToString(&encoded_query_string);
2081 EXPECT_EQ(expected_query_string, encoded_query_string); 2084 EXPECT_EQ(expected_query_string, encoded_query_string);
2082 2085
2083 FormData malformed_form(form); 2086 FormData malformed_form(form);
2084 // Add 50 address fields - the form is not valid anymore, but previous ones 2087 // Add 50 address fields - the form is not valid anymore, but previous ones
2085 // are. The result should be the same as in previous test. 2088 // are. The result should be the same as in previous test.
2086 for (size_t i = 0; i < 50; ++i) { 2089 for (size_t i = 0; i < 50; ++i) {
2087 field.label = ASCIIToUTF16("Address"); 2090 field.label = ASCIIToUTF16("Address");
2088 field.name = ASCIIToUTF16("address"); 2091 field.name = ASCIIToUTF16("address");
2089 malformed_form.fields.push_back(field); 2092 malformed_form.fields.push_back(field);
2090 } 2093 }
2091 2094
2092 forms.push_back(new FormStructure(malformed_form)); 2095 FormStructure malformed_form_structure(malformed_form);
2096 forms.push_back(&malformed_form_structure);
2093 AutofillQueryContents encoded_query4; 2097 AutofillQueryContents encoded_query4;
2094 ASSERT_TRUE(FormStructure::EncodeQueryRequest( 2098 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
2095 forms.get(), &encoded_signatures, &encoded_query4)); 2099 &encoded_query4));
2096 ASSERT_EQ(2U, encoded_signatures.size()); 2100 ASSERT_EQ(2U, encoded_signatures.size());
2097 EXPECT_EQ(kSignature1, encoded_signatures[0]); 2101 EXPECT_EQ(kSignature1, encoded_signatures[0]);
2098 EXPECT_EQ(kSignature2, encoded_signatures[1]); 2102 EXPECT_EQ(kSignature2, encoded_signatures[1]);
2099 2103
2100 encoded_query4.SerializeToString(&encoded_query_string); 2104 encoded_query4.SerializeToString(&encoded_query_string);
2101 EXPECT_EQ(expected_query_string, encoded_query_string); 2105 EXPECT_EQ(expected_query_string, encoded_query_string);
2102 2106
2103 // Check that we fail if there are only bad form(s). 2107 // Check that we fail if there are only bad form(s).
2104 ScopedVector<FormStructure> bad_forms; 2108 std::vector<FormStructure*> bad_forms;
2105 bad_forms.push_back(new FormStructure(malformed_form)); 2109 bad_forms.push_back(&malformed_form_structure);
2106 AutofillQueryContents encoded_query5; 2110 AutofillQueryContents encoded_query5;
2107 EXPECT_FALSE(FormStructure::EncodeQueryRequest( 2111 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms, &encoded_signatures,
2108 bad_forms.get(), &encoded_signatures, &encoded_query5)); 2112 &encoded_query5));
2109 } 2113 }
2110 2114
2111 TEST_F(FormStructureTest, EncodeUploadRequest) { 2115 TEST_F(FormStructureTest, EncodeUploadRequest) {
2112 std::unique_ptr<FormStructure> form_structure; 2116 std::unique_ptr<FormStructure> form_structure;
2113 std::vector<ServerFieldTypeSet> possible_field_types; 2117 std::vector<ServerFieldTypeSet> possible_field_types;
2114 FormData form; 2118 FormData form;
2115 form_structure.reset(new FormStructure(form)); 2119 form_structure.reset(new FormStructure(form));
2116 form_structure->DetermineHeuristicTypes(); 2120 form_structure->DetermineHeuristicTypes();
2117 2121
2118 FormFieldData field; 2122 FormFieldData field;
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
3395 field.form_control_type = "checkbox"; 3399 field.form_control_type = "checkbox";
3396 field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; 3400 field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED;
3397 form.fields.push_back(field); 3401 form.fields.push_back(field);
3398 3402
3399 field.label = base::string16(); 3403 field.label = base::string16();
3400 field.name = ASCIIToUTF16("email"); 3404 field.name = ASCIIToUTF16("email");
3401 field.form_control_type = "text"; 3405 field.form_control_type = "text";
3402 field.check_status = FormFieldData::NOT_CHECKABLE; 3406 field.check_status = FormFieldData::NOT_CHECKABLE;
3403 form.fields.push_back(field); 3407 form.fields.push_back(field);
3404 3408
3405 ScopedVector<FormStructure> forms; 3409 FormStructure form_structure(form);
3406 forms.push_back(new FormStructure(form)); 3410 std::vector<FormStructure*> forms;
3411 forms.push_back(&form_structure);
3407 std::vector<std::string> encoded_signatures; 3412 std::vector<std::string> encoded_signatures;
3408 AutofillQueryContents encoded_query; 3413 AutofillQueryContents encoded_query;
3409 3414
3410 // Create the expected query and serialize it to a string. 3415 // Create the expected query and serialize it to a string.
3411 AutofillQueryContents query; 3416 AutofillQueryContents query;
3412 query.set_client_version("6.1.1715.1442/en (GGLL)"); 3417 query.set_client_version("6.1.1715.1442/en (GGLL)");
3413 AutofillQueryContents::Form* query_form = query.add_form(); 3418 AutofillQueryContents::Form* query_form = query.add_form();
3414 query_form->set_signature(18006745212084723782U); 3419 query_form->set_signature(18006745212084723782U);
3415 3420
3416 test::FillQueryField(query_form->add_field(), 239111655U, "username", "text"); 3421 test::FillQueryField(query_form->add_field(), 239111655U, "username", "text");
3417 test::FillQueryField(query_form->add_field(), 420638584U, "email", "text"); 3422 test::FillQueryField(query_form->add_field(), 420638584U, "email", "text");
3418 3423
3419 std::string expected_query_string; 3424 std::string expected_query_string;
3420 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); 3425 ASSERT_TRUE(query.SerializeToString(&expected_query_string));
3421 3426
3422 const char kExpectedSignature[] = "18006745212084723782"; 3427 const char kExpectedSignature[] = "18006745212084723782";
3423 3428
3424 ASSERT_TRUE(FormStructure::EncodeQueryRequest( 3429 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
3425 forms.get(), &encoded_signatures, &encoded_query)); 3430 &encoded_query));
3426 ASSERT_EQ(1U, encoded_signatures.size()); 3431 ASSERT_EQ(1U, encoded_signatures.size());
3427 EXPECT_EQ(kExpectedSignature, encoded_signatures[0]); 3432 EXPECT_EQ(kExpectedSignature, encoded_signatures[0]);
3428 3433
3429 std::string encoded_query_string; 3434 std::string encoded_query_string;
3430 encoded_query.SerializeToString(&encoded_query_string); 3435 encoded_query.SerializeToString(&encoded_query_string);
3431 EXPECT_EQ(expected_query_string, encoded_query_string); 3436 EXPECT_EQ(expected_query_string, encoded_query_string);
3432 } 3437 }
3433 3438
3434 TEST_F(FormStructureTest, EncodeQueryRequest_WithLabels) { 3439 TEST_F(FormStructureTest, EncodeQueryRequest_WithLabels) {
3435 FormData form; 3440 FormData form;
(...skipping 10 matching lines...) Expand all
3446 field.label = ASCIIToUTF16("Enter your Email address"); 3451 field.label = ASCIIToUTF16("Enter your Email address");
3447 field.name = ASCIIToUTF16("email"); 3452 field.name = ASCIIToUTF16("email");
3448 field.form_control_type = "text"; 3453 field.form_control_type = "text";
3449 form.fields.push_back(field); 3454 form.fields.push_back(field);
3450 3455
3451 field.label = ASCIIToUTF16("Enter your Password"); 3456 field.label = ASCIIToUTF16("Enter your Password");
3452 field.name = ASCIIToUTF16("password"); 3457 field.name = ASCIIToUTF16("password");
3453 field.form_control_type = "password"; 3458 field.form_control_type = "password";
3454 form.fields.push_back(field); 3459 form.fields.push_back(field);
3455 3460
3456 ScopedVector<FormStructure> forms; 3461 std::vector<FormStructure*> forms;
3457 forms.push_back(new FormStructure(form)); 3462 FormStructure form_structure(form);
3463 forms.push_back(&form_structure);
3458 std::vector<std::string> encoded_signatures; 3464 std::vector<std::string> encoded_signatures;
3459 AutofillQueryContents encoded_query; 3465 AutofillQueryContents encoded_query;
3460 3466
3461 // Create the expected query and serialize it to a string. 3467 // Create the expected query and serialize it to a string.
3462 AutofillQueryContents query; 3468 AutofillQueryContents query;
3463 query.set_client_version("6.1.1715.1442/en (GGLL)"); 3469 query.set_client_version("6.1.1715.1442/en (GGLL)");
3464 AutofillQueryContents::Form* query_form = query.add_form(); 3470 AutofillQueryContents::Form* query_form = query.add_form();
3465 query_form->set_signature(13906559713264665730U); 3471 query_form->set_signature(13906559713264665730U);
3466 3472
3467 test::FillQueryField(query_form->add_field(), 239111655U, "username", "text"); 3473 test::FillQueryField(query_form->add_field(), 239111655U, "username", "text");
3468 test::FillQueryField(query_form->add_field(), 420638584U, "email", "text"); 3474 test::FillQueryField(query_form->add_field(), 420638584U, "email", "text");
3469 test::FillQueryField(query_form->add_field(), 2051817934U, "password", 3475 test::FillQueryField(query_form->add_field(), 2051817934U, "password",
3470 "password"); 3476 "password");
3471 3477
3472 std::string expected_query_string; 3478 std::string expected_query_string;
3473 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); 3479 ASSERT_TRUE(query.SerializeToString(&expected_query_string));
3474 3480
3475 EXPECT_TRUE(FormStructure::EncodeQueryRequest( 3481 EXPECT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
3476 forms.get(), &encoded_signatures, &encoded_query)); 3482 &encoded_query));
3477 3483
3478 std::string encoded_query_string; 3484 std::string encoded_query_string;
3479 encoded_query.SerializeToString(&encoded_query_string); 3485 encoded_query.SerializeToString(&encoded_query_string);
3480 EXPECT_EQ(expected_query_string, encoded_query_string); 3486 EXPECT_EQ(expected_query_string, encoded_query_string);
3481 } 3487 }
3482 3488
3483 TEST_F(FormStructureTest, EncodeQueryRequest_WithLongLabels) { 3489 TEST_F(FormStructureTest, EncodeQueryRequest_WithLongLabels) {
3484 FormData form; 3490 FormData form;
3485 form.name = ASCIIToUTF16("the-name"); 3491 form.name = ASCIIToUTF16("the-name");
3486 form.origin = GURL("http://cool.com"); 3492 form.origin = GURL("http://cool.com");
(...skipping 13 matching lines...) Expand all
3500 "Exceeding A Certain Number Of Characters..."); 3506 "Exceeding A Certain Number Of Characters...");
3501 field.name = ASCIIToUTF16("email"); 3507 field.name = ASCIIToUTF16("email");
3502 field.form_control_type = "text"; 3508 field.form_control_type = "text";
3503 form.fields.push_back(field); 3509 form.fields.push_back(field);
3504 3510
3505 field.label = ASCIIToUTF16("Enter your Password"); 3511 field.label = ASCIIToUTF16("Enter your Password");
3506 field.name = ASCIIToUTF16("password"); 3512 field.name = ASCIIToUTF16("password");
3507 field.form_control_type = "password"; 3513 field.form_control_type = "password";
3508 form.fields.push_back(field); 3514 form.fields.push_back(field);
3509 3515
3510 ScopedVector<FormStructure> forms; 3516 FormStructure form_structure(form);
3511 forms.push_back(new FormStructure(form)); 3517 std::vector<FormStructure*> forms;
3518 forms.push_back(&form_structure);
3512 std::vector<std::string> encoded_signatures; 3519 std::vector<std::string> encoded_signatures;
3513 AutofillQueryContents encoded_query; 3520 AutofillQueryContents encoded_query;
3514 3521
3515 // Create the expected query and serialize it to a string. 3522 // Create the expected query and serialize it to a string.
3516 AutofillQueryContents query; 3523 AutofillQueryContents query;
3517 query.set_client_version("6.1.1715.1442/en (GGLL)"); 3524 query.set_client_version("6.1.1715.1442/en (GGLL)");
3518 AutofillQueryContents::Form* query_form = query.add_form(); 3525 AutofillQueryContents::Form* query_form = query.add_form();
3519 query_form->set_signature(13906559713264665730U); 3526 query_form->set_signature(13906559713264665730U);
3520 3527
3521 test::FillQueryField(query_form->add_field(), 239111655U, "username", "text"); 3528 test::FillQueryField(query_form->add_field(), 239111655U, "username", "text");
3522 test::FillQueryField(query_form->add_field(), 420638584U, "email", "text"); 3529 test::FillQueryField(query_form->add_field(), 420638584U, "email", "text");
3523 test::FillQueryField(query_form->add_field(), 2051817934U, "password", 3530 test::FillQueryField(query_form->add_field(), 2051817934U, "password",
3524 "password"); 3531 "password");
3525 3532
3526 std::string expected_query_string; 3533 std::string expected_query_string;
3527 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); 3534 ASSERT_TRUE(query.SerializeToString(&expected_query_string));
3528 3535
3529 EXPECT_TRUE(FormStructure::EncodeQueryRequest( 3536 EXPECT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
3530 forms.get(), &encoded_signatures, &encoded_query)); 3537 &encoded_query));
3531 3538
3532 std::string encoded_query_string; 3539 std::string encoded_query_string;
3533 encoded_query.SerializeToString(&encoded_query_string); 3540 encoded_query.SerializeToString(&encoded_query_string);
3534 EXPECT_EQ(expected_query_string, encoded_query_string); 3541 EXPECT_EQ(expected_query_string, encoded_query_string);
3535 } 3542 }
3536 3543
3537 // One name is missing from one field. 3544 // One name is missing from one field.
3538 TEST_F(FormStructureTest, EncodeQueryRequest_MissingNames) { 3545 TEST_F(FormStructureTest, EncodeQueryRequest_MissingNames) {
3539 FormData form; 3546 FormData form;
3540 // No name set for the form. 3547 // No name set for the form.
3541 form.origin = GURL("http://cool.com"); 3548 form.origin = GURL("http://cool.com");
3542 form.action = form.origin.Resolve("/login"); 3549 form.action = form.origin.Resolve("/login");
3543 3550
3544 FormFieldData field; 3551 FormFieldData field;
3545 field.label = ASCIIToUTF16("username"); 3552 field.label = ASCIIToUTF16("username");
3546 field.name = ASCIIToUTF16("username"); 3553 field.name = ASCIIToUTF16("username");
3547 field.form_control_type = "text"; 3554 field.form_control_type = "text";
3548 form.fields.push_back(field); 3555 form.fields.push_back(field);
3549 3556
3550 field.label = base::string16(); 3557 field.label = base::string16();
3551 // No name set for this field. 3558 // No name set for this field.
3552 field.name = ASCIIToUTF16(""); 3559 field.name = ASCIIToUTF16("");
3553 field.form_control_type = "text"; 3560 field.form_control_type = "text";
3554 field.check_status = FormFieldData::NOT_CHECKABLE; 3561 field.check_status = FormFieldData::NOT_CHECKABLE;
3555 form.fields.push_back(field); 3562 form.fields.push_back(field);
3556 3563
3557 ScopedVector<FormStructure> forms; 3564 FormStructure form_structure(form);
3558 forms.push_back(new FormStructure(form)); 3565
3566 std::vector<FormStructure*> forms;
3567 forms.push_back(&form_structure);
3559 std::vector<std::string> encoded_signatures; 3568 std::vector<std::string> encoded_signatures;
3560 AutofillQueryContents encoded_query; 3569 AutofillQueryContents encoded_query;
3561 3570
3562 // Create the expected query and serialize it to a string. 3571 // Create the expected query and serialize it to a string.
3563 AutofillQueryContents query; 3572 AutofillQueryContents query;
3564 query.set_client_version("6.1.1715.1442/en (GGLL)"); 3573 query.set_client_version("6.1.1715.1442/en (GGLL)");
3565 AutofillQueryContents::Form* query_form = query.add_form(); 3574 AutofillQueryContents::Form* query_form = query.add_form();
3566 query_form->set_signature(16416961345885087496U); 3575 query_form->set_signature(16416961345885087496U);
3567 3576
3568 test::FillQueryField(query_form->add_field(), 239111655U, "username", "text"); 3577 test::FillQueryField(query_form->add_field(), 239111655U, "username", "text");
3569 test::FillQueryField(query_form->add_field(), 1318412689U, nullptr, "text"); 3578 test::FillQueryField(query_form->add_field(), 1318412689U, nullptr, "text");
3570 3579
3571 std::string expected_query_string; 3580 std::string expected_query_string;
3572 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); 3581 ASSERT_TRUE(query.SerializeToString(&expected_query_string));
3573 3582
3574 const char kExpectedSignature[] = "16416961345885087496"; 3583 const char kExpectedSignature[] = "16416961345885087496";
3575 3584
3576 ASSERT_TRUE(FormStructure::EncodeQueryRequest( 3585 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
3577 forms.get(), &encoded_signatures, &encoded_query)); 3586 &encoded_query));
3578 ASSERT_EQ(1U, encoded_signatures.size()); 3587 ASSERT_EQ(1U, encoded_signatures.size());
3579 EXPECT_EQ(kExpectedSignature, encoded_signatures[0]); 3588 EXPECT_EQ(kExpectedSignature, encoded_signatures[0]);
3580 3589
3581 std::string encoded_query_string; 3590 std::string encoded_query_string;
3582 encoded_query.SerializeToString(&encoded_query_string); 3591 encoded_query.SerializeToString(&encoded_query_string);
3583 EXPECT_EQ(expected_query_string, encoded_query_string); 3592 EXPECT_EQ(expected_query_string, encoded_query_string);
3584 } 3593 }
3585 3594
3586 // Sending field metadata to the server is disabled. 3595 // Sending field metadata to the server is disabled.
3587 TEST_F(FormStructureTest, EncodeQueryRequest_DisabledMetadataTrial) { 3596 TEST_F(FormStructureTest, EncodeQueryRequest_DisabledMetadataTrial) {
3588 DisableAutofillMetadataFieldTrial(); 3597 DisableAutofillMetadataFieldTrial();
3589 3598
3590 FormData form; 3599 FormData form;
3591 // No name set for the form. 3600 // No name set for the form.
3592 form.origin = GURL("http://cool.com"); 3601 form.origin = GURL("http://cool.com");
3593 form.action = form.origin.Resolve("/login"); 3602 form.action = form.origin.Resolve("/login");
3594 3603
3595 FormFieldData field; 3604 FormFieldData field;
3596 field.label = ASCIIToUTF16("username"); 3605 field.label = ASCIIToUTF16("username");
3597 field.name = ASCIIToUTF16("username"); 3606 field.name = ASCIIToUTF16("username");
3598 field.form_control_type = "text"; 3607 field.form_control_type = "text";
3599 form.fields.push_back(field); 3608 form.fields.push_back(field);
3600 3609
3601 field.label = base::string16(); 3610 field.label = base::string16();
3602 field.name = ASCIIToUTF16("country"); 3611 field.name = ASCIIToUTF16("country");
3603 field.form_control_type = "text"; 3612 field.form_control_type = "text";
3604 field.check_status = FormFieldData::NOT_CHECKABLE; 3613 field.check_status = FormFieldData::NOT_CHECKABLE;
3605 form.fields.push_back(field); 3614 form.fields.push_back(field);
3606 3615
3607 ScopedVector<FormStructure> forms; 3616 FormStructure form_structure(form);
3608 forms.push_back(new FormStructure(form)); 3617 std::vector<FormStructure*> forms;
3618 forms.push_back(&form_structure);
3609 std::vector<std::string> encoded_signatures; 3619 std::vector<std::string> encoded_signatures;
3610 AutofillQueryContents encoded_query; 3620 AutofillQueryContents encoded_query;
3611 3621
3612 // Create the expected query and serialize it to a string. 3622 // Create the expected query and serialize it to a string.
3613 AutofillQueryContents query; 3623 AutofillQueryContents query;
3614 query.set_client_version("6.1.1715.1442/en (GGLL)"); 3624 query.set_client_version("6.1.1715.1442/en (GGLL)");
3615 AutofillQueryContents::Form* query_form = query.add_form(); 3625 AutofillQueryContents::Form* query_form = query.add_form();
3616 query_form->set_signature(7635954436925888745U); 3626 query_form->set_signature(7635954436925888745U);
3617 3627
3618 test::FillQueryField(query_form->add_field(), 239111655U, nullptr, nullptr); 3628 test::FillQueryField(query_form->add_field(), 239111655U, nullptr, nullptr);
3619 test::FillQueryField(query_form->add_field(), 3654076265U, nullptr, nullptr); 3629 test::FillQueryField(query_form->add_field(), 3654076265U, nullptr, nullptr);
3620 3630
3621 std::string expected_query_string; 3631 std::string expected_query_string;
3622 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); 3632 ASSERT_TRUE(query.SerializeToString(&expected_query_string));
3623 3633
3624 const char kExpectedSignature[] = "7635954436925888745"; 3634 const char kExpectedSignature[] = "7635954436925888745";
3625 3635
3626 ASSERT_TRUE(FormStructure::EncodeQueryRequest( 3636 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms, &encoded_signatures,
3627 forms.get(), &encoded_signatures, &encoded_query)); 3637 &encoded_query));
3628 ASSERT_EQ(1U, encoded_signatures.size()); 3638 ASSERT_EQ(1U, encoded_signatures.size());
3629 EXPECT_EQ(kExpectedSignature, encoded_signatures[0]); 3639 EXPECT_EQ(kExpectedSignature, encoded_signatures[0]);
3630 3640
3631 std::string encoded_query_string; 3641 std::string encoded_query_string;
3632 encoded_query.SerializeToString(&encoded_query_string); 3642 encoded_query.SerializeToString(&encoded_query_string);
3633 EXPECT_EQ(expected_query_string, encoded_query_string); 3643 EXPECT_EQ(expected_query_string, encoded_query_string);
3634 } 3644 }
3635 3645
3636 TEST_F(FormStructureTest, PossibleValues) { 3646 TEST_F(FormStructureTest, PossibleValues) {
3637 FormData form_data; 3647 FormData form_data;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3688 field.name = ASCIIToUTF16("address"); 3698 field.name = ASCIIToUTF16("address");
3689 form.fields.push_back(field); 3699 form.fields.push_back(field);
3690 3700
3691 // Checkable fields should be ignored in parsing 3701 // Checkable fields should be ignored in parsing
3692 FormFieldData checkable_field; 3702 FormFieldData checkable_field;
3693 checkable_field.label = ASCIIToUTF16("radio_button"); 3703 checkable_field.label = ASCIIToUTF16("radio_button");
3694 checkable_field.form_control_type = "radio"; 3704 checkable_field.form_control_type = "radio";
3695 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; 3705 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED;
3696 form.fields.push_back(checkable_field); 3706 form.fields.push_back(checkable_field);
3697 3707
3698 ScopedVector<FormStructure> forms; 3708 FormStructure form_structure(form);
3699 forms.push_back(new FormStructure(form)); 3709 std::vector<FormStructure*> forms;
3710 forms.push_back(&form_structure);
3700 3711
3701 field.label = ASCIIToUTF16("email"); 3712 field.label = ASCIIToUTF16("email");
3702 field.name = ASCIIToUTF16("email"); 3713 field.name = ASCIIToUTF16("email");
3703 form.fields.push_back(field); 3714 form.fields.push_back(field);
3704 3715
3705 field.label = ASCIIToUTF16("password"); 3716 field.label = ASCIIToUTF16("password");
3706 field.name = ASCIIToUTF16("password"); 3717 field.name = ASCIIToUTF16("password");
3707 field.form_control_type = "password"; 3718 field.form_control_type = "password";
3708 form.fields.push_back(field); 3719 form.fields.push_back(field);
3709 3720
3710 forms.push_back(new FormStructure(form)); 3721 FormStructure form_structure2(form);
3722 forms.push_back(&form_structure2);
3711 3723
3712 AutofillQueryResponseContents response; 3724 AutofillQueryResponseContents response;
3713 response.add_field()->set_autofill_type(7); 3725 response.add_field()->set_autofill_type(7);
3714 response.add_field()->set_autofill_type(30); 3726 response.add_field()->set_autofill_type(30);
3715 response.add_field()->set_autofill_type(9); 3727 response.add_field()->set_autofill_type(9);
3716 response.add_field()->set_autofill_type(0); 3728 response.add_field()->set_autofill_type(0);
3717 3729
3718 std::string response_string; 3730 std::string response_string;
3719 ASSERT_TRUE(response.SerializeToString(&response_string)); 3731 ASSERT_TRUE(response.SerializeToString(&response_string));
3720 FormStructure::ParseQueryResponse(response_string, forms.get(), nullptr); 3732 FormStructure::ParseQueryResponse(response_string, forms, nullptr);
3721 3733
3722 ASSERT_GE(forms[0]->field_count(), 2U); 3734 ASSERT_GE(forms[0]->field_count(), 2U);
3723 ASSERT_GE(forms[1]->field_count(), 2U); 3735 ASSERT_GE(forms[1]->field_count(), 2U);
3724 EXPECT_EQ(7, forms[0]->field(0)->server_type()); 3736 EXPECT_EQ(7, forms[0]->field(0)->server_type());
3725 EXPECT_EQ(30, forms[0]->field(1)->server_type()); 3737 EXPECT_EQ(30, forms[0]->field(1)->server_type());
3726 EXPECT_EQ(9, forms[1]->field(0)->server_type()); 3738 EXPECT_EQ(9, forms[1]->field(0)->server_type());
3727 EXPECT_EQ(0, forms[1]->field(1)->server_type()); 3739 EXPECT_EQ(0, forms[1]->field(1)->server_type());
3728 } 3740 }
3729 3741
3730 TEST_F(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) { 3742 TEST_F(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) {
3731 FormData form; 3743 FormData form;
3732 form.origin = GURL("http://foo.com"); 3744 form.origin = GURL("http://foo.com");
3733 FormFieldData field; 3745 FormFieldData field;
3734 3746
3735 field.label = ASCIIToUTF16("email"); 3747 field.label = ASCIIToUTF16("email");
3736 field.name = ASCIIToUTF16("email"); 3748 field.name = ASCIIToUTF16("email");
3737 field.form_control_type = "text"; 3749 field.form_control_type = "text";
3738 field.autocomplete_attribute = "email"; 3750 field.autocomplete_attribute = "email";
3739 form.fields.push_back(field); 3751 form.fields.push_back(field);
3740 3752
3741 field.label = ASCIIToUTF16("password"); 3753 field.label = ASCIIToUTF16("password");
3742 field.name = ASCIIToUTF16("password"); 3754 field.name = ASCIIToUTF16("password");
3743 field.form_control_type = "password"; 3755 field.form_control_type = "password";
3744 field.autocomplete_attribute = "new-password"; 3756 field.autocomplete_attribute = "new-password";
3745 form.fields.push_back(field); 3757 form.fields.push_back(field);
3746 3758
3747 ScopedVector<FormStructure> forms; 3759 FormStructure form_structure(form);
3748 forms.push_back(new FormStructure(form)); 3760 std::vector<FormStructure*> forms;
3761 forms.push_back(&form_structure);
3749 forms.front()->DetermineHeuristicTypes(); 3762 forms.front()->DetermineHeuristicTypes();
3750 3763
3751 AutofillQueryResponseContents response; 3764 AutofillQueryResponseContents response;
3752 response.add_field()->set_autofill_type(EMAIL_ADDRESS); 3765 response.add_field()->set_autofill_type(EMAIL_ADDRESS);
3753 response.add_field()->set_autofill_type(ACCOUNT_CREATION_PASSWORD); 3766 response.add_field()->set_autofill_type(ACCOUNT_CREATION_PASSWORD);
3754 3767
3755 std::string response_string; 3768 std::string response_string;
3756 ASSERT_TRUE(response.SerializeToString(&response_string)); 3769 ASSERT_TRUE(response.SerializeToString(&response_string));
3757 FormStructure::ParseQueryResponse(response_string, forms.get(), nullptr); 3770 FormStructure::ParseQueryResponse(response_string, forms, nullptr);
3758 3771
3759 ASSERT_GE(forms[0]->field_count(), 2U); 3772 ASSERT_GE(forms[0]->field_count(), 2U);
3760 // Server type is parsed from the response and is the end result type. 3773 // Server type is parsed from the response and is the end result type.
3761 EXPECT_EQ(EMAIL_ADDRESS, forms[0]->field(0)->server_type()); 3774 EXPECT_EQ(EMAIL_ADDRESS, forms[0]->field(0)->server_type());
3762 EXPECT_EQ(EMAIL_ADDRESS, forms[0]->field(0)->Type().GetStorableType()); 3775 EXPECT_EQ(EMAIL_ADDRESS, forms[0]->field(0)->Type().GetStorableType());
3763 EXPECT_EQ(ACCOUNT_CREATION_PASSWORD, forms[0]->field(1)->server_type()); 3776 EXPECT_EQ(ACCOUNT_CREATION_PASSWORD, forms[0]->field(1)->server_type());
3764 // TODO(crbug.com/613666): Should be a properly defined type, and not 3777 // TODO(crbug.com/613666): Should be a properly defined type, and not
3765 // UNKNOWN_TYPE. 3778 // UNKNOWN_TYPE.
3766 EXPECT_EQ(UNKNOWN_TYPE, forms[0]->field(1)->Type().GetStorableType()); 3779 EXPECT_EQ(UNKNOWN_TYPE, forms[0]->field(1)->Type().GetStorableType());
3767 } 3780 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3800 prefix = FormStructure::FindLongestCommonPrefix(strings); 3813 prefix = FormStructure::FindLongestCommonPrefix(strings);
3801 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix); 3814 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix);
3802 3815
3803 // Empty vector. 3816 // Empty vector.
3804 strings.clear(); 3817 strings.clear();
3805 prefix = FormStructure::FindLongestCommonPrefix(strings); 3818 prefix = FormStructure::FindLongestCommonPrefix(strings);
3806 EXPECT_EQ(ASCIIToUTF16(""), prefix); 3819 EXPECT_EQ(ASCIIToUTF16(""), prefix);
3807 } 3820 }
3808 3821
3809 } // namespace autofill 3822 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698