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/browser/sync/profile_sync_test_util.h | |
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/browser/sync/profile_sync_test_util.h')
-rw-r--r-- | chrome/browser/sync/profile_sync_test_util.h | 117 |
1 files changed, 117 insertions, 0 deletions
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_ |