OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "chrome/browser/sync/notifier/chrome_invalidation_client.h" | 8 #include "chrome/browser/sync/notifier/chrome_invalidation_client.h" |
9 #include "chrome/browser/sync/notifier/state_writer.h" | 9 #include "chrome/browser/sync/notifier/state_writer.h" |
10 #include "chrome/browser/sync/syncable/model_type.h" | 10 #include "chrome/browser/sync/syncable/model_type.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 135 |
136 namespace { | 136 namespace { |
137 | 137 |
138 syncable::ModelTypePayloadMap MakeMap(syncable::ModelType model_type, | 138 syncable::ModelTypePayloadMap MakeMap(syncable::ModelType model_type, |
139 const std::string& payload) { | 139 const std::string& payload) { |
140 syncable::ModelTypePayloadMap type_payloads; | 140 syncable::ModelTypePayloadMap type_payloads; |
141 type_payloads[model_type] = payload; | 141 type_payloads[model_type] = payload; |
142 return type_payloads; | 142 return type_payloads; |
143 } | 143 } |
144 | 144 |
145 syncable::ModelTypePayloadMap MakeMapFromSet(syncable::ModelEnumSet types, | 145 syncable::ModelTypePayloadMap MakeMapFromSet(syncable::ModelTypeSet types, |
146 const std::string& payload) { | 146 const std::string& payload) { |
147 return syncable::ModelTypePayloadMapFromEnumSet(types, payload); | 147 return syncable::ModelTypePayloadMapFromEnumSet(types, payload); |
148 } | 148 } |
149 | 149 |
150 } // namespace | 150 } // namespace |
151 | 151 |
152 TEST_F(ChromeInvalidationClientTest, InvalidateBadObjectId) { | 152 TEST_F(ChromeInvalidationClientTest, InvalidateBadObjectId) { |
153 syncable::ModelEnumSet types(syncable::BOOKMARKS, syncable::APPS); | 153 syncable::ModelTypeSet types(syncable::BOOKMARKS, syncable::APPS); |
154 client_.RegisterTypes(types); | 154 client_.RegisterTypes(types); |
155 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); | 155 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); |
156 FireInvalidate("bad", 1, NULL); | 156 FireInvalidate("bad", 1, NULL); |
157 message_loop_.RunAllPending(); | 157 message_loop_.RunAllPending(); |
158 } | 158 } |
159 | 159 |
160 TEST_F(ChromeInvalidationClientTest, InvalidateNoPayload) { | 160 TEST_F(ChromeInvalidationClientTest, InvalidateNoPayload) { |
161 EXPECT_CALL(mock_listener_, | 161 EXPECT_CALL(mock_listener_, |
162 OnInvalidate(MakeMap(syncable::BOOKMARKS, ""))); | 162 OnInvalidate(MakeMap(syncable::BOOKMARKS, ""))); |
163 EXPECT_CALL(mock_invalidation_version_tracker_, | 163 EXPECT_CALL(mock_invalidation_version_tracker_, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 .Times(2); | 196 .Times(2); |
197 | 197 |
198 // Should trigger twice. | 198 // Should trigger twice. |
199 FireInvalidateUnknownVersion("EXTENSION"); | 199 FireInvalidateUnknownVersion("EXTENSION"); |
200 FireInvalidateUnknownVersion("EXTENSION"); | 200 FireInvalidateUnknownVersion("EXTENSION"); |
201 } | 201 } |
202 | 202 |
203 TEST_F(ChromeInvalidationClientTest, InvalidateVersionMultipleTypes) { | 203 TEST_F(ChromeInvalidationClientTest, InvalidateVersionMultipleTypes) { |
204 using ::testing::Mock; | 204 using ::testing::Mock; |
205 | 205 |
206 syncable::ModelEnumSet types(syncable::BOOKMARKS, syncable::APPS); | 206 syncable::ModelTypeSet types(syncable::BOOKMARKS, syncable::APPS); |
207 client_.RegisterTypes(types); | 207 client_.RegisterTypes(types); |
208 | 208 |
209 EXPECT_CALL(mock_listener_, | 209 EXPECT_CALL(mock_listener_, |
210 OnInvalidate(MakeMap(syncable::APPS, ""))); | 210 OnInvalidate(MakeMap(syncable::APPS, ""))); |
211 EXPECT_CALL(mock_listener_, | 211 EXPECT_CALL(mock_listener_, |
212 OnInvalidate(MakeMap(syncable::EXTENSIONS, ""))); | 212 OnInvalidate(MakeMap(syncable::EXTENSIONS, ""))); |
213 | 213 |
214 EXPECT_CALL(mock_invalidation_version_tracker_, | 214 EXPECT_CALL(mock_invalidation_version_tracker_, |
215 SetMaxVersion(syncable::APPS, 3)); | 215 SetMaxVersion(syncable::APPS, 3)); |
216 EXPECT_CALL(mock_invalidation_version_tracker_, | 216 EXPECT_CALL(mock_invalidation_version_tracker_, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 EXPECT_CALL(mock_invalidation_version_tracker_, | 251 EXPECT_CALL(mock_invalidation_version_tracker_, |
252 SetMaxVersion(syncable::APPS, 4)); | 252 SetMaxVersion(syncable::APPS, 4)); |
253 | 253 |
254 // Should trigger all three. | 254 // Should trigger all three. |
255 FireInvalidate("PREFERENCE", 5, NULL); | 255 FireInvalidate("PREFERENCE", 5, NULL); |
256 FireInvalidate("EXTENSION", 3, NULL); | 256 FireInvalidate("EXTENSION", 3, NULL); |
257 FireInvalidate("APP", 4, NULL); | 257 FireInvalidate("APP", 4, NULL); |
258 } | 258 } |
259 | 259 |
260 TEST_F(ChromeInvalidationClientTest, InvalidateAll) { | 260 TEST_F(ChromeInvalidationClientTest, InvalidateAll) { |
261 syncable::ModelEnumSet types(syncable::PREFERENCES, syncable::EXTENSIONS); | 261 syncable::ModelTypeSet types(syncable::PREFERENCES, syncable::EXTENSIONS); |
262 client_.RegisterTypes(types); | 262 client_.RegisterTypes(types); |
263 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); | 263 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); |
264 FireInvalidateAll(); | 264 FireInvalidateAll(); |
265 } | 265 } |
266 | 266 |
267 TEST_F(ChromeInvalidationClientTest, RegisterTypes) { | 267 TEST_F(ChromeInvalidationClientTest, RegisterTypes) { |
268 syncable::ModelEnumSet types(syncable::PREFERENCES, syncable::EXTENSIONS); | 268 syncable::ModelTypeSet types(syncable::PREFERENCES, syncable::EXTENSIONS); |
269 client_.RegisterTypes(types); | 269 client_.RegisterTypes(types); |
270 // Registered types should be preserved across Stop/Start. | 270 // Registered types should be preserved across Stop/Start. |
271 TearDown(); | 271 TearDown(); |
272 SetUp(); | 272 SetUp(); |
273 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); | 273 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); |
274 FireInvalidateAll(); | 274 FireInvalidateAll(); |
275 } | 275 } |
276 | 276 |
277 // TODO(akalin): Flesh out unit tests. | 277 // TODO(akalin): Flesh out unit tests. |
278 | 278 |
279 } // namespace sync_notifier | 279 } // namespace sync_notifier |
OLD | NEW |