| 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" |
| 11 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 11 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 12 #include "chrome/browser/sync/test/integration/sync_test.h" | 12 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 13 #include "chrome/browser/webdata/autofill_entry.h" | 13 #include "chrome/browser/webdata/autofill_entry.h" |
| 14 #include "chrome/browser/webdata/autofill_table.h" | 14 #include "chrome/browser/webdata/autofill_table.h" |
| 15 #include "chrome/browser/webdata/web_data_service.h" | 15 #include "chrome/browser/webdata/web_data_service.h" |
| 16 #include "chrome/browser/webdata/web_data_service_factory.h" | 16 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 17 #include "chrome/browser/webdata/web_database.h" | 17 #include "chrome/browser/webdata/web_database.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/test/base/thread_observer_helper.h" | |
| 20 #include "components/autofill/browser/autofill_common_test.h" | 19 #include "components/autofill/browser/autofill_common_test.h" |
| 21 #include "components/autofill/browser/autofill_profile.h" | 20 #include "components/autofill/browser/autofill_profile.h" |
| 22 #include "components/autofill/browser/autofill_type.h" | 21 #include "components/autofill/browser/autofill_type.h" |
| 23 #include "components/autofill/browser/personal_data_manager.h" | 22 #include "components/autofill/browser/personal_data_manager.h" |
| 24 #include "components/autofill/browser/personal_data_manager_observer.h" | 23 #include "components/autofill/browser/personal_data_manager_observer.h" |
| 25 #include "components/autofill/common/form_field_data.h" | 24 #include "components/autofill/common/form_field_data.h" |
| 26 | 25 |
| 27 using base::WaitableEvent; | 26 using base::WaitableEvent; |
| 28 using content::BrowserThread; | 27 using content::BrowserThread; |
| 29 using sync_datatype_helper::test; | 28 using sync_datatype_helper::test; |
| 30 using testing::_; | 29 using testing::_; |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 ACTION_P(SignalEvent, event) { | 33 ACTION_P(SignalEvent, event) { |
| 35 event->Signal(); | 34 event->Signal(); |
| 36 } | 35 } |
| 37 | 36 |
| 38 class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { | 37 class MockWebDataServiceObserver : public WebDataServiceObserver { |
| 39 protected: | 38 public: |
| 40 virtual ~AutofillDBThreadObserverHelper() {} | 39 MOCK_METHOD1(AutofillEntriesChanged, |
| 41 | 40 void(const AutofillChangeList& changes)); |
| 42 virtual void RegisterObservers() OVERRIDE { | |
| 43 registrar_.Add(&observer_, | |
| 44 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | |
| 45 content::NotificationService::AllSources()); | |
| 46 registrar_.Add(&observer_, | |
| 47 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | |
| 48 content::NotificationService::AllSources()); | |
| 49 } | |
| 50 }; | 41 }; |
| 51 | 42 |
| 52 class MockPersonalDataManagerObserver : public PersonalDataManagerObserver { | 43 class MockPersonalDataManagerObserver : public PersonalDataManagerObserver { |
| 53 public: | 44 public: |
| 54 MOCK_METHOD0(OnPersonalDataChanged, void()); | 45 MOCK_METHOD0(OnPersonalDataChanged, void()); |
| 55 }; | 46 }; |
| 56 | 47 |
| 57 void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { | 48 void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { |
| 58 WaitableEvent done_event(false, false); | 49 WaitableEvent done_event(false, false); |
| 59 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( | |
| 60 new AutofillDBThreadObserverHelper()); | |
| 61 observer_helper->Init(); | |
| 62 | 50 |
| 63 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). | 51 MockWebDataServiceObserver mock_observer; |
| 64 WillOnce(SignalEvent(&done_event)); | 52 EXPECT_CALL(mock_observer, AutofillEntriesChanged(_)) |
| 53 .WillOnce(SignalEvent(&done_event)); |
| 54 |
| 65 scoped_refptr<WebDataService> wds = | 55 scoped_refptr<WebDataService> wds = |
| 66 autofill_helper::GetWebDataService(profile); | 56 autofill_helper::GetWebDataService(profile); |
| 57 wds->AddObserver(&mock_observer); |
| 58 |
| 67 wds->RemoveFormValueForElementName(key.name(), key.value()); | 59 wds->RemoveFormValueForElementName(key.name(), key.value()); |
| 68 done_event.Wait(); | 60 done_event.Wait(); |
| 61 |
| 62 wds->RemoveObserver(&mock_observer); |
| 69 } | 63 } |
| 70 | 64 |
| 71 void RunOnDBThreadAndSignal(base::Closure task, | 65 void RunOnDBThreadAndSignal(base::Closure task, |
| 72 base::WaitableEvent* done_event) { | 66 base::WaitableEvent* done_event) { |
| 73 if (!task.is_null()) { | 67 if (!task.is_null()) { |
| 74 task.Run(); | 68 task.Run(); |
| 75 } | 69 } |
| 76 done_event->Signal(); | 70 done_event->Signal(); |
| 77 } | 71 } |
| 78 | 72 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 for (std::set<AutofillKey>::const_iterator i = keys.begin(); | 157 for (std::set<AutofillKey>::const_iterator i = keys.begin(); |
| 164 i != keys.end(); | 158 i != keys.end(); |
| 165 ++i) { | 159 ++i) { |
| 166 FormFieldData field; | 160 FormFieldData field; |
| 167 field.name = i->name(); | 161 field.name = i->name(); |
| 168 field.value = i->value(); | 162 field.value = i->value(); |
| 169 form_fields.push_back(field); | 163 form_fields.push_back(field); |
| 170 } | 164 } |
| 171 | 165 |
| 172 WaitableEvent done_event(false, false); | 166 WaitableEvent done_event(false, false); |
| 173 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( | 167 MockWebDataServiceObserver mock_observer; |
| 174 new AutofillDBThreadObserverHelper()); | 168 EXPECT_CALL(mock_observer, AutofillEntriesChanged(_)) |
| 175 observer_helper->Init(); | 169 .WillOnce(SignalEvent(&done_event)); |
| 176 | 170 |
| 177 EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). | |
| 178 WillOnce(SignalEvent(&done_event)); | |
| 179 scoped_refptr<WebDataService> wds = GetWebDataService(profile); | 171 scoped_refptr<WebDataService> wds = GetWebDataService(profile); |
| 172 wds->AddObserver(&mock_observer); |
| 173 |
| 180 wds->AddFormFields(form_fields); | 174 wds->AddFormFields(form_fields); |
| 181 done_event.Wait(); | 175 done_event.Wait(); |
| 182 BlockForPendingDBThreadTasks(); | 176 BlockForPendingDBThreadTasks(); |
| 177 |
| 178 wds->RemoveObserver(&mock_observer); |
| 183 } | 179 } |
| 184 | 180 |
| 185 void RemoveKey(int profile, const AutofillKey& key) { | 181 void RemoveKey(int profile, const AutofillKey& key) { |
| 186 RemoveKeyDontBlockForSync(profile, key); | 182 RemoveKeyDontBlockForSync(profile, key); |
| 187 BlockForPendingDBThreadTasks(); | 183 BlockForPendingDBThreadTasks(); |
| 188 } | 184 } |
| 189 | 185 |
| 190 void RemoveKeys(int profile) { | 186 void RemoveKeys(int profile) { |
| 191 std::set<AutofillEntry> keys = GetAllKeys(profile); | 187 std::set<AutofillEntry> keys = GetAllKeys(profile); |
| 192 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); | 188 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 if (!ProfilesMatch(0, i)) { | 323 if (!ProfilesMatch(0, i)) { |
| 328 LOG(ERROR) << "Profile " << i << "does not contain the same autofill " | 324 LOG(ERROR) << "Profile " << i << "does not contain the same autofill " |
| 329 "profiles as profile 0."; | 325 "profiles as profile 0."; |
| 330 return false; | 326 return false; |
| 331 } | 327 } |
| 332 } | 328 } |
| 333 return true; | 329 return true; |
| 334 } | 330 } |
| 335 | 331 |
| 336 } // namespace autofill_helper | 332 } // namespace autofill_helper |
| OLD | NEW |