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

Side by Side Diff: chrome/browser/sync/sessions/sync_session_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 "chrome/browser/sync/sessions/sync_session.h" 5 #include "chrome/browser/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"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 *out = routes_; 101 *out = routes_;
102 } 102 }
103 103
104 StatusController* status() { return session_->mutable_status_controller(); } 104 StatusController* status() { return session_->mutable_status_controller(); }
105 protected: 105 protected:
106 void FailControllerInvocationIfDisabled(const std::string& msg) { 106 void FailControllerInvocationIfDisabled(const std::string& msg) {
107 if (!controller_invocations_allowed_) 107 if (!controller_invocations_allowed_)
108 FAIL() << msg; 108 FAIL() << msg;
109 } 109 }
110 110
111 syncable::ModelTypeBitSet ParamsMeaningAllEnabledTypes() { 111 syncable::ModelEnumSet ParamsMeaningAllEnabledTypes() {
112 syncable::ModelTypeBitSet request_params; 112 syncable::ModelEnumSet request_params(
113 request_params[syncable::BOOKMARKS] = true; 113 syncable::BOOKMARKS, syncable::AUTOFILL);
114 request_params[syncable::AUTOFILL] = true;
115 return request_params; 114 return request_params;
116 } 115 }
117 116
118 syncable::ModelTypeBitSet ParamsMeaningJustOneEnabledType() { 117 syncable::ModelEnumSet ParamsMeaningJustOneEnabledType() {
119 syncable::ModelTypeBitSet request_params; 118 return syncable::ModelEnumSet(syncable::AUTOFILL);
120 request_params[syncable::AUTOFILL] = true;
121 return request_params;
122 } 119 }
123 120
124 MessageLoop message_loop_; 121 MessageLoop message_loop_;
125 bool controller_invocations_allowed_; 122 bool controller_invocations_allowed_;
126 scoped_ptr<SyncSession> session_; 123 scoped_ptr<SyncSession> session_;
127 scoped_ptr<SyncSessionContext> context_; 124 scoped_ptr<SyncSessionContext> context_;
128 std::vector<scoped_refptr<ModelSafeWorker> > workers_; 125 std::vector<scoped_refptr<ModelSafeWorker> > workers_;
129 ModelSafeRoutingInfo routes_; 126 ModelSafeRoutingInfo routes_;
130 }; 127 };
131 128
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 session_->ResetTransientState(); 327 session_->ResetTransientState();
331 EXPECT_FALSE(status()->conflicts_resolved()); 328 EXPECT_FALSE(status()->conflicts_resolved());
332 EXPECT_FALSE(session_->HasMoreToSync()); 329 EXPECT_FALSE(session_->HasMoreToSync());
333 EXPECT_FALSE(status()->TestAndClearIsDirty()); 330 EXPECT_FALSE(status()->TestAndClearIsDirty());
334 } 331 }
335 332
336 TEST_F(SyncSessionTest, Coalesce) { 333 TEST_F(SyncSessionTest, Coalesce) {
337 std::vector<ModelSafeWorker*> workers_one, workers_two; 334 std::vector<ModelSafeWorker*> workers_one, workers_two;
338 ModelSafeRoutingInfo routes_one, routes_two; 335 ModelSafeRoutingInfo routes_one, routes_two;
339 syncable::ModelTypePayloadMap one_type = 336 syncable::ModelTypePayloadMap one_type =
340 syncable::ModelTypePayloadMapFromBitSet( 337 syncable::ModelTypePayloadMapFromEnumSet(
341 ParamsMeaningJustOneEnabledType(), 338 ParamsMeaningJustOneEnabledType(),
342 std::string()); 339 std::string());
343 syncable::ModelTypePayloadMap all_types = 340 syncable::ModelTypePayloadMap all_types =
344 syncable::ModelTypePayloadMapFromBitSet( 341 syncable::ModelTypePayloadMapFromEnumSet(
345 ParamsMeaningAllEnabledTypes(), 342 ParamsMeaningAllEnabledTypes(),
346 std::string()); 343 std::string());
347 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); 344 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type);
348 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); 345 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types);
349 346
350 scoped_refptr<ModelSafeWorker> passive_worker( 347 scoped_refptr<ModelSafeWorker> passive_worker(
351 new FakeModelWorker(GROUP_PASSIVE)); 348 new FakeModelWorker(GROUP_PASSIVE));
352 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); 349 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB));
353 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); 350 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI));
354 workers_one.push_back(passive_worker); 351 workers_one.push_back(passive_worker);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 std::find(one.workers().begin(), one.workers().end(), ui_worker); 384 std::find(one.workers().begin(), one.workers().end(), ui_worker);
388 EXPECT_NE(it_db, one.workers().end()); 385 EXPECT_NE(it_db, one.workers().end());
389 EXPECT_NE(it_ui, one.workers().end()); 386 EXPECT_NE(it_ui, one.workers().end());
390 EXPECT_EQ(routes_two, one.routing_info()); 387 EXPECT_EQ(routes_two, one.routing_info());
391 } 388 }
392 389
393 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { 390 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) {
394 std::vector<ModelSafeWorker*> workers_one, workers_two; 391 std::vector<ModelSafeWorker*> workers_one, workers_two;
395 ModelSafeRoutingInfo routes_one, routes_two; 392 ModelSafeRoutingInfo routes_one, routes_two;
396 syncable::ModelTypePayloadMap one_type = 393 syncable::ModelTypePayloadMap one_type =
397 syncable::ModelTypePayloadMapFromBitSet( 394 syncable::ModelTypePayloadMapFromEnumSet(
398 ParamsMeaningJustOneEnabledType(), 395 ParamsMeaningJustOneEnabledType(),
399 std::string()); 396 std::string());
400 syncable::ModelTypePayloadMap all_types = 397 syncable::ModelTypePayloadMap all_types =
401 syncable::ModelTypePayloadMapFromBitSet( 398 syncable::ModelTypePayloadMapFromEnumSet(
402 ParamsMeaningAllEnabledTypes(), 399 ParamsMeaningAllEnabledTypes(),
403 std::string()); 400 std::string());
404 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); 401 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type);
405 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); 402 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types);
406 403
407 scoped_refptr<ModelSafeWorker> passive_worker( 404 scoped_refptr<ModelSafeWorker> passive_worker(
408 new FakeModelWorker(GROUP_PASSIVE)); 405 new FakeModelWorker(GROUP_PASSIVE));
409 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); 406 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB));
410 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); 407 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI));
411 workers_one.push_back(passive_worker); 408 workers_one.push_back(passive_worker);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 two.routing_info().find(syncable::AUTOFILL); 454 two.routing_info().find(syncable::AUTOFILL);
458 EXPECT_NE(it, two.routing_info().end()); 455 EXPECT_NE(it, two.routing_info().end());
459 EXPECT_EQ(it->second, GROUP_DB); 456 EXPECT_EQ(it->second, GROUP_DB);
460 EXPECT_EQ(two.routing_info().size(), 1U); 457 EXPECT_EQ(two.routing_info().size(), 1U);
461 } 458 }
462 459
463 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { 460 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) {
464 std::vector<ModelSafeWorker*> workers_first, workers_second; 461 std::vector<ModelSafeWorker*> workers_first, workers_second;
465 ModelSafeRoutingInfo routes_first, routes_second; 462 ModelSafeRoutingInfo routes_first, routes_second;
466 syncable::ModelTypePayloadMap all_types = 463 syncable::ModelTypePayloadMap all_types =
467 syncable::ModelTypePayloadMapFromBitSet( 464 syncable::ModelTypePayloadMapFromEnumSet(
468 ParamsMeaningAllEnabledTypes(), 465 ParamsMeaningAllEnabledTypes(),
469 std::string()); 466 std::string());
470 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC, 467 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC,
471 all_types); 468 all_types);
472 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL, 469 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL,
473 all_types); 470 all_types);
474 471
475 scoped_refptr<ModelSafeWorker> passive_worker( 472 scoped_refptr<ModelSafeWorker> passive_worker(
476 new FakeModelWorker(GROUP_PASSIVE)); 473 new FakeModelWorker(GROUP_PASSIVE));
477 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB)); 474 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 EXPECT_NE(it1, second.routing_info().end()); 530 EXPECT_NE(it1, second.routing_info().end());
534 EXPECT_EQ(it1->second, GROUP_DB); 531 EXPECT_EQ(it1->second, GROUP_DB);
535 532
536 EXPECT_NE(it2, second.routing_info().end()); 533 EXPECT_NE(it2, second.routing_info().end());
537 EXPECT_EQ(it2->second, GROUP_UI); 534 EXPECT_EQ(it2->second, GROUP_UI);
538 EXPECT_EQ(second.routing_info().size(), 2U); 535 EXPECT_EQ(second.routing_info().size(), 2U);
539 } 536 }
540 537
541 538
542 TEST_F(SyncSessionTest, MakeTypePayloadMapFromBitSet) { 539 TEST_F(SyncSessionTest, MakeTypePayloadMapFromBitSet) {
543 syncable::ModelTypeBitSet types; 540 syncable::ModelEnumSet types;
544 std::string payload = "test"; 541 std::string payload = "test";
545 syncable::ModelTypePayloadMap types_with_payloads = 542 syncable::ModelTypePayloadMap types_with_payloads =
546 syncable::ModelTypePayloadMapFromBitSet(types, 543 syncable::ModelTypePayloadMapFromEnumSet(types, payload);
547 payload);
548 EXPECT_TRUE(types_with_payloads.empty()); 544 EXPECT_TRUE(types_with_payloads.empty());
549 545
550 types[syncable::BOOKMARKS] = true; 546 types.Put(syncable::BOOKMARKS);
551 types[syncable::PASSWORDS] = true; 547 types.Put(syncable::PASSWORDS);
552 types[syncable::AUTOFILL] = true; 548 types.Put(syncable::AUTOFILL);
553 payload = "test2"; 549 payload = "test2";
554 types_with_payloads = syncable::ModelTypePayloadMapFromBitSet(types, payload); 550 types_with_payloads =
551 syncable::ModelTypePayloadMapFromEnumSet(types, payload);
555 552
556 ASSERT_EQ(3U, types_with_payloads.size()); 553 ASSERT_EQ(3U, types_with_payloads.size());
557 EXPECT_EQ(types_with_payloads[syncable::BOOKMARKS], payload); 554 EXPECT_EQ(types_with_payloads[syncable::BOOKMARKS], payload);
558 EXPECT_EQ(types_with_payloads[syncable::PASSWORDS], payload); 555 EXPECT_EQ(types_with_payloads[syncable::PASSWORDS], payload);
559 EXPECT_EQ(types_with_payloads[syncable::AUTOFILL], payload); 556 EXPECT_EQ(types_with_payloads[syncable::AUTOFILL], payload);
560 } 557 }
561 558
562 TEST_F(SyncSessionTest, MakeTypePayloadMapFromRoutingInfo) { 559 TEST_F(SyncSessionTest, MakeTypePayloadMapFromRoutingInfo) {
563 std::string payload = "test"; 560 std::string payload = "test";
564 syncable::ModelTypePayloadMap types_with_payloads 561 syncable::ModelTypePayloadMap types_with_payloads
(...skipping 29 matching lines...) Expand all
594 EXPECT_EQ(empty_payload, original[syncable::BOOKMARKS]); 591 EXPECT_EQ(empty_payload, original[syncable::BOOKMARKS]);
595 EXPECT_EQ(payload1, original[syncable::PASSWORDS]); 592 EXPECT_EQ(payload1, original[syncable::PASSWORDS]);
596 EXPECT_EQ(payload1, original[syncable::AUTOFILL]); 593 EXPECT_EQ(payload1, original[syncable::AUTOFILL]);
597 EXPECT_EQ(payload2, original[syncable::SESSIONS]); 594 EXPECT_EQ(payload2, original[syncable::SESSIONS]);
598 EXPECT_EQ(payload3, original[syncable::THEMES]); 595 EXPECT_EQ(payload3, original[syncable::THEMES]);
599 } 596 }
600 597
601 } // namespace 598 } // namespace
602 } // namespace sessions 599 } // namespace sessions
603 } // namespace browser_sync 600 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/status_controller.h ('k') | chrome/browser/sync/syncable/directory_backing_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698