| 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 23 matching lines...) Expand all Loading... |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { | 56 void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { |
| 56 WaitableEvent done_event(false, false); | 57 WaitableEvent done_event(false, false); |
| 57 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( | 58 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( |
| 58 new AutofillDBThreadObserverHelper()); | 59 new AutofillDBThreadObserverHelper()); |
| 59 observer_helper->Init(); | 60 observer_helper->Init(); |
| 60 | 61 |
| 61 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). | 62 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). |
| 62 WillOnce(SignalEvent(&done_event)); | 63 WillOnce(SignalEvent(&done_event)); |
| 63 WebDataService* wds = autofill_helper::GetWebDataService(profile); | 64 scoped_refptr<WebDataService> wds = |
| 65 autofill_helper::GetWebDataService(profile); |
| 64 wds->RemoveFormValueForElementName(key.name(), key.value()); | 66 wds->RemoveFormValueForElementName(key.name(), key.value()); |
| 65 done_event.Wait(); | 67 done_event.Wait(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void RunOnDBThreadAndSignal(base::Closure task, | 70 void RunOnDBThreadAndSignal(base::Closure task, |
| 69 base::WaitableEvent* done_event) { | 71 base::WaitableEvent* done_event) { |
| 70 if (!task.is_null()) { | 72 if (!task.is_null()) { |
| 71 task.Run(); | 73 task.Run(); |
| 72 } | 74 } |
| 73 done_event->Signal(); | 75 done_event->Signal(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 break; | 141 break; |
| 140 case PROFILE_NULL: | 142 case PROFILE_NULL: |
| 141 autofill_test::SetProfileInfoWithGuid(&profile, | 143 autofill_test::SetProfileInfoWithGuid(&profile, |
| 142 "FE461507-7E13-4198-8E66-74C7DB6D8322", | 144 "FE461507-7E13-4198-8E66-74C7DB6D8322", |
| 143 "", "", "", "", "", "", "", "", "", "", "", ""); | 145 "", "", "", "", "", "", "", "", "", "", "", ""); |
| 144 break; | 146 break; |
| 145 } | 147 } |
| 146 return profile; | 148 return profile; |
| 147 } | 149 } |
| 148 | 150 |
| 149 WebDataService* GetWebDataService(int index) { | 151 scoped_refptr<WebDataService> GetWebDataService(int index) { |
| 150 return test()->GetProfile(index)->GetWebDataService(Profile::EXPLICIT_ACCESS); | 152 return WebDataServiceFactory::GetForProfile( |
| 153 test()->GetProfile(index), Profile::EXPLICIT_ACCESS); |
| 151 } | 154 } |
| 152 | 155 |
| 153 PersonalDataManager* GetPersonalDataManager(int index) { | 156 PersonalDataManager* GetPersonalDataManager(int index) { |
| 154 return PersonalDataManagerFactory::GetForProfile(test()->GetProfile(index)); | 157 return PersonalDataManagerFactory::GetForProfile(test()->GetProfile(index)); |
| 155 } | 158 } |
| 156 | 159 |
| 157 void AddKeys(int profile, const std::set<AutofillKey>& keys) { | 160 void AddKeys(int profile, const std::set<AutofillKey>& keys) { |
| 158 std::vector<webkit::forms::FormField> form_fields; | 161 std::vector<webkit::forms::FormField> form_fields; |
| 159 for (std::set<AutofillKey>::const_iterator i = keys.begin(); | 162 for (std::set<AutofillKey>::const_iterator i = keys.begin(); |
| 160 i != keys.end(); | 163 i != keys.end(); |
| 161 ++i) { | 164 ++i) { |
| 162 webkit::forms::FormField field; | 165 webkit::forms::FormField field; |
| 163 field.name = i->name(); | 166 field.name = i->name(); |
| 164 field.value = i->value(); | 167 field.value = i->value(); |
| 165 form_fields.push_back(field); | 168 form_fields.push_back(field); |
| 166 } | 169 } |
| 167 | 170 |
| 168 WaitableEvent done_event(false, false); | 171 WaitableEvent done_event(false, false); |
| 169 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( | 172 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( |
| 170 new AutofillDBThreadObserverHelper()); | 173 new AutofillDBThreadObserverHelper()); |
| 171 observer_helper->Init(); | 174 observer_helper->Init(); |
| 172 | 175 |
| 173 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). | 176 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). |
| 174 WillOnce(SignalEvent(&done_event)); | 177 WillOnce(SignalEvent(&done_event)); |
| 175 WebDataService* wds = GetWebDataService(profile); | 178 scoped_refptr<WebDataService> wds = GetWebDataService(profile); |
| 176 wds->AddFormFields(form_fields); | 179 wds->AddFormFields(form_fields); |
| 177 done_event.Wait(); | 180 done_event.Wait(); |
| 178 BlockForPendingDBThreadTasks(); | 181 BlockForPendingDBThreadTasks(); |
| 179 } | 182 } |
| 180 | 183 |
| 181 void RemoveKey(int profile, const AutofillKey& key) { | 184 void RemoveKey(int profile, const AutofillKey& key) { |
| 182 RemoveKeyDontBlockForSync(profile, key); | 185 RemoveKeyDontBlockForSync(profile, key); |
| 183 BlockForPendingDBThreadTasks(); | 186 BlockForPendingDBThreadTasks(); |
| 184 } | 187 } |
| 185 | 188 |
| 186 void RemoveKeys(int profile) { | 189 void RemoveKeys(int profile) { |
| 187 std::set<AutofillEntry> keys = GetAllKeys(profile); | 190 std::set<AutofillEntry> keys = GetAllKeys(profile); |
| 188 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); | 191 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); |
| 189 it != keys.end(); ++it) { | 192 it != keys.end(); ++it) { |
| 190 RemoveKeyDontBlockForSync(profile, it->key()); | 193 RemoveKeyDontBlockForSync(profile, it->key()); |
| 191 } | 194 } |
| 192 BlockForPendingDBThreadTasks(); | 195 BlockForPendingDBThreadTasks(); |
| 193 } | 196 } |
| 194 | 197 |
| 195 std::set<AutofillEntry> GetAllKeys(int profile) { | 198 std::set<AutofillEntry> GetAllKeys(int profile) { |
| 196 WebDataService* wds = GetWebDataService(profile); | 199 scoped_refptr<WebDataService> wds = GetWebDataService(profile); |
| 197 std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds); | 200 std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds); |
| 198 std::set<AutofillEntry> all_keys; | 201 std::set<AutofillEntry> all_keys; |
| 199 for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); | 202 for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); |
| 200 it != all_entries.end(); ++it) { | 203 it != all_entries.end(); ++it) { |
| 201 all_keys.insert(*it); | 204 all_keys.insert(*it); |
| 202 } | 205 } |
| 203 return all_keys; | 206 return all_keys; |
| 204 } | 207 } |
| 205 | 208 |
| 206 bool KeysMatch(int profile_a, int profile_b) { | 209 bool KeysMatch(int profile_a, int profile_b) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 if (!ProfilesMatch(0, i)) { | 315 if (!ProfilesMatch(0, i)) { |
| 313 LOG(ERROR) << "Profile " << i << "does not contain the same autofill " | 316 LOG(ERROR) << "Profile " << i << "does not contain the same autofill " |
| 314 "profiles as profile 0."; | 317 "profiles as profile 0."; |
| 315 return false; | 318 return false; |
| 316 } | 319 } |
| 317 } | 320 } |
| 318 return true; | 321 return true; |
| 319 } | 322 } |
| 320 | 323 |
| 321 } // namespace autofill_helper | 324 } // namespace autofill_helper |
| OLD | NEW |