| 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/personal_data_manager_factory.h" | 7 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/sync/profile_sync_service.h" | 9 #include "chrome/browser/sync/profile_sync_service.h" |
| 10 #include "chrome/browser/sync/profile_sync_test_util.h" | 10 #include "chrome/browser/sync/profile_sync_test_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 using autofill::AutofillKey; | 27 using autofill::AutofillKey; |
| 28 using autofill::AutofillProfile; | 28 using autofill::AutofillProfile; |
| 29 using autofill::AutofillTable; | 29 using autofill::AutofillTable; |
| 30 using autofill::AutofillType; | 30 using autofill::AutofillType; |
| 31 using autofill::AutofillWebDataService; | 31 using autofill::AutofillWebDataService; |
| 32 using autofill::AutofillWebDataServiceObserverOnDBThread; | 32 using autofill::AutofillWebDataServiceObserverOnDBThread; |
| 33 using autofill::CreditCard; | 33 using autofill::CreditCard; |
| 34 using autofill::FormFieldData; | 34 using autofill::FormFieldData; |
| 35 using autofill::PersonalDataManager; | 35 using autofill::PersonalDataManager; |
| 36 using autofill::PersonalDataManagerObserver; | 36 using autofill::PersonalDataManagerObserver; |
| 37 using base::Bind; |
| 38 using base::Unretained; |
| 37 using base::WaitableEvent; | 39 using base::WaitableEvent; |
| 38 using content::BrowserThread; | 40 using content::BrowserThread; |
| 39 using sync_datatype_helper::test; | 41 using sync_datatype_helper::test; |
| 40 using testing::_; | 42 using testing::_; |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 ACTION_P(SignalEvent, event) { | 46 ACTION_P(SignalEvent, event) { |
| 45 event->Signal(); | 47 event->Signal(); |
| 46 } | 48 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 73 done_event.Wait(); | 75 done_event.Wait(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { | 78 void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { |
| 77 WaitableEvent done_event(false, false); | 79 WaitableEvent done_event(false, false); |
| 78 | 80 |
| 79 MockWebDataServiceObserver mock_observer; | 81 MockWebDataServiceObserver mock_observer; |
| 80 EXPECT_CALL(mock_observer, AutofillEntriesChanged(_)) | 82 EXPECT_CALL(mock_observer, AutofillEntriesChanged(_)) |
| 81 .WillOnce(SignalEvent(&done_event)); | 83 .WillOnce(SignalEvent(&done_event)); |
| 82 | 84 |
| 83 scoped_refptr<AutofillWebDataService> wds = | 85 AutofillWebDataService* wds = |
| 84 autofill_helper::GetWebDataService(profile); | 86 autofill_helper::GetWebDataService(profile); |
| 85 | 87 |
| 86 void(AutofillWebDataService::*add_observer_func)( | 88 void(AutofillWebDataService::*add_observer_func)( |
| 87 AutofillWebDataServiceObserverOnDBThread*) = | 89 AutofillWebDataServiceObserverOnDBThread*) = |
| 88 &AutofillWebDataService::AddObserver; | 90 &AutofillWebDataService::AddObserver; |
| 89 RunOnDBThreadAndBlock(Bind(add_observer_func, wds, &mock_observer)); | 91 RunOnDBThreadAndBlock(Bind(add_observer_func, |
| 92 Unretained(wds), |
| 93 &mock_observer)); |
| 90 | 94 |
| 91 wds->RemoveFormValueForElementName(key.name(), key.value()); | 95 wds->RemoveFormValueForElementName(key.name(), key.value()); |
| 92 done_event.Wait(); | 96 done_event.Wait(); |
| 93 | 97 |
| 94 void(AutofillWebDataService::*remove_observer_func)( | 98 void(AutofillWebDataService::*remove_observer_func)( |
| 95 AutofillWebDataServiceObserverOnDBThread*) = | 99 AutofillWebDataServiceObserverOnDBThread*) = |
| 96 &AutofillWebDataService::RemoveObserver; | 100 &AutofillWebDataService::RemoveObserver; |
| 97 RunOnDBThreadAndBlock(Bind(remove_observer_func, wds, &mock_observer)); | 101 RunOnDBThreadAndBlock(Bind(remove_observer_func, |
| 102 Unretained(wds), |
| 103 &mock_observer)); |
| 98 } | 104 } |
| 99 | 105 |
| 100 void GetAllAutofillEntriesOnDBThread(AutofillWebDataService* wds, | 106 void GetAllAutofillEntriesOnDBThread(AutofillWebDataService* wds, |
| 101 std::vector<AutofillEntry>* entries) { | 107 std::vector<AutofillEntry>* entries) { |
| 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 103 AutofillTable::FromWebDatabase( | 109 AutofillTable::FromWebDatabase( |
| 104 wds->GetDatabase())->GetAllAutofillEntries(entries); | 110 wds->GetDatabase())->GetAllAutofillEntries(entries); |
| 105 } | 111 } |
| 106 | 112 |
| 107 std::vector<AutofillEntry> GetAllAutofillEntries(AutofillWebDataService* wds) { | 113 std::vector<AutofillEntry> GetAllAutofillEntries(AutofillWebDataService* wds) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 break; | 162 break; |
| 157 case PROFILE_NULL: | 163 case PROFILE_NULL: |
| 158 autofill::test::SetProfileInfoWithGuid(&profile, | 164 autofill::test::SetProfileInfoWithGuid(&profile, |
| 159 "FE461507-7E13-4198-8E66-74C7DB6D8322", | 165 "FE461507-7E13-4198-8E66-74C7DB6D8322", |
| 160 "", "", "", "", "", "", "", "", "", "", "", ""); | 166 "", "", "", "", "", "", "", "", "", "", "", ""); |
| 161 break; | 167 break; |
| 162 } | 168 } |
| 163 return profile; | 169 return profile; |
| 164 } | 170 } |
| 165 | 171 |
| 166 scoped_refptr<AutofillWebDataService> GetWebDataService(int index) { | 172 AutofillWebDataService* GetWebDataService(int index) { |
| 167 return AutofillWebDataService::FromBrowserContext(test()->GetProfile(index)); | 173 return AutofillWebDataService::FromBrowserContext(test()->GetProfile(index)); |
| 168 } | 174 } |
| 169 | 175 |
| 170 PersonalDataManager* GetPersonalDataManager(int index) { | 176 PersonalDataManager* GetPersonalDataManager(int index) { |
| 171 return autofill::PersonalDataManagerFactory::GetForProfile( | 177 return autofill::PersonalDataManagerFactory::GetForProfile( |
| 172 test()->GetProfile(index)); | 178 test()->GetProfile(index)); |
| 173 } | 179 } |
| 174 | 180 |
| 175 void AddKeys(int profile, const std::set<AutofillKey>& keys) { | 181 void AddKeys(int profile, const std::set<AutofillKey>& keys) { |
| 176 std::vector<FormFieldData> form_fields; | 182 std::vector<FormFieldData> form_fields; |
| 177 for (std::set<AutofillKey>::const_iterator i = keys.begin(); | 183 for (std::set<AutofillKey>::const_iterator i = keys.begin(); |
| 178 i != keys.end(); | 184 i != keys.end(); |
| 179 ++i) { | 185 ++i) { |
| 180 FormFieldData field; | 186 FormFieldData field; |
| 181 field.name = i->name(); | 187 field.name = i->name(); |
| 182 field.value = i->value(); | 188 field.value = i->value(); |
| 183 form_fields.push_back(field); | 189 form_fields.push_back(field); |
| 184 } | 190 } |
| 185 | 191 |
| 186 WaitableEvent done_event(false, false); | 192 WaitableEvent done_event(false, false); |
| 187 MockWebDataServiceObserver mock_observer; | 193 MockWebDataServiceObserver mock_observer; |
| 188 EXPECT_CALL(mock_observer, AutofillEntriesChanged(_)) | 194 EXPECT_CALL(mock_observer, AutofillEntriesChanged(_)) |
| 189 .WillOnce(SignalEvent(&done_event)); | 195 .WillOnce(SignalEvent(&done_event)); |
| 190 | 196 |
| 191 scoped_refptr<AutofillWebDataService> wds = GetWebDataService(profile); | 197 AutofillWebDataService* wds = GetWebDataService(profile); |
| 192 | 198 |
| 193 void(AutofillWebDataService::*add_observer_func)( | 199 void(AutofillWebDataService::*add_observer_func)( |
| 194 AutofillWebDataServiceObserverOnDBThread*) = | 200 AutofillWebDataServiceObserverOnDBThread*) = |
| 195 &AutofillWebDataService::AddObserver; | 201 &AutofillWebDataService::AddObserver; |
| 196 RunOnDBThreadAndBlock(Bind(add_observer_func, wds, &mock_observer)); | 202 RunOnDBThreadAndBlock(Bind(add_observer_func, |
| 203 Unretained(wds), |
| 204 &mock_observer)); |
| 197 | 205 |
| 198 wds->AddFormFields(form_fields); | 206 wds->AddFormFields(form_fields); |
| 199 done_event.Wait(); | 207 done_event.Wait(); |
| 200 BlockForPendingDBThreadTasks(); | 208 BlockForPendingDBThreadTasks(); |
| 201 | 209 |
| 202 void(AutofillWebDataService::*remove_observer_func)( | 210 void(AutofillWebDataService::*remove_observer_func)( |
| 203 AutofillWebDataServiceObserverOnDBThread*) = | 211 AutofillWebDataServiceObserverOnDBThread*) = |
| 204 &AutofillWebDataService::RemoveObserver; | 212 &AutofillWebDataService::RemoveObserver; |
| 205 RunOnDBThreadAndBlock(Bind(remove_observer_func, wds, &mock_observer)); | 213 RunOnDBThreadAndBlock(Bind(remove_observer_func, |
| 214 Unretained(wds), |
| 215 &mock_observer)); |
| 206 } | 216 } |
| 207 | 217 |
| 208 void RemoveKey(int profile, const AutofillKey& key) { | 218 void RemoveKey(int profile, const AutofillKey& key) { |
| 209 RemoveKeyDontBlockForSync(profile, key); | 219 RemoveKeyDontBlockForSync(profile, key); |
| 210 BlockForPendingDBThreadTasks(); | 220 BlockForPendingDBThreadTasks(); |
| 211 } | 221 } |
| 212 | 222 |
| 213 void RemoveKeys(int profile) { | 223 void RemoveKeys(int profile) { |
| 214 std::set<AutofillEntry> keys = GetAllKeys(profile); | 224 std::set<AutofillEntry> keys = GetAllKeys(profile); |
| 215 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); | 225 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); |
| 216 it != keys.end(); ++it) { | 226 it != keys.end(); ++it) { |
| 217 RemoveKeyDontBlockForSync(profile, it->key()); | 227 RemoveKeyDontBlockForSync(profile, it->key()); |
| 218 } | 228 } |
| 219 BlockForPendingDBThreadTasks(); | 229 BlockForPendingDBThreadTasks(); |
| 220 } | 230 } |
| 221 | 231 |
| 222 std::set<AutofillEntry> GetAllKeys(int profile) { | 232 std::set<AutofillEntry> GetAllKeys(int profile) { |
| 223 scoped_refptr<AutofillWebDataService> wds = GetWebDataService(profile); | 233 AutofillWebDataService* wds = GetWebDataService(profile); |
| 224 std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds.get()); | 234 std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds); |
| 225 std::set<AutofillEntry> all_keys; | 235 std::set<AutofillEntry> all_keys; |
| 226 for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); | 236 for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); |
| 227 it != all_entries.end(); ++it) { | 237 it != all_entries.end(); ++it) { |
| 228 all_keys.insert(*it); | 238 all_keys.insert(*it); |
| 229 } | 239 } |
| 230 return all_keys; | 240 return all_keys; |
| 231 } | 241 } |
| 232 | 242 |
| 233 bool KeysMatch(int profile_a, int profile_b) { | 243 bool KeysMatch(int profile_a, int profile_b) { |
| 234 return GetAllKeys(profile_a) == GetAllKeys(profile_b); | 244 return GetAllKeys(profile_a) == GetAllKeys(profile_b); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 if (!ProfilesMatch(0, i)) { | 360 if (!ProfilesMatch(0, i)) { |
| 351 LOG(ERROR) << "Profile " << i << "does not contain the same autofill " | 361 LOG(ERROR) << "Profile " << i << "does not contain the same autofill " |
| 352 "profiles as profile 0."; | 362 "profiles as profile 0."; |
| 353 return false; | 363 return false; |
| 354 } | 364 } |
| 355 } | 365 } |
| 356 return true; | 366 return true; |
| 357 } | 367 } |
| 358 | 368 |
| 359 } // namespace autofill_helper | 369 } // namespace autofill_helper |
| OLD | NEW |