| OLD | NEW |
| 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_state_map.h" | 11 #include "sync/internal_api/public/base/model_type_state_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/object_id_state_map_test_util.h" | 14 #include "sync/notifier/object_id_state_map_test_util.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace syncer { | 17 namespace syncer { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 21 class P2PInvalidatorTestDelegate { |
| 22 public: |
| 23 P2PInvalidatorTestDelegate() : fake_push_client_(NULL) {} |
| 24 |
| 25 ~P2PInvalidatorTestDelegate() { |
| 26 DestroyInvalidator(); |
| 27 } |
| 28 |
| 29 void CreateInvalidator( |
| 30 const std::string& initial_state, |
| 31 const base::WeakPtr<InvalidationStateTracker>& |
| 32 invalidation_state_tracker) { |
| 33 DCHECK(!fake_push_client_); |
| 34 DCHECK(!invalidator_.get()); |
| 35 fake_push_client_ = new notifier::FakePushClient(); |
| 36 invalidator_.reset( |
| 37 new P2PInvalidator( |
| 38 scoped_ptr<notifier::PushClient>(fake_push_client_), |
| 39 NOTIFY_OTHERS)); |
| 40 } |
| 41 |
| 42 P2PInvalidator* GetInvalidator() { |
| 43 return invalidator_.get(); |
| 44 } |
| 45 |
| 46 notifier::FakePushClient* GetPushClient() { |
| 47 return fake_push_client_; |
| 48 } |
| 49 |
| 50 void DestroyInvalidator() { |
| 51 invalidator_.reset(); |
| 52 fake_push_client_ = NULL; |
| 53 } |
| 54 |
| 55 void WaitForInvalidator() { |
| 56 // Do Nothing. |
| 57 } |
| 58 |
| 59 void TriggerOnNotificationsEnabled() { |
| 60 fake_push_client_->EnableNotifications(); |
| 61 } |
| 62 |
| 63 void TriggerOnIncomingNotification(const ObjectIdStateMap& id_state_map, |
| 64 IncomingNotificationSource source) { |
| 65 const P2PNotificationData notification_data( |
| 66 "", NOTIFY_ALL, id_state_map, source); |
| 67 notifier::Notification notification; |
| 68 notification.channel = kSyncP2PNotificationChannel; |
| 69 notification.data = notification_data.ToString(); |
| 70 fake_push_client_->SimulateIncomingNotification(notification); |
| 71 } |
| 72 |
| 73 void TriggerOnNotificationsDisabled(NotificationsDisabledReason reason) { |
| 74 fake_push_client_->DisableNotifications(ToNotifierReasonForTest(reason)); |
| 75 } |
| 76 |
| 77 static bool InvalidatorHandlesDeprecatedState() { |
| 78 return false; |
| 79 } |
| 80 |
| 81 private: |
| 82 // Owned by |invalidator_|. |
| 83 notifier::FakePushClient* fake_push_client_; |
| 84 scoped_ptr<P2PInvalidator> invalidator_; |
| 85 }; |
| 86 |
| 20 class P2PInvalidatorTest : public testing::Test { | 87 class P2PInvalidatorTest : public testing::Test { |
| 21 protected: | 88 protected: |
| 22 P2PInvalidatorTest() | 89 P2PInvalidatorTest() |
| 23 : fake_push_client_(new notifier::FakePushClient()), | 90 : next_sent_notification_to_reflect_(0) { |
| 24 p2p_notifier_( | 91 delegate_.CreateInvalidator("fake_state", |
| 25 scoped_ptr<notifier::PushClient>(fake_push_client_), | 92 base::WeakPtr<InvalidationStateTracker>()); |
| 26 NOTIFY_OTHERS), | 93 delegate_.GetInvalidator()->RegisterHandler(&fake_handler_); |
| 27 next_sent_notification_to_reflect_(0) { | |
| 28 p2p_notifier_.RegisterHandler(&fake_handler_); | |
| 29 } | 94 } |
| 30 | 95 |
| 31 virtual ~P2PInvalidatorTest() { | 96 virtual ~P2PInvalidatorTest() { |
| 32 p2p_notifier_.UnregisterHandler(&fake_handler_); | 97 delegate_.GetInvalidator()->UnregisterHandler(&fake_handler_); |
| 33 } | 98 } |
| 34 | 99 |
| 35 ModelTypeStateMap MakeStateMap(ModelTypeSet types) { | 100 ModelTypeStateMap MakeStateMap(ModelTypeSet types) { |
| 36 return ModelTypeSetToStateMap(types, std::string()); | 101 return ModelTypeSetToStateMap(types, std::string()); |
| 37 } | 102 } |
| 38 | 103 |
| 39 // Simulate receiving all the notifications we sent out since last | 104 // Simulate receiving all the notifications we sent out since last |
| 40 // time this was called. | 105 // time this was called. |
| 41 void ReflectSentNotifications() { | 106 void ReflectSentNotifications() { |
| 42 const std::vector<notifier::Notification>& sent_notifications = | 107 const std::vector<notifier::Notification>& sent_notifications = |
| 43 fake_push_client_->sent_notifications(); | 108 delegate_.GetPushClient()->sent_notifications(); |
| 44 for(size_t i = next_sent_notification_to_reflect_; | 109 for(size_t i = next_sent_notification_to_reflect_; |
| 45 i < sent_notifications.size(); ++i) { | 110 i < sent_notifications.size(); ++i) { |
| 46 p2p_notifier_.OnIncomingNotification(sent_notifications[i]); | 111 delegate_.GetInvalidator()->OnIncomingNotification(sent_notifications[i]); |
| 47 } | 112 } |
| 48 next_sent_notification_to_reflect_ = sent_notifications.size(); | 113 next_sent_notification_to_reflect_ = sent_notifications.size(); |
| 49 } | 114 } |
| 50 | 115 |
| 51 // Owned by |p2p_notifier_|. | |
| 52 notifier::FakePushClient* fake_push_client_; | |
| 53 P2PInvalidator p2p_notifier_; | |
| 54 FakeInvalidationHandler fake_handler_; | 116 FakeInvalidationHandler fake_handler_; |
| 117 P2PInvalidatorTestDelegate delegate_; |
| 55 | 118 |
| 56 private: | 119 private: |
| 57 size_t next_sent_notification_to_reflect_; | 120 size_t next_sent_notification_to_reflect_; |
| 58 }; | 121 }; |
| 59 | 122 |
| 60 // Make sure the P2PNotificationTarget <-> string conversions work. | 123 // Make sure the P2PNotificationTarget <-> string conversions work. |
| 61 TEST_F(P2PInvalidatorTest, P2PNotificationTarget) { | 124 TEST_F(P2PInvalidatorTest, P2PNotificationTarget) { |
| 62 for (int i = FIRST_NOTIFICATION_TARGET; | 125 for (int i = FIRST_NOTIFICATION_TARGET; |
| 63 i <= LAST_NOTIFICATION_TARGET; ++i) { | 126 i <= LAST_NOTIFICATION_TARGET; ++i) { |
| 64 P2PNotificationTarget target = static_cast<P2PNotificationTarget>(i); | 127 P2PNotificationTarget target = static_cast<P2PNotificationTarget>(i); |
| 65 const std::string& target_str = P2PNotificationTargetToString(target); | 128 const std::string& target_str = P2PNotificationTargetToString(target); |
| 66 EXPECT_FALSE(target_str.empty()); | 129 EXPECT_FALSE(target_str.empty()); |
| 67 EXPECT_EQ(target, P2PNotificationTargetFromString(target_str)); | 130 EXPECT_EQ(target, P2PNotificationTargetFromString(target_str)); |
| 68 } | 131 } |
| 69 EXPECT_EQ(NOTIFY_SELF, P2PNotificationTargetFromString("unknown")); | 132 EXPECT_EQ(NOTIFY_SELF, P2PNotificationTargetFromString("unknown")); |
| 70 } | 133 } |
| 71 | 134 |
| 72 // Make sure notification targeting works correctly. | 135 // Make sure notification targeting works correctly. |
| 73 TEST_F(P2PInvalidatorTest, P2PNotificationDataIsTargeted) { | 136 TEST_F(P2PInvalidatorTest, P2PNotificationDataIsTargeted) { |
| 74 { | 137 { |
| 75 const P2PNotificationData notification_data( | 138 const P2PNotificationData notification_data( |
| 76 "sender", NOTIFY_SELF, ModelTypeSet()); | 139 "sender", NOTIFY_SELF, ObjectIdStateMap(), REMOTE_NOTIFICATION); |
| 77 EXPECT_TRUE(notification_data.IsTargeted("sender")); | 140 EXPECT_TRUE(notification_data.IsTargeted("sender")); |
| 78 EXPECT_FALSE(notification_data.IsTargeted("other1")); | 141 EXPECT_FALSE(notification_data.IsTargeted("other1")); |
| 79 EXPECT_FALSE(notification_data.IsTargeted("other2")); | 142 EXPECT_FALSE(notification_data.IsTargeted("other2")); |
| 80 } | 143 } |
| 81 { | 144 { |
| 82 const P2PNotificationData notification_data( | 145 const P2PNotificationData notification_data( |
| 83 "sender", NOTIFY_OTHERS, ModelTypeSet()); | 146 "sender", NOTIFY_OTHERS, ObjectIdStateMap(), REMOTE_NOTIFICATION); |
| 84 EXPECT_FALSE(notification_data.IsTargeted("sender")); | 147 EXPECT_FALSE(notification_data.IsTargeted("sender")); |
| 85 EXPECT_TRUE(notification_data.IsTargeted("other1")); | 148 EXPECT_TRUE(notification_data.IsTargeted("other1")); |
| 86 EXPECT_TRUE(notification_data.IsTargeted("other2")); | 149 EXPECT_TRUE(notification_data.IsTargeted("other2")); |
| 87 } | 150 } |
| 88 { | 151 { |
| 89 const P2PNotificationData notification_data( | 152 const P2PNotificationData notification_data( |
| 90 "sender", NOTIFY_ALL, ModelTypeSet()); | 153 "sender", NOTIFY_ALL, ObjectIdStateMap(), REMOTE_NOTIFICATION); |
| 91 EXPECT_TRUE(notification_data.IsTargeted("sender")); | 154 EXPECT_TRUE(notification_data.IsTargeted("sender")); |
| 92 EXPECT_TRUE(notification_data.IsTargeted("other1")); | 155 EXPECT_TRUE(notification_data.IsTargeted("other1")); |
| 93 EXPECT_TRUE(notification_data.IsTargeted("other2")); | 156 EXPECT_TRUE(notification_data.IsTargeted("other2")); |
| 94 } | 157 } |
| 95 } | 158 } |
| 96 | 159 |
| 97 // Make sure the P2PNotificationData <-> string conversions work for a | 160 // Make sure the P2PNotificationData <-> string conversions work for a |
| 98 // default-constructed P2PNotificationData. | 161 // default-constructed P2PNotificationData. |
| 99 TEST_F(P2PInvalidatorTest, P2PNotificationDataDefault) { | 162 TEST_F(P2PInvalidatorTest, P2PNotificationDataDefault) { |
| 100 const P2PNotificationData notification_data; | 163 const P2PNotificationData notification_data; |
| 101 EXPECT_TRUE(notification_data.IsTargeted("")); | 164 EXPECT_TRUE(notification_data.IsTargeted("")); |
| 102 EXPECT_FALSE(notification_data.IsTargeted("other1")); | 165 EXPECT_FALSE(notification_data.IsTargeted("other1")); |
| 103 EXPECT_FALSE(notification_data.IsTargeted("other2")); | 166 EXPECT_FALSE(notification_data.IsTargeted("other2")); |
| 104 EXPECT_TRUE(notification_data.GetChangedTypes().Empty()); | 167 EXPECT_TRUE(notification_data.GetIdStateMap().empty()); |
| 105 const std::string& notification_data_str = notification_data.ToString(); | 168 const std::string& notification_data_str = notification_data.ToString(); |
| 106 EXPECT_EQ( | 169 EXPECT_EQ( |
| 107 "{\"changedTypes\":[],\"notificationType\":\"notifySelf\"," | 170 "{\"idStateMap\":[],\"notificationType\":\"notifySelf\",\"senderId\":" |
| 108 "\"senderId\":\"\"}", notification_data_str); | 171 "\"\",\"source\":0}", notification_data_str); |
| 109 | 172 |
| 110 P2PNotificationData notification_data_parsed; | 173 P2PNotificationData notification_data_parsed; |
| 111 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str)); | 174 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str)); |
| 112 EXPECT_TRUE(notification_data.Equals(notification_data_parsed)); | 175 EXPECT_TRUE(notification_data.Equals(notification_data_parsed)); |
| 113 } | 176 } |
| 114 | 177 |
| 115 // Make sure the P2PNotificationData <-> string conversions work for a | 178 // Make sure the P2PNotificationData <-> string conversions work for a |
| 116 // non-default-constructed P2PNotificationData. | 179 // non-default-constructed P2PNotificationData. |
| 117 TEST_F(P2PInvalidatorTest, P2PNotificationDataNonDefault) { | 180 TEST_F(P2PInvalidatorTest, P2PNotificationDataNonDefault) { |
| 118 const ModelTypeSet changed_types(BOOKMARKS, THEMES); | 181 const ObjectIdStateMap& id_state_map = |
| 182 ObjectIdSetToStateMap( |
| 183 ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, THEMES)), ""); |
| 119 const P2PNotificationData notification_data( | 184 const P2PNotificationData notification_data( |
| 120 "sender", NOTIFY_ALL, changed_types); | 185 "sender", NOTIFY_ALL, id_state_map, LOCAL_NOTIFICATION); |
| 121 EXPECT_TRUE(notification_data.IsTargeted("sender")); | 186 EXPECT_TRUE(notification_data.IsTargeted("sender")); |
| 122 EXPECT_TRUE(notification_data.IsTargeted("other1")); | 187 EXPECT_TRUE(notification_data.IsTargeted("other1")); |
| 123 EXPECT_TRUE(notification_data.IsTargeted("other2")); | 188 EXPECT_TRUE(notification_data.IsTargeted("other2")); |
| 124 EXPECT_TRUE(notification_data.GetChangedTypes().Equals(changed_types)); | 189 EXPECT_THAT(id_state_map, Eq(notification_data.GetIdStateMap())); |
| 125 const std::string& notification_data_str = notification_data.ToString(); | 190 const std::string& notification_data_str = notification_data.ToString(); |
| 126 EXPECT_EQ( | 191 EXPECT_EQ( |
| 127 "{\"changedTypes\":[\"Bookmarks\",\"Themes\"]," | 192 "{\"idStateMap\":[" |
| 128 "\"notificationType\":\"notifyAll\"," | 193 "{\"objectId\":{\"name\":\"BOOKMARK\",\"source\":1004}," |
| 129 "\"senderId\":\"sender\"}", notification_data_str); | 194 "\"state\":{\"ackHandle\":{},\"payload\":\"\"}}," |
| 195 "{\"objectId\":{\"name\":\"THEME\",\"source\":1004}," |
| 196 "\"state\":{\"ackHandle\":{},\"payload\":\"\"}}" |
| 197 "],\"notificationType\":\"notifyAll\"," |
| 198 "\"senderId\":\"sender\",\"source\":1}", notification_data_str); |
| 130 | 199 |
| 131 P2PNotificationData notification_data_parsed; | 200 P2PNotificationData notification_data_parsed; |
| 132 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str)); | 201 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str)); |
| 133 EXPECT_TRUE(notification_data.Equals(notification_data_parsed)); | 202 EXPECT_TRUE(notification_data.Equals(notification_data_parsed)); |
| 134 } | 203 } |
| 135 | 204 |
| 136 // Set up the P2PInvalidator, simulate a successful connection, and send | 205 // Set up the P2PInvalidator, simulate a successful connection, and send |
| 137 // a notification with the default target (NOTIFY_OTHERS). The | 206 // a notification with the default target (NOTIFY_OTHERS). The |
| 138 // observer should receive only a notification from the call to | 207 // observer should receive only a notification from the call to |
| 139 // UpdateEnabledTypes(). | 208 // UpdateEnabledTypes(). |
| 140 TEST_F(P2PInvalidatorTest, NotificationsBasic) { | 209 TEST_F(P2PInvalidatorTest, NotificationsBasic) { |
| 141 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES); | 210 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES); |
| 142 | 211 |
| 143 p2p_notifier_.UpdateRegisteredIds(&fake_handler_, | 212 P2PInvalidator* const invalidator = delegate_.GetInvalidator(); |
| 144 ModelTypeSetToObjectIdSet(enabled_types)); | 213 notifier::FakePushClient* const push_client = delegate_.GetPushClient(); |
| 145 | 214 |
| 146 p2p_notifier_.SetUniqueId("sender"); | 215 invalidator->UpdateRegisteredIds(&fake_handler_, |
| 216 ModelTypeSetToObjectIdSet(enabled_types)); |
| 217 |
| 218 invalidator->SetUniqueId("sender"); |
| 147 | 219 |
| 148 const char kEmail[] = "foo@bar.com"; | 220 const char kEmail[] = "foo@bar.com"; |
| 149 const char kToken[] = "token"; | 221 const char kToken[] = "token"; |
| 150 p2p_notifier_.UpdateCredentials(kEmail, kToken); | 222 invalidator->UpdateCredentials(kEmail, kToken); |
| 151 { | 223 { |
| 152 notifier::Subscription expected_subscription; | 224 notifier::Subscription expected_subscription; |
| 153 expected_subscription.channel = kSyncP2PNotificationChannel; | 225 expected_subscription.channel = kSyncP2PNotificationChannel; |
| 154 expected_subscription.from = kEmail; | 226 expected_subscription.from = kEmail; |
| 155 EXPECT_TRUE(notifier::SubscriptionListsEqual( | 227 EXPECT_TRUE(notifier::SubscriptionListsEqual( |
| 156 fake_push_client_->subscriptions(), | 228 push_client->subscriptions(), |
| 157 notifier::SubscriptionList(1, expected_subscription))); | 229 notifier::SubscriptionList(1, expected_subscription))); |
| 158 } | 230 } |
| 159 EXPECT_EQ(kEmail, fake_push_client_->email()); | 231 EXPECT_EQ(kEmail, push_client->email()); |
| 160 EXPECT_EQ(kToken, fake_push_client_->token()); | 232 EXPECT_EQ(kToken, push_client->token()); |
| 161 | 233 |
| 162 ReflectSentNotifications(); | 234 ReflectSentNotifications(); |
| 163 fake_push_client_->EnableNotifications(); | 235 push_client->EnableNotifications(); |
| 164 EXPECT_EQ(NO_NOTIFICATION_ERROR, | 236 EXPECT_EQ(NO_NOTIFICATION_ERROR, |
| 165 fake_handler_.GetNotificationsDisabledReason()); | 237 fake_handler_.GetNotificationsDisabledReason()); |
| 166 | 238 |
| 167 ReflectSentNotifications(); | 239 ReflectSentNotifications(); |
| 168 EXPECT_EQ(1, fake_handler_.GetNotificationCount()); | 240 EXPECT_EQ(1, fake_handler_.GetNotificationCount()); |
| 169 EXPECT_THAT( | 241 EXPECT_THAT( |
| 170 ModelTypeStateMapToObjectIdStateMap(MakeStateMap(enabled_types)), | 242 ModelTypeStateMapToObjectIdStateMap(MakeStateMap(enabled_types)), |
| 171 Eq(fake_handler_.GetLastNotificationIdStateMap())); | 243 Eq(fake_handler_.GetLastNotificationIdStateMap())); |
| 172 EXPECT_EQ(REMOTE_NOTIFICATION, fake_handler_.GetLastNotificationSource()); | 244 EXPECT_EQ(REMOTE_NOTIFICATION, fake_handler_.GetLastNotificationSource()); |
| 173 | 245 |
| 174 // Sent with target NOTIFY_OTHERS so should not be propagated to | 246 // Sent with target NOTIFY_OTHERS so should not be propagated to |
| 175 // |fake_handler_|. | 247 // |fake_handler_|. |
| 176 { | 248 { |
| 177 ModelTypeSet changed_types(THEMES, APPS); | 249 const ObjectIdStateMap& id_state_map = |
| 178 p2p_notifier_.SendNotification(changed_types); | 250 ObjectIdSetToStateMap( |
| 251 ModelTypeSetToObjectIdSet(ModelTypeSet(THEMES, APPS)), ""); |
| 252 invalidator->SendNotification(id_state_map); |
| 179 } | 253 } |
| 180 | 254 |
| 181 ReflectSentNotifications(); | 255 ReflectSentNotifications(); |
| 182 EXPECT_EQ(1, fake_handler_.GetNotificationCount()); | 256 EXPECT_EQ(1, fake_handler_.GetNotificationCount()); |
| 183 } | 257 } |
| 184 | 258 |
| 185 // Set up the P2PInvalidator and send out notifications with various | 259 // Set up the P2PInvalidator and send out notifications with various |
| 186 // target settings. The notifications received by the observer should | 260 // target settings. The notifications received by the observer should |
| 187 // be consistent with the target settings. | 261 // be consistent with the target settings. |
| 188 TEST_F(P2PInvalidatorTest, SendNotificationData) { | 262 TEST_F(P2PInvalidatorTest, SendNotificationData) { |
| 189 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES, THEMES); | 263 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES, THEMES); |
| 190 const ModelTypeSet changed_types(THEMES, APPS); | 264 const ModelTypeSet changed_types(THEMES, APPS); |
| 191 const ModelTypeSet expected_types(THEMES); | 265 const ModelTypeSet expected_types(THEMES); |
| 192 | 266 |
| 193 p2p_notifier_.UpdateRegisteredIds(&fake_handler_, | 267 const ObjectIdStateMap& id_state_map = |
| 194 ModelTypeSetToObjectIdSet(enabled_types)); | 268 ObjectIdSetToStateMap( |
| 269 ModelTypeSetToObjectIdSet(changed_types), ""); |
| 195 | 270 |
| 196 p2p_notifier_.SetUniqueId("sender"); | 271 P2PInvalidator* const invalidator = delegate_.GetInvalidator(); |
| 197 p2p_notifier_.UpdateCredentials("foo@bar.com", "fake_token"); | 272 notifier::FakePushClient* const push_client = delegate_.GetPushClient(); |
| 273 |
| 274 invalidator->UpdateRegisteredIds(&fake_handler_, |
| 275 ModelTypeSetToObjectIdSet(enabled_types)); |
| 276 |
| 277 invalidator->SetUniqueId("sender"); |
| 278 invalidator->UpdateCredentials("foo@bar.com", "fake_token"); |
| 198 | 279 |
| 199 ReflectSentNotifications(); | 280 ReflectSentNotifications(); |
| 200 fake_push_client_->EnableNotifications(); | 281 push_client->EnableNotifications(); |
| 201 EXPECT_EQ(NO_NOTIFICATION_ERROR, | 282 EXPECT_EQ(NO_NOTIFICATION_ERROR, |
| 202 fake_handler_.GetNotificationsDisabledReason()); | 283 fake_handler_.GetNotificationsDisabledReason()); |
| 203 | 284 |
| 204 ReflectSentNotifications(); | 285 ReflectSentNotifications(); |
| 205 EXPECT_EQ(1, fake_handler_.GetNotificationCount()); | 286 EXPECT_EQ(1, fake_handler_.GetNotificationCount()); |
| 206 EXPECT_THAT( | 287 EXPECT_THAT( |
| 207 ModelTypeStateMapToObjectIdStateMap(MakeStateMap(enabled_types)), | 288 ModelTypeStateMapToObjectIdStateMap(MakeStateMap(enabled_types)), |
| 208 Eq(fake_handler_.GetLastNotificationIdStateMap())); | 289 Eq(fake_handler_.GetLastNotificationIdStateMap())); |
| 209 EXPECT_EQ(REMOTE_NOTIFICATION, fake_handler_.GetLastNotificationSource()); | 290 EXPECT_EQ(REMOTE_NOTIFICATION, fake_handler_.GetLastNotificationSource()); |
| 210 | 291 |
| 211 // Should be dropped. | 292 // Should be dropped. |
| 212 p2p_notifier_.SendNotificationDataForTest(P2PNotificationData()); | 293 invalidator->SendNotificationDataForTest(P2PNotificationData()); |
| 213 ReflectSentNotifications(); | 294 ReflectSentNotifications(); |
| 214 EXPECT_EQ(1, fake_handler_.GetNotificationCount()); | 295 EXPECT_EQ(1, fake_handler_.GetNotificationCount()); |
| 215 | 296 |
| 216 const ObjectIdStateMap& expected_ids = | 297 const ObjectIdStateMap& expected_ids = |
| 217 ModelTypeStateMapToObjectIdStateMap(MakeStateMap(expected_types)); | 298 ModelTypeStateMapToObjectIdStateMap(MakeStateMap(expected_types)); |
| 218 | 299 |
| 219 // Should be propagated. | 300 // Should be propagated. |
| 220 p2p_notifier_.SendNotificationDataForTest( | 301 invalidator->SendNotificationDataForTest( |
| 221 P2PNotificationData("sender", NOTIFY_SELF, changed_types)); | 302 P2PNotificationData("sender", NOTIFY_SELF, |
| 303 id_state_map, REMOTE_NOTIFICATION)); |
| 222 ReflectSentNotifications(); | 304 ReflectSentNotifications(); |
| 223 EXPECT_EQ(2, fake_handler_.GetNotificationCount()); | 305 EXPECT_EQ(2, fake_handler_.GetNotificationCount()); |
| 224 EXPECT_THAT( | 306 EXPECT_THAT( |
| 225 expected_ids, | 307 expected_ids, |
| 226 Eq(fake_handler_.GetLastNotificationIdStateMap())); | 308 Eq(fake_handler_.GetLastNotificationIdStateMap())); |
| 227 | 309 |
| 228 // Should be dropped. | 310 // Should be dropped. |
| 229 p2p_notifier_.SendNotificationDataForTest( | 311 invalidator->SendNotificationDataForTest( |
| 230 P2PNotificationData("sender2", NOTIFY_SELF, changed_types)); | 312 P2PNotificationData("sender2", NOTIFY_SELF, |
| 313 id_state_map, REMOTE_NOTIFICATION)); |
| 231 ReflectSentNotifications(); | 314 ReflectSentNotifications(); |
| 232 EXPECT_EQ(2, fake_handler_.GetNotificationCount()); | 315 EXPECT_EQ(2, fake_handler_.GetNotificationCount()); |
| 233 | 316 |
| 234 // Should be dropped. | 317 // Should be dropped. |
| 235 p2p_notifier_.SendNotificationDataForTest( | 318 invalidator->SendNotificationDataForTest( |
| 236 P2PNotificationData("sender", NOTIFY_SELF, ModelTypeSet())); | 319 P2PNotificationData("sender", NOTIFY_SELF, |
| 320 ObjectIdStateMap(), REMOTE_NOTIFICATION)); |
| 237 ReflectSentNotifications(); | 321 ReflectSentNotifications(); |
| 238 EXPECT_EQ(2, fake_handler_.GetNotificationCount()); | 322 EXPECT_EQ(2, fake_handler_.GetNotificationCount()); |
| 239 | 323 |
| 240 // Should be dropped. | 324 // Should be dropped. |
| 241 p2p_notifier_.SendNotificationDataForTest( | 325 invalidator->SendNotificationDataForTest( |
| 242 P2PNotificationData("sender", NOTIFY_OTHERS, changed_types)); | 326 P2PNotificationData("sender", NOTIFY_OTHERS, |
| 327 id_state_map, REMOTE_NOTIFICATION)); |
| 243 ReflectSentNotifications(); | 328 ReflectSentNotifications(); |
| 244 EXPECT_EQ(2, fake_handler_.GetNotificationCount()); | 329 EXPECT_EQ(2, fake_handler_.GetNotificationCount()); |
| 245 | 330 |
| 246 // Should be propagated. | 331 // Should be propagated. |
| 247 p2p_notifier_.SendNotificationDataForTest( | 332 invalidator->SendNotificationDataForTest( |
| 248 P2PNotificationData("sender2", NOTIFY_OTHERS, changed_types)); | 333 P2PNotificationData("sender2", NOTIFY_OTHERS, |
| 334 id_state_map, REMOTE_NOTIFICATION)); |
| 249 ReflectSentNotifications(); | 335 ReflectSentNotifications(); |
| 250 EXPECT_EQ(3, fake_handler_.GetNotificationCount()); | 336 EXPECT_EQ(3, fake_handler_.GetNotificationCount()); |
| 251 EXPECT_THAT( | 337 EXPECT_THAT( |
| 252 expected_ids, | 338 expected_ids, |
| 253 Eq(fake_handler_.GetLastNotificationIdStateMap())); | 339 Eq(fake_handler_.GetLastNotificationIdStateMap())); |
| 254 | 340 |
| 255 // Should be dropped. | 341 // Should be dropped. |
| 256 p2p_notifier_.SendNotificationDataForTest( | 342 invalidator->SendNotificationDataForTest( |
| 257 P2PNotificationData("sender2", NOTIFY_OTHERS, ModelTypeSet())); | 343 P2PNotificationData("sender2", NOTIFY_OTHERS, |
| 344 ObjectIdStateMap(), REMOTE_NOTIFICATION)); |
| 258 ReflectSentNotifications(); | 345 ReflectSentNotifications(); |
| 259 EXPECT_EQ(3, fake_handler_.GetNotificationCount()); | 346 EXPECT_EQ(3, fake_handler_.GetNotificationCount()); |
| 260 | 347 |
| 261 // Should be propagated. | 348 // Should be propagated. |
| 262 p2p_notifier_.SendNotificationDataForTest( | 349 invalidator->SendNotificationDataForTest( |
| 263 P2PNotificationData("sender", NOTIFY_ALL, changed_types)); | 350 P2PNotificationData("sender", NOTIFY_ALL, |
| 351 id_state_map, REMOTE_NOTIFICATION)); |
| 264 ReflectSentNotifications(); | 352 ReflectSentNotifications(); |
| 265 EXPECT_EQ(4, fake_handler_.GetNotificationCount()); | 353 EXPECT_EQ(4, fake_handler_.GetNotificationCount()); |
| 266 EXPECT_THAT( | 354 EXPECT_THAT( |
| 267 expected_ids, | 355 expected_ids, |
| 268 Eq(fake_handler_.GetLastNotificationIdStateMap())); | 356 Eq(fake_handler_.GetLastNotificationIdStateMap())); |
| 269 | 357 |
| 270 // Should be propagated. | 358 // Should be propagated. |
| 271 p2p_notifier_.SendNotificationDataForTest( | 359 invalidator->SendNotificationDataForTest( |
| 272 P2PNotificationData("sender2", NOTIFY_ALL, changed_types)); | 360 P2PNotificationData("sender2", NOTIFY_ALL, |
| 361 id_state_map, REMOTE_NOTIFICATION)); |
| 273 ReflectSentNotifications(); | 362 ReflectSentNotifications(); |
| 274 EXPECT_EQ(5, fake_handler_.GetNotificationCount()); | 363 EXPECT_EQ(5, fake_handler_.GetNotificationCount()); |
| 275 EXPECT_THAT( | 364 EXPECT_THAT( |
| 276 expected_ids, | 365 expected_ids, |
| 277 Eq(fake_handler_.GetLastNotificationIdStateMap())); | 366 Eq(fake_handler_.GetLastNotificationIdStateMap())); |
| 278 | 367 |
| 279 // Should be dropped. | 368 // Should be dropped. |
| 280 p2p_notifier_.SendNotificationDataForTest( | 369 invalidator->SendNotificationDataForTest( |
| 281 P2PNotificationData("sender2", NOTIFY_ALL, ModelTypeSet())); | 370 P2PNotificationData("sender2", NOTIFY_ALL, |
| 371 ObjectIdStateMap(), REMOTE_NOTIFICATION)); |
| 282 ReflectSentNotifications(); | 372 ReflectSentNotifications(); |
| 283 EXPECT_EQ(5, fake_handler_.GetNotificationCount()); | 373 EXPECT_EQ(5, fake_handler_.GetNotificationCount()); |
| 284 } | 374 } |
| 285 | 375 |
| 376 INSTANTIATE_TYPED_TEST_CASE_P( |
| 377 P2PInvalidatorTest, InvalidatorTest, |
| 378 P2PInvalidatorTestDelegate); |
| 379 |
| 286 } // namespace | 380 } // namespace |
| 287 | 381 |
| 288 } // namespace syncer | 382 } // namespace syncer |
| OLD | NEW |