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/api/webdata/autofill_web_data_service.h" |
7 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 8 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
10 #include "chrome/browser/sync/profile_sync_test_util.h" | 11 #include "chrome/browser/sync/profile_sync_test_util.h" |
11 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 12 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
12 #include "chrome/browser/sync/test/integration/sync_test.h" | 13 #include "chrome/browser/sync/test/integration/sync_test.h" |
13 #include "chrome/browser/webdata/autofill_entry.h" | 14 #include "chrome/browser/webdata/autofill_entry.h" |
14 #include "chrome/browser/webdata/autofill_table.h" | 15 #include "chrome/browser/webdata/autofill_table.h" |
15 #include "chrome/browser/webdata/web_data_service.h" | |
16 #include "chrome/browser/webdata/web_database.h" | 16 #include "chrome/browser/webdata/web_database.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/test/base/thread_observer_helper.h" | 18 #include "chrome/test/base/thread_observer_helper.h" |
19 #include "components/autofill/browser/autofill_common_test.h" | 19 #include "components/autofill/browser/autofill_common_test.h" |
20 #include "components/autofill/browser/autofill_profile.h" | 20 #include "components/autofill/browser/autofill_profile.h" |
21 #include "components/autofill/browser/autofill_type.h" | 21 #include "components/autofill/browser/autofill_type.h" |
22 #include "components/autofill/browser/personal_data_manager.h" | 22 #include "components/autofill/browser/personal_data_manager.h" |
23 #include "components/autofill/browser/personal_data_manager_observer.h" | 23 #include "components/autofill/browser/personal_data_manager_observer.h" |
24 #include "components/autofill/common/form_field_data.h" | 24 #include "components/autofill/common/form_field_data.h" |
25 | 25 |
(...skipping 28 matching lines...) Expand all Loading... |
54 }; | 54 }; |
55 | 55 |
56 void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { | 56 void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { |
57 WaitableEvent done_event(false, false); | 57 WaitableEvent done_event(false, false); |
58 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( | 58 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( |
59 new AutofillDBThreadObserverHelper()); | 59 new AutofillDBThreadObserverHelper()); |
60 observer_helper->Init(); | 60 observer_helper->Init(); |
61 | 61 |
62 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). | 62 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). |
63 WillOnce(SignalEvent(&done_event)); | 63 WillOnce(SignalEvent(&done_event)); |
64 scoped_refptr<WebDataService> wds = | 64 scoped_refptr<AutofillWebDataService> wds = |
65 autofill_helper::GetWebDataService(profile); | 65 autofill_helper::GetWebDataService(profile); |
66 wds->RemoveFormValueForElementName(key.name(), key.value()); | 66 wds->RemoveFormValueForElementName(key.name(), key.value()); |
67 done_event.Wait(); | 67 done_event.Wait(); |
68 } | 68 } |
69 | 69 |
70 void RunOnDBThreadAndSignal(base::Closure task, | 70 void RunOnDBThreadAndSignal(base::Closure task, |
71 base::WaitableEvent* done_event) { | 71 base::WaitableEvent* done_event) { |
72 if (!task.is_null()) { | 72 if (!task.is_null()) { |
73 task.Run(); | 73 task.Run(); |
74 } | 74 } |
75 done_event->Signal(); | 75 done_event->Signal(); |
76 } | 76 } |
77 | 77 |
78 void RunOnDBThreadAndBlock(base::Closure task) { | 78 void RunOnDBThreadAndBlock(base::Closure task) { |
79 WaitableEvent done_event(false, false); | 79 WaitableEvent done_event(false, false); |
80 BrowserThread::PostTask(BrowserThread::DB, | 80 BrowserThread::PostTask(BrowserThread::DB, |
81 FROM_HERE, | 81 FROM_HERE, |
82 Bind(&RunOnDBThreadAndSignal, task, &done_event)); | 82 Bind(&RunOnDBThreadAndSignal, task, &done_event)); |
83 done_event.Wait(); | 83 done_event.Wait(); |
84 } | 84 } |
85 | 85 |
86 void GetAllAutofillEntriesOnDBThread(WebDataService* wds, | 86 void GetAllAutofillEntriesOnDBThread(AutofillWebDataService* wds, |
87 std::vector<AutofillEntry>* entries) { | 87 std::vector<AutofillEntry>* entries) { |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
89 AutofillTable::FromWebDatabase( | 89 AutofillTable::FromWebDatabase( |
90 wds->GetDatabase())->GetAllAutofillEntries(entries); | 90 wds->GetDatabase())->GetAllAutofillEntries(entries); |
91 } | 91 } |
92 | 92 |
93 std::vector<AutofillEntry> GetAllAutofillEntries(WebDataService* wds) { | 93 std::vector<AutofillEntry> GetAllAutofillEntries(AutofillWebDataService* wds) { |
94 std::vector<AutofillEntry> entries; | 94 std::vector<AutofillEntry> entries; |
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
96 RunOnDBThreadAndBlock(Bind(&GetAllAutofillEntriesOnDBThread, | 96 RunOnDBThreadAndBlock(Bind(&GetAllAutofillEntriesOnDBThread, |
97 Unretained(wds), | 97 Unretained(wds), |
98 &entries)); | 98 &entries)); |
99 return entries; | 99 return entries; |
100 } | 100 } |
101 | 101 |
102 // UI thread returns from the update operations on the DB thread and schedules | 102 // UI thread returns from the update operations on the DB thread and schedules |
103 // the sync. This function blocks until after this scheduled sync is complete by | 103 // the sync. This function blocks until after this scheduled sync is complete by |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 break; | 142 break; |
143 case PROFILE_NULL: | 143 case PROFILE_NULL: |
144 autofill_test::SetProfileInfoWithGuid(&profile, | 144 autofill_test::SetProfileInfoWithGuid(&profile, |
145 "FE461507-7E13-4198-8E66-74C7DB6D8322", | 145 "FE461507-7E13-4198-8E66-74C7DB6D8322", |
146 "", "", "", "", "", "", "", "", "", "", "", ""); | 146 "", "", "", "", "", "", "", "", "", "", "", ""); |
147 break; | 147 break; |
148 } | 148 } |
149 return profile; | 149 return profile; |
150 } | 150 } |
151 | 151 |
152 scoped_refptr<WebDataService> GetWebDataService(int index) { | 152 scoped_refptr<AutofillWebDataService> GetWebDataService(int index) { |
153 return WebDataService::FromBrowserContext(test()->GetProfile(index)); | 153 return AutofillWebDataService::FromBrowserContext(test()->GetProfile(index)); |
154 } | 154 } |
155 | 155 |
156 PersonalDataManager* GetPersonalDataManager(int index) { | 156 PersonalDataManager* GetPersonalDataManager(int index) { |
157 return PersonalDataManagerFactory::GetForProfile(test()->GetProfile(index)); | 157 return PersonalDataManagerFactory::GetForProfile(test()->GetProfile(index)); |
158 } | 158 } |
159 | 159 |
160 void AddKeys(int profile, const std::set<AutofillKey>& keys) { | 160 void AddKeys(int profile, const std::set<AutofillKey>& keys) { |
161 std::vector<FormFieldData> form_fields; | 161 std::vector<FormFieldData> form_fields; |
162 for (std::set<AutofillKey>::const_iterator i = keys.begin(); | 162 for (std::set<AutofillKey>::const_iterator i = keys.begin(); |
163 i != keys.end(); | 163 i != keys.end(); |
164 ++i) { | 164 ++i) { |
165 FormFieldData field; | 165 FormFieldData field; |
166 field.name = i->name(); | 166 field.name = i->name(); |
167 field.value = i->value(); | 167 field.value = i->value(); |
168 form_fields.push_back(field); | 168 form_fields.push_back(field); |
169 } | 169 } |
170 | 170 |
171 WaitableEvent done_event(false, false); | 171 WaitableEvent done_event(false, false); |
172 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( | 172 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( |
173 new AutofillDBThreadObserverHelper()); | 173 new AutofillDBThreadObserverHelper()); |
174 observer_helper->Init(); | 174 observer_helper->Init(); |
175 | 175 |
176 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). | 176 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). |
177 WillOnce(SignalEvent(&done_event)); | 177 WillOnce(SignalEvent(&done_event)); |
178 scoped_refptr<WebDataService> wds = GetWebDataService(profile); | 178 scoped_refptr<AutofillWebDataService> wds = GetWebDataService(profile); |
179 wds->AddFormFields(form_fields); | 179 wds->AddFormFields(form_fields); |
180 done_event.Wait(); | 180 done_event.Wait(); |
181 BlockForPendingDBThreadTasks(); | 181 BlockForPendingDBThreadTasks(); |
182 } | 182 } |
183 | 183 |
184 void RemoveKey(int profile, const AutofillKey& key) { | 184 void RemoveKey(int profile, const AutofillKey& key) { |
185 RemoveKeyDontBlockForSync(profile, key); | 185 RemoveKeyDontBlockForSync(profile, key); |
186 BlockForPendingDBThreadTasks(); | 186 BlockForPendingDBThreadTasks(); |
187 } | 187 } |
188 | 188 |
189 void RemoveKeys(int profile) { | 189 void RemoveKeys(int profile) { |
190 std::set<AutofillEntry> keys = GetAllKeys(profile); | 190 std::set<AutofillEntry> keys = GetAllKeys(profile); |
191 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); | 191 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); |
192 it != keys.end(); ++it) { | 192 it != keys.end(); ++it) { |
193 RemoveKeyDontBlockForSync(profile, it->key()); | 193 RemoveKeyDontBlockForSync(profile, it->key()); |
194 } | 194 } |
195 BlockForPendingDBThreadTasks(); | 195 BlockForPendingDBThreadTasks(); |
196 } | 196 } |
197 | 197 |
198 std::set<AutofillEntry> GetAllKeys(int profile) { | 198 std::set<AutofillEntry> GetAllKeys(int profile) { |
199 scoped_refptr<WebDataService> wds = GetWebDataService(profile); | 199 scoped_refptr<AutofillWebDataService> wds = GetWebDataService(profile); |
200 std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds); | 200 std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds); |
201 std::set<AutofillEntry> all_keys; | 201 std::set<AutofillEntry> all_keys; |
202 for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); | 202 for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); |
203 it != all_entries.end(); ++it) { | 203 it != all_entries.end(); ++it) { |
204 all_keys.insert(*it); | 204 all_keys.insert(*it); |
205 } | 205 } |
206 return all_keys; | 206 return all_keys; |
207 } | 207 } |
208 | 208 |
209 bool KeysMatch(int profile_a, int profile_b) { | 209 bool KeysMatch(int profile_a, int profile_b) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 if (!ProfilesMatch(0, i)) { | 326 if (!ProfilesMatch(0, i)) { |
327 LOG(ERROR) << "Profile " << i << "does not contain the same autofill " | 327 LOG(ERROR) << "Profile " << i << "does not contain the same autofill " |
328 "profiles as profile 0."; | 328 "profiles as profile 0."; |
329 return false; | 329 return false; |
330 } | 330 } |
331 } | 331 } |
332 return true; | 332 return true; |
333 } | 333 } |
334 | 334 |
335 } // namespace autofill_helper | 335 } // namespace autofill_helper |
OLD | NEW |