| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/ref_counted.h" |
| 7 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 8 #include "chrome/browser/autofill/autofill_common_unittest.h" | 9 #include "chrome/browser/autofill/autofill_common_unittest.h" |
| 9 #include "chrome/browser/autofill/autofill_profile.h" | 10 #include "chrome/browser/autofill/autofill_profile.h" |
| 10 #include "chrome/browser/autofill/form_structure.h" | 11 #include "chrome/browser/autofill/form_structure.h" |
| 11 #include "chrome/browser/autofill/personal_data_manager.h" | 12 #include "chrome/browser/autofill/personal_data_manager.h" |
| 12 #include "chrome/browser/chrome_thread.h" | 13 #include "chrome/browser/chrome_thread.h" |
| 13 #include "chrome/browser/pref_service.h" | 14 #include "chrome/browser/pref_service.h" |
| 14 #include "chrome/common/notification_details.h" | 15 #include "chrome/common/notification_details.h" |
| 15 #include "chrome/common/notification_observer_mock.h" | 16 #include "chrome/common/notification_observer_mock.h" |
| 16 #include "chrome/common/notification_registrar.h" | 17 #include "chrome/common/notification_registrar.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 virtual void TearDown() { | 55 virtual void TearDown() { |
| 55 if (profile_.get()) | 56 if (profile_.get()) |
| 56 profile_.reset(NULL); | 57 profile_.reset(NULL); |
| 57 | 58 |
| 58 db_thread_.Stop(); | 59 db_thread_.Stop(); |
| 59 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); | 60 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); |
| 60 MessageLoop::current()->Run(); | 61 MessageLoop::current()->Run(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void ResetPersonalDataManager() { | 64 void ResetPersonalDataManager() { |
| 64 personal_data_.reset(new PersonalDataManager()); | 65 personal_data_ = new PersonalDataManager(); |
| 65 personal_data_->Init(profile_.get()); | 66 personal_data_->Init(profile_.get()); |
| 66 personal_data_->SetObserver(&personal_data_observer_); | 67 personal_data_->SetObserver(&personal_data_observer_); |
| 67 | 68 |
| 68 // Disable auxiliary profiles for unit testing. These reach out to system | 69 // Disable auxiliary profiles for unit testing. These reach out to system |
| 69 // services on the Mac. | 70 // services on the Mac. |
| 70 profile_->GetPrefs()->SetBoolean( | 71 profile_->GetPrefs()->SetBoolean( |
| 71 prefs::kAutoFillAuxiliaryProfilesEnabled, false); | 72 prefs::kAutoFillAuxiliaryProfilesEnabled, false); |
| 72 } | 73 } |
| 73 | 74 |
| 74 AutoFillProfile* MakeProfile() { | 75 AutoFillProfile* MakeProfile() { |
| 75 AutoLock lock(personal_data_->unique_ids_lock_); | 76 AutoLock lock(personal_data_->unique_ids_lock_); |
| 76 return new AutoFillProfile(string16(), | 77 return new AutoFillProfile(string16(), |
| 77 personal_data_->CreateNextUniqueID( | 78 personal_data_->CreateNextUniqueID( |
| 78 &personal_data_->unique_profile_ids_)); | 79 &personal_data_->unique_profile_ids_)); |
| 79 } | 80 } |
| 80 | 81 |
| 81 MessageLoopForUI message_loop_; | 82 MessageLoopForUI message_loop_; |
| 82 ChromeThread ui_thread_; | 83 ChromeThread ui_thread_; |
| 83 ChromeThread db_thread_; | 84 ChromeThread db_thread_; |
| 84 scoped_ptr<TestingProfile> profile_; | 85 scoped_ptr<TestingProfile> profile_; |
| 85 scoped_ptr<PersonalDataManager> personal_data_; | 86 scoped_refptr<PersonalDataManager> personal_data_; |
| 86 NotificationRegistrar registrar_; | 87 NotificationRegistrar registrar_; |
| 87 NotificationObserverMock observer_; | 88 NotificationObserverMock observer_; |
| 88 PersonalDataLoadedObserverMock personal_data_observer_; | 89 PersonalDataLoadedObserverMock personal_data_observer_; |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 // TODO(jhawkins): Test SetProfiles w/out a WebDataService in the profile. | 92 // TODO(jhawkins): Test SetProfiles w/out a WebDataService in the profile. |
| 92 TEST_F(PersonalDataManagerTest, SetProfiles) { | 93 TEST_F(PersonalDataManagerTest, SetProfiles) { |
| 93 AutoFillProfile profile0(string16(), 0); | 94 AutoFillProfile profile0(string16(), 0); |
| 94 autofill_unittest::SetProfileInfo(&profile0, | 95 autofill_unittest::SetProfileInfo(&profile0, |
| 95 "Billing", "Marion", "Mitchell", "Morrison", | 96 "Billing", "Marion", "Mitchell", "Morrison", |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 631 |
| 631 const std::vector<CreditCard*>& results = personal_data_->credit_cards(); | 632 const std::vector<CreditCard*>& results = personal_data_->credit_cards(); |
| 632 ASSERT_EQ(6U, results.size()); | 633 ASSERT_EQ(6U, results.size()); |
| 633 EXPECT_EQ(ASCIIToUTF16("Home"), results[0]->Label()); | 634 EXPECT_EQ(ASCIIToUTF16("Home"), results[0]->Label()); |
| 634 EXPECT_EQ(ASCIIToUTF16("Home2"), results[1]->Label()); | 635 EXPECT_EQ(ASCIIToUTF16("Home2"), results[1]->Label()); |
| 635 EXPECT_EQ(ASCIIToUTF16("Home3"), results[2]->Label()); | 636 EXPECT_EQ(ASCIIToUTF16("Home3"), results[2]->Label()); |
| 636 EXPECT_EQ(ASCIIToUTF16("NotHome"), results[3]->Label()); | 637 EXPECT_EQ(ASCIIToUTF16("NotHome"), results[3]->Label()); |
| 637 EXPECT_EQ(ASCIIToUTF16("Work"), results[4]->Label()); | 638 EXPECT_EQ(ASCIIToUTF16("Work"), results[4]->Label()); |
| 638 EXPECT_EQ(ASCIIToUTF16("Work2"), results[5]->Label()); | 639 EXPECT_EQ(ASCIIToUTF16("Work2"), results[5]->Label()); |
| 639 } | 640 } |
| OLD | NEW |