diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-19 00:52:02 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-19 00:52:02 +0000 |
commit | 375aaee8262cc6a6502447f59668aa91d05274fb (patch) | |
tree | be5fabff88035c7db2e0925dae76c53eb65059d4 /chrome | |
parent | c4b34163c0745d698d1960c1cab65e1e101d9eec (diff) | |
download | chromium_src-375aaee8262cc6a6502447f59668aa91d05274fb.zip chromium_src-375aaee8262cc6a6502447f59668aa91d05274fb.tar.gz chromium_src-375aaee8262cc6a6502447f59668aa91d05274fb.tar.bz2 |
Combine similar code from sync unit tests and add additional unit tests for typed url syncing.
BUG=none
TEST=run unit tests
Review URL: http://codereview.chromium.org/1124002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42048 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/sync/profile_sync_service_autofill_unittest.cc | 119 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_preference_unittest.cc | 12 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_typed_url_unittest.cc | 189 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_test_util.h | 117 | ||||
-rw-r--r-- | chrome/test/profile_mock.h | 2 |
5 files changed, 234 insertions, 205 deletions
diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index 9d3db02..85c12b0 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -28,8 +28,6 @@ #include "chrome/browser/webdata/autofill_change.h" #include "chrome/browser/webdata/autofill_entry.h" #include "chrome/browser/webdata/web_database.h" -#include "chrome/common/notification_details.h" -#include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" #include "chrome/test/sync/engine/test_id_factory.h" #include "chrome/test/profile_mock.h" @@ -69,34 +67,6 @@ using testing::Invoke; using testing::Return; using testing::SetArgumentPointee; -class TestingProfileSyncService : public ProfileSyncService { - public: - explicit TestingProfileSyncService(ProfileSyncFactory* factory, - Profile* profile, - bool bootstrap_sync_authentication) - : ProfileSyncService(factory, profile, bootstrap_sync_authentication) { - RegisterPreferences(); - SetSyncSetupCompleted(); - } - virtual ~TestingProfileSyncService() { - } - - virtual void InitializeBackend(bool delete_sync_data_folder) { - browser_sync::TestHttpBridgeFactory* factory = - new browser_sync::TestHttpBridgeFactory(); - browser_sync::TestHttpBridgeFactory* factory2 = - new browser_sync::TestHttpBridgeFactory(); - backend()->InitializeForTestMode(L"testuser", factory, factory2, - delete_sync_data_folder, browser_sync::kDefaultNotificationMethod); - } - private: - // When testing under ChromiumOS, this method must not return an empty - // value value in order for the profile sync service to start. - virtual std::string GetLsidForAuthBootstraping() { - return "foo"; - } -}; - class WebDatabaseMock : public WebDatabase { public: MOCK_METHOD2(RemoveFormElement, @@ -111,73 +81,6 @@ class WebDatabaseMock : public WebDatabase { bool(const std::vector<AutofillEntry>& entries)); // NOLINT }; -class DBThreadNotificationService : // NOLINT - public base::RefCountedThreadSafe<DBThreadNotificationService> { - public: - DBThreadNotificationService() : done_event_(false, false) {} - - void Init() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - ChromeThread::PostTask( - ChromeThread::DB, - FROM_HERE, - NewRunnableMethod(this, &DBThreadNotificationService::InitTask)); - done_event_.Wait(); - } - - void TearDown() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - ChromeThread::PostTask( - ChromeThread::DB, - FROM_HERE, - NewRunnableMethod(this, &DBThreadNotificationService::TearDownTask)); - done_event_.Wait(); - } - - private: - friend class base::RefCountedThreadSafe<DBThreadNotificationService>; - - void InitTask() { - service_.reset(new NotificationService()); - done_event_.Signal(); - } - - void TearDownTask() { - service_.reset(NULL); - done_event_.Signal(); - } - - WaitableEvent done_event_; - scoped_ptr<NotificationService> service_; -}; - -class DBThreadNotifier : // NOLINT - public base::RefCountedThreadSafe<DBThreadNotifier> { - public: - DBThreadNotifier() : done_event_(false, false) {} - - void Notify(NotificationType type, const NotificationDetails& details) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - ChromeThread::PostTask( - ChromeThread::DB, - FROM_HERE, - NewRunnableMethod(this, &DBThreadNotifier::NotifyTask, type, details)); - done_event_.Wait(); - } - - private: - friend class base::RefCountedThreadSafe<DBThreadNotifier>; - - void NotifyTask(NotificationType type, const NotificationDetails& details) { - NotificationService::current()->Notify(type, - NotificationService::AllSources(), - details); - done_event_.Signal(); - } - - WaitableEvent done_event_; -}; - class WebDataServiceFake : public WebDataService { public: virtual bool IsDatabaseLoaded() { @@ -191,11 +94,6 @@ class WebDataServiceFake : public WebDataService { } }; -ACTION(QuitUIMessageLoop) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - MessageLoop::current()->Quit(); -} - ACTION_P3(MakeAutofillSyncComponents, service, wd, dtc) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB)); AutofillModelAssociator* model_associator = @@ -210,15 +108,14 @@ class ProfileSyncServiceAutofillTest : public testing::Test { protected: ProfileSyncServiceAutofillTest() : ui_thread_(ChromeThread::UI, &message_loop_), - db_thread_(ChromeThread::DB), - done_event_(false, false) { + db_thread_(ChromeThread::DB) { } virtual void SetUp() { web_data_service_ = new WebDataServiceFake(); db_thread_.Start(); - notification_service_ = new DBThreadNotificationService(); + notification_service_ = new ThreadNotificationService(&db_thread_); notification_service_->Init(); } @@ -356,8 +253,7 @@ class ProfileSyncServiceAutofillTest : public testing::Test { MessageLoopForUI message_loop_; ChromeThread ui_thread_; ChromeThread db_thread_; - WaitableEvent done_event_; - scoped_refptr<DBThreadNotificationService> notification_service_; + scoped_refptr<ThreadNotificationService> notification_service_; scoped_ptr<TestingProfileSyncService> service_; ProfileMock profile_; @@ -405,7 +301,6 @@ class AddAutofillEntriesTask : public Task { // TODO(skrul): Test abort startup. // TODO(skrul): Test processing of cloud changes. - TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { // Backend will be paused but not resumed. EXPECT_CALL(backend_, RequestPause()). @@ -523,7 +418,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAdd) { AutofillChangeList changes; changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key())); - scoped_refptr<DBThreadNotifier> notifier = new DBThreadNotifier(); + scoped_refptr<ThreadNotifier> notifier = new ThreadNotifier(&db_thread_); notifier->Notify(NotificationType::AUTOFILL_ENTRIES_CHANGED, Details<AutofillChangeList>(&changes)); @@ -552,7 +447,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdate) { AutofillChangeList changes; changes.push_back(AutofillChange(AutofillChange::UPDATE, updated_entry.key())); - scoped_refptr<DBThreadNotifier> notifier = new DBThreadNotifier(); + scoped_refptr<ThreadNotifier> notifier = new ThreadNotifier(&db_thread_); notifier->Notify(NotificationType::AUTOFILL_ENTRIES_CHANGED, Details<AutofillChangeList>(&changes)); @@ -575,7 +470,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemove) { AutofillChangeList changes; changes.push_back(AutofillChange(AutofillChange::REMOVE, original_entry.key())); - scoped_refptr<DBThreadNotifier> notifier = new DBThreadNotifier(); + scoped_refptr<ThreadNotifier> notifier = new ThreadNotifier(&db_thread_); notifier->Notify(NotificationType::AUTOFILL_ENTRIES_CHANGED, Details<AutofillChangeList>(&changes)); @@ -597,7 +492,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeError) { AutofillChangeList changes; changes.push_back(AutofillChange(AutofillChange::ADD, evil_entry.key())); - scoped_refptr<DBThreadNotifier> notifier = new DBThreadNotifier(); + scoped_refptr<ThreadNotifier> notifier = new ThreadNotifier(&db_thread_); notifier->Notify(NotificationType::AUTOFILL_ENTRIES_CHANGED, Details<AutofillChangeList>(&changes)); diff --git a/chrome/browser/sync/profile_sync_service_preference_unittest.cc b/chrome/browser/sync/profile_sync_service_preference_unittest.cc index 76bc94b..0c3bd2d 100644 --- a/chrome/browser/sync/profile_sync_service_preference_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_preference_unittest.cc @@ -29,14 +29,6 @@ using sync_api::SyncManager; using testing::_; using testing::Return; -class TestPreferenceModelAssociator - : public TestModelAssociator<PreferenceModelAssociator> { - public: - explicit TestPreferenceModelAssociator(ProfileSyncService* service) - : TestModelAssociator<PreferenceModelAssociator>(service, service) { - } -}; - class ProfileSyncServicePreferenceTest : public testing::Test { protected: ProfileSyncServicePreferenceTest() @@ -61,7 +53,9 @@ class ProfileSyncServicePreferenceTest : public testing::Test { false)); // Register the preference data type. - model_associator_ = new TestPreferenceModelAssociator(service_.get()); + model_associator_ = + new TestModelAssociator<PreferenceModelAssociator>(service_.get(), + service_.get()); change_processor_ = new PreferenceChangeProcessor(model_associator_, service_.get()); EXPECT_CALL(factory_, CreatePreferenceSyncComponents(_, _)). diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc index 6c18b59..ce2f753 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -10,8 +10,8 @@ #include "base/string16.h" #include "base/thread.h" #include "base/time.h" -#include "base/waitable_event.h" #include "chrome/browser/history/history_backend.h" +#include "chrome/browser/history/history_notifications.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/sync_backend_host.h" @@ -34,7 +34,6 @@ using base::Time; using base::Thread; -using base::WaitableEvent; using browser_sync::SyncBackendHost; using browser_sync::SyncBackendHostMock; using browser_sync::TestIdFactory; @@ -71,35 +70,6 @@ using testing::Return; using testing::SetArgumentPointee; using testing::WithArgs; -class TestingProfileSyncService : public ProfileSyncService { - public: - explicit TestingProfileSyncService(ProfileSyncFactory* factory, - Profile* profile, - bool bootstrap_sync_authentication) - : ProfileSyncService(factory, profile, bootstrap_sync_authentication) { - RegisterPreferences(); - SetSyncSetupCompleted(); - } - virtual ~TestingProfileSyncService() { - } - - virtual void InitializeBackend(bool delete_sync_data_folder) { - browser_sync::TestHttpBridgeFactory* factory = - new browser_sync::TestHttpBridgeFactory(); - browser_sync::TestHttpBridgeFactory* factory2 = - new browser_sync::TestHttpBridgeFactory(); - backend()->InitializeForTestMode(L"testuser", factory, factory2, - delete_sync_data_folder, browser_sync::kDefaultNotificationMethod); - } - - private: - // When testing under ChromiumOS, this method must not return an empty - // value value in order for the profile sync service to start. - virtual std::string GetLsidForAuthBootstraping() { - return "foo"; - } -}; - class HistoryBackendMock : public HistoryBackend { public: HistoryBackendMock() : HistoryBackend(FilePath(), NULL, NULL) {} @@ -110,48 +80,6 @@ class HistoryBackendMock : public HistoryBackend { MOCK_METHOD1(DeleteURL, void(const GURL& url)); }; -class HistoryThreadNotificationService : - public base::RefCountedThreadSafe<HistoryThreadNotificationService> { - public: - explicit HistoryThreadNotificationService(Thread* history_thread) - : done_event_(false, false), - history_thread_(history_thread) {} - - void Init() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - history_thread_->message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &HistoryThreadNotificationService::InitTask)); - done_event_.Wait(); - } - - void TearDown() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - history_thread_->message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, - &HistoryThreadNotificationService::TearDownTask)); - done_event_.Wait(); - } - - private: - friend class base::RefCountedThreadSafe<HistoryThreadNotificationService>; - - void InitTask() { - service_.reset(new NotificationService()); - done_event_.Signal(); - } - - void TearDownTask() { - service_.reset(NULL); - done_event_.Signal(); - } - - WaitableEvent done_event_; - Thread* history_thread_; - scoped_ptr<NotificationService> service_; -}; - class HistoryServiceMock : public HistoryService { public: HistoryServiceMock() {} @@ -178,11 +106,6 @@ ACTION_P2(RunTaskOnDBThread, thread, backend) { return 0; } -ACTION(QuitUIMessageLoop) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - MessageLoop::current()->Quit(); -} - ACTION_P3(MakeTypedUrlSyncComponents, service, hb, dtc) { TypedUrlModelAssociator* model_associator = new TypedUrlModelAssociator(service, hb, dtc); @@ -195,8 +118,7 @@ class ProfileSyncServiceTypedUrlTest : public testing::Test { protected: ProfileSyncServiceTypedUrlTest() : ui_thread_(ChromeThread::UI, &message_loop_), - history_thread_("history"), - done_event_(false, false) { + history_thread_("history") { } virtual void SetUp() { @@ -208,7 +130,7 @@ class ProfileSyncServiceTypedUrlTest : public testing::Test { history_thread_.Start(); notification_service_ = - new HistoryThreadNotificationService(&history_thread_); + new ThreadNotificationService(&history_thread_); notification_service_->Init(); } @@ -362,8 +284,7 @@ class ProfileSyncServiceTypedUrlTest : public testing::Test { MessageLoopForUI message_loop_; ChromeThread ui_thread_; Thread history_thread_; - WaitableEvent done_event_; - scoped_refptr<HistoryThreadNotificationService> notification_service_; + scoped_refptr<ThreadNotificationService> notification_service_; scoped_ptr<TestingProfileSyncService> service_; ProfileMock profile_; @@ -496,3 +417,105 @@ TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeHasSyncMerge) { ASSERT_EQ(1U, new_sync_entries.size()); EXPECT_TRUE(URLsEqual(merged_entry, new_sync_entries[0])); } + +TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAdd) { + EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)). + WillOnce(Return(true)); + SetIdleChangeProcessorExpectations(); + CreateTypedUrlRootTask task(this); + StartSyncService(&task); + + history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry", + 1, 2, 15, false)); + + history::URLsModifiedDetails details; + details.changed_urls.push_back(added_entry); + scoped_refptr<ThreadNotifier> notifier = new ThreadNotifier(&history_thread_); + notifier->Notify(NotificationType::HISTORY_TYPED_URLS_MODIFIED, + Details<history::URLsModifiedDetails>(&details)); + + std::vector<history::URLRow> new_sync_entries; + GetTypedUrlsFromSyncDB(&new_sync_entries); + ASSERT_EQ(1U, new_sync_entries.size()); + EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0])); +} + +TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdate) { + history::URLRow original_entry(MakeTypedUrlEntry("http://mine.com", "entry", + 1, 2, 15, false)); + std::vector<history::URLRow> original_entries; + original_entries.push_back(original_entry); + + EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)). + WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); + CreateTypedUrlRootTask task(this); + StartSyncService(&task); + + history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry", + 3, 7, 19, false)); + + history::URLsModifiedDetails details; + details.changed_urls.push_back(updated_entry); + scoped_refptr<ThreadNotifier> notifier = new ThreadNotifier(&history_thread_); + notifier->Notify(NotificationType::HISTORY_TYPED_URLS_MODIFIED, + Details<history::URLsModifiedDetails>(&details)); + + std::vector<history::URLRow> new_sync_entries; + GetTypedUrlsFromSyncDB(&new_sync_entries); + ASSERT_EQ(1U, new_sync_entries.size()); + EXPECT_TRUE(URLsEqual(updated_entry, new_sync_entries[0])); +} + +TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemove) { + history::URLRow original_entry1(MakeTypedUrlEntry("http://mine.com", "entry", + 1, 2, 15, false)); + history::URLRow original_entry2(MakeTypedUrlEntry("http://mine2.com", + "entry2", + 2, 3, 17, false)); + std::vector<history::URLRow> original_entries; + original_entries.push_back(original_entry1); + original_entries.push_back(original_entry2); + + EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)). + WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); + CreateTypedUrlRootTask task(this); + StartSyncService(&task); + + history::URLsDeletedDetails changes; + changes.all_history = false; + changes.urls.insert(GURL("http://mine.com")); + scoped_refptr<ThreadNotifier> notifier = new ThreadNotifier(&history_thread_); + notifier->Notify(NotificationType::HISTORY_URLS_DELETED, + Details<history::URLsDeletedDetails>(&changes)); + + std::vector<history::URLRow> new_sync_entries; + GetTypedUrlsFromSyncDB(&new_sync_entries); + ASSERT_EQ(1U, new_sync_entries.size()); + EXPECT_TRUE(URLsEqual(original_entry2, new_sync_entries[0])); +} + +TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemoveAll) { + history::URLRow original_entry1(MakeTypedUrlEntry("http://mine.com", "entry", + 1, 2, 15, false)); + history::URLRow original_entry2(MakeTypedUrlEntry("http://mine2.com", + "entry2", + 2, 3, 17, false)); + std::vector<history::URLRow> original_entries; + original_entries.push_back(original_entry1); + original_entries.push_back(original_entry2); + + EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)). + WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); + CreateTypedUrlRootTask task(this); + StartSyncService(&task); + + history::URLsDeletedDetails changes; + changes.all_history = true; + scoped_refptr<ThreadNotifier> notifier = new ThreadNotifier(&history_thread_); + notifier->Notify(NotificationType::HISTORY_URLS_DELETED, + Details<history::URLsDeletedDetails>(&changes)); + + std::vector<history::URLRow> new_sync_entries; + GetTypedUrlsFromSyncDB(&new_sync_entries); + ASSERT_EQ(0U, new_sync_entries.size()); +} diff --git a/chrome/browser/sync/profile_sync_test_util.h b/chrome/browser/sync/profile_sync_test_util.h index e480e337..1e8842a 100644 --- a/chrome/browser/sync/profile_sync_test_util.h +++ b/chrome/browser/sync/profile_sync_test_util.h @@ -7,16 +7,28 @@ #include <string> +#include "base/logging.h" +#include "base/message_loop.h" +#include "base/ref_counted.h" +#include "base/scoped_ptr.h" +#include "base/task.h" +#include "base/thread.h" +#include "base/waitable_event.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/profile.h" #include "chrome/browser/webdata/web_database.h" #include "chrome/browser/sync/glue/bookmark_change_processor.h" #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" #include "chrome/browser/sync/glue/bookmark_model_associator.h" #include "chrome/browser/sync/glue/change_processor.h" #include "chrome/browser/sync/glue/data_type_manager_impl.h" +#include "chrome/browser/sync/notification_method.h" #include "chrome/browser/sync/profile_sync_factory.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/unrecoverable_error_handler.h" +#include "chrome/common/notification_details.h" #include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" #include "chrome/test/sync/test_http_bridge_factory.h" #include "testing/gmock/include/gmock/gmock.h" @@ -35,6 +47,11 @@ ACTION_P(MakeDataTypeManager, backend_mock) { return new browser_sync::DataTypeManagerImpl(backend_mock, arg1); } +ACTION(QuitUIMessageLoop) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + MessageLoop::current()->Quit(); +} + ACTION_P(InvokeTask, task) { if (task) task->Run(); @@ -100,4 +117,104 @@ class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver { MOCK_METHOD0(OnStateChanged, void()); }; +class TestingProfileSyncService : public ProfileSyncService { + public: + explicit TestingProfileSyncService(ProfileSyncFactory* factory, + Profile* profile, + bool bootstrap_sync_authentication) + : ProfileSyncService(factory, profile, bootstrap_sync_authentication) { + RegisterPreferences(); + SetSyncSetupCompleted(); + } + virtual ~TestingProfileSyncService() { + } + + virtual void InitializeBackend(bool delete_sync_data_folder) { + browser_sync::TestHttpBridgeFactory* factory = + new browser_sync::TestHttpBridgeFactory(); + browser_sync::TestHttpBridgeFactory* factory2 = + new browser_sync::TestHttpBridgeFactory(); + backend()->InitializeForTestMode(L"testuser", factory, factory2, + delete_sync_data_folder, browser_sync::kDefaultNotificationMethod); + } + + private: + // When testing under ChromiumOS, this method must not return an empty + // value value in order for the profile sync service to start. + virtual std::string GetLsidForAuthBootstraping() { + return "foo"; + } +}; + +class ThreadNotificationService + : public base::RefCountedThreadSafe<ThreadNotificationService> { + public: + explicit ThreadNotificationService(base::Thread* notification_thread) + : done_event_(false, false), + notification_thread_(notification_thread) {} + + void Init() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + notification_thread_->message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(this, &ThreadNotificationService::InitTask)); + done_event_.Wait(); + } + + void TearDown() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + notification_thread_->message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(this, + &ThreadNotificationService::TearDownTask)); + done_event_.Wait(); + } + + private: + friend class base::RefCountedThreadSafe<ThreadNotificationService>; + + void InitTask() { + service_.reset(new NotificationService()); + done_event_.Signal(); + } + + void TearDownTask() { + service_.reset(NULL); + done_event_.Signal(); + } + + base::WaitableEvent done_event_; + base::Thread* notification_thread_; + scoped_ptr<NotificationService> service_; +}; + +class ThreadNotifier : // NOLINT + public base::RefCountedThreadSafe<ThreadNotifier> { + public: + explicit ThreadNotifier(base::Thread* notify_thread) + : done_event_(false, false), + notify_thread_(notify_thread) {} + + void Notify(NotificationType type, const NotificationDetails& details) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + notify_thread_->message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(this, &ThreadNotifier::NotifyTask, type, details)); + done_event_.Wait(); + } + + private: + friend class base::RefCountedThreadSafe<ThreadNotifier>; + + void NotifyTask(NotificationType type, const NotificationDetails& details) { + NotificationService::current()->Notify(type, + NotificationService::AllSources(), + details); + done_event_.Signal(); + } + + base::WaitableEvent done_event_; + base::Thread* notify_thread_; +}; + #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ diff --git a/chrome/test/profile_mock.h b/chrome/test/profile_mock.h index 388d282..11401ea 100644 --- a/chrome/test/profile_mock.h +++ b/chrome/test/profile_mock.h @@ -12,9 +12,9 @@ class ProfileMock : public TestingProfile { public: MOCK_METHOD0(GetBookmarkModel, BookmarkModel*()); - MOCK_METHOD1(GetWebDataService, WebDataService*(ServiceAccessType access)); MOCK_METHOD1(GetHistoryService, HistoryService*(ServiceAccessType access)); MOCK_METHOD0(GetHistoryServiceWithoutCreating, HistoryService*()); + MOCK_METHOD1(GetWebDataService, WebDataService*(ServiceAccessType access)); }; #endif // CHROME_TEST_PROFILE_MOCK_H__ |