OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 new AutofillWebDataService(web_database_, | 76 new AutofillWebDataService(web_database_, |
77 base::MessageLoopProxy::current(), | 77 base::MessageLoopProxy::current(), |
78 base::MessageLoopProxy::current(), | 78 base::MessageLoopProxy::current(), |
79 WebDataServiceBase::ProfileErrorCallback()); | 79 WebDataServiceBase::ProfileErrorCallback()); |
80 autofill_database_service_->Init(); | 80 autofill_database_service_->Init(); |
81 | 81 |
82 test::DisableSystemServices(prefs_.get()); | 82 test::DisableSystemServices(prefs_.get()); |
83 ResetPersonalDataManager(USER_MODE_NORMAL); | 83 ResetPersonalDataManager(USER_MODE_NORMAL); |
84 } | 84 } |
85 | 85 |
86 virtual void TearDown() { | |
87 // Destruction order is imposed explicitly here. | |
88 personal_data_.reset(NULL); | |
89 | |
90 autofill_database_service_->ShutdownOnUIThread(); | |
91 web_database_->ShutdownDatabase(); | |
92 autofill_database_service_ = NULL; | |
93 web_database_ = NULL; | |
94 } | |
95 | |
96 void ResetPersonalDataManager(UserMode user_mode) { | 86 void ResetPersonalDataManager(UserMode user_mode) { |
97 bool is_incognito = (user_mode == USER_MODE_INCOGNITO); | 87 bool is_incognito = (user_mode == USER_MODE_INCOGNITO); |
98 personal_data_.reset(new PersonalDataManager("en-US")); | 88 personal_data_.reset(new PersonalDataManager("en-US")); |
99 personal_data_->Init( | 89 personal_data_->Init( |
100 scoped_refptr<AutofillWebDataService>(autofill_database_service_), | 90 scoped_refptr<AutofillWebDataService>(autofill_database_service_), |
101 prefs_.get(), | 91 prefs_.get(), |
102 is_incognito); | 92 is_incognito); |
103 personal_data_->AddObserver(&personal_data_observer_); | 93 personal_data_->AddObserver(&personal_data_observer_); |
104 | 94 |
105 // Verify that the web database has been updated and the notification sent. | 95 // Verify that the web database has been updated and the notification sent. |
106 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 96 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
107 .WillOnce(QuitMainMessageLoop()); | 97 .WillOnce(QuitMainMessageLoop()); |
108 base::MessageLoop::current()->Run(); | 98 base::MessageLoop::current()->Run(); |
109 } | 99 } |
110 | 100 |
101 // Directory should be deleted at the end to ensure that | |
Ilya Sherman
2014/09/10 19:24:10
nit: "Directory" -> "The temporary directory"
| |
102 // files are not used anymore and deletion succeeds. | |
103 base::ScopedTempDir temp_dir_; | |
111 base::MessageLoopForUI message_loop_; | 104 base::MessageLoopForUI message_loop_; |
112 scoped_ptr<PrefService> prefs_; | 105 scoped_ptr<PrefService> prefs_; |
113 scoped_refptr<AutofillWebDataService> autofill_database_service_; | 106 scoped_refptr<AutofillWebDataService> autofill_database_service_; |
114 scoped_refptr<WebDatabaseService> web_database_; | 107 scoped_refptr<WebDatabaseService> web_database_; |
115 base::ScopedTempDir temp_dir_; | 108 PersonalDataLoadedObserverMock personal_data_observer_; |
116 scoped_ptr<PersonalDataManager> personal_data_; | 109 scoped_ptr<PersonalDataManager> personal_data_; |
117 PersonalDataLoadedObserverMock personal_data_observer_; | |
118 }; | 110 }; |
119 | 111 |
120 TEST_F(PersonalDataManagerTest, AddProfile) { | 112 TEST_F(PersonalDataManagerTest, AddProfile) { |
121 // Add profile0 to the database. | 113 // Add profile0 to the database. |
122 AutofillProfile profile0(autofill::test::GetFullProfile()); | 114 AutofillProfile profile0(autofill::test::GetFullProfile()); |
123 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); | 115 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); |
124 personal_data_->AddProfile(profile0); | 116 personal_data_->AddProfile(profile0); |
125 | 117 |
126 // Reload the database. | 118 // Reload the database. |
127 ResetPersonalDataManager(USER_MODE_NORMAL); | 119 ResetPersonalDataManager(USER_MODE_NORMAL); |
(...skipping 2555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2683 | 2675 |
2684 prefs_->SetBoolean(prefs::kAutofillEnabled, true); | 2676 prefs_->SetBoolean(prefs::kAutofillEnabled, true); |
2685 EXPECT_TRUE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); | 2677 EXPECT_TRUE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); |
2686 | 2678 |
2687 prefs_->SetBoolean(prefs::kAutofillEnabled, false); | 2679 prefs_->SetBoolean(prefs::kAutofillEnabled, false); |
2688 EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); | 2680 EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); |
2689 } | 2681 } |
2690 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 2682 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
2691 | 2683 |
2692 } // namespace autofill | 2684 } // namespace autofill |
OLD | NEW |