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

Side by Side Diff: sync/sessions/sync_session_unittest.cc

Issue 10837214: Refactor ModelTypePayloadMap and ObjectIdPayloadMap to StateMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 8 years, 4 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/sessions/sync_session.cc ('k') | sync/sync.gyp » ('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/sessions/sync_session.h" 5 #include "sync/sessions/sync_session.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "sync/engine/conflict_resolver.h" 11 #include "sync/engine/conflict_resolver.h"
12 #include "sync/engine/syncer_types.h" 12 #include "sync/engine/syncer_types.h"
13 #include "sync/engine/throttled_data_type_tracker.h" 13 #include "sync/engine/throttled_data_type_tracker.h"
14 #include "sync/internal_api/public/base/model_type.h" 14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/base/model_type_state_map_test_util.h"
15 #include "sync/sessions/session_state.h" 16 #include "sync/sessions/session_state.h"
16 #include "sync/sessions/status_controller.h" 17 #include "sync/sessions/status_controller.h"
17 #include "sync/syncable/syncable_id.h" 18 #include "sync/syncable/syncable_id.h"
18 #include "sync/syncable/write_transaction.h" 19 #include "sync/syncable/write_transaction.h"
19 #include "sync/test/engine/fake_model_worker.h" 20 #include "sync/test/engine/fake_model_worker.h"
20 #include "sync/test/engine/test_directory_setter_upper.h" 21 #include "sync/test/engine/test_directory_setter_upper.h"
21 #include "sync/test/fake_extensions_activity_monitor.h" 22 #include "sync/test/fake_extensions_activity_monitor.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 namespace syncer { 25 namespace syncer {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 session_->PrepareForAnotherSyncCycle(); 266 session_->PrepareForAnotherSyncCycle();
266 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, 267 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION,
267 session_->source().updates_source); 268 session_->source().updates_source);
268 EXPECT_FALSE(status()->conflicts_resolved()); 269 EXPECT_FALSE(status()->conflicts_resolved());
269 EXPECT_FALSE(session_->HasMoreToSync()); 270 EXPECT_FALSE(session_->HasMoreToSync());
270 } 271 }
271 272
272 TEST_F(SyncSessionTest, Coalesce) { 273 TEST_F(SyncSessionTest, Coalesce) {
273 std::vector<ModelSafeWorker*> workers_one, workers_two; 274 std::vector<ModelSafeWorker*> workers_one, workers_two;
274 ModelSafeRoutingInfo routes_one, routes_two; 275 ModelSafeRoutingInfo routes_one, routes_two;
275 ModelTypePayloadMap one_type = 276 ModelTypeStateMap one_type =
276 ModelTypePayloadMapFromEnumSet( 277 ModelTypeSetToStateMap(
277 ParamsMeaningJustOneEnabledType(), 278 ParamsMeaningJustOneEnabledType(),
278 std::string()); 279 std::string());
279 ModelTypePayloadMap all_types = 280 ModelTypeStateMap all_types =
280 ModelTypePayloadMapFromEnumSet( 281 ModelTypeSetToStateMap(
281 ParamsMeaningAllEnabledTypes(), 282 ParamsMeaningAllEnabledTypes(),
282 std::string()); 283 std::string());
283 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); 284 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type);
284 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); 285 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types);
285 286
286 scoped_refptr<ModelSafeWorker> passive_worker( 287 scoped_refptr<ModelSafeWorker> passive_worker(
287 new FakeModelWorker(GROUP_PASSIVE)); 288 new FakeModelWorker(GROUP_PASSIVE));
288 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); 289 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB));
289 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); 290 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI));
290 workers_one.push_back(passive_worker); 291 workers_one.push_back(passive_worker);
(...skipping 18 matching lines...) Expand all
309 310
310 EXPECT_EQ(expected_enabled_groups_one, one.GetEnabledGroups()); 311 EXPECT_EQ(expected_enabled_groups_one, one.GetEnabledGroups());
311 EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups()); 312 EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups());
312 313
313 one.Coalesce(two); 314 one.Coalesce(two);
314 315
315 EXPECT_EQ(expected_enabled_groups_two, one.GetEnabledGroups()); 316 EXPECT_EQ(expected_enabled_groups_two, one.GetEnabledGroups());
316 EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups()); 317 EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups());
317 318
318 EXPECT_EQ(two.source().updates_source, one.source().updates_source); 319 EXPECT_EQ(two.source().updates_source, one.source().updates_source);
319 EXPECT_EQ(all_types, one.source().types); 320 EXPECT_THAT(all_types, Eq(one.source().types));
320 std::vector<ModelSafeWorker*>::const_iterator it_db = 321 std::vector<ModelSafeWorker*>::const_iterator it_db =
321 std::find(one.workers().begin(), one.workers().end(), db_worker); 322 std::find(one.workers().begin(), one.workers().end(), db_worker);
322 std::vector<ModelSafeWorker*>::const_iterator it_ui = 323 std::vector<ModelSafeWorker*>::const_iterator it_ui =
323 std::find(one.workers().begin(), one.workers().end(), ui_worker); 324 std::find(one.workers().begin(), one.workers().end(), ui_worker);
324 EXPECT_NE(it_db, one.workers().end()); 325 EXPECT_NE(it_db, one.workers().end());
325 EXPECT_NE(it_ui, one.workers().end()); 326 EXPECT_NE(it_ui, one.workers().end());
326 EXPECT_EQ(routes_two, one.routing_info()); 327 EXPECT_EQ(routes_two, one.routing_info());
327 } 328 }
328 329
329 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { 330 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) {
330 std::vector<ModelSafeWorker*> workers_one, workers_two; 331 std::vector<ModelSafeWorker*> workers_one, workers_two;
331 ModelSafeRoutingInfo routes_one, routes_two; 332 ModelSafeRoutingInfo routes_one, routes_two;
332 ModelTypePayloadMap one_type = 333 ModelTypeStateMap one_type =
333 ModelTypePayloadMapFromEnumSet( 334 ModelTypeSetToStateMap(
334 ParamsMeaningJustOneEnabledType(), 335 ParamsMeaningJustOneEnabledType(),
335 std::string()); 336 std::string());
336 ModelTypePayloadMap all_types = 337 ModelTypeStateMap all_types =
337 ModelTypePayloadMapFromEnumSet( 338 ModelTypeSetToStateMap(
338 ParamsMeaningAllEnabledTypes(), 339 ParamsMeaningAllEnabledTypes(),
339 std::string()); 340 std::string());
340 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); 341 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type);
341 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); 342 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types);
342 343
343 scoped_refptr<ModelSafeWorker> passive_worker( 344 scoped_refptr<ModelSafeWorker> passive_worker(
344 new FakeModelWorker(GROUP_PASSIVE)); 345 new FakeModelWorker(GROUP_PASSIVE));
345 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); 346 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB));
346 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); 347 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI));
347 workers_one.push_back(passive_worker); 348 workers_one.push_back(passive_worker);
(...skipping 22 matching lines...) Expand all
370 two.RebaseRoutingInfoWithLatest(one); 371 two.RebaseRoutingInfoWithLatest(one);
371 372
372 EXPECT_EQ(expected_enabled_groups_one, one.GetEnabledGroups()); 373 EXPECT_EQ(expected_enabled_groups_one, one.GetEnabledGroups());
373 EXPECT_EQ(expected_enabled_groups_one, two.GetEnabledGroups()); 374 EXPECT_EQ(expected_enabled_groups_one, two.GetEnabledGroups());
374 375
375 // Make sure the source has not been touched. 376 // Make sure the source has not been touched.
376 EXPECT_EQ(two.source().updates_source, 377 EXPECT_EQ(two.source().updates_source,
377 sync_pb::GetUpdatesCallerInfo::LOCAL); 378 sync_pb::GetUpdatesCallerInfo::LOCAL);
378 379
379 // Make sure the payload is reduced to one. 380 // Make sure the payload is reduced to one.
380 EXPECT_EQ(one_type, two.source().types); 381 EXPECT_THAT(one_type, Eq(two.source().types));
381 382
382 // Make sure the workers are udpated. 383 // Make sure the workers are udpated.
383 std::vector<ModelSafeWorker*>::const_iterator it_db = 384 std::vector<ModelSafeWorker*>::const_iterator it_db =
384 std::find(two.workers().begin(), two.workers().end(), db_worker); 385 std::find(two.workers().begin(), two.workers().end(), db_worker);
385 std::vector<ModelSafeWorker*>::const_iterator it_ui = 386 std::vector<ModelSafeWorker*>::const_iterator it_ui =
386 std::find(two.workers().begin(), two.workers().end(), ui_worker); 387 std::find(two.workers().begin(), two.workers().end(), ui_worker);
387 EXPECT_NE(it_db, two.workers().end()); 388 EXPECT_NE(it_db, two.workers().end());
388 EXPECT_EQ(it_ui, two.workers().end()); 389 EXPECT_EQ(it_ui, two.workers().end());
389 EXPECT_EQ(two.workers().size(), 2U); 390 EXPECT_EQ(two.workers().size(), 2U);
390 391
391 // Make sure the model safe routing info is reduced to one type. 392 // Make sure the model safe routing info is reduced to one type.
392 ModelSafeRoutingInfo::const_iterator it = 393 ModelSafeRoutingInfo::const_iterator it =
393 two.routing_info().find(AUTOFILL); 394 two.routing_info().find(AUTOFILL);
394 // Note that attempting to use EXPECT_NE would fail for an Android build due 395 // Note that attempting to use EXPECT_NE would fail for an Android build due
395 // to seeming incompatibility with gtest and stlport. 396 // to seeming incompatibility with gtest and stlport.
396 EXPECT_TRUE(it != two.routing_info().end()); 397 EXPECT_TRUE(it != two.routing_info().end());
397 EXPECT_EQ(it->second, GROUP_DB); 398 EXPECT_EQ(it->second, GROUP_DB);
398 EXPECT_EQ(two.routing_info().size(), 1U); 399 EXPECT_EQ(two.routing_info().size(), 1U);
399 } 400 }
400 401
401 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { 402 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) {
402 std::vector<ModelSafeWorker*> workers_first, workers_second; 403 std::vector<ModelSafeWorker*> workers_first, workers_second;
403 ModelSafeRoutingInfo routes_first, routes_second; 404 ModelSafeRoutingInfo routes_first, routes_second;
404 ModelTypePayloadMap all_types = 405 ModelTypeStateMap all_types =
405 ModelTypePayloadMapFromEnumSet( 406 ModelTypeSetToStateMap(
406 ParamsMeaningAllEnabledTypes(), 407 ParamsMeaningAllEnabledTypes(),
407 std::string()); 408 std::string());
408 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC, 409 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC,
409 all_types); 410 all_types);
410 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL, 411 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL,
411 all_types); 412 all_types);
412 413
413 scoped_refptr<ModelSafeWorker> passive_worker( 414 scoped_refptr<ModelSafeWorker> passive_worker(
414 new FakeModelWorker(GROUP_PASSIVE)); 415 new FakeModelWorker(GROUP_PASSIVE));
415 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB)); 416 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB));
(...skipping 24 matching lines...) Expand all
440 second.RebaseRoutingInfoWithLatest(first); 441 second.RebaseRoutingInfoWithLatest(first);
441 442
442 EXPECT_EQ(expected_enabled_groups, first.GetEnabledGroups()); 443 EXPECT_EQ(expected_enabled_groups, first.GetEnabledGroups());
443 EXPECT_EQ(expected_enabled_groups, second.GetEnabledGroups()); 444 EXPECT_EQ(expected_enabled_groups, second.GetEnabledGroups());
444 445
445 // Make sure the source has not been touched. 446 // Make sure the source has not been touched.
446 EXPECT_EQ(second.source().updates_source, 447 EXPECT_EQ(second.source().updates_source,
447 sync_pb::GetUpdatesCallerInfo::LOCAL); 448 sync_pb::GetUpdatesCallerInfo::LOCAL);
448 449
449 // Make sure our payload is still the same. 450 // Make sure our payload is still the same.
450 EXPECT_EQ(all_types, second.source().types); 451 EXPECT_THAT(all_types, Eq(second.source().types));
451 452
452 // Make sure the workers are still the same. 453 // Make sure the workers are still the same.
453 std::vector<ModelSafeWorker*>::const_iterator it_passive = 454 std::vector<ModelSafeWorker*>::const_iterator it_passive =
454 std::find(second.workers().begin(), second.workers().end(), 455 std::find(second.workers().begin(), second.workers().end(),
455 passive_worker); 456 passive_worker);
456 std::vector<ModelSafeWorker*>::const_iterator it_db = 457 std::vector<ModelSafeWorker*>::const_iterator it_db =
457 std::find(second.workers().begin(), second.workers().end(), db_worker); 458 std::find(second.workers().begin(), second.workers().end(), db_worker);
458 std::vector<ModelSafeWorker*>::const_iterator it_ui = 459 std::vector<ModelSafeWorker*>::const_iterator it_ui =
459 std::find(second.workers().begin(), second.workers().end(), ui_worker); 460 std::find(second.workers().begin(), second.workers().end(), ui_worker);
460 EXPECT_NE(it_passive, second.workers().end()); 461 EXPECT_NE(it_passive, second.workers().end());
(...skipping 13 matching lines...) Expand all
474 EXPECT_EQ(it1->second, GROUP_DB); 475 EXPECT_EQ(it1->second, GROUP_DB);
475 476
476 // Note that attempting to use EXPECT_NE would fail for an Android build due 477 // Note that attempting to use EXPECT_NE would fail for an Android build due
477 // to seeming incompatibility with gtest and stlport. 478 // to seeming incompatibility with gtest and stlport.
478 EXPECT_TRUE(it2 != second.routing_info().end()); 479 EXPECT_TRUE(it2 != second.routing_info().end());
479 EXPECT_EQ(it2->second, GROUP_UI); 480 EXPECT_EQ(it2->second, GROUP_UI);
480 EXPECT_EQ(second.routing_info().size(), 2U); 481 EXPECT_EQ(second.routing_info().size(), 2U);
481 } 482 }
482 483
483 484
484 TEST_F(SyncSessionTest, MakeTypePayloadMapFromBitSet) { 485 TEST_F(SyncSessionTest, MakeTypeStateMapFromBitSet) {
485 ModelTypeSet types; 486 ModelTypeSet types;
486 std::string payload = "test"; 487 std::string payload = "test";
487 ModelTypePayloadMap types_with_payloads = 488 ModelTypeStateMap type_state_map =
488 ModelTypePayloadMapFromEnumSet(types, payload); 489 ModelTypeSetToStateMap(types, payload);
489 EXPECT_TRUE(types_with_payloads.empty()); 490 EXPECT_TRUE(type_state_map.empty());
490 491
491 types.Put(BOOKMARKS); 492 types.Put(BOOKMARKS);
492 types.Put(PASSWORDS); 493 types.Put(PASSWORDS);
493 types.Put(AUTOFILL); 494 types.Put(AUTOFILL);
494 payload = "test2"; 495 payload = "test2";
495 types_with_payloads = ModelTypePayloadMapFromEnumSet(types, payload); 496 type_state_map = ModelTypeSetToStateMap(types, payload);
496 497
497 ASSERT_EQ(3U, types_with_payloads.size()); 498 ASSERT_EQ(3U, type_state_map.size());
498 EXPECT_EQ(types_with_payloads[BOOKMARKS], payload); 499 EXPECT_EQ(type_state_map[BOOKMARKS].payload, payload);
499 EXPECT_EQ(types_with_payloads[PASSWORDS], payload); 500 EXPECT_EQ(type_state_map[PASSWORDS].payload, payload);
500 EXPECT_EQ(types_with_payloads[AUTOFILL], payload); 501 EXPECT_EQ(type_state_map[AUTOFILL].payload, payload);
501 } 502 }
502 503
503 } // namespace 504 } // namespace
504 } // namespace sessions 505 } // namespace sessions
505 } // namespace syncer 506 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sessions/sync_session.cc ('k') | sync/sync.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698