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

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

Issue 8771044: Revert 112743 - [Sync] Make syncer commands avoid posting tasks on threads with no work to do (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « chrome/browser/sync/sessions/sync_session.cc ('k') | chrome/browser/sync/syncable/syncable.h » ('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) 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"
11 #include "chrome/browser/sync/engine/conflict_resolver.h" 11 #include "chrome/browser/sync/engine/conflict_resolver.h"
12 #include "chrome/browser/sync/engine/syncer_types.h" 12 #include "chrome/browser/sync/engine/syncer_types.h"
13 #include "chrome/browser/sync/sessions/session_state.h"
14 #include "chrome/browser/sync/sessions/status_controller.h"
15 #include "chrome/browser/sync/syncable/directory_manager.h" 13 #include "chrome/browser/sync/syncable/directory_manager.h"
16 #include "chrome/browser/sync/syncable/model_type.h" 14 #include "chrome/browser/sync/syncable/model_type.h"
17 #include "chrome/browser/sync/syncable/syncable.h" 15 #include "chrome/browser/sync/syncable/syncable.h"
18 #include "chrome/browser/sync/syncable/syncable_id.h"
19 #include "chrome/browser/sync/test/engine/fake_model_worker.h" 16 #include "chrome/browser/sync/test/engine/fake_model_worker.h"
20 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" 17 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h"
21 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
22 19
23 using syncable::WriteTransaction; 20 using syncable::WriteTransaction;
24 21
25 namespace browser_sync { 22 namespace browser_sync {
26 namespace sessions { 23 namespace sessions {
27 namespace { 24 namespace {
28 25
29 class SyncSessionTest : public testing::Test, 26 class SyncSessionTest : public testing::Test,
30 public SyncSession::Delegate, 27 public SyncSession::Delegate,
31 public ModelSafeWorkerRegistrar { 28 public ModelSafeWorkerRegistrar {
32 public: 29 public:
33 SyncSessionTest() : controller_invocations_allowed_(false) {} 30 SyncSessionTest() : controller_invocations_allowed_(false) {
31 GetModelSafeRoutingInfo(&routes_);
32 }
34 33
35 SyncSession* MakeSession() { 34 SyncSession* MakeSession() {
36 std::vector<ModelSafeWorker*> workers; 35 return new SyncSession(context_.get(), this, SyncSourceInfo(), routes_,
37 GetWorkers(&workers); 36 std::vector<ModelSafeWorker*>());
38 return new SyncSession(context_.get(), this, SyncSourceInfo(),
39 routes_, workers);
40 } 37 }
41 38
42 virtual void SetUp() { 39 virtual void SetUp() {
43 context_.reset(new SyncSessionContext(NULL, NULL, this, 40 context_.reset(new SyncSessionContext(NULL, NULL, this,
44 std::vector<SyncEngineEventListener*>(), NULL)); 41 std::vector<SyncEngineEventListener*>(), NULL));
45 routes_.clear(); 42 routes_.clear();
46 routes_[syncable::BOOKMARKS] = GROUP_UI; 43 routes_[syncable::BOOKMARKS] = GROUP_UI;
47 routes_[syncable::AUTOFILL] = GROUP_DB; 44 routes_[syncable::AUTOFILL] = GROUP_UI;
48 scoped_refptr<ModelSafeWorker> passive_worker(
49 new FakeModelWorker(GROUP_PASSIVE));
50 scoped_refptr<ModelSafeWorker> ui_worker(
51 new FakeModelWorker(GROUP_UI));
52 scoped_refptr<ModelSafeWorker> db_worker(
53 new FakeModelWorker(GROUP_DB));
54 workers_.clear();
55 workers_.push_back(passive_worker);
56 workers_.push_back(ui_worker);
57 workers_.push_back(db_worker);
58 session_.reset(MakeSession()); 45 session_.reset(MakeSession());
59 } 46 }
60 virtual void TearDown() { 47 virtual void TearDown() {
61 session_.reset(); 48 session_.reset();
62 context_.reset(); 49 context_.reset();
63 } 50 }
64 51
65 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) OVERRIDE { 52 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) OVERRIDE {
66 FailControllerInvocationIfDisabled("OnSilencedUntil"); 53 FailControllerInvocationIfDisabled("OnSilencedUntil");
67 } 54 }
(...skipping 15 matching lines...) Expand all
83 } 70 }
84 virtual void OnShouldStopSyncingPermanently() OVERRIDE { 71 virtual void OnShouldStopSyncingPermanently() OVERRIDE {
85 FailControllerInvocationIfDisabled("OnShouldStopSyncingPermanently"); 72 FailControllerInvocationIfDisabled("OnShouldStopSyncingPermanently");
86 } 73 }
87 virtual void OnSyncProtocolError( 74 virtual void OnSyncProtocolError(
88 const sessions::SyncSessionSnapshot& snapshot) { 75 const sessions::SyncSessionSnapshot& snapshot) {
89 FailControllerInvocationIfDisabled("SyncProtocolError"); 76 FailControllerInvocationIfDisabled("SyncProtocolError");
90 } 77 }
91 78
92 // ModelSafeWorkerRegistrar implementation. 79 // ModelSafeWorkerRegistrar implementation.
93 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) OVERRIDE { 80 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) OVERRIDE {}
94 out->clear();
95 for (std::vector<scoped_refptr<ModelSafeWorker> >::const_iterator it =
96 workers_.begin(); it != workers_.end(); ++it) {
97 out->push_back(it->get());
98 }
99 }
100 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) OVERRIDE { 81 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) OVERRIDE {
101 *out = routes_; 82 out->swap(routes_);
102 } 83 }
103 84
104 StatusController* status() { return session_->mutable_status_controller(); } 85 StatusController* status() { return session_->mutable_status_controller(); }
105 protected: 86 protected:
106 void FailControllerInvocationIfDisabled(const std::string& msg) { 87 void FailControllerInvocationIfDisabled(const std::string& msg) {
107 if (!controller_invocations_allowed_) 88 if (!controller_invocations_allowed_)
108 FAIL() << msg; 89 FAIL() << msg;
109 } 90 }
110 91
111 syncable::ModelTypeBitSet ParamsMeaningAllEnabledTypes() { 92 syncable::ModelTypeBitSet ParamsMeaningAllEnabledTypes() {
112 syncable::ModelTypeBitSet request_params; 93 syncable::ModelTypeBitSet request_params;
113 request_params[syncable::BOOKMARKS] = true; 94 request_params[syncable::BOOKMARKS] = true;
114 request_params[syncable::AUTOFILL] = true; 95 request_params[syncable::AUTOFILL] = true;
115 return request_params; 96 return request_params;
116 } 97 }
117 98
118 syncable::ModelTypeBitSet ParamsMeaningJustOneEnabledType() { 99 syncable::ModelTypeBitSet ParamsMeaningJustOneEnabledType() {
119 syncable::ModelTypeBitSet request_params; 100 syncable::ModelTypeBitSet request_params;
120 request_params[syncable::AUTOFILL] = true; 101 request_params[syncable::AUTOFILL] = true;
121 return request_params; 102 return request_params;
122 } 103 }
123 104
124 MessageLoop message_loop_; 105 MessageLoop message_loop_;
125 bool controller_invocations_allowed_; 106 bool controller_invocations_allowed_;
126 scoped_ptr<SyncSession> session_; 107 scoped_ptr<SyncSession> session_;
127 scoped_ptr<SyncSessionContext> context_; 108 scoped_ptr<SyncSessionContext> context_;
128 std::vector<scoped_refptr<ModelSafeWorker> > workers_;
129 ModelSafeRoutingInfo routes_; 109 ModelSafeRoutingInfo routes_;
130 }; 110 };
131 111
132 TEST_F(SyncSessionTest, EnabledGroupsEmpty) {
133 routes_.clear();
134 workers_.clear();
135 scoped_ptr<SyncSession> session(MakeSession());
136 std::set<ModelSafeGroup> expected_enabled_groups;
137 expected_enabled_groups.insert(GROUP_PASSIVE);
138 EXPECT_EQ(expected_enabled_groups, session->GetEnabledGroups());
139 }
140
141 TEST_F(SyncSessionTest, EnabledGroups) {
142 scoped_ptr<SyncSession> session(MakeSession());
143 std::set<ModelSafeGroup> expected_enabled_groups;
144 expected_enabled_groups.insert(GROUP_PASSIVE);
145 expected_enabled_groups.insert(GROUP_UI);
146 expected_enabled_groups.insert(GROUP_DB);
147 EXPECT_EQ(expected_enabled_groups, session->GetEnabledGroups());
148 }
149
150 TEST_F(SyncSessionTest, EnabledGroupsWithConflictsEmpty) {
151 scoped_ptr<SyncSession> session(MakeSession());
152 // Auto-create conflict progress. This shouldn't put that group in
153 // conflict.
154 session->mutable_status_controller()->
155 GetUnrestrictedMutableConflictProgressForTest(GROUP_PASSIVE);
156 EXPECT_TRUE(session->GetEnabledGroupsWithConflicts().empty());
157 }
158
159 TEST_F(SyncSessionTest, EnabledGroupsWithConflicts) {
160 scoped_ptr<SyncSession> session(MakeSession());
161 // Put GROUP_UI in conflict.
162 session->mutable_status_controller()->
163 GetUnrestrictedMutableConflictProgressForTest(GROUP_UI)->
164 AddConflictingItemById(syncable::Id());
165 std::set<ModelSafeGroup> expected_enabled_groups_with_conflicts;
166 expected_enabled_groups_with_conflicts.insert(GROUP_UI);
167 EXPECT_EQ(expected_enabled_groups_with_conflicts,
168 session->GetEnabledGroupsWithConflicts());
169 }
170
171 TEST_F(SyncSessionTest, ScopedContextHelpers) { 112 TEST_F(SyncSessionTest, ScopedContextHelpers) {
172 ConflictResolver resolver; 113 ConflictResolver resolver;
173 EXPECT_FALSE(context_->resolver()); 114 EXPECT_FALSE(context_->resolver());
174 { 115 {
175 ScopedSessionContextConflictResolver s_resolver(context_.get(), &resolver); 116 ScopedSessionContextConflictResolver s_resolver(context_.get(), &resolver);
176 EXPECT_EQ(&resolver, context_->resolver()); 117 EXPECT_EQ(&resolver, context_->resolver());
177 } 118 }
178 EXPECT_FALSE(context_->resolver()); 119 EXPECT_FALSE(context_->resolver());
179 } 120 }
180 121
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 syncable::ModelTypePayloadMapFromBitSet( 281 syncable::ModelTypePayloadMapFromBitSet(
341 ParamsMeaningJustOneEnabledType(), 282 ParamsMeaningJustOneEnabledType(),
342 std::string()); 283 std::string());
343 syncable::ModelTypePayloadMap all_types = 284 syncable::ModelTypePayloadMap all_types =
344 syncable::ModelTypePayloadMapFromBitSet( 285 syncable::ModelTypePayloadMapFromBitSet(
345 ParamsMeaningAllEnabledTypes(), 286 ParamsMeaningAllEnabledTypes(),
346 std::string()); 287 std::string());
347 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); 288 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type);
348 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); 289 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types);
349 290
350 scoped_refptr<ModelSafeWorker> passive_worker(
351 new FakeModelWorker(GROUP_PASSIVE));
352 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); 291 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB));
353 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); 292 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI));
354 workers_one.push_back(passive_worker);
355 workers_one.push_back(db_worker); 293 workers_one.push_back(db_worker);
356 workers_two.push_back(passive_worker);
357 workers_two.push_back(db_worker); 294 workers_two.push_back(db_worker);
358 workers_two.push_back(ui_worker); 295 workers_two.push_back(ui_worker);
359 routes_one[syncable::AUTOFILL] = GROUP_DB; 296 routes_one[syncable::AUTOFILL] = GROUP_DB;
360 routes_two[syncable::AUTOFILL] = GROUP_DB; 297 routes_two[syncable::AUTOFILL] = GROUP_DB;
361 routes_two[syncable::BOOKMARKS] = GROUP_UI; 298 routes_two[syncable::BOOKMARKS] = GROUP_UI;
362 SyncSession one(context_.get(), this, source_one, routes_one, workers_one); 299 SyncSession one(context_.get(), this, source_one, routes_one, workers_one);
363 SyncSession two(context_.get(), this, source_two, routes_two, workers_two); 300 SyncSession two(context_.get(), this, source_two, routes_two, workers_two);
364 301
365 std::set<ModelSafeGroup> expected_enabled_groups_one;
366 expected_enabled_groups_one.insert(GROUP_PASSIVE);
367 expected_enabled_groups_one.insert(GROUP_DB);
368
369 std::set<ModelSafeGroup> expected_enabled_groups_two;
370 expected_enabled_groups_two.insert(GROUP_PASSIVE);
371 expected_enabled_groups_two.insert(GROUP_DB);
372 expected_enabled_groups_two.insert(GROUP_UI);
373
374 EXPECT_EQ(expected_enabled_groups_one, one.GetEnabledGroups());
375 EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups());
376
377 one.Coalesce(two); 302 one.Coalesce(two);
378 303
379 EXPECT_EQ(expected_enabled_groups_two, one.GetEnabledGroups());
380 EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups());
381
382 EXPECT_EQ(two.source().updates_source, one.source().updates_source); 304 EXPECT_EQ(two.source().updates_source, one.source().updates_source);
383 EXPECT_EQ(all_types, one.source().types); 305 EXPECT_EQ(all_types, one.source().types);
384 std::vector<ModelSafeWorker*>::const_iterator it_db = 306 std::vector<ModelSafeWorker*>::const_iterator it_db =
385 std::find(one.workers().begin(), one.workers().end(), db_worker); 307 std::find(one.workers().begin(), one.workers().end(), db_worker);
386 std::vector<ModelSafeWorker*>::const_iterator it_ui = 308 std::vector<ModelSafeWorker*>::const_iterator it_ui =
387 std::find(one.workers().begin(), one.workers().end(), ui_worker); 309 std::find(one.workers().begin(), one.workers().end(), ui_worker);
388 EXPECT_NE(it_db, one.workers().end()); 310 EXPECT_NE(it_db, one.workers().end());
389 EXPECT_NE(it_ui, one.workers().end()); 311 EXPECT_NE(it_ui, one.workers().end());
390 EXPECT_EQ(routes_two, one.routing_info()); 312 EXPECT_EQ(routes_two, one.routing_info());
391 } 313 }
392 314
393 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { 315 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) {
394 std::vector<ModelSafeWorker*> workers_one, workers_two; 316 std::vector<ModelSafeWorker*> workers_one, workers_two;
395 ModelSafeRoutingInfo routes_one, routes_two; 317 ModelSafeRoutingInfo routes_one, routes_two;
396 syncable::ModelTypePayloadMap one_type = 318 syncable::ModelTypePayloadMap one_type =
397 syncable::ModelTypePayloadMapFromBitSet( 319 syncable::ModelTypePayloadMapFromBitSet(
398 ParamsMeaningJustOneEnabledType(), 320 ParamsMeaningJustOneEnabledType(),
399 std::string()); 321 std::string());
400 syncable::ModelTypePayloadMap all_types = 322 syncable::ModelTypePayloadMap all_types =
401 syncable::ModelTypePayloadMapFromBitSet( 323 syncable::ModelTypePayloadMapFromBitSet(
402 ParamsMeaningAllEnabledTypes(), 324 ParamsMeaningAllEnabledTypes(),
403 std::string()); 325 std::string());
404 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); 326 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type);
405 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); 327 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types);
406 328
407 scoped_refptr<ModelSafeWorker> passive_worker(
408 new FakeModelWorker(GROUP_PASSIVE));
409 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); 329 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB));
410 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); 330 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI));
411 workers_one.push_back(passive_worker);
412 workers_one.push_back(db_worker); 331 workers_one.push_back(db_worker);
413 workers_two.push_back(passive_worker);
414 workers_two.push_back(db_worker); 332 workers_two.push_back(db_worker);
415 workers_two.push_back(ui_worker); 333 workers_two.push_back(ui_worker);
416 routes_one[syncable::AUTOFILL] = GROUP_DB; 334 routes_one[syncable::AUTOFILL] = GROUP_DB;
417 routes_two[syncable::AUTOFILL] = GROUP_DB; 335 routes_two[syncable::AUTOFILL] = GROUP_UI;
418 routes_two[syncable::BOOKMARKS] = GROUP_UI; 336 routes_two[syncable::BOOKMARKS] = GROUP_UI;
419 SyncSession one(context_.get(), this, source_one, routes_one, workers_one); 337 SyncSession one(context_.get(), this, source_one, routes_one, workers_one);
420 SyncSession two(context_.get(), this, source_two, routes_two, workers_two); 338 SyncSession two(context_.get(), this, source_two, routes_two, workers_two);
421 339
422 std::set<ModelSafeGroup> expected_enabled_groups_one; 340 two.RebaseRoutingInfoWithLatest(&one);
423 expected_enabled_groups_one.insert(GROUP_PASSIVE);
424 expected_enabled_groups_one.insert(GROUP_DB);
425
426 std::set<ModelSafeGroup> expected_enabled_groups_two;
427 expected_enabled_groups_two.insert(GROUP_PASSIVE);
428 expected_enabled_groups_two.insert(GROUP_DB);
429 expected_enabled_groups_two.insert(GROUP_UI);
430
431 EXPECT_EQ(expected_enabled_groups_one, one.GetEnabledGroups());
432 EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups());
433
434 two.RebaseRoutingInfoWithLatest(one);
435
436 EXPECT_EQ(expected_enabled_groups_one, one.GetEnabledGroups());
437 EXPECT_EQ(expected_enabled_groups_one, two.GetEnabledGroups());
438 341
439 // Make sure the source has not been touched. 342 // Make sure the source has not been touched.
440 EXPECT_EQ(two.source().updates_source, 343 EXPECT_EQ(two.source().updates_source,
441 sync_pb::GetUpdatesCallerInfo::LOCAL); 344 sync_pb::GetUpdatesCallerInfo::LOCAL);
442 345
443 // Make sure the payload is reduced to one. 346 // Make sure the payload is reduced to one.
444 EXPECT_EQ(one_type, two.source().types); 347 EXPECT_EQ(one_type, two.source().types);
445 348
446 // Make sure the workers are udpated. 349 // Make sure the workers are udpated.
447 std::vector<ModelSafeWorker*>::const_iterator it_db = 350 std::vector<ModelSafeWorker*>::const_iterator it_db =
448 std::find(two.workers().begin(), two.workers().end(), db_worker); 351 std::find(two.workers().begin(), two.workers().end(), db_worker);
449 std::vector<ModelSafeWorker*>::const_iterator it_ui = 352 std::vector<ModelSafeWorker*>::const_iterator it_ui =
450 std::find(two.workers().begin(), two.workers().end(), ui_worker); 353 std::find(two.workers().begin(), two.workers().end(), ui_worker);
451 EXPECT_NE(it_db, two.workers().end()); 354 EXPECT_NE(it_db, two.workers().end());
452 EXPECT_EQ(it_ui, two.workers().end()); 355 EXPECT_EQ(it_ui, two.workers().end());
453 EXPECT_EQ(two.workers().size(), 2U); 356 EXPECT_EQ(two.workers().size(), 1U);
454 357
455 // Make sure the model safe routing info is reduced to one type. 358 // Make sure the model safe routing info is reduced to one type.
456 ModelSafeRoutingInfo::const_iterator it = 359 ModelSafeRoutingInfo::const_iterator it =
457 two.routing_info().find(syncable::AUTOFILL); 360 two.routing_info().find(syncable::AUTOFILL);
458 EXPECT_NE(it, two.routing_info().end()); 361 EXPECT_NE(it, two.routing_info().end());
459 EXPECT_EQ(it->second, GROUP_DB); 362 EXPECT_EQ(it->second, GROUP_DB);
460 EXPECT_EQ(two.routing_info().size(), 1U); 363 EXPECT_EQ(two.routing_info().size(), 1U);
461 } 364 }
462 365
463 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { 366 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) {
464 std::vector<ModelSafeWorker*> workers_first, workers_second; 367 std::vector<ModelSafeWorker*> workers_first, workers_second;
465 ModelSafeRoutingInfo routes_first, routes_second; 368 ModelSafeRoutingInfo routes_first, routes_second;
466 syncable::ModelTypePayloadMap all_types = 369 syncable::ModelTypePayloadMap all_types =
467 syncable::ModelTypePayloadMapFromBitSet( 370 syncable::ModelTypePayloadMapFromBitSet(
468 ParamsMeaningAllEnabledTypes(), 371 ParamsMeaningAllEnabledTypes(),
469 std::string()); 372 std::string());
470 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC, 373 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC,
471 all_types); 374 all_types);
472 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL, 375 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL,
473 all_types); 376 all_types);
474 377
475 scoped_refptr<ModelSafeWorker> passive_worker(
476 new FakeModelWorker(GROUP_PASSIVE));
477 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB)); 378 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB));
478 scoped_refptr<FakeModelWorker> ui_worker(new FakeModelWorker(GROUP_UI)); 379 scoped_refptr<FakeModelWorker> ui_worker(new FakeModelWorker(GROUP_UI));
479 workers_first.push_back(passive_worker);
480 workers_first.push_back(db_worker); 380 workers_first.push_back(db_worker);
481 workers_first.push_back(ui_worker); 381 workers_first.push_back(ui_worker);
482 workers_second.push_back(passive_worker);
483 workers_second.push_back(db_worker); 382 workers_second.push_back(db_worker);
484 workers_second.push_back(ui_worker); 383 workers_second.push_back(ui_worker);
485 routes_first[syncable::AUTOFILL] = GROUP_DB; 384 routes_first[syncable::AUTOFILL] = GROUP_DB;
486 routes_first[syncable::BOOKMARKS] = GROUP_UI; 385 routes_first[syncable::BOOKMARKS] = GROUP_UI;
487 routes_second[syncable::AUTOFILL] = GROUP_DB; 386 routes_second[syncable::AUTOFILL] = GROUP_DB;
488 routes_second[syncable::BOOKMARKS] = GROUP_UI; 387 routes_second[syncable::BOOKMARKS] = GROUP_UI;
489 SyncSession first(context_.get(), this, source_first, routes_first, 388 SyncSession first(context_.get(), this, source_first, routes_first,
490 workers_first); 389 workers_first);
491 SyncSession second(context_.get(), this, source_second, routes_second, 390 SyncSession second(context_.get(), this, source_second, routes_second,
492 workers_second); 391 workers_second);
493 392
494 std::set<ModelSafeGroup> expected_enabled_groups; 393 second.RebaseRoutingInfoWithLatest(&first);
495 expected_enabled_groups.insert(GROUP_PASSIVE);
496 expected_enabled_groups.insert(GROUP_DB);
497 expected_enabled_groups.insert(GROUP_UI);
498
499 EXPECT_EQ(expected_enabled_groups, first.GetEnabledGroups());
500 EXPECT_EQ(expected_enabled_groups, second.GetEnabledGroups());
501
502 second.RebaseRoutingInfoWithLatest(first);
503
504 EXPECT_EQ(expected_enabled_groups, first.GetEnabledGroups());
505 EXPECT_EQ(expected_enabled_groups, second.GetEnabledGroups());
506 394
507 // Make sure the source has not been touched. 395 // Make sure the source has not been touched.
508 EXPECT_EQ(second.source().updates_source, 396 EXPECT_EQ(second.source().updates_source,
509 sync_pb::GetUpdatesCallerInfo::LOCAL); 397 sync_pb::GetUpdatesCallerInfo::LOCAL);
510 398
511 // Make sure our payload is still the same. 399 // Make sure our payload is still the same.
512 EXPECT_EQ(all_types, second.source().types); 400 EXPECT_EQ(all_types, second.source().types);
513 401
514 // Make sure the workers are still the same. 402 // Make sure the workers are still the same.
515 std::vector<ModelSafeWorker*>::const_iterator it_passive =
516 std::find(second.workers().begin(), second.workers().end(),
517 passive_worker);
518 std::vector<ModelSafeWorker*>::const_iterator it_db = 403 std::vector<ModelSafeWorker*>::const_iterator it_db =
519 std::find(second.workers().begin(), second.workers().end(), db_worker); 404 std::find(second.workers().begin(), second.workers().end(), db_worker);
520 std::vector<ModelSafeWorker*>::const_iterator it_ui = 405 std::vector<ModelSafeWorker*>::const_iterator it_ui =
521 std::find(second.workers().begin(), second.workers().end(), ui_worker); 406 std::find(second.workers().begin(), second.workers().end(), ui_worker);
522 EXPECT_NE(it_passive, second.workers().end());
523 EXPECT_NE(it_db, second.workers().end()); 407 EXPECT_NE(it_db, second.workers().end());
524 EXPECT_NE(it_ui, second.workers().end()); 408 EXPECT_NE(it_ui, second.workers().end());
525 EXPECT_EQ(second.workers().size(), 3U); 409 EXPECT_EQ(second.workers().size(), 2U);
526 410
527 // Make sure the model safe routing info is reduced to first type. 411 // Make sure the model safe routing info is reduced to first type.
528 ModelSafeRoutingInfo::const_iterator it1 = 412 ModelSafeRoutingInfo::const_iterator it1 =
529 second.routing_info().find(syncable::AUTOFILL); 413 second.routing_info().find(syncable::AUTOFILL);
530 ModelSafeRoutingInfo::const_iterator it2 = 414 ModelSafeRoutingInfo::const_iterator it2 =
531 second.routing_info().find(syncable::BOOKMARKS); 415 second.routing_info().find(syncable::BOOKMARKS);
532 416
533 EXPECT_NE(it1, second.routing_info().end()); 417 EXPECT_NE(it1, second.routing_info().end());
534 EXPECT_EQ(it1->second, GROUP_DB); 418 EXPECT_EQ(it1->second, GROUP_DB);
535 419
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 EXPECT_EQ(empty_payload, original[syncable::BOOKMARKS]); 478 EXPECT_EQ(empty_payload, original[syncable::BOOKMARKS]);
595 EXPECT_EQ(payload1, original[syncable::PASSWORDS]); 479 EXPECT_EQ(payload1, original[syncable::PASSWORDS]);
596 EXPECT_EQ(payload1, original[syncable::AUTOFILL]); 480 EXPECT_EQ(payload1, original[syncable::AUTOFILL]);
597 EXPECT_EQ(payload2, original[syncable::SESSIONS]); 481 EXPECT_EQ(payload2, original[syncable::SESSIONS]);
598 EXPECT_EQ(payload3, original[syncable::THEMES]); 482 EXPECT_EQ(payload3, original[syncable::THEMES]);
599 } 483 }
600 484
601 } // namespace 485 } // namespace
602 } // namespace sessions 486 } // namespace sessions
603 } // namespace browser_sync 487 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/sync_session.cc ('k') | chrome/browser/sync/syncable/syncable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698