Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3057)

Unified Diff: chrome/browser/sync/profile_sync_service_autofill_unittest.cc

Issue 12476031: Refactor notifications of chrome/browser/webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/profile_sync_service_autofill_unittest.cc
diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
index f8072b802e48c4572b5c58fbf39a9bda0c7306a5..edd273bb33ad80a8fbe4dfdd61c72c5ae2f55c7a 100644
--- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
@@ -43,10 +43,8 @@
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/browser/webdata/web_database.h"
-#include "chrome/common/chrome_notification_types.h"
#include "components/autofill/browser/autofill_common_test.h"
#include "components/autofill/browser/personal_data_manager.h"
-#include "content/public/browser/notification_source.h"
#include "content/public/test/test_browser_thread.h"
#include "google_apis/gaia/gaia_constants.h"
#include "sync/internal_api/public/base/model_type.h"
@@ -92,6 +90,15 @@ class Id;
class HistoryService;
+namespace {
+
+void RunAndSignal(const base::Closure& cb, WaitableEvent* event) {
+ cb.Run();
+ event->Signal();
+}
+
+} // namespace
+
class AutofillTableMock : public AutofillTable {
public:
AutofillTableMock() : AutofillTable(NULL, NULL) {}
@@ -222,6 +229,34 @@ class WebDataServiceFake : public WebDataService {
virtual void ShutdownOnUIThread() OVERRIDE {}
+ void OnAutofillEntriesChanged(const AutofillChangeList& changes) {
+ WaitableEvent event(true, false);
+
+ base::Closure notify_cb =
+ base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged,
+ base::Unretained(autocomplete_syncable_service_),
+ changes);
+ BrowserThread::PostTask(
+ BrowserThread::DB,
+ FROM_HERE,
+ base::Bind(&RunAndSignal, notify_cb, &event));
+ event.Wait();
+ }
+
+ void OnAutofillProfileChanged(const AutofillProfileChange& changes) {
+ WaitableEvent event(true, false);
+
+ base::Closure notify_cb =
+ base::Bind(&AutocompleteSyncableService::AutofillProfileChanged,
+ base::Unretained(autofill_profile_syncable_service_),
+ changes);
+ BrowserThread::PostTask(
+ BrowserThread::DB,
+ FROM_HERE,
+ base::Bind(&RunAndSignal, notify_cb, &event));
+ event.Wait();
+ }
+
private:
virtual ~WebDataServiceFake() {}
@@ -358,15 +393,21 @@ class MockPersonalDataManagerService : public PersonalDataManagerService {
return new MockPersonalDataManagerService();
}
- MockPersonalDataManagerService() {}
+ MockPersonalDataManagerService() {
+ personal_data_manager_.reset(new MockPersonalDataManager());
+ }
virtual ~MockPersonalDataManagerService() {}
+ virtual void Shutdown() OVERRIDE {
+ personal_data_manager_.reset();
+ }
+
virtual MockPersonalDataManager* GetPersonalDataManager() OVERRIDE {
- return &personal_data_manager_;
+ return personal_data_manager_.get();
}
private:
- MockPersonalDataManager personal_data_manager_;
+ scoped_ptr<MockPersonalDataManager> personal_data_manager_;
DISALLOW_COPY_AND_ASSIGN(MockPersonalDataManagerService);
};
@@ -431,7 +472,6 @@ class ProfileSyncServiceAutofillTest
personal_data_manager_->Init(profile_.get());
- // Note: This must be called *after* the notification service is created.
web_data_service_->StartSyncableService();
}
@@ -1133,11 +1173,8 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddEntry) {
AutofillChangeList changes;
changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key()));
- scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(
- db_thread_.DeprecatedGetThreadObject()));
- notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
- content::Source<WebDataService>(web_data_service_.get()),
- content::Details<AutofillChangeList>(&changes));
+
+ web_data_service_->OnAutofillEntriesChanged(changes);
std::vector<AutofillEntry> new_sync_entries;
std::vector<AutofillProfile> new_sync_profiles;
@@ -1161,13 +1198,9 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) {
"joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
"32801", "US", "19482937549");
- AutofillProfileChange change(AutofillProfileChange::ADD,
- added_profile.guid(), &added_profile);
- scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(
- db_thread_.DeprecatedGetThreadObject()));
- notifier->Notify(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
- content::Source<WebDataService>(web_data_service_.get()),
- content::Details<AutofillProfileChange>(&change));
+ AutofillProfileChange change(
+ AutofillProfileChange::ADD, added_profile.guid(), &added_profile);
+ web_data_service_->OnAutofillProfileChanged(change);
std::vector<AutofillProfile> new_sync_profiles;
ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
@@ -1197,11 +1230,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) {
AutofillChangeList changes;
changes.push_back(AutofillChange(AutofillChange::UPDATE,
updated_entry.key()));
- scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(
- db_thread_.DeprecatedGetThreadObject()));
- notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
- content::Source<WebDataService>(web_data_service_.get()),
- content::Details<AutofillChangeList>(&changes));
+ web_data_service_->OnAutofillEntriesChanged(changes);
std::vector<AutofillEntry> new_sync_entries;
std::vector<AutofillProfile> new_sync_profiles;
@@ -1227,11 +1256,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) {
AutofillChangeList changes;
changes.push_back(AutofillChange(AutofillChange::REMOVE,
original_entry.key()));
- scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(
- db_thread_.DeprecatedGetThreadObject()));
- notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
- content::Source<WebDataService>(web_data_service_.get()),
- content::Details<AutofillChangeList>(&changes));
+ web_data_service_->OnAutofillEntriesChanged(changes);
std::vector<AutofillEntry> new_sync_entries;
std::vector<AutofillProfile> new_sync_profiles;
@@ -1264,13 +1289,9 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) {
StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL_PROFILE);
ASSERT_TRUE(add_autofill.success());
- AutofillProfileChange change(AutofillProfileChange::REMOVE,
- sync_profile.guid(), NULL);
- scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(
- db_thread_.DeprecatedGetThreadObject()));
- notifier->Notify(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
- content::Source<WebDataService>(web_data_service_.get()),
- content::Details<AutofillProfileChange>(&change));
+ AutofillProfileChange change(
+ AutofillProfileChange::REMOVE, sync_profile.guid(), NULL);
+ web_data_service_->OnAutofillProfileChanged(change);
std::vector<AutofillProfile> new_sync_profiles;
ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(

Powered by Google App Engine
This is Rietveld 408576698