OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ | 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ |
6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ | 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/logging.h" | |
12 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
13 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
14 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
15 #include "base/task.h" | |
16 #include "base/threading/thread.h" | |
17 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
18 #include "base/utf_string_conversions.h" | |
19 #include "chrome/browser/browser_thread.h" | 15 #include "chrome/browser/browser_thread.h" |
20 #include "chrome/browser/webdata/web_database.h" | 16 #include "chrome/browser/sync/profile_sync_service_observer.h" |
21 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | |
22 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | |
23 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" | |
24 #include "chrome/browser/sync/glue/bookmark_model_associator.h" | |
25 #include "chrome/browser/sync/glue/change_processor.h" | |
26 #include "chrome/browser/sync/glue/data_type_manager_impl.h" | |
27 #include "chrome/browser/sync/glue/sync_backend_host.h" | |
28 #include "chrome/browser/sync/profile_sync_factory.h" | |
29 #include "chrome/browser/sync/profile_sync_service.h" | |
30 #include "chrome/browser/sync/syncable/model_type.h" | |
31 #include "chrome/browser/sync/unrecoverable_error_handler.h" | |
32 #include "chrome/common/notification_details.h" | |
33 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
34 #include "chrome/common/notification_source.h" | 18 #include "chrome/common/notification_source.h" |
35 #include "chrome/common/notification_type.h" | 19 #include "chrome/common/notification_type.h" |
36 #include "chrome/test/sync/test_http_bridge_factory.h" | |
37 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
38 | 21 |
| 22 namespace base { |
| 23 class Thread; |
| 24 } |
| 25 |
39 ACTION_P(Notify, type) { | 26 ACTION_P(Notify, type) { |
40 NotificationService::current()->Notify(type, | 27 NotificationService::current()->Notify(type, |
41 NotificationService::AllSources(), | 28 NotificationService::AllSources(), |
42 NotificationService::NoDetails()); | 29 NotificationService::NoDetails()); |
43 } | 30 } |
44 | 31 |
45 ACTION(QuitUIMessageLoop) { | 32 ACTION(QuitUIMessageLoop) { |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
47 MessageLoop::current()->Quit(); | 34 MessageLoop::current()->Quit(); |
48 } | 35 } |
49 | 36 |
50 class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver { | 37 class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver { |
51 public: | 38 public: |
| 39 ProfileSyncServiceObserverMock(); |
| 40 virtual ~ProfileSyncServiceObserverMock(); |
| 41 |
52 MOCK_METHOD0(OnStateChanged, void()); | 42 MOCK_METHOD0(OnStateChanged, void()); |
53 }; | 43 }; |
54 | 44 |
55 class ThreadNotificationService | 45 class ThreadNotificationService |
56 : public base::RefCountedThreadSafe<ThreadNotificationService> { | 46 : public base::RefCountedThreadSafe<ThreadNotificationService> { |
57 public: | 47 public: |
58 explicit ThreadNotificationService(base::Thread* notification_thread) | 48 explicit ThreadNotificationService(base::Thread* notification_thread); |
59 : done_event_(false, false), | |
60 notification_thread_(notification_thread) {} | |
61 | 49 |
62 void Init() { | 50 void Init(); |
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 void TearDown(); |
64 notification_thread_->message_loop()->PostTask( | |
65 FROM_HERE, | |
66 NewRunnableMethod(this, &ThreadNotificationService::InitTask)); | |
67 done_event_.Wait(); | |
68 } | |
69 | |
70 void TearDown() { | |
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
72 notification_thread_->message_loop()->PostTask( | |
73 FROM_HERE, | |
74 NewRunnableMethod(this, | |
75 &ThreadNotificationService::TearDownTask)); | |
76 done_event_.Wait(); | |
77 } | |
78 | 52 |
79 private: | 53 private: |
80 friend class base::RefCountedThreadSafe<ThreadNotificationService>; | 54 friend class base::RefCountedThreadSafe<ThreadNotificationService>; |
| 55 virtual ~ThreadNotificationService(); |
81 | 56 |
82 void InitTask() { | 57 void InitTask(); |
83 service_.reset(new NotificationService()); | 58 void TearDownTask(); |
84 done_event_.Signal(); | |
85 } | |
86 | |
87 void TearDownTask() { | |
88 service_.reset(NULL); | |
89 done_event_.Signal(); | |
90 } | |
91 | 59 |
92 base::WaitableEvent done_event_; | 60 base::WaitableEvent done_event_; |
93 base::Thread* notification_thread_; | 61 base::Thread* notification_thread_; |
94 scoped_ptr<NotificationService> service_; | 62 scoped_ptr<NotificationService> service_; |
95 }; | 63 }; |
96 | 64 |
97 class ThreadNotifier : // NOLINT | 65 class ThreadNotifier : // NOLINT |
98 public base::RefCountedThreadSafe<ThreadNotifier> { | 66 public base::RefCountedThreadSafe<ThreadNotifier> { |
99 public: | 67 public: |
100 explicit ThreadNotifier(base::Thread* notify_thread) | 68 explicit ThreadNotifier(base::Thread* notify_thread); |
101 : done_event_(false, false), | |
102 notify_thread_(notify_thread) {} | |
103 | 69 |
104 void Notify(NotificationType type, const NotificationDetails& details) { | 70 void Notify(NotificationType type, const NotificationDetails& details); |
105 Notify(type, NotificationService::AllSources(), details); | |
106 } | |
107 | 71 |
108 void Notify(NotificationType type, | 72 void Notify(NotificationType type, |
109 const NotificationSource& source, | 73 const NotificationSource& source, |
110 const NotificationDetails& details) { | 74 const NotificationDetails& details); |
111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
112 notify_thread_->message_loop()->PostTask( | |
113 FROM_HERE, | |
114 NewRunnableMethod(this, | |
115 &ThreadNotifier::NotifyTask, | |
116 type, | |
117 source, | |
118 details)); | |
119 done_event_.Wait(); | |
120 } | |
121 | 75 |
122 private: | 76 private: |
123 friend class base::RefCountedThreadSafe<ThreadNotifier>; | 77 friend class base::RefCountedThreadSafe<ThreadNotifier>; |
| 78 virtual ~ThreadNotifier(); |
124 | 79 |
125 void NotifyTask(NotificationType type, | 80 void NotifyTask(NotificationType type, |
126 const NotificationSource& source, | 81 const NotificationSource& source, |
127 const NotificationDetails& details) { | 82 const NotificationDetails& details); |
128 NotificationService::current()->Notify(type, source, details); | |
129 done_event_.Signal(); | |
130 } | |
131 | 83 |
132 base::WaitableEvent done_event_; | 84 base::WaitableEvent done_event_; |
133 base::Thread* notify_thread_; | 85 base::Thread* notify_thread_; |
134 }; | 86 }; |
135 | 87 |
136 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ | 88 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ |
OLD | NEW |