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

Side by Side Diff: chrome/browser/sync/glue/chrome_sync_notification_bridge_unittest.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" 5 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 20 matching lines...) Expand all
31 using content::BrowserThread; 31 using content::BrowserThread;
32 32
33 // Receives a ChromeSyncNotificationBridge to register to, and an expected 33 // Receives a ChromeSyncNotificationBridge to register to, and an expected
34 // ModelTypePayloadMap. ReceivedProperNotification() will return true only 34 // ModelTypePayloadMap. ReceivedProperNotification() will return true only
35 // if the observer has received a notification with the proper source and 35 // if the observer has received a notification with the proper source and
36 // payload. 36 // payload.
37 // Note: Because this object lives on the IO thread, we use a fake (vs a mock) 37 // Note: Because this object lives on the IO thread, we use a fake (vs a mock)
38 // so we don't have to worry about possible thread safety issues within 38 // so we don't have to worry about possible thread safety issues within
39 // GTest/GMock. 39 // GTest/GMock.
40 class FakeSyncNotifierObserverIO 40 class FakeSyncNotifierObserverIO
41 : public csync::SyncNotifierObserver { 41 : public syncer::SyncNotifierObserver {
42 public: 42 public:
43 FakeSyncNotifierObserverIO( 43 FakeSyncNotifierObserverIO(
44 ChromeSyncNotificationBridge* bridge, 44 ChromeSyncNotificationBridge* bridge,
45 const syncable::ModelTypePayloadMap& expected_payloads) 45 const syncable::ModelTypePayloadMap& expected_payloads)
46 : bridge_(bridge), 46 : bridge_(bridge),
47 received_improper_notification_(false), 47 received_improper_notification_(false),
48 notification_count_(0), 48 notification_count_(0),
49 expected_payloads_(expected_payloads) { 49 expected_payloads_(expected_payloads) {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
51 bridge_->AddObserver(this); 51 bridge_->AddObserver(this);
52 } 52 }
53 virtual ~FakeSyncNotifierObserverIO() { 53 virtual ~FakeSyncNotifierObserverIO() {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
55 bridge_->RemoveObserver(this); 55 bridge_->RemoveObserver(this);
56 } 56 }
57 57
58 // SyncNotifierObserver implementation. 58 // SyncNotifierObserver implementation.
59 virtual void OnIncomingNotification( 59 virtual void OnIncomingNotification(
60 const syncable::ModelTypePayloadMap& type_payloads, 60 const syncable::ModelTypePayloadMap& type_payloads,
61 csync::IncomingNotificationSource source) OVERRIDE { 61 syncer::IncomingNotificationSource source) OVERRIDE {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
63 notification_count_++; 63 notification_count_++;
64 if (source != csync::LOCAL_NOTIFICATION) { 64 if (source != syncer::LOCAL_NOTIFICATION) {
65 LOG(ERROR) << "Received notification with wrong source."; 65 LOG(ERROR) << "Received notification with wrong source.";
66 received_improper_notification_ = true; 66 received_improper_notification_ = true;
67 } 67 }
68 if (expected_payloads_ != type_payloads) { 68 if (expected_payloads_ != type_payloads) {
69 LOG(ERROR) << "Received wrong payload."; 69 LOG(ERROR) << "Received wrong payload.";
70 received_improper_notification_ = true; 70 received_improper_notification_ = true;
71 } 71 }
72 } 72 }
73 virtual void OnNotificationsEnabled() OVERRIDE { 73 virtual void OnNotificationsEnabled() OVERRIDE {
74 NOTREACHED(); 74 NOTREACHED();
75 } 75 }
76 virtual void OnNotificationsDisabled( 76 virtual void OnNotificationsDisabled(
77 csync::NotificationsDisabledReason reason) OVERRIDE { 77 syncer::NotificationsDisabledReason reason) OVERRIDE {
78 NOTREACHED(); 78 NOTREACHED();
79 } 79 }
80 80
81 bool ReceivedProperNotification() const { 81 bool ReceivedProperNotification() const {
82 return (notification_count_ == 1) && !received_improper_notification_; 82 return (notification_count_ == 1) && !received_improper_notification_;
83 } 83 }
84 84
85 private: 85 private:
86 ChromeSyncNotificationBridge* bridge_; 86 ChromeSyncNotificationBridge* bridge_;
87 bool received_improper_notification_; 87 bool received_improper_notification_;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 bool io_observer_notification_failure_; 185 bool io_observer_notification_failure_;
186 ChromeSyncNotificationBridge bridge_; 186 ChromeSyncNotificationBridge bridge_;
187 base::WaitableEvent done_; 187 base::WaitableEvent done_;
188 }; 188 };
189 189
190 // Adds an observer on the UI thread, triggers a local refresh notification, and 190 // Adds an observer on the UI thread, triggers a local refresh notification, and
191 // ensures the bridge posts a LOCAL_NOTIFICATION with the proper payload to it. 191 // ensures the bridge posts a LOCAL_NOTIFICATION with the proper payload to it.
192 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotification) { 192 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotification) {
193 syncable::ModelTypePayloadMap payload_map; 193 syncable::ModelTypePayloadMap payload_map;
194 payload_map[syncable::SESSIONS] = ""; 194 payload_map[syncable::SESSIONS] = "";
195 StrictMock<csync::MockSyncNotifierObserver> observer; 195 StrictMock<syncer::MockSyncNotifierObserver> observer;
196 EXPECT_CALL(observer, 196 EXPECT_CALL(observer,
197 OnIncomingNotification(payload_map, 197 OnIncomingNotification(payload_map,
198 csync::LOCAL_NOTIFICATION)); 198 syncer::LOCAL_NOTIFICATION));
199 bridge_.AddObserver(&observer); 199 bridge_.AddObserver(&observer);
200 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 200 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
201 payload_map); 201 payload_map);
202 ui_loop_.RunAllPending(); 202 ui_loop_.RunAllPending();
203 Mock::VerifyAndClearExpectations(&observer); 203 Mock::VerifyAndClearExpectations(&observer);
204 } 204 }
205 205
206 // Adds an observer on the UI thread, triggers a remote refresh notification, 206 // Adds an observer on the UI thread, triggers a remote refresh notification,
207 // and ensures the bridge posts a REMOTE_NOTIFICATION with the proper payload 207 // and ensures the bridge posts a REMOTE_NOTIFICATION with the proper payload
208 // to it. 208 // to it.
209 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotification) { 209 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotification) {
210 syncable::ModelTypePayloadMap payload_map; 210 syncable::ModelTypePayloadMap payload_map;
211 payload_map[syncable::BOOKMARKS] = ""; 211 payload_map[syncable::BOOKMARKS] = "";
212 StrictMock<csync::MockSyncNotifierObserver> observer; 212 StrictMock<syncer::MockSyncNotifierObserver> observer;
213 EXPECT_CALL(observer, 213 EXPECT_CALL(observer,
214 OnIncomingNotification(payload_map, 214 OnIncomingNotification(payload_map,
215 csync::REMOTE_NOTIFICATION)); 215 syncer::REMOTE_NOTIFICATION));
216 bridge_.AddObserver(&observer); 216 bridge_.AddObserver(&observer);
217 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, 217 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
218 payload_map); 218 payload_map);
219 ui_loop_.RunAllPending(); 219 ui_loop_.RunAllPending();
220 Mock::VerifyAndClearExpectations(&observer); 220 Mock::VerifyAndClearExpectations(&observer);
221 } 221 }
222 222
223 // Adds an observer on the UI thread, triggers a local refresh notification 223 // Adds an observer on the UI thread, triggers a local refresh notification
224 // with empty payload map and ensures the bridge posts a 224 // with empty payload map and ensures the bridge posts a
225 // LOCAL_NOTIFICATION with the proper payload to it. 225 // LOCAL_NOTIFICATION with the proper payload to it.
226 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotificationEmptyPayloadMap) { 226 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotificationEmptyPayloadMap) {
227 const syncable::ModelTypeSet enabled_types( 227 const syncable::ModelTypeSet enabled_types(
228 syncable::BOOKMARKS, syncable::PASSWORDS); 228 syncable::BOOKMARKS, syncable::PASSWORDS);
229 const syncable::ModelTypePayloadMap enabled_types_payload_map = 229 const syncable::ModelTypePayloadMap enabled_types_payload_map =
230 syncable::ModelTypePayloadMapFromEnumSet(enabled_types, std::string()); 230 syncable::ModelTypePayloadMapFromEnumSet(enabled_types, std::string());
231 231
232 StrictMock<csync::MockSyncNotifierObserver> observer; 232 StrictMock<syncer::MockSyncNotifierObserver> observer;
233 EXPECT_CALL(observer, 233 EXPECT_CALL(observer,
234 OnIncomingNotification(enabled_types_payload_map, 234 OnIncomingNotification(enabled_types_payload_map,
235 csync::LOCAL_NOTIFICATION)); 235 syncer::LOCAL_NOTIFICATION));
236 bridge_.AddObserver(&observer); 236 bridge_.AddObserver(&observer);
237 // Set enabled types on the bridge. 237 // Set enabled types on the bridge.
238 bridge_.UpdateEnabledTypes(enabled_types); 238 bridge_.UpdateEnabledTypes(enabled_types);
239 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 239 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
240 syncable::ModelTypePayloadMap()); 240 syncable::ModelTypePayloadMap());
241 ui_loop_.RunAllPending(); 241 ui_loop_.RunAllPending();
242 Mock::VerifyAndClearExpectations(&observer); 242 Mock::VerifyAndClearExpectations(&observer);
243 } 243 }
244 244
245 // Adds an observer on the UI thread, triggers a remote refresh notification 245 // Adds an observer on the UI thread, triggers a remote refresh notification
246 // with empty payload map and ensures the bridge posts a 246 // with empty payload map and ensures the bridge posts a
247 // REMOTE_NOTIFICATION with the proper payload to it. 247 // REMOTE_NOTIFICATION with the proper payload to it.
248 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotificationEmptyPayloadMap) { 248 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotificationEmptyPayloadMap) {
249 const syncable::ModelTypeSet enabled_types( 249 const syncable::ModelTypeSet enabled_types(
250 syncable::BOOKMARKS, syncable::TYPED_URLS); 250 syncable::BOOKMARKS, syncable::TYPED_URLS);
251 const syncable::ModelTypePayloadMap enabled_types_payload_map = 251 const syncable::ModelTypePayloadMap enabled_types_payload_map =
252 syncable::ModelTypePayloadMapFromEnumSet(enabled_types, std::string()); 252 syncable::ModelTypePayloadMapFromEnumSet(enabled_types, std::string());
253 253
254 StrictMock<csync::MockSyncNotifierObserver> observer; 254 StrictMock<syncer::MockSyncNotifierObserver> observer;
255 EXPECT_CALL(observer, 255 EXPECT_CALL(observer,
256 OnIncomingNotification(enabled_types_payload_map, 256 OnIncomingNotification(enabled_types_payload_map,
257 csync::REMOTE_NOTIFICATION)); 257 syncer::REMOTE_NOTIFICATION));
258 bridge_.AddObserver(&observer); 258 bridge_.AddObserver(&observer);
259 // Set enabled types on the bridge. 259 // Set enabled types on the bridge.
260 bridge_.UpdateEnabledTypes(enabled_types); 260 bridge_.UpdateEnabledTypes(enabled_types);
261 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, 261 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
262 syncable::ModelTypePayloadMap()); 262 syncable::ModelTypePayloadMap());
263 ui_loop_.RunAllPending(); 263 ui_loop_.RunAllPending();
264 Mock::VerifyAndClearExpectations(&observer); 264 Mock::VerifyAndClearExpectations(&observer);
265 } 265 }
266 266
267 // Adds an observer on the I/O thread. Then triggers a refresh notification on 267 // Adds an observer on the I/O thread. Then triggers a refresh notification on
268 // the UI thread. We finally verify the proper notification was received by the 268 // the UI thread. We finally verify the proper notification was received by the
269 // observer and destroy it on the I/O thread. 269 // observer and destroy it on the I/O thread.
270 TEST_F(ChromeSyncNotificationBridgeTest, BasicThreaded) { 270 TEST_F(ChromeSyncNotificationBridgeTest, BasicThreaded) {
271 syncable::ModelTypePayloadMap payload_map; 271 syncable::ModelTypePayloadMap payload_map;
272 payload_map[syncable::SESSIONS] = ""; 272 payload_map[syncable::SESSIONS] = "";
273 CreateObserverWithExpectedPayload(payload_map); 273 CreateObserverWithExpectedPayload(payload_map);
274 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 274 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
275 payload_map); 275 payload_map);
276 VerifyAndDestroyObserver(); 276 VerifyAndDestroyObserver();
277 } 277 }
278 278
279 } // namespace 279 } // namespace
280 } // namespace browser_sync 280 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/chrome_sync_notification_bridge.cc ('k') | chrome/browser/sync/glue/data_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698