1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_
6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h"
14 #include "base/synchronization/waitable_event.h"
15 #include "chrome/browser/sync/profile_sync_service_observer.h"
16 #include "content/browser/browser_thread.h"
17 #include "content/common/notification_service.h"
18 #include "content/common/notification_source.h"
19 #include "content/common/notification_type.h"
20 #include "testing/gmock/include/gmock/gmock.h"
21
22 namespace base {
23 class Thread;
24 }
25
ACTION_P(Notify,type)26 ACTION_P(Notify, type) {
27 NotificationService::current()->Notify(type,
28 NotificationService::AllSources(),
29 NotificationService::NoDetails());
30 }
31
ACTION(QuitUIMessageLoop)32 ACTION(QuitUIMessageLoop) {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
34 MessageLoop::current()->Quit();
35 }
36
37 class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver {
38 public:
39 ProfileSyncServiceObserverMock();
40 virtual ~ProfileSyncServiceObserverMock();
41
42 MOCK_METHOD0(OnStateChanged, void());
43 };
44
45 class ThreadNotificationService
46 : public base::RefCountedThreadSafe<ThreadNotificationService> {
47 public:
48 explicit ThreadNotificationService(base::Thread* notification_thread);
49
50 void Init();
51 void TearDown();
52
53 private:
54 friend class base::RefCountedThreadSafe<ThreadNotificationService>;
55 virtual ~ThreadNotificationService();
56
57 void InitTask();
58 void TearDownTask();
59
60 base::WaitableEvent done_event_;
61 base::Thread* notification_thread_;
62 scoped_ptr<NotificationService> service_;
63 };
64
65 class ThreadNotifier : // NOLINT
66 public base::RefCountedThreadSafe<ThreadNotifier> {
67 public:
68 explicit ThreadNotifier(base::Thread* notify_thread);
69
70 void Notify(NotificationType type, const NotificationDetails& details);
71
72 void Notify(NotificationType type,
73 const NotificationSource& source,
74 const NotificationDetails& details);
75
76 private:
77 friend class base::RefCountedThreadSafe<ThreadNotifier>;
78 virtual ~ThreadNotifier();
79
80 void NotifyTask(NotificationType type,
81 const NotificationSource& source,
82 const NotificationDetails& details);
83
84 base::WaitableEvent done_event_;
85 base::Thread* notify_thread_;
86 };
87
88 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_
89