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 "chrome/browser/sync/test/integration/autofill_helper.h" | 5 #include "chrome/browser/sync/test/integration/autofill_helper.h" |
6 | 6 |
7 #include "chrome/browser/autofill/autofill_common_test.h" | 7 #include "chrome/browser/autofill/autofill_common_test.h" |
8 #include "chrome/browser/autofill/autofill_profile.h" | 8 #include "chrome/browser/autofill/autofill_profile.h" |
9 #include "chrome/browser/autofill/autofill_type.h" | 9 #include "chrome/browser/autofill/autofill_type.h" |
10 #include "chrome/browser/autofill/personal_data_manager.h" | 10 #include "chrome/browser/autofill/personal_data_manager.h" |
11 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 11 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
12 #include "chrome/browser/autofill/personal_data_manager_observer.h" | 12 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
15 #include "chrome/browser/sync/profile_sync_test_util.h" | 15 #include "chrome/browser/sync/profile_sync_test_util.h" |
16 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 16 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
17 #include "chrome/browser/sync/test/integration/sync_test.h" | 17 #include "chrome/browser/sync/test/integration/sync_test.h" |
18 #include "chrome/browser/webdata/autofill_entry.h" | 18 #include "chrome/browser/webdata/autofill_entry.h" |
19 #include "chrome/browser/webdata/autofill_table.h" | 19 #include "chrome/browser/webdata/autofill_table.h" |
| 20 #include "chrome/browser/webdata/web_data_service_factory.h" |
20 #include "chrome/browser/webdata/web_database.h" | 21 #include "chrome/browser/webdata/web_database.h" |
21 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/test/base/thread_observer_helper.h" | 23 #include "chrome/test/base/thread_observer_helper.h" |
23 #include "webkit/forms/form_field.h" | 24 #include "webkit/forms/form_field.h" |
24 | 25 |
25 using base::WaitableEvent; | 26 using base::WaitableEvent; |
26 using content::BrowserThread; | 27 using content::BrowserThread; |
27 using sync_datatype_helper::test; | 28 using sync_datatype_helper::test; |
28 using testing::_; | 29 using testing::_; |
29 | 30 |
(...skipping 21 matching lines...) Expand all Loading... |
51 }; | 52 }; |
52 | 53 |
53 void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { | 54 void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { |
54 WaitableEvent done_event(false, false); | 55 WaitableEvent done_event(false, false); |
55 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( | 56 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( |
56 new AutofillDBThreadObserverHelper()); | 57 new AutofillDBThreadObserverHelper()); |
57 observer_helper->Init(); | 58 observer_helper->Init(); |
58 | 59 |
59 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). | 60 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). |
60 WillOnce(SignalEvent(&done_event)); | 61 WillOnce(SignalEvent(&done_event)); |
61 WebDataService* wds = autofill_helper::GetWebDataService(profile); | 62 scoped_refptr<WebDataService> wds = |
| 63 autofill_helper::GetWebDataService(profile); |
62 wds->RemoveFormValueForElementName(key.name(), key.value()); | 64 wds->RemoveFormValueForElementName(key.name(), key.value()); |
63 done_event.Wait(); | 65 done_event.Wait(); |
64 } | 66 } |
65 | 67 |
66 void RunOnDBThreadAndSignal(base::Closure task, | 68 void RunOnDBThreadAndSignal(base::Closure task, |
67 base::WaitableEvent* done_event) { | 69 base::WaitableEvent* done_event) { |
68 if (!task.is_null()) { | 70 if (!task.is_null()) { |
69 task.Run(); | 71 task.Run(); |
70 } | 72 } |
71 done_event->Signal(); | 73 done_event->Signal(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 break; | 139 break; |
138 case PROFILE_NULL: | 140 case PROFILE_NULL: |
139 autofill_test::SetProfileInfoWithGuid(&profile, | 141 autofill_test::SetProfileInfoWithGuid(&profile, |
140 "FE461507-7E13-4198-8E66-74C7DB6D8322", | 142 "FE461507-7E13-4198-8E66-74C7DB6D8322", |
141 "", "", "", "", "", "", "", "", "", "", "", ""); | 143 "", "", "", "", "", "", "", "", "", "", "", ""); |
142 break; | 144 break; |
143 } | 145 } |
144 return profile; | 146 return profile; |
145 } | 147 } |
146 | 148 |
147 WebDataService* GetWebDataService(int index) { | 149 scoped_refptr<WebDataService> GetWebDataService(int index) { |
148 return test()->GetProfile(index)->GetWebDataService(Profile::EXPLICIT_ACCESS); | 150 return WebDataServiceFactory::GetForProfile( |
| 151 test()->GetProfile(index), Profile::EXPLICIT_ACCESS); |
149 } | 152 } |
150 | 153 |
151 PersonalDataManager* GetPersonalDataManager(int index) { | 154 PersonalDataManager* GetPersonalDataManager(int index) { |
152 return PersonalDataManagerFactory::GetForProfile(test()->GetProfile(index)); | 155 return PersonalDataManagerFactory::GetForProfile(test()->GetProfile(index)); |
153 } | 156 } |
154 | 157 |
155 void AddKeys(int profile, const std::set<AutofillKey>& keys) { | 158 void AddKeys(int profile, const std::set<AutofillKey>& keys) { |
156 std::vector<webkit::forms::FormField> form_fields; | 159 std::vector<webkit::forms::FormField> form_fields; |
157 for (std::set<AutofillKey>::const_iterator i = keys.begin(); | 160 for (std::set<AutofillKey>::const_iterator i = keys.begin(); |
158 i != keys.end(); | 161 i != keys.end(); |
159 ++i) { | 162 ++i) { |
160 webkit::forms::FormField field; | 163 webkit::forms::FormField field; |
161 field.name = i->name(); | 164 field.name = i->name(); |
162 field.value = i->value(); | 165 field.value = i->value(); |
163 form_fields.push_back(field); | 166 form_fields.push_back(field); |
164 } | 167 } |
165 | 168 |
166 WaitableEvent done_event(false, false); | 169 WaitableEvent done_event(false, false); |
167 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( | 170 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( |
168 new AutofillDBThreadObserverHelper()); | 171 new AutofillDBThreadObserverHelper()); |
169 observer_helper->Init(); | 172 observer_helper->Init(); |
170 | 173 |
171 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). | 174 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). |
172 WillOnce(SignalEvent(&done_event)); | 175 WillOnce(SignalEvent(&done_event)); |
173 WebDataService* wds = GetWebDataService(profile); | 176 scoped_refptr<WebDataService> wds = GetWebDataService(profile); |
174 wds->AddFormFields(form_fields); | 177 wds->AddFormFields(form_fields); |
175 done_event.Wait(); | 178 done_event.Wait(); |
176 BlockForPendingDBThreadTasks(); | 179 BlockForPendingDBThreadTasks(); |
177 } | 180 } |
178 | 181 |
179 void RemoveKey(int profile, const AutofillKey& key) { | 182 void RemoveKey(int profile, const AutofillKey& key) { |
180 RemoveKeyDontBlockForSync(profile, key); | 183 RemoveKeyDontBlockForSync(profile, key); |
181 BlockForPendingDBThreadTasks(); | 184 BlockForPendingDBThreadTasks(); |
182 } | 185 } |
183 | 186 |
184 void RemoveKeys(int profile) { | 187 void RemoveKeys(int profile) { |
185 std::set<AutofillEntry> keys = GetAllKeys(profile); | 188 std::set<AutofillEntry> keys = GetAllKeys(profile); |
186 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); | 189 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); |
187 it != keys.end(); ++it) { | 190 it != keys.end(); ++it) { |
188 RemoveKeyDontBlockForSync(profile, it->key()); | 191 RemoveKeyDontBlockForSync(profile, it->key()); |
189 } | 192 } |
190 BlockForPendingDBThreadTasks(); | 193 BlockForPendingDBThreadTasks(); |
191 } | 194 } |
192 | 195 |
193 std::set<AutofillEntry> GetAllKeys(int profile) { | 196 std::set<AutofillEntry> GetAllKeys(int profile) { |
194 WebDataService* wds = GetWebDataService(profile); | 197 scoped_refptr<WebDataService> wds = GetWebDataService(profile); |
195 std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds); | 198 std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds); |
196 std::set<AutofillEntry> all_keys; | 199 std::set<AutofillEntry> all_keys; |
197 for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); | 200 for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); |
198 it != all_entries.end(); ++it) { | 201 it != all_entries.end(); ++it) { |
199 all_keys.insert(*it); | 202 all_keys.insert(*it); |
200 } | 203 } |
201 return all_keys; | 204 return all_keys; |
202 } | 205 } |
203 | 206 |
204 bool KeysMatch(int profile_a, int profile_b) { | 207 bool KeysMatch(int profile_a, int profile_b) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 if (!ProfilesMatch(0, i)) { | 313 if (!ProfilesMatch(0, i)) { |
311 LOG(ERROR) << "Profile " << i << "does not contain the same autofill " | 314 LOG(ERROR) << "Profile " << i << "does not contain the same autofill " |
312 "profiles as profile 0."; | 315 "profiles as profile 0."; |
313 return false; | 316 return false; |
314 } | 317 } |
315 } | 318 } |
316 return true; | 319 return true; |
317 } | 320 } |
318 | 321 |
319 } // namespace autofill_helper | 322 } // namespace autofill_helper |
OLD | NEW |