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