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

Side by Side Diff: chrome/browser/sync/notifier/chrome_invalidation_client_unittest.cc

Issue 8772074: [Sync] Convert syncable/ directory to ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 9 years 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
OLDNEW
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
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::ModelTypeSet types, 145 syncable::ModelTypePayloadMap MakeMapFromSet(syncable::ModelEnumSet types,
146 const std::string& payload) { 146 const std::string& payload) {
147 syncable::ModelTypePayloadMap type_payloads; 147 return syncable::ModelTypePayloadMapFromEnumSet(types, payload);
148 for (syncable::ModelTypeSet::const_iterator it = types.begin();
149 it != types.end(); ++it) {
150 type_payloads[*it] = payload;
151 }
152 return type_payloads;
153 } 148 }
154 149
155 } // namespace 150 } // namespace
156 151
157 TEST_F(ChromeInvalidationClientTest, InvalidateBadObjectId) { 152 TEST_F(ChromeInvalidationClientTest, InvalidateBadObjectId) {
158 syncable::ModelTypeSet types; 153 syncable::ModelEnumSet types(syncable::BOOKMARKS, syncable::APPS);
159 types.insert(syncable::BOOKMARKS);
160 types.insert(syncable::APPS);
161 client_.RegisterTypes(types); 154 client_.RegisterTypes(types);
162 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); 155 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, "")));
163 FireInvalidate("bad", 1, NULL); 156 FireInvalidate("bad", 1, NULL);
164 message_loop_.RunAllPending(); 157 message_loop_.RunAllPending();
165 } 158 }
166 159
167 TEST_F(ChromeInvalidationClientTest, InvalidateNoPayload) { 160 TEST_F(ChromeInvalidationClientTest, InvalidateNoPayload) {
168 EXPECT_CALL(mock_listener_, 161 EXPECT_CALL(mock_listener_,
169 OnInvalidate(MakeMap(syncable::BOOKMARKS, ""))); 162 OnInvalidate(MakeMap(syncable::BOOKMARKS, "")));
170 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
203 .Times(2); 196 .Times(2);
204 197
205 // Should trigger twice. 198 // Should trigger twice.
206 FireInvalidateUnknownVersion("EXTENSION"); 199 FireInvalidateUnknownVersion("EXTENSION");
207 FireInvalidateUnknownVersion("EXTENSION"); 200 FireInvalidateUnknownVersion("EXTENSION");
208 } 201 }
209 202
210 TEST_F(ChromeInvalidationClientTest, InvalidateVersionMultipleTypes) { 203 TEST_F(ChromeInvalidationClientTest, InvalidateVersionMultipleTypes) {
211 using ::testing::Mock; 204 using ::testing::Mock;
212 205
213 syncable::ModelTypeSet types; 206 syncable::ModelEnumSet types(syncable::BOOKMARKS, syncable::APPS);
214 types.insert(syncable::BOOKMARKS);
215 types.insert(syncable::APPS);
216 client_.RegisterTypes(types); 207 client_.RegisterTypes(types);
217 208
218 EXPECT_CALL(mock_listener_, 209 EXPECT_CALL(mock_listener_,
219 OnInvalidate(MakeMap(syncable::APPS, ""))); 210 OnInvalidate(MakeMap(syncable::APPS, "")));
220 EXPECT_CALL(mock_listener_, 211 EXPECT_CALL(mock_listener_,
221 OnInvalidate(MakeMap(syncable::EXTENSIONS, ""))); 212 OnInvalidate(MakeMap(syncable::EXTENSIONS, "")));
222 213
223 EXPECT_CALL(mock_invalidation_version_tracker_, 214 EXPECT_CALL(mock_invalidation_version_tracker_,
224 SetMaxVersion(syncable::APPS, 3)); 215 SetMaxVersion(syncable::APPS, 3));
225 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
260 EXPECT_CALL(mock_invalidation_version_tracker_, 251 EXPECT_CALL(mock_invalidation_version_tracker_,
261 SetMaxVersion(syncable::APPS, 4)); 252 SetMaxVersion(syncable::APPS, 4));
262 253
263 // Should trigger all three. 254 // Should trigger all three.
264 FireInvalidate("PREFERENCE", 5, NULL); 255 FireInvalidate("PREFERENCE", 5, NULL);
265 FireInvalidate("EXTENSION", 3, NULL); 256 FireInvalidate("EXTENSION", 3, NULL);
266 FireInvalidate("APP", 4, NULL); 257 FireInvalidate("APP", 4, NULL);
267 } 258 }
268 259
269 TEST_F(ChromeInvalidationClientTest, InvalidateAll) { 260 TEST_F(ChromeInvalidationClientTest, InvalidateAll) {
270 syncable::ModelTypeSet types; 261 syncable::ModelEnumSet types(syncable::PREFERENCES, syncable::EXTENSIONS);
271 types.insert(syncable::PREFERENCES);
272 types.insert(syncable::EXTENSIONS);
273 client_.RegisterTypes(types); 262 client_.RegisterTypes(types);
274 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); 263 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, "")));
275 FireInvalidateAll(); 264 FireInvalidateAll();
276 } 265 }
277 266
278 TEST_F(ChromeInvalidationClientTest, RegisterTypes) { 267 TEST_F(ChromeInvalidationClientTest, RegisterTypes) {
279 syncable::ModelTypeSet types; 268 syncable::ModelEnumSet types(syncable::PREFERENCES, syncable::EXTENSIONS);
280 types.insert(syncable::PREFERENCES);
281 types.insert(syncable::EXTENSIONS);
282 client_.RegisterTypes(types); 269 client_.RegisterTypes(types);
283 // Registered types should be preserved across Stop/Start. 270 // Registered types should be preserved across Stop/Start.
284 TearDown(); 271 TearDown();
285 SetUp(); 272 SetUp();
286 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); 273 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, "")));
287 FireInvalidateAll(); 274 FireInvalidateAll();
288 } 275 }
289 276
290 // TODO(akalin): Flesh out unit tests. 277 // TODO(akalin): Flesh out unit tests.
291 278
292 } // namespace sync_notifier 279 } // namespace sync_notifier
OLDNEW
« no previous file with comments | « chrome/browser/sync/notifier/chrome_invalidation_client.cc ('k') | chrome/browser/sync/notifier/invalidation_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698