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/invalidation_notifier.h" | 5 #include "sync/notifier/invalidation_notifier.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "jingle/notifier/base/fake_base_task.h" | 9 #include "jingle/notifier/base/fake_base_task.h" |
10 #include "jingle/notifier/base/notifier_options.h" | 10 #include "jingle/notifier/base/notifier_options.h" |
11 #include "jingle/notifier/listener/fake_push_client.h" | 11 #include "jingle/notifier/listener/fake_push_client.h" |
12 #include "net/url_request/url_request_test_util.h" | 12 #include "net/url_request/url_request_test_util.h" |
13 #include "sync/internal_api/public/base/model_type.h" | 13 #include "sync/internal_api/public/base/model_type.h" |
14 #include "sync/internal_api/public/base/model_type_payload_map.h" | 14 #include "sync/internal_api/public/base/model_type_state_map.h" |
15 #include "sync/internal_api/public/util/weak_handle.h" | 15 #include "sync/internal_api/public/util/weak_handle.h" |
16 #include "sync/notifier/fake_invalidation_state_tracker.h" | 16 #include "sync/notifier/fake_invalidation_state_tracker.h" |
17 #include "sync/notifier/invalidation_state_tracker.h" | 17 #include "sync/notifier/invalidation_state_tracker.h" |
18 #include "sync/notifier/mock_sync_notifier_observer.h" | 18 #include "sync/notifier/mock_sync_notifier_observer.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 namespace syncer { | 22 namespace syncer { |
23 | 23 |
24 namespace { | 24 namespace { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 FakeInvalidationStateTracker fake_tracker_; | 77 FakeInvalidationStateTracker fake_tracker_; |
78 StrictMock<MockSyncNotifierObserver> mock_observer_; | 78 StrictMock<MockSyncNotifierObserver> mock_observer_; |
79 }; | 79 }; |
80 | 80 |
81 TEST_F(InvalidationNotifierTest, Basic) { | 81 TEST_F(InvalidationNotifierTest, Basic) { |
82 InSequence dummy; | 82 InSequence dummy; |
83 | 83 |
84 CreateNotifier("fake_state"); | 84 CreateNotifier("fake_state"); |
85 | 85 |
86 const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); | 86 const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); |
87 const ModelTypePayloadMap& type_payloads = | 87 const ModelTypeStateMap& type_state_map = |
88 ModelTypePayloadMapFromEnumSet(models, "payload"); | 88 ModelTypeStateMapFromEnumSet(models, "payload"); |
89 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); | 89 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); |
90 EXPECT_CALL(mock_observer_, OnIncomingNotification( | 90 EXPECT_CALL(mock_observer_, OnIncomingNotification( |
91 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), | 91 ModelTypeStateMapToObjectIdStateMap(type_state_map), |
92 REMOTE_NOTIFICATION)); | 92 REMOTE_NOTIFICATION)); |
93 EXPECT_CALL(mock_observer_, | 93 EXPECT_CALL(mock_observer_, |
94 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); | 94 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); |
95 EXPECT_CALL(mock_observer_, | 95 EXPECT_CALL(mock_observer_, |
96 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); | 96 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); |
97 | 97 |
98 invalidation_notifier_->UpdateRegisteredIds( | 98 invalidation_notifier_->UpdateRegisteredIds( |
99 &mock_observer_, ModelTypeSetToObjectIdSet(models)); | 99 &mock_observer_, ModelTypeSetToObjectIdSet(models)); |
100 | 100 |
101 // TODO(tim): This call should be a no-op, Remove once bug 124140 and | 101 // TODO(tim): This call should be a no-op, Remove once bug 124140 and |
102 // associated issues are fixed. | 102 // associated issues are fixed. |
103 invalidation_notifier_->SetStateDeprecated("fake_state"); | 103 invalidation_notifier_->SetStateDeprecated("fake_state"); |
104 // We don't expect |fake_tracker_|'s state to change, as we | 104 // We don't expect |fake_tracker_|'s state to change, as we |
105 // initialized with non-empty initial_invalidation_state above. | 105 // initialized with non-empty initial_invalidation_state above. |
106 EXPECT_TRUE(fake_tracker_.GetInvalidationState().empty()); | 106 EXPECT_TRUE(fake_tracker_.GetInvalidationState().empty()); |
107 invalidation_notifier_->SetUniqueId("fake_id"); | 107 invalidation_notifier_->SetUniqueId("fake_id"); |
108 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); | 108 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); |
109 | 109 |
110 invalidation_notifier_->OnNotificationsEnabled(); | 110 invalidation_notifier_->OnNotificationsEnabled(); |
111 | 111 |
112 invalidation_notifier_->OnInvalidate( | 112 invalidation_notifier_->OnInvalidate( |
113 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads)); | 113 ModelTypeStateMapToObjectIdStateMap(type_state_map)); |
114 | 114 |
115 invalidation_notifier_->OnNotificationsDisabled( | 115 invalidation_notifier_->OnNotificationsDisabled( |
116 TRANSIENT_NOTIFICATION_ERROR); | 116 TRANSIENT_NOTIFICATION_ERROR); |
117 invalidation_notifier_->OnNotificationsDisabled( | 117 invalidation_notifier_->OnNotificationsDisabled( |
118 NOTIFICATION_CREDENTIALS_REJECTED); | 118 NOTIFICATION_CREDENTIALS_REJECTED); |
119 } | 119 } |
120 | 120 |
121 TEST_F(InvalidationNotifierTest, MigrateState) { | 121 TEST_F(InvalidationNotifierTest, MigrateState) { |
122 CreateNotifier(std::string()); | 122 CreateNotifier(std::string()); |
123 | 123 |
124 SetStateDeprecated("fake_state"); | 124 SetStateDeprecated("fake_state"); |
125 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState()); | 125 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState()); |
126 | 126 |
127 // Should do nothing. | 127 // Should do nothing. |
128 SetStateDeprecated("spurious_fake_state"); | 128 SetStateDeprecated("spurious_fake_state"); |
129 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState()); | 129 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState()); |
130 | 130 |
131 // Pretend Chrome shut down. | 131 // Pretend Chrome shut down. |
132 ResetNotifier(); | 132 ResetNotifier(); |
133 | 133 |
134 CreateNotifier("fake_state"); | 134 CreateNotifier("fake_state"); |
135 // Should do nothing. | 135 // Should do nothing. |
136 SetStateDeprecated("more_spurious_fake_state"); | 136 SetStateDeprecated("more_spurious_fake_state"); |
137 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState()); | 137 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState()); |
138 } | 138 } |
139 | 139 |
140 } // namespace | 140 } // namespace |
141 | 141 |
142 } // namespace syncer | 142 } // namespace syncer |
OLD | NEW |