OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/guid.h" |
8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/autofill/autofill_common_test.h" | 12 #include "chrome/browser/autofill/autofill_common_test.h" |
12 #include "chrome/browser/autofill/autofill_profile.h" | 13 #include "chrome/browser/autofill/autofill_profile.h" |
13 #include "chrome/browser/autofill/form_structure.h" | 14 #include "chrome/browser/autofill/form_structure.h" |
14 #include "chrome/browser/autofill/personal_data_manager.h" | 15 #include "chrome/browser/autofill/personal_data_manager.h" |
15 #include "chrome/browser/autofill/personal_data_manager_observer.h" | 16 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
16 #include "chrome/browser/password_manager/encryptor.h" | 17 #include "chrome/browser/password_manager/encryptor.h" |
17 #include "chrome/browser/webdata/web_data_service_factory.h" | 18 #include "chrome/browser/webdata/web_data_service_factory.h" |
18 #include "chrome/common/guid.h" | |
19 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
21 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
23 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
24 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
25 #include "content/public/test/mock_notification_observer.h" | 25 #include "content/public/test/mock_notification_observer.h" |
26 #include "content/public/test/test_browser_thread.h" | 26 #include "content/public/test/test_browser_thread.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Reload the database. | 105 // Reload the database. |
106 ResetPersonalDataManager(); | 106 ResetPersonalDataManager(); |
107 | 107 |
108 // Verify the addition. | 108 // Verify the addition. |
109 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles(); | 109 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles(); |
110 ASSERT_EQ(1U, results1.size()); | 110 ASSERT_EQ(1U, results1.size()); |
111 EXPECT_EQ(0, profile0.Compare(*results1[0])); | 111 EXPECT_EQ(0, profile0.Compare(*results1[0])); |
112 | 112 |
113 // Add profile with identical values. Duplicates should not get saved. | 113 // Add profile with identical values. Duplicates should not get saved. |
114 AutofillProfile profile0a = profile0; | 114 AutofillProfile profile0a = profile0; |
115 profile0a.set_guid(guid::GenerateGUID()); | 115 profile0a.set_guid(base::GenerateGUID()); |
116 personal_data_->AddProfile(profile0a); | 116 personal_data_->AddProfile(profile0a); |
117 | 117 |
118 // Reload the database. | 118 // Reload the database. |
119 ResetPersonalDataManager(); | 119 ResetPersonalDataManager(); |
120 | 120 |
121 // Verify the non-addition. | 121 // Verify the non-addition. |
122 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles(); | 122 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles(); |
123 ASSERT_EQ(1U, results2.size()); | 123 ASSERT_EQ(1U, results2.size()); |
124 EXPECT_EQ(0, profile0.Compare(*results2[0])); | 124 EXPECT_EQ(0, profile0.Compare(*results2[0])); |
125 | 125 |
126 // New profile with different email. | 126 // New profile with different email. |
127 AutofillProfile profile1 = profile0; | 127 AutofillProfile profile1 = profile0; |
128 profile1.set_guid(guid::GenerateGUID()); | 128 profile1.set_guid(base::GenerateGUID()); |
129 profile1.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com")); | 129 profile1.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com")); |
130 | 130 |
131 // Add the different profile. This should save as a separate profile. | 131 // Add the different profile. This should save as a separate profile. |
132 // Note that if this same profile was "merged" it would collapse to one | 132 // Note that if this same profile was "merged" it would collapse to one |
133 // profile with a multi-valued entry for email. | 133 // profile with a multi-valued entry for email. |
134 personal_data_->AddProfile(profile1); | 134 personal_data_->AddProfile(profile1); |
135 | 135 |
136 // Reload the database. | 136 // Reload the database. |
137 ResetPersonalDataManager(); | 137 ResetPersonalDataManager(); |
138 | 138 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 346 |
347 // Verify that the web database has been updated and the notification sent. | 347 // Verify that the web database has been updated and the notification sent. |
348 EXPECT_CALL(personal_data_observer_, | 348 EXPECT_CALL(personal_data_observer_, |
349 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 349 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
350 MessageLoop::current()->Run(); | 350 MessageLoop::current()->Run(); |
351 | 351 |
352 // Make sure the two profiles have different GUIDs, both valid. | 352 // Make sure the two profiles have different GUIDs, both valid. |
353 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles(); | 353 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles(); |
354 ASSERT_EQ(2U, results3.size()); | 354 ASSERT_EQ(2U, results3.size()); |
355 EXPECT_NE(results3[0]->guid(), results3[1]->guid()); | 355 EXPECT_NE(results3[0]->guid(), results3[1]->guid()); |
356 EXPECT_TRUE(guid::IsValidGUID(results3[0]->guid())); | 356 EXPECT_TRUE(base::IsValidGUID(results3[0]->guid())); |
357 EXPECT_TRUE(guid::IsValidGUID(results3[1]->guid())); | 357 EXPECT_TRUE(base::IsValidGUID(results3[1]->guid())); |
358 } | 358 } |
359 | 359 |
360 TEST_F(PersonalDataManagerTest, SetEmptyProfile) { | 360 TEST_F(PersonalDataManagerTest, SetEmptyProfile) { |
361 AutofillProfile profile0; | 361 AutofillProfile profile0; |
362 autofill_test::SetProfileInfo(&profile0, | 362 autofill_test::SetProfileInfo(&profile0, |
363 "", "", "", "", "", "", "", "", "", "", "", ""); | 363 "", "", "", "", "", "", "", "", "", "", "", ""); |
364 | 364 |
365 // Add the empty profile to the database. | 365 // Add the empty profile to the database. |
366 personal_data_->AddProfile(profile0); | 366 personal_data_->AddProfile(profile0); |
367 | 367 |
(...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1951 | 1951 |
1952 // Modify expected to include multi-valued fields. | 1952 // Modify expected to include multi-valued fields. |
1953 std::vector<string16> values; | 1953 std::vector<string16> values; |
1954 expected.GetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, &values); | 1954 expected.GetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, &values); |
1955 values.push_back(ASCIIToUTF16("214-555-1234")); | 1955 values.push_back(ASCIIToUTF16("214-555-1234")); |
1956 expected.SetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, values); | 1956 expected.SetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, values); |
1957 | 1957 |
1958 ASSERT_EQ(1U, results2.size()); | 1958 ASSERT_EQ(1U, results2.size()); |
1959 EXPECT_EQ(0, expected.Compare(*results2[0])); | 1959 EXPECT_EQ(0, expected.Compare(*results2[0])); |
1960 } | 1960 } |
OLD | NEW |