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

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

Issue 19381005: Add version field to syncer::Invalidation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
« no previous file with comments | « sync/notifier/p2p_invalidator.cc ('k') | sync/notifier/sync_invalidation_listener.h » ('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 "sync/notifier/p2p_invalidator.h" 5 #include "sync/notifier/p2p_invalidator.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "jingle/notifier/listener/fake_push_client.h" 9 #include "jingle/notifier/listener/fake_push_client.h"
10 #include "sync/internal_api/public/base/model_type.h" 10 #include "sync/internal_api/public/base/model_type.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str)); 173 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str));
174 EXPECT_TRUE(notification_data.Equals(notification_data_parsed)); 174 EXPECT_TRUE(notification_data.Equals(notification_data_parsed));
175 } 175 }
176 176
177 // Make sure the P2PNotificationData <-> string conversions work for a 177 // Make sure the P2PNotificationData <-> string conversions work for a
178 // non-default-constructed P2PNotificationData. 178 // non-default-constructed P2PNotificationData.
179 TEST_F(P2PInvalidatorTest, P2PNotificationDataNonDefault) { 179 TEST_F(P2PInvalidatorTest, P2PNotificationDataNonDefault) {
180 const ObjectIdInvalidationMap& invalidation_map = 180 const ObjectIdInvalidationMap& invalidation_map =
181 ObjectIdSetToInvalidationMap( 181 ObjectIdSetToInvalidationMap(
182 ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, THEMES)), 182 ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, THEMES)),
183 Invalidation::kUnknownVersion,
183 std::string()); 184 std::string());
184 const P2PNotificationData notification_data( 185 const P2PNotificationData notification_data(
185 "sender", NOTIFY_ALL, invalidation_map); 186 "sender", NOTIFY_ALL, invalidation_map);
186 EXPECT_TRUE(notification_data.IsTargeted("sender")); 187 EXPECT_TRUE(notification_data.IsTargeted("sender"));
187 EXPECT_TRUE(notification_data.IsTargeted("other1")); 188 EXPECT_TRUE(notification_data.IsTargeted("other1"));
188 EXPECT_TRUE(notification_data.IsTargeted("other2")); 189 EXPECT_TRUE(notification_data.IsTargeted("other2"));
189 EXPECT_THAT(invalidation_map, 190 EXPECT_THAT(invalidation_map,
190 Eq(notification_data.GetIdInvalidationMap())); 191 Eq(notification_data.GetIdInvalidationMap()));
191 const std::string& notification_data_str = notification_data.ToString(); 192 const std::string& notification_data_str = notification_data.ToString();
192 EXPECT_EQ( 193 EXPECT_EQ(
193 "{\"idInvalidationMap\":[" 194 "{\"idInvalidationMap\":["
194 "{\"objectId\":{\"name\":\"BOOKMARK\",\"source\":1004}," 195 "{\"objectId\":{\"name\":\"BOOKMARK\",\"source\":1004},"
195 "\"state\":{\"ackHandle\":{\"state\":\"\",\"timestamp\":\"0\"}," 196 "\"state\":{\"ackHandle\":{\"state\":\"\",\"timestamp\":\"0\"},"
196 "\"payload\":\"\"}}," 197 "\"payload\":\"\",\"version\":\"-1\"}},"
197 "{\"objectId\":{\"name\":\"THEME\",\"source\":1004}," 198 "{\"objectId\":{\"name\":\"THEME\",\"source\":1004},"
198 "\"state\":{\"ackHandle\":{\"state\":\"\",\"timestamp\":\"0\"}," 199 "\"state\":{\"ackHandle\":{\"state\":\"\",\"timestamp\":\"0\"},"
199 "\"payload\":\"\"}}" 200 "\"payload\":\"\",\"version\":\"-1\"}}"
200 "],\"notificationType\":\"notifyAll\"," 201 "],\"notificationType\":\"notifyAll\","
201 "\"senderId\":\"sender\"}", notification_data_str); 202 "\"senderId\":\"sender\"}", notification_data_str);
202 203
203 P2PNotificationData notification_data_parsed; 204 P2PNotificationData notification_data_parsed;
204 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str)); 205 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str));
205 EXPECT_TRUE(notification_data.Equals(notification_data_parsed)); 206 EXPECT_TRUE(notification_data.Equals(notification_data_parsed));
206 } 207 }
207 208
208 // Set up the P2PInvalidator, simulate a successful connection, and send 209 // Set up the P2PInvalidator, simulate a successful connection, and send
209 // a notification with the default target (NOTIFY_OTHERS). The 210 // a notification with the default target (NOTIFY_OTHERS). The
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 ModelTypeInvalidationMapToObjectIdInvalidationMap( 243 ModelTypeInvalidationMapToObjectIdInvalidationMap(
243 MakeInvalidationMap(enabled_types)), 244 MakeInvalidationMap(enabled_types)),
244 Eq(fake_handler_.GetLastInvalidationMap())); 245 Eq(fake_handler_.GetLastInvalidationMap()));
245 246
246 // Sent with target NOTIFY_OTHERS so should not be propagated to 247 // Sent with target NOTIFY_OTHERS so should not be propagated to
247 // |fake_handler_|. 248 // |fake_handler_|.
248 { 249 {
249 const ObjectIdInvalidationMap& invalidation_map = 250 const ObjectIdInvalidationMap& invalidation_map =
250 ObjectIdSetToInvalidationMap( 251 ObjectIdSetToInvalidationMap(
251 ModelTypeSetToObjectIdSet(ModelTypeSet(THEMES, APPS)), 252 ModelTypeSetToObjectIdSet(ModelTypeSet(THEMES, APPS)),
253 Invalidation::kUnknownVersion,
252 std::string()); 254 std::string());
253 invalidator->SendInvalidation(invalidation_map); 255 invalidator->SendInvalidation(invalidation_map);
254 } 256 }
255 257
256 ReflectSentNotifications(); 258 ReflectSentNotifications();
257 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); 259 EXPECT_EQ(1, fake_handler_.GetInvalidationCount());
258 } 260 }
259 261
260 // Set up the P2PInvalidator and send out notifications with various 262 // Set up the P2PInvalidator and send out notifications with various
261 // target settings. The notifications received by the observer should 263 // target settings. The notifications received by the observer should
262 // be consistent with the target settings. 264 // be consistent with the target settings.
263 TEST_F(P2PInvalidatorTest, SendNotificationData) { 265 TEST_F(P2PInvalidatorTest, SendNotificationData) {
264 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES, THEMES); 266 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES, THEMES);
265 const ModelTypeSet changed_types(THEMES, APPS); 267 const ModelTypeSet changed_types(THEMES, APPS);
266 const ModelTypeSet expected_types(THEMES); 268 const ModelTypeSet expected_types(THEMES);
267 269
268 const ObjectIdInvalidationMap& invalidation_map = 270 const ObjectIdInvalidationMap& invalidation_map =
269 ObjectIdSetToInvalidationMap(ModelTypeSetToObjectIdSet(changed_types), 271 ObjectIdSetToInvalidationMap(ModelTypeSetToObjectIdSet(changed_types),
272 Invalidation::kUnknownVersion,
270 std::string()); 273 std::string());
271 274
272 P2PInvalidator* const invalidator = delegate_.GetInvalidator(); 275 P2PInvalidator* const invalidator = delegate_.GetInvalidator();
273 notifier::FakePushClient* const push_client = delegate_.GetPushClient(); 276 notifier::FakePushClient* const push_client = delegate_.GetPushClient();
274 277
275 invalidator->UpdateRegisteredIds(&fake_handler_, 278 invalidator->UpdateRegisteredIds(&fake_handler_,
276 ModelTypeSetToObjectIdSet(enabled_types)); 279 ModelTypeSetToObjectIdSet(enabled_types));
277 280
278 invalidator->UpdateCredentials("foo@bar.com", "fake_token"); 281 invalidator->UpdateCredentials("foo@bar.com", "fake_token");
279 282
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 EXPECT_EQ(5, fake_handler_.GetInvalidationCount()); 359 EXPECT_EQ(5, fake_handler_.GetInvalidationCount());
357 } 360 }
358 361
359 INSTANTIATE_TYPED_TEST_CASE_P( 362 INSTANTIATE_TYPED_TEST_CASE_P(
360 P2PInvalidatorTest, InvalidatorTest, 363 P2PInvalidatorTest, InvalidatorTest,
361 P2PInvalidatorTestDelegate); 364 P2PInvalidatorTestDelegate);
362 365
363 } // namespace 366 } // namespace
364 367
365 } // namespace syncer 368 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/p2p_invalidator.cc ('k') | sync/notifier/sync_invalidation_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698