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

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

Issue 10702074: Refactor sync-specific parts out of SyncNotifier/SyncNotifierObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor cleanup 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 syncer::ObjectIdSet GetHandledIds() OVERRIDE {
60 NOTREACHED();
61 return syncer::ObjectIdSet();
62 }
63
59 virtual void OnIncomingNotification( 64 virtual void OnIncomingNotification(
60 const syncer::ModelTypePayloadMap& type_payloads, 65 const syncer::ObjectIdPayloadMap& id_payloads,
61 syncer::IncomingNotificationSource source) OVERRIDE { 66 syncer::IncomingNotificationSource source) OVERRIDE {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
63 notification_count_++; 68 notification_count_++;
64 if (source != syncer::LOCAL_NOTIFICATION) { 69 if (source != syncer::LOCAL_NOTIFICATION) {
65 LOG(ERROR) << "Received notification with wrong source."; 70 LOG(ERROR) << "Received notification with wrong source.";
66 received_improper_notification_ = true; 71 received_improper_notification_ = true;
67 } 72 }
68 if (expected_payloads_ != type_payloads) { 73 const syncer::ModelTypePayloadMap& actual_payloads =
74 syncer::ObjectIdPayloadMapToModelTypePayloadMap(id_payloads);
75 if (expected_payloads_ != actual_payloads) {
69 LOG(ERROR) << "Received wrong payload."; 76 LOG(ERROR) << "Received wrong payload.";
70 received_improper_notification_ = true; 77 received_improper_notification_ = true;
71 } 78 }
72 } 79 }
73 virtual void OnNotificationsEnabled() OVERRIDE { 80 virtual void OnNotificationsEnabled() OVERRIDE {
74 NOTREACHED(); 81 NOTREACHED();
75 } 82 }
76 virtual void OnNotificationsDisabled( 83 virtual void OnNotificationsDisabled(
77 syncer::NotificationsDisabledReason reason) OVERRIDE { 84 syncer::NotificationsDisabledReason reason) OVERRIDE {
78 NOTREACHED(); 85 NOTREACHED();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 ChromeSyncNotificationBridge bridge_; 193 ChromeSyncNotificationBridge bridge_;
187 base::WaitableEvent done_; 194 base::WaitableEvent done_;
188 }; 195 };
189 196
190 // Adds an observer on the UI thread, triggers a local refresh notification, and 197 // 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. 198 // ensures the bridge posts a LOCAL_NOTIFICATION with the proper payload to it.
192 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotification) { 199 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotification) {
193 syncer::ModelTypePayloadMap payload_map; 200 syncer::ModelTypePayloadMap payload_map;
194 payload_map[syncer::SESSIONS] = ""; 201 payload_map[syncer::SESSIONS] = "";
195 StrictMock<syncer::MockSyncNotifierObserver> observer; 202 StrictMock<syncer::MockSyncNotifierObserver> observer;
196 EXPECT_CALL(observer, 203 EXPECT_CALL(observer, OnIncomingNotification(
197 OnIncomingNotification(payload_map, 204 ModelTypePayloadMapToObjectIdPayloadMap(payload_map),
198 syncer::LOCAL_NOTIFICATION)); 205 syncer::LOCAL_NOTIFICATION));
199 bridge_.AddObserver(&observer); 206 bridge_.AddObserver(&observer);
200 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 207 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
201 payload_map); 208 payload_map);
202 ui_loop_.RunAllPending(); 209 ui_loop_.RunAllPending();
203 Mock::VerifyAndClearExpectations(&observer); 210 Mock::VerifyAndClearExpectations(&observer);
204 } 211 }
205 212
206 // Adds an observer on the UI thread, triggers a remote refresh notification, 213 // 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 214 // and ensures the bridge posts a REMOTE_NOTIFICATION with the proper payload
208 // to it. 215 // to it.
209 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotification) { 216 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotification) {
210 syncer::ModelTypePayloadMap payload_map; 217 syncer::ModelTypePayloadMap payload_map;
211 payload_map[syncer::BOOKMARKS] = ""; 218 payload_map[syncer::BOOKMARKS] = "";
212 StrictMock<syncer::MockSyncNotifierObserver> observer; 219 StrictMock<syncer::MockSyncNotifierObserver> observer;
213 EXPECT_CALL(observer, 220 EXPECT_CALL(observer, OnIncomingNotification(
214 OnIncomingNotification(payload_map, 221 ModelTypePayloadMapToObjectIdPayloadMap(payload_map),
215 syncer::REMOTE_NOTIFICATION)); 222 syncer::REMOTE_NOTIFICATION));
216 bridge_.AddObserver(&observer); 223 bridge_.AddObserver(&observer);
217 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, 224 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
218 payload_map); 225 payload_map);
219 ui_loop_.RunAllPending(); 226 ui_loop_.RunAllPending();
220 Mock::VerifyAndClearExpectations(&observer); 227 Mock::VerifyAndClearExpectations(&observer);
221 } 228 }
222 229
223 // Adds an observer on the UI thread, triggers a local refresh notification 230 // Adds an observer on the UI thread, triggers a local refresh notification
224 // with empty payload map and ensures the bridge posts a 231 // with empty payload map and ensures the bridge posts a
225 // LOCAL_NOTIFICATION with the proper payload to it. 232 // LOCAL_NOTIFICATION with the proper payload to it.
226 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotificationEmptyPayloadMap) { 233 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotificationEmptyPayloadMap) {
227 const syncer::ModelTypeSet enabled_types( 234 const syncer::ModelTypeSet enabled_types(
228 syncer::BOOKMARKS, syncer::PASSWORDS); 235 syncer::BOOKMARKS, syncer::PASSWORDS);
229 const syncer::ModelTypePayloadMap enabled_types_payload_map = 236 const syncer::ModelTypePayloadMap enabled_types_payload_map =
230 syncer::ModelTypePayloadMapFromEnumSet(enabled_types, std::string()); 237 syncer::ModelTypePayloadMapFromEnumSet(enabled_types, std::string());
231 238
232 StrictMock<syncer::MockSyncNotifierObserver> observer; 239 StrictMock<syncer::MockSyncNotifierObserver> observer;
233 EXPECT_CALL(observer, 240 EXPECT_CALL(observer, OnIncomingNotification(
234 OnIncomingNotification(enabled_types_payload_map, 241 ModelTypePayloadMapToObjectIdPayloadMap(enabled_types_payload_map),
235 syncer::LOCAL_NOTIFICATION)); 242 syncer::LOCAL_NOTIFICATION));
236 bridge_.AddObserver(&observer); 243 bridge_.AddObserver(&observer);
237 // Set enabled types on the bridge. 244 // Set enabled types on the bridge.
238 bridge_.UpdateEnabledTypes(enabled_types); 245 bridge_.UpdateEnabledTypes(enabled_types);
239 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 246 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
240 syncer::ModelTypePayloadMap()); 247 syncer::ModelTypePayloadMap());
241 ui_loop_.RunAllPending(); 248 ui_loop_.RunAllPending();
242 Mock::VerifyAndClearExpectations(&observer); 249 Mock::VerifyAndClearExpectations(&observer);
243 } 250 }
244 251
245 // Adds an observer on the UI thread, triggers a remote refresh notification 252 // Adds an observer on the UI thread, triggers a remote refresh notification
246 // with empty payload map and ensures the bridge posts a 253 // with empty payload map and ensures the bridge posts a
247 // REMOTE_NOTIFICATION with the proper payload to it. 254 // REMOTE_NOTIFICATION with the proper payload to it.
248 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotificationEmptyPayloadMap) { 255 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotificationEmptyPayloadMap) {
249 const syncer::ModelTypeSet enabled_types( 256 const syncer::ModelTypeSet enabled_types(
250 syncer::BOOKMARKS, syncer::TYPED_URLS); 257 syncer::BOOKMARKS, syncer::TYPED_URLS);
251 const syncer::ModelTypePayloadMap enabled_types_payload_map = 258 const syncer::ModelTypePayloadMap enabled_types_payload_map =
252 syncer::ModelTypePayloadMapFromEnumSet(enabled_types, std::string()); 259 syncer::ModelTypePayloadMapFromEnumSet(enabled_types, std::string());
253 260
254 StrictMock<syncer::MockSyncNotifierObserver> observer; 261 StrictMock<syncer::MockSyncNotifierObserver> observer;
255 EXPECT_CALL(observer, 262 EXPECT_CALL(observer, OnIncomingNotification(
256 OnIncomingNotification(enabled_types_payload_map, 263 ModelTypePayloadMapToObjectIdPayloadMap(enabled_types_payload_map),
257 syncer::REMOTE_NOTIFICATION)); 264 syncer::REMOTE_NOTIFICATION));
258 bridge_.AddObserver(&observer); 265 bridge_.AddObserver(&observer);
259 // Set enabled types on the bridge. 266 // Set enabled types on the bridge.
260 bridge_.UpdateEnabledTypes(enabled_types); 267 bridge_.UpdateEnabledTypes(enabled_types);
261 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, 268 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
262 syncer::ModelTypePayloadMap()); 269 syncer::ModelTypePayloadMap());
263 ui_loop_.RunAllPending(); 270 ui_loop_.RunAllPending();
264 Mock::VerifyAndClearExpectations(&observer); 271 Mock::VerifyAndClearExpectations(&observer);
265 } 272 }
266 273
267 // Adds an observer on the I/O thread. Then triggers a refresh notification on 274 // 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 275 // the UI thread. We finally verify the proper notification was received by the
269 // observer and destroy it on the I/O thread. 276 // observer and destroy it on the I/O thread.
270 TEST_F(ChromeSyncNotificationBridgeTest, BasicThreaded) { 277 TEST_F(ChromeSyncNotificationBridgeTest, BasicThreaded) {
271 syncer::ModelTypePayloadMap payload_map; 278 syncer::ModelTypePayloadMap payload_map;
272 payload_map[syncer::SESSIONS] = ""; 279 payload_map[syncer::SESSIONS] = "";
273 CreateObserverWithExpectedPayload(payload_map); 280 CreateObserverWithExpectedPayload(payload_map);
274 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 281 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
275 payload_map); 282 payload_map);
276 VerifyAndDestroyObserver(); 283 VerifyAndDestroyObserver();
277 } 284 }
278 285
279 } // namespace 286 } // namespace
280 } // namespace browser_sync 287 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698