Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/ref_counted.h" | |
| 9 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 11 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/autofill/autofill_common_test.h" | 11 #include "chrome/browser/autofill/autofill_common_test.h" |
| 13 #include "chrome/browser/autofill/autofill_profile.h" | 12 #include "chrome/browser/autofill/autofill_profile.h" |
| 14 #include "chrome/browser/autofill/form_structure.h" | 13 #include "chrome/browser/autofill/form_structure.h" |
| 15 #include "chrome/browser/autofill/personal_data_manager.h" | 14 #include "chrome/browser/autofill/personal_data_manager.h" |
| 16 #include "chrome/browser/autofill/personal_data_manager_observer.h" | 15 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
| 17 #include "chrome/browser/password_manager/encryptor.h" | 16 #include "chrome/browser/password_manager/encryptor.h" |
| 18 #include "chrome/common/guid.h" | 17 #include "chrome/common/guid.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 db_thread_.Start(); | 53 db_thread_.Start(); |
| 55 | 54 |
| 56 profile_.reset(new TestingProfile); | 55 profile_.reset(new TestingProfile); |
| 57 profile_->CreateWebDataService(false); | 56 profile_->CreateWebDataService(false); |
| 58 | 57 |
| 59 autofill_test::DisableSystemServices(profile_.get()); | 58 autofill_test::DisableSystemServices(profile_.get()); |
| 60 ResetPersonalDataManager(); | 59 ResetPersonalDataManager(); |
| 61 } | 60 } |
| 62 | 61 |
| 63 virtual void TearDown() { | 62 virtual void TearDown() { |
| 64 personal_data_ = NULL; | 63 personal_data_.reset(NULL); |
| 65 if (profile_.get()) | 64 profile_.reset(NULL); |
|
Ilya Sherman
2011/09/23 03:56:34
nit: Are these calls to reset() really necessary?
dhollowa
2011/09/23 16:30:03
Yes, these are necessary. Destruction order needs
Ilya Sherman
2011/09/23 21:41:38
Ok, in that case, please add a comment noting that
dhollowa
2011/09/23 22:00:58
Done.
GeorgeY
2011/09/23 22:53:27
FYI, the order of the destruction is reverse to or
| |
| 66 profile_.reset(NULL); | |
| 67 | 65 |
| 68 db_thread_.Stop(); | 66 db_thread_.Stop(); |
| 69 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); | 67 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); |
| 70 MessageLoop::current()->Run(); | 68 MessageLoop::current()->Run(); |
| 71 } | 69 } |
| 72 | 70 |
| 73 void ResetPersonalDataManager() { | 71 void ResetPersonalDataManager() { |
| 74 personal_data_ = new PersonalDataManager(); | 72 personal_data_.reset(new PersonalDataManager); |
| 75 personal_data_->Init(profile_.get()); | 73 personal_data_->Init(profile_.get()); |
| 76 personal_data_->SetObserver(&personal_data_observer_); | 74 personal_data_->SetObserver(&personal_data_observer_); |
| 77 | 75 |
| 78 // Verify that the web database has been updated and the notification sent. | 76 // Verify that the web database has been updated and the notification sent. |
| 79 EXPECT_CALL(personal_data_observer_, | 77 EXPECT_CALL(personal_data_observer_, |
| 80 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 78 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 81 MessageLoop::current()->Run(); | 79 MessageLoop::current()->Run(); |
| 82 } | 80 } |
| 83 | 81 |
| 84 MessageLoopForUI message_loop_; | 82 MessageLoopForUI message_loop_; |
| 85 BrowserThread ui_thread_; | 83 BrowserThread ui_thread_; |
| 86 BrowserThread db_thread_; | 84 BrowserThread db_thread_; |
| 87 scoped_ptr<TestingProfile> profile_; | 85 scoped_ptr<TestingProfile> profile_; |
| 88 scoped_refptr<PersonalDataManager> personal_data_; | 86 scoped_ptr<PersonalDataManager> personal_data_; |
| 89 NotificationRegistrar registrar_; | 87 NotificationRegistrar registrar_; |
| 90 NotificationObserverMock observer_; | 88 NotificationObserverMock observer_; |
| 91 PersonalDataLoadedObserverMock personal_data_observer_; | 89 PersonalDataLoadedObserverMock personal_data_observer_; |
| 92 }; | 90 }; |
| 93 | 91 |
| 94 TEST_F(PersonalDataManagerTest, AddProfile) { | 92 TEST_F(PersonalDataManagerTest, AddProfile) { |
| 95 AutofillProfile profile0; | 93 AutofillProfile profile0; |
| 96 autofill_test::SetProfileInfo(&profile0, | 94 autofill_test::SetProfileInfo(&profile0, |
| 97 "John", "Mitchell", "Smith", | 95 "John", "Mitchell", "Smith", |
| 98 "j@s.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", | 96 "j@s.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", |
| (...skipping 1740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1839 | 1837 |
| 1840 // Modify expected to include multi-valued fields. | 1838 // Modify expected to include multi-valued fields. |
| 1841 std::vector<string16> values; | 1839 std::vector<string16> values; |
| 1842 expected.GetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, &values); | 1840 expected.GetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, &values); |
| 1843 values.push_back(ASCIIToUTF16("214-555-1234")); | 1841 values.push_back(ASCIIToUTF16("214-555-1234")); |
| 1844 expected.SetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, values); | 1842 expected.SetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, values); |
| 1845 | 1843 |
| 1846 ASSERT_EQ(1U, results2.size()); | 1844 ASSERT_EQ(1U, results2.size()); |
| 1847 EXPECT_EQ(0, expected.CompareMulti(*results2[0])); | 1845 EXPECT_EQ(0, expected.CompareMulti(*results2[0])); |
| 1848 } | 1846 } |
| OLD | NEW |