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

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

Issue 12847003: Separate invalidator and sync client ID (part 2/2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix sync_listen_notifications utility Created 7 years, 9 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/p2p_invalidator.cc ('k') | sync/notifier/sync_invalidation_listener.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 "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"
11 #include "sync/internal_api/public/base/model_type_invalidation_map.h" 11 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
12 #include "sync/notifier/fake_invalidation_handler.h" 12 #include "sync/notifier/fake_invalidation_handler.h"
13 #include "sync/notifier/invalidator_test_template.h" 13 #include "sync/notifier/invalidator_test_template.h"
14 #include "sync/notifier/object_id_invalidation_map_test_util.h" 14 #include "sync/notifier/object_id_invalidation_map_test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace syncer { 17 namespace syncer {
18 18
19 namespace { 19 namespace {
20 20
21 class P2PInvalidatorTestDelegate { 21 class P2PInvalidatorTestDelegate {
22 public: 22 public:
23 P2PInvalidatorTestDelegate() : fake_push_client_(NULL) {} 23 P2PInvalidatorTestDelegate() : fake_push_client_(NULL) {}
24 24
25 ~P2PInvalidatorTestDelegate() { 25 ~P2PInvalidatorTestDelegate() {
26 DestroyInvalidator(); 26 DestroyInvalidator();
27 } 27 }
28 28
29 void CreateInvalidator( 29 void CreateInvalidator(
30 const std::string& invalidator_client_id,
30 const std::string& initial_state, 31 const std::string& initial_state,
31 const base::WeakPtr<InvalidationStateTracker>& 32 const base::WeakPtr<InvalidationStateTracker>&
32 invalidation_state_tracker) { 33 invalidation_state_tracker) {
33 DCHECK(!fake_push_client_); 34 DCHECK(!fake_push_client_);
34 DCHECK(!invalidator_.get()); 35 DCHECK(!invalidator_.get());
35 fake_push_client_ = new notifier::FakePushClient(); 36 fake_push_client_ = new notifier::FakePushClient();
36 invalidator_.reset( 37 invalidator_.reset(
37 new P2PInvalidator( 38 new P2PInvalidator(
38 scoped_ptr<notifier::PushClient>(fake_push_client_), 39 scoped_ptr<notifier::PushClient>(fake_push_client_),
40 invalidator_client_id,
39 NOTIFY_OTHERS)); 41 NOTIFY_OTHERS));
40 } 42 }
41 43
42 P2PInvalidator* GetInvalidator() { 44 P2PInvalidator* GetInvalidator() {
43 return invalidator_.get(); 45 return invalidator_.get();
44 } 46 }
45 47
46 notifier::FakePushClient* GetPushClient() { 48 notifier::FakePushClient* GetPushClient() {
47 return fake_push_client_; 49 return fake_push_client_;
48 } 50 }
(...skipping 28 matching lines...) Expand all
77 private: 79 private:
78 // Owned by |invalidator_|. 80 // Owned by |invalidator_|.
79 notifier::FakePushClient* fake_push_client_; 81 notifier::FakePushClient* fake_push_client_;
80 scoped_ptr<P2PInvalidator> invalidator_; 82 scoped_ptr<P2PInvalidator> invalidator_;
81 }; 83 };
82 84
83 class P2PInvalidatorTest : public testing::Test { 85 class P2PInvalidatorTest : public testing::Test {
84 protected: 86 protected:
85 P2PInvalidatorTest() 87 P2PInvalidatorTest()
86 : next_sent_notification_to_reflect_(0) { 88 : next_sent_notification_to_reflect_(0) {
87 delegate_.CreateInvalidator("fake_state", 89 delegate_.CreateInvalidator("sender",
90 "fake_state",
88 base::WeakPtr<InvalidationStateTracker>()); 91 base::WeakPtr<InvalidationStateTracker>());
89 delegate_.GetInvalidator()->RegisterHandler(&fake_handler_); 92 delegate_.GetInvalidator()->RegisterHandler(&fake_handler_);
90 } 93 }
91 94
92 virtual ~P2PInvalidatorTest() { 95 virtual ~P2PInvalidatorTest() {
93 delegate_.GetInvalidator()->UnregisterHandler(&fake_handler_); 96 delegate_.GetInvalidator()->UnregisterHandler(&fake_handler_);
94 } 97 }
95 98
96 ModelTypeInvalidationMap MakeInvalidationMap(ModelTypeSet types) { 99 ModelTypeInvalidationMap MakeInvalidationMap(ModelTypeSet types) {
97 return ModelTypeSetToInvalidationMap(types, std::string()); 100 return ModelTypeSetToInvalidationMap(types, std::string());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // UpdateEnabledTypes(). 210 // UpdateEnabledTypes().
208 TEST_F(P2PInvalidatorTest, NotificationsBasic) { 211 TEST_F(P2PInvalidatorTest, NotificationsBasic) {
209 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES); 212 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES);
210 213
211 P2PInvalidator* const invalidator = delegate_.GetInvalidator(); 214 P2PInvalidator* const invalidator = delegate_.GetInvalidator();
212 notifier::FakePushClient* const push_client = delegate_.GetPushClient(); 215 notifier::FakePushClient* const push_client = delegate_.GetPushClient();
213 216
214 invalidator->UpdateRegisteredIds(&fake_handler_, 217 invalidator->UpdateRegisteredIds(&fake_handler_,
215 ModelTypeSetToObjectIdSet(enabled_types)); 218 ModelTypeSetToObjectIdSet(enabled_types));
216 219
217 invalidator->SetUniqueId("sender");
218
219 const char kEmail[] = "foo@bar.com"; 220 const char kEmail[] = "foo@bar.com";
220 const char kToken[] = "token"; 221 const char kToken[] = "token";
221 invalidator->UpdateCredentials(kEmail, kToken); 222 invalidator->UpdateCredentials(kEmail, kToken);
222 { 223 {
223 notifier::Subscription expected_subscription; 224 notifier::Subscription expected_subscription;
224 expected_subscription.channel = kSyncP2PNotificationChannel; 225 expected_subscription.channel = kSyncP2PNotificationChannel;
225 expected_subscription.from = kEmail; 226 expected_subscription.from = kEmail;
226 EXPECT_TRUE(notifier::SubscriptionListsEqual( 227 EXPECT_TRUE(notifier::SubscriptionListsEqual(
227 push_client->subscriptions(), 228 push_client->subscriptions(),
228 notifier::SubscriptionList(1, expected_subscription))); 229 notifier::SubscriptionList(1, expected_subscription)));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 const ObjectIdInvalidationMap& invalidation_map = 266 const ObjectIdInvalidationMap& invalidation_map =
266 ObjectIdSetToInvalidationMap( 267 ObjectIdSetToInvalidationMap(
267 ModelTypeSetToObjectIdSet(changed_types), ""); 268 ModelTypeSetToObjectIdSet(changed_types), "");
268 269
269 P2PInvalidator* const invalidator = delegate_.GetInvalidator(); 270 P2PInvalidator* const invalidator = delegate_.GetInvalidator();
270 notifier::FakePushClient* const push_client = delegate_.GetPushClient(); 271 notifier::FakePushClient* const push_client = delegate_.GetPushClient();
271 272
272 invalidator->UpdateRegisteredIds(&fake_handler_, 273 invalidator->UpdateRegisteredIds(&fake_handler_,
273 ModelTypeSetToObjectIdSet(enabled_types)); 274 ModelTypeSetToObjectIdSet(enabled_types));
274 275
275 invalidator->SetUniqueId("sender");
276 invalidator->UpdateCredentials("foo@bar.com", "fake_token"); 276 invalidator->UpdateCredentials("foo@bar.com", "fake_token");
277 277
278 ReflectSentNotifications(); 278 ReflectSentNotifications();
279 push_client->EnableNotifications(); 279 push_client->EnableNotifications();
280 EXPECT_EQ(INVALIDATIONS_ENABLED, fake_handler_.GetInvalidatorState()); 280 EXPECT_EQ(INVALIDATIONS_ENABLED, fake_handler_.GetInvalidatorState());
281 281
282 ReflectSentNotifications(); 282 ReflectSentNotifications();
283 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); 283 EXPECT_EQ(1, fake_handler_.GetInvalidationCount());
284 EXPECT_THAT( 284 EXPECT_THAT(
285 ModelTypeInvalidationMapToObjectIdInvalidationMap( 285 ModelTypeInvalidationMapToObjectIdInvalidationMap(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 EXPECT_EQ(5, fake_handler_.GetInvalidationCount()); 354 EXPECT_EQ(5, fake_handler_.GetInvalidationCount());
355 } 355 }
356 356
357 INSTANTIATE_TYPED_TEST_CASE_P( 357 INSTANTIATE_TYPED_TEST_CASE_P(
358 P2PInvalidatorTest, InvalidatorTest, 358 P2PInvalidatorTest, InvalidatorTest,
359 P2PInvalidatorTestDelegate); 359 P2PInvalidatorTestDelegate);
360 360
361 } // namespace 361 } // namespace
362 362
363 } // namespace syncer 363 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/p2p_invalidator.cc ('k') | sync/notifier/sync_invalidation_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698