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

Side by Side Diff: sync/notifier/sync_notifier_registrar_unittest.cc

Issue 10837214: Refactor ModelTypePayloadMap and ObjectIdPayloadMap to StateMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 8 years, 4 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
« no previous file with comments | « sync/notifier/sync_notifier_registrar.cc ('k') | sync/sessions/session_state_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "google/cacheinvalidation/types.pb.h" 5 #include "google/cacheinvalidation/types.pb.h"
6 #include "sync/notifier/mock_sync_notifier_observer.h" 6 #include "sync/notifier/mock_sync_notifier_observer.h"
7 #include "sync/notifier/object_id_state_map_test_util.h"
7 #include "sync/notifier/sync_notifier_registrar.h" 8 #include "sync/notifier/sync_notifier_registrar.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 namespace syncer { 11 namespace syncer {
11 12
12 namespace { 13 namespace {
13 14
14 using testing::InSequence; 15 using testing::InSequence;
15 using testing::Mock; 16 using testing::Mock;
16 using testing::StrictMock; 17 using testing::StrictMock;
(...skipping 16 matching lines...) Expand all
33 // Register a handler, register some IDs for that handler, and then unregister 34 // Register a handler, register some IDs for that handler, and then unregister
34 // the handler, dispatching invalidations in between. The handler should only 35 // the handler, dispatching invalidations in between. The handler should only
35 // see invalidations when its registered and its IDs are registered. 36 // see invalidations when its registered and its IDs are registered.
36 TEST_F(SyncNotifierRegistrarTest, Basic) { 37 TEST_F(SyncNotifierRegistrarTest, Basic) {
37 StrictMock<MockSyncNotifierObserver> handler; 38 StrictMock<MockSyncNotifierObserver> handler;
38 39
39 SyncNotifierRegistrar registrar; 40 SyncNotifierRegistrar registrar;
40 41
41 registrar.RegisterHandler(&handler); 42 registrar.RegisterHandler(&handler);
42 43
43 ObjectIdPayloadMap payloads; 44 ObjectIdStateMap states;
44 payloads[kObjectId1] = "1"; 45 states[kObjectId1].payload = "1";
45 payloads[kObjectId2] = "2"; 46 states[kObjectId2].payload = "2";
46 payloads[kObjectId3] = "3"; 47 states[kObjectId3].payload = "3";
47 48
48 // Should be ignored since no IDs are registered to |handler|. 49 // Should be ignored since no IDs are registered to |handler|.
49 registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); 50 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
50 51
51 Mock::VerifyAndClearExpectations(&handler); 52 Mock::VerifyAndClearExpectations(&handler);
52 53
53 ObjectIdSet ids; 54 ObjectIdSet ids;
54 ids.insert(kObjectId1); 55 ids.insert(kObjectId1);
55 ids.insert(kObjectId2); 56 ids.insert(kObjectId2);
56 registrar.UpdateRegisteredIds(&handler, ids); 57 registrar.UpdateRegisteredIds(&handler, ids);
57 58
58 { 59 {
59 ObjectIdPayloadMap expected_payloads; 60 ObjectIdStateMap expected_states;
60 expected_payloads[kObjectId1] = "1"; 61 expected_states[kObjectId1].payload = "1";
61 expected_payloads[kObjectId2] = "2"; 62 expected_states[kObjectId2].payload = "2";
62 EXPECT_CALL(handler, OnIncomingNotification(expected_payloads, 63 EXPECT_CALL(handler, OnIncomingNotification(
63 REMOTE_NOTIFICATION)); 64 expected_states, REMOTE_NOTIFICATION));
64 } 65 }
65 66
66 registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); 67 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
67 68
68 Mock::VerifyAndClearExpectations(&handler); 69 Mock::VerifyAndClearExpectations(&handler);
69 70
70 ids.erase(kObjectId1); 71 ids.erase(kObjectId1);
71 ids.insert(kObjectId3); 72 ids.insert(kObjectId3);
72 registrar.UpdateRegisteredIds(&handler, ids); 73 registrar.UpdateRegisteredIds(&handler, ids);
73 74
74 { 75 {
75 ObjectIdPayloadMap expected_payloads; 76 ObjectIdStateMap expected_states;
76 expected_payloads[kObjectId2] = "2"; 77 expected_states[kObjectId2].payload = "2";
77 expected_payloads[kObjectId3] = "3"; 78 expected_states[kObjectId3].payload = "3";
78 EXPECT_CALL(handler, OnIncomingNotification(expected_payloads, 79 EXPECT_CALL(handler, OnIncomingNotification(
79 REMOTE_NOTIFICATION)); 80 expected_states, REMOTE_NOTIFICATION));
80 } 81 }
81 82
82 // Removed object IDs should not be notified, newly-added ones should. 83 // Removed object IDs should not be notified, newly-added ones should.
83 registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); 84 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
84 85
85 Mock::VerifyAndClearExpectations(&handler); 86 Mock::VerifyAndClearExpectations(&handler);
86 87
87 registrar.UnregisterHandler(&handler); 88 registrar.UnregisterHandler(&handler);
88 89
89 // Should be ignored since |handler| isn't registered anymore. 90 // Should be ignored since |handler| isn't registered anymore.
90 registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); 91 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
91 } 92 }
92 93
93 // Register handlers and some IDs for those handlers, register a handler with 94 // Register handlers and some IDs for those handlers, register a handler with
94 // no IDs, and register a handler with some IDs but unregister it. Then, 95 // no IDs, and register a handler with some IDs but unregister it. Then,
95 // dispatch some notifications and invalidations. Handlers that are registered 96 // dispatch some notifications and invalidations. Handlers that are registered
96 // should get notifications, and the ones that have registered IDs should 97 // should get notifications, and the ones that have registered IDs should
97 // receive invalidations for those IDs. 98 // receive invalidations for those IDs.
98 TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) { 99 TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) {
99 StrictMock<MockSyncNotifierObserver> handler1; 100 StrictMock<MockSyncNotifierObserver> handler1;
100 EXPECT_CALL(handler1, OnNotificationsEnabled()); 101 EXPECT_CALL(handler1, OnNotificationsEnabled());
101 { 102 {
102 ObjectIdPayloadMap expected_payloads; 103 ObjectIdStateMap expected_states;
103 expected_payloads[kObjectId1] = "1"; 104 expected_states[kObjectId1].payload = "1";
104 expected_payloads[kObjectId2] = "2"; 105 expected_states[kObjectId2].payload = "2";
105 EXPECT_CALL(handler1, OnIncomingNotification(expected_payloads, 106 EXPECT_CALL(handler1, OnIncomingNotification(
106 REMOTE_NOTIFICATION)); 107 expected_states, REMOTE_NOTIFICATION));
107 } 108 }
108 EXPECT_CALL(handler1, 109 EXPECT_CALL(handler1,
109 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); 110 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
110 111
111 StrictMock<MockSyncNotifierObserver> handler2; 112 StrictMock<MockSyncNotifierObserver> handler2;
112 EXPECT_CALL(handler2, OnNotificationsEnabled()); 113 EXPECT_CALL(handler2, OnNotificationsEnabled());
113 { 114 {
114 ObjectIdPayloadMap expected_payloads; 115 ObjectIdStateMap expected_states;
115 expected_payloads[kObjectId3] = "3"; 116 expected_states[kObjectId3].payload = "3";
116 EXPECT_CALL(handler2, OnIncomingNotification(expected_payloads, 117 EXPECT_CALL(handler2, OnIncomingNotification(
117 REMOTE_NOTIFICATION)); 118 expected_states, REMOTE_NOTIFICATION));
118 } 119 }
119 EXPECT_CALL(handler2, 120 EXPECT_CALL(handler2,
120 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); 121 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
121 122
122 StrictMock<MockSyncNotifierObserver> handler3; 123 StrictMock<MockSyncNotifierObserver> handler3;
123 EXPECT_CALL(handler3, OnNotificationsEnabled()); 124 EXPECT_CALL(handler3, OnNotificationsEnabled());
124 EXPECT_CALL(handler3, 125 EXPECT_CALL(handler3,
125 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); 126 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
126 127
127 StrictMock<MockSyncNotifierObserver> handler4; 128 StrictMock<MockSyncNotifierObserver> handler4;
(...skipping 23 matching lines...) Expand all
151 { 152 {
152 ObjectIdSet ids; 153 ObjectIdSet ids;
153 ids.insert(kObjectId4); 154 ids.insert(kObjectId4);
154 registrar.UpdateRegisteredIds(&handler4, ids); 155 registrar.UpdateRegisteredIds(&handler4, ids);
155 } 156 }
156 157
157 registrar.UnregisterHandler(&handler4); 158 registrar.UnregisterHandler(&handler4);
158 159
159 registrar.EmitOnNotificationsEnabled(); 160 registrar.EmitOnNotificationsEnabled();
160 { 161 {
161 ObjectIdPayloadMap payloads; 162 ObjectIdStateMap states;
162 payloads[kObjectId1] = "1"; 163 states[kObjectId1].payload = "1";
163 payloads[kObjectId2] = "2"; 164 states[kObjectId2].payload = "2";
164 payloads[kObjectId3] = "3"; 165 states[kObjectId3].payload = "3";
165 payloads[kObjectId4] = "4"; 166 states[kObjectId4].payload = "4";
166 registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); 167 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
167 } 168 }
168 registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); 169 registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR);
169 } 170 }
170 171
171 // Multiple registrations by different handlers on the same object ID should 172 // Multiple registrations by different handlers on the same object ID should
172 // cause a CHECK. 173 // cause a CHECK.
173 TEST_F(SyncNotifierRegistrarTest, MultipleRegistration) { 174 TEST_F(SyncNotifierRegistrarTest, MultipleRegistration) {
174 SyncNotifierRegistrar registrar; 175 SyncNotifierRegistrar registrar;
175 176
176 StrictMock<MockSyncNotifierObserver> handler1; 177 StrictMock<MockSyncNotifierObserver> handler1;
(...skipping 18 matching lines...) Expand all
195 TEST_F(SyncNotifierRegistrarTest, EmptySetUnregisters) { 196 TEST_F(SyncNotifierRegistrarTest, EmptySetUnregisters) {
196 StrictMock<MockSyncNotifierObserver> handler1; 197 StrictMock<MockSyncNotifierObserver> handler1;
197 EXPECT_CALL(handler1, OnNotificationsEnabled()); 198 EXPECT_CALL(handler1, OnNotificationsEnabled());
198 EXPECT_CALL(handler1, 199 EXPECT_CALL(handler1,
199 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); 200 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
200 201
201 // Control observer. 202 // Control observer.
202 StrictMock<MockSyncNotifierObserver> handler2; 203 StrictMock<MockSyncNotifierObserver> handler2;
203 EXPECT_CALL(handler2, OnNotificationsEnabled()); 204 EXPECT_CALL(handler2, OnNotificationsEnabled());
204 { 205 {
205 ObjectIdPayloadMap expected_payloads; 206 ObjectIdStateMap expected_states;
206 expected_payloads[kObjectId3] = "3"; 207 expected_states[kObjectId3].payload = "3";
207 EXPECT_CALL(handler2, OnIncomingNotification(expected_payloads, 208 EXPECT_CALL(handler2, OnIncomingNotification(
208 REMOTE_NOTIFICATION)); 209 expected_states, REMOTE_NOTIFICATION));
209 } 210 }
210 EXPECT_CALL(handler2, 211 EXPECT_CALL(handler2,
211 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); 212 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
212 213
213 SyncNotifierRegistrar registrar; 214 SyncNotifierRegistrar registrar;
214 215
215 registrar.RegisterHandler(&handler1); 216 registrar.RegisterHandler(&handler1);
216 registrar.RegisterHandler(&handler2); 217 registrar.RegisterHandler(&handler2);
217 218
218 { 219 {
219 ObjectIdSet ids; 220 ObjectIdSet ids;
220 ids.insert(kObjectId1); 221 ids.insert(kObjectId1);
221 ids.insert(kObjectId2); 222 ids.insert(kObjectId2);
222 registrar.UpdateRegisteredIds(&handler1, ids); 223 registrar.UpdateRegisteredIds(&handler1, ids);
223 } 224 }
224 225
225 { 226 {
226 ObjectIdSet ids; 227 ObjectIdSet ids;
227 ids.insert(kObjectId3); 228 ids.insert(kObjectId3);
228 registrar.UpdateRegisteredIds(&handler2, ids); 229 registrar.UpdateRegisteredIds(&handler2, ids);
229 } 230 }
230 231
231 // Unregister the IDs for the first observer. It should not receive any 232 // Unregister the IDs for the first observer. It should not receive any
232 // further invalidations. 233 // further invalidations.
233 registrar.UpdateRegisteredIds(&handler1, ObjectIdSet()); 234 registrar.UpdateRegisteredIds(&handler1, ObjectIdSet());
234 235
235 registrar.EmitOnNotificationsEnabled(); 236 registrar.EmitOnNotificationsEnabled();
236 { 237 {
237 ObjectIdPayloadMap payloads; 238 ObjectIdStateMap states;
238 payloads[kObjectId1] = "1"; 239 states[kObjectId1].payload = "1";
239 payloads[kObjectId2] = "2"; 240 states[kObjectId2].payload = "2";
240 payloads[kObjectId3] = "3"; 241 states[kObjectId3].payload = "3";
241 registrar.DispatchInvalidationsToHandlers(payloads, 242 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
242 REMOTE_NOTIFICATION);
243 } 243 }
244 registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); 244 registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR);
245 } 245 }
246 246
247 } // namespace 247 } // namespace
248 248
249 } // namespace syncer 249 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/sync_notifier_registrar.cc ('k') | sync/sessions/session_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698