OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <list> | 5 #include <list> |
6 #include <map> | 6 #include <map> |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 std::vector<AutofillEntry> all_entries; | 899 std::vector<AutofillEntry> all_entries; |
900 ASSERT_TRUE(db.GetAllAutofillEntries(&all_entries)); | 900 ASSERT_TRUE(db.GetAllAutofillEntries(&all_entries)); |
901 ASSERT_EQ(2U, all_entries.size()); | 901 ASSERT_EQ(2U, all_entries.size()); |
902 AutofillEntrySet expected_entries(all_entries.begin(), | 902 AutofillEntrySet expected_entries(all_entries.begin(), |
903 all_entries.end(), | 903 all_entries.end(), |
904 CompareAutofillEntries); | 904 CompareAutofillEntries); |
905 EXPECT_EQ(1U, expected_entries.count(existing)); | 905 EXPECT_EQ(1U, expected_entries.count(existing)); |
906 EXPECT_EQ(1U, expected_entries.count(entry)); | 906 EXPECT_EQ(1U, expected_entries.count(entry)); |
907 } | 907 } |
908 | 908 |
| 909 TEST_F(WebDatabaseTest, Autofill_AddFormFieldValues) { |
| 910 WebDatabase db; |
| 911 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| 912 |
| 913 Time t = Time::Now(); |
| 914 |
| 915 // Add multiple values for "firstname" and "lastname" names. Test that only |
| 916 // first value of each gets added. Related to security issue: |
| 917 // http://crbug.com/51727. |
| 918 std::vector<FormField> elements; |
| 919 elements.push_back(FormField(string16(), |
| 920 ASCIIToUTF16("firstname"), |
| 921 ASCIIToUTF16("Joe"), |
| 922 string16(), |
| 923 0)); |
| 924 elements.push_back(FormField(string16(), |
| 925 ASCIIToUTF16("firstname"), |
| 926 ASCIIToUTF16("Jane"), |
| 927 string16(), |
| 928 0)); |
| 929 elements.push_back(FormField(string16(), |
| 930 ASCIIToUTF16("lastname"), |
| 931 ASCIIToUTF16("Smith"), |
| 932 string16(), |
| 933 0)); |
| 934 elements.push_back(FormField(string16(), |
| 935 ASCIIToUTF16("lastname"), |
| 936 ASCIIToUTF16("Jones"), |
| 937 string16(), |
| 938 0)); |
| 939 |
| 940 std::vector<AutofillChange> changes; |
| 941 db.AddFormFieldValuesTime(elements, &changes, t); |
| 942 |
| 943 ASSERT_EQ(2U, changes.size()); |
| 944 EXPECT_EQ(changes[0], AutofillChange(AutofillChange::ADD, |
| 945 AutofillKey(ASCIIToUTF16("firstname"), |
| 946 ASCIIToUTF16("Joe")))); |
| 947 EXPECT_EQ(changes[1], AutofillChange(AutofillChange::ADD, |
| 948 AutofillKey(ASCIIToUTF16("lastname"), |
| 949 ASCIIToUTF16("Smith")))); |
| 950 |
| 951 std::vector<AutofillEntry> all_entries; |
| 952 ASSERT_TRUE(db.GetAllAutofillEntries(&all_entries)); |
| 953 ASSERT_EQ(2U, all_entries.size()); |
| 954 } |
| 955 |
909 static bool AddTimestampedLogin(WebDatabase* db, std::string url, | 956 static bool AddTimestampedLogin(WebDatabase* db, std::string url, |
910 const std::string& unique_string, | 957 const std::string& unique_string, |
911 const Time& time) { | 958 const Time& time) { |
912 // Example password form. | 959 // Example password form. |
913 PasswordForm form; | 960 PasswordForm form; |
914 form.origin = GURL(url + std::string("/LoginAuth")); | 961 form.origin = GURL(url + std::string("/LoginAuth")); |
915 form.username_element = ASCIIToUTF16(unique_string); | 962 form.username_element = ASCIIToUTF16(unique_string); |
916 form.username_value = ASCIIToUTF16(unique_string); | 963 form.username_value = ASCIIToUTF16(unique_string); |
917 form.password_element = ASCIIToUTF16(unique_string); | 964 form.password_element = ASCIIToUTF16(unique_string); |
918 form.submit_element = ASCIIToUTF16("signIn"); | 965 form.submit_element = ASCIIToUTF16("signIn"); |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 | 1430 |
1384 // make sure the lists of entries match | 1431 // make sure the lists of entries match |
1385 ASSERT_EQ(expected_entries.size(), entry_set.size()); | 1432 ASSERT_EQ(expected_entries.size(), entry_set.size()); |
1386 AutofillEntrySetIterator it; | 1433 AutofillEntrySetIterator it; |
1387 for (it = entry_set.begin(); it != entry_set.end(); it++) { | 1434 for (it = entry_set.begin(); it != entry_set.end(); it++) { |
1388 expected_entries.erase(*it); | 1435 expected_entries.erase(*it); |
1389 } | 1436 } |
1390 | 1437 |
1391 EXPECT_EQ(0U, expected_entries.size()); | 1438 EXPECT_EQ(0U, expected_entries.size()); |
1392 } | 1439 } |
OLD | NEW |