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 "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" |
13 #include "chrome/browser/sync/syncable/directory_manager.h" | 15 #include "chrome/browser/sync/syncable/directory_manager.h" |
14 #include "chrome/browser/sync/syncable/model_type.h" | 16 #include "chrome/browser/sync/syncable/model_type.h" |
15 #include "chrome/browser/sync/syncable/syncable.h" | 17 #include "chrome/browser/sync/syncable/syncable.h" |
| 18 #include "chrome/browser/sync/syncable/syncable_id.h" |
16 #include "chrome/browser/sync/test/engine/fake_model_worker.h" | 19 #include "chrome/browser/sync/test/engine/fake_model_worker.h" |
17 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" | 20 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
19 | 22 |
20 using syncable::WriteTransaction; | 23 using syncable::WriteTransaction; |
21 | 24 |
22 namespace browser_sync { | 25 namespace browser_sync { |
23 namespace sessions { | 26 namespace sessions { |
24 namespace { | 27 namespace { |
25 | 28 |
26 class SyncSessionTest : public testing::Test, | 29 class SyncSessionTest : public testing::Test, |
27 public SyncSession::Delegate, | 30 public SyncSession::Delegate, |
28 public ModelSafeWorkerRegistrar { | 31 public ModelSafeWorkerRegistrar { |
29 public: | 32 public: |
30 SyncSessionTest() : controller_invocations_allowed_(false) { | 33 SyncSessionTest() : controller_invocations_allowed_(false) {} |
31 GetModelSafeRoutingInfo(&routes_); | |
32 } | |
33 | 34 |
34 SyncSession* MakeSession() { | 35 SyncSession* MakeSession() { |
35 return new SyncSession(context_.get(), this, SyncSourceInfo(), routes_, | 36 std::vector<ModelSafeWorker*> workers; |
36 std::vector<ModelSafeWorker*>()); | 37 GetWorkers(&workers); |
| 38 return new SyncSession(context_.get(), this, SyncSourceInfo(), |
| 39 routes_, workers); |
37 } | 40 } |
38 | 41 |
39 virtual void SetUp() { | 42 virtual void SetUp() { |
40 context_.reset(new SyncSessionContext(NULL, NULL, this, | 43 context_.reset(new SyncSessionContext(NULL, NULL, this, |
41 std::vector<SyncEngineEventListener*>(), NULL)); | 44 std::vector<SyncEngineEventListener*>(), NULL)); |
42 routes_.clear(); | 45 routes_.clear(); |
43 routes_[syncable::BOOKMARKS] = GROUP_UI; | 46 routes_[syncable::BOOKMARKS] = GROUP_UI; |
44 routes_[syncable::AUTOFILL] = GROUP_UI; | 47 routes_[syncable::AUTOFILL] = GROUP_DB; |
| 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); |
45 session_.reset(MakeSession()); | 58 session_.reset(MakeSession()); |
46 } | 59 } |
47 virtual void TearDown() { | 60 virtual void TearDown() { |
48 session_.reset(); | 61 session_.reset(); |
49 context_.reset(); | 62 context_.reset(); |
50 } | 63 } |
51 | 64 |
52 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) OVERRIDE { | 65 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) OVERRIDE { |
53 FailControllerInvocationIfDisabled("OnSilencedUntil"); | 66 FailControllerInvocationIfDisabled("OnSilencedUntil"); |
54 } | 67 } |
(...skipping 15 matching lines...) Expand all Loading... |
70 } | 83 } |
71 virtual void OnShouldStopSyncingPermanently() OVERRIDE { | 84 virtual void OnShouldStopSyncingPermanently() OVERRIDE { |
72 FailControllerInvocationIfDisabled("OnShouldStopSyncingPermanently"); | 85 FailControllerInvocationIfDisabled("OnShouldStopSyncingPermanently"); |
73 } | 86 } |
74 virtual void OnSyncProtocolError( | 87 virtual void OnSyncProtocolError( |
75 const sessions::SyncSessionSnapshot& snapshot) { | 88 const sessions::SyncSessionSnapshot& snapshot) { |
76 FailControllerInvocationIfDisabled("SyncProtocolError"); | 89 FailControllerInvocationIfDisabled("SyncProtocolError"); |
77 } | 90 } |
78 | 91 |
79 // ModelSafeWorkerRegistrar implementation. | 92 // ModelSafeWorkerRegistrar implementation. |
80 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) OVERRIDE {} | 93 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 } |
81 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) OVERRIDE { | 100 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) OVERRIDE { |
82 out->swap(routes_); | 101 *out = routes_; |
83 } | 102 } |
84 | 103 |
85 StatusController* status() { return session_->mutable_status_controller(); } | 104 StatusController* status() { return session_->mutable_status_controller(); } |
86 protected: | 105 protected: |
87 void FailControllerInvocationIfDisabled(const std::string& msg) { | 106 void FailControllerInvocationIfDisabled(const std::string& msg) { |
88 if (!controller_invocations_allowed_) | 107 if (!controller_invocations_allowed_) |
89 FAIL() << msg; | 108 FAIL() << msg; |
90 } | 109 } |
91 | 110 |
92 syncable::ModelTypeBitSet ParamsMeaningAllEnabledTypes() { | 111 syncable::ModelTypeBitSet ParamsMeaningAllEnabledTypes() { |
93 syncable::ModelTypeBitSet request_params; | 112 syncable::ModelTypeBitSet request_params; |
94 request_params[syncable::BOOKMARKS] = true; | 113 request_params[syncable::BOOKMARKS] = true; |
95 request_params[syncable::AUTOFILL] = true; | 114 request_params[syncable::AUTOFILL] = true; |
96 return request_params; | 115 return request_params; |
97 } | 116 } |
98 | 117 |
99 syncable::ModelTypeBitSet ParamsMeaningJustOneEnabledType() { | 118 syncable::ModelTypeBitSet ParamsMeaningJustOneEnabledType() { |
100 syncable::ModelTypeBitSet request_params; | 119 syncable::ModelTypeBitSet request_params; |
101 request_params[syncable::AUTOFILL] = true; | 120 request_params[syncable::AUTOFILL] = true; |
102 return request_params; | 121 return request_params; |
103 } | 122 } |
104 | 123 |
105 MessageLoop message_loop_; | 124 MessageLoop message_loop_; |
106 bool controller_invocations_allowed_; | 125 bool controller_invocations_allowed_; |
107 scoped_ptr<SyncSession> session_; | 126 scoped_ptr<SyncSession> session_; |
108 scoped_ptr<SyncSessionContext> context_; | 127 scoped_ptr<SyncSessionContext> context_; |
| 128 std::vector<scoped_refptr<ModelSafeWorker> > workers_; |
109 ModelSafeRoutingInfo routes_; | 129 ModelSafeRoutingInfo routes_; |
110 }; | 130 }; |
111 | 131 |
| 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 |
112 TEST_F(SyncSessionTest, ScopedContextHelpers) { | 171 TEST_F(SyncSessionTest, ScopedContextHelpers) { |
113 ConflictResolver resolver; | 172 ConflictResolver resolver; |
114 EXPECT_FALSE(context_->resolver()); | 173 EXPECT_FALSE(context_->resolver()); |
115 { | 174 { |
116 ScopedSessionContextConflictResolver s_resolver(context_.get(), &resolver); | 175 ScopedSessionContextConflictResolver s_resolver(context_.get(), &resolver); |
117 EXPECT_EQ(&resolver, context_->resolver()); | 176 EXPECT_EQ(&resolver, context_->resolver()); |
118 } | 177 } |
119 EXPECT_FALSE(context_->resolver()); | 178 EXPECT_FALSE(context_->resolver()); |
120 } | 179 } |
121 | 180 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 syncable::ModelTypePayloadMapFromBitSet( | 340 syncable::ModelTypePayloadMapFromBitSet( |
282 ParamsMeaningJustOneEnabledType(), | 341 ParamsMeaningJustOneEnabledType(), |
283 std::string()); | 342 std::string()); |
284 syncable::ModelTypePayloadMap all_types = | 343 syncable::ModelTypePayloadMap all_types = |
285 syncable::ModelTypePayloadMapFromBitSet( | 344 syncable::ModelTypePayloadMapFromBitSet( |
286 ParamsMeaningAllEnabledTypes(), | 345 ParamsMeaningAllEnabledTypes(), |
287 std::string()); | 346 std::string()); |
288 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); | 347 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); |
289 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); | 348 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); |
290 | 349 |
| 350 scoped_refptr<ModelSafeWorker> passive_worker( |
| 351 new FakeModelWorker(GROUP_PASSIVE)); |
291 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); | 352 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); |
292 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); | 353 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); |
| 354 workers_one.push_back(passive_worker); |
293 workers_one.push_back(db_worker); | 355 workers_one.push_back(db_worker); |
| 356 workers_two.push_back(passive_worker); |
294 workers_two.push_back(db_worker); | 357 workers_two.push_back(db_worker); |
295 workers_two.push_back(ui_worker); | 358 workers_two.push_back(ui_worker); |
296 routes_one[syncable::AUTOFILL] = GROUP_DB; | 359 routes_one[syncable::AUTOFILL] = GROUP_DB; |
297 routes_two[syncable::AUTOFILL] = GROUP_DB; | 360 routes_two[syncable::AUTOFILL] = GROUP_DB; |
298 routes_two[syncable::BOOKMARKS] = GROUP_UI; | 361 routes_two[syncable::BOOKMARKS] = GROUP_UI; |
299 SyncSession one(context_.get(), this, source_one, routes_one, workers_one); | 362 SyncSession one(context_.get(), this, source_one, routes_one, workers_one); |
300 SyncSession two(context_.get(), this, source_two, routes_two, workers_two); | 363 SyncSession two(context_.get(), this, source_two, routes_two, workers_two); |
301 | 364 |
| 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 |
302 one.Coalesce(two); | 377 one.Coalesce(two); |
303 | 378 |
| 379 EXPECT_EQ(expected_enabled_groups_two, one.GetEnabledGroups()); |
| 380 EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups()); |
| 381 |
304 EXPECT_EQ(two.source().updates_source, one.source().updates_source); | 382 EXPECT_EQ(two.source().updates_source, one.source().updates_source); |
305 EXPECT_EQ(all_types, one.source().types); | 383 EXPECT_EQ(all_types, one.source().types); |
306 std::vector<ModelSafeWorker*>::const_iterator it_db = | 384 std::vector<ModelSafeWorker*>::const_iterator it_db = |
307 std::find(one.workers().begin(), one.workers().end(), db_worker); | 385 std::find(one.workers().begin(), one.workers().end(), db_worker); |
308 std::vector<ModelSafeWorker*>::const_iterator it_ui = | 386 std::vector<ModelSafeWorker*>::const_iterator it_ui = |
309 std::find(one.workers().begin(), one.workers().end(), ui_worker); | 387 std::find(one.workers().begin(), one.workers().end(), ui_worker); |
310 EXPECT_NE(it_db, one.workers().end()); | 388 EXPECT_NE(it_db, one.workers().end()); |
311 EXPECT_NE(it_ui, one.workers().end()); | 389 EXPECT_NE(it_ui, one.workers().end()); |
312 EXPECT_EQ(routes_two, one.routing_info()); | 390 EXPECT_EQ(routes_two, one.routing_info()); |
313 } | 391 } |
314 | 392 |
315 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { | 393 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { |
316 std::vector<ModelSafeWorker*> workers_one, workers_two; | 394 std::vector<ModelSafeWorker*> workers_one, workers_two; |
317 ModelSafeRoutingInfo routes_one, routes_two; | 395 ModelSafeRoutingInfo routes_one, routes_two; |
318 syncable::ModelTypePayloadMap one_type = | 396 syncable::ModelTypePayloadMap one_type = |
319 syncable::ModelTypePayloadMapFromBitSet( | 397 syncable::ModelTypePayloadMapFromBitSet( |
320 ParamsMeaningJustOneEnabledType(), | 398 ParamsMeaningJustOneEnabledType(), |
321 std::string()); | 399 std::string()); |
322 syncable::ModelTypePayloadMap all_types = | 400 syncable::ModelTypePayloadMap all_types = |
323 syncable::ModelTypePayloadMapFromBitSet( | 401 syncable::ModelTypePayloadMapFromBitSet( |
324 ParamsMeaningAllEnabledTypes(), | 402 ParamsMeaningAllEnabledTypes(), |
325 std::string()); | 403 std::string()); |
326 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); | 404 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); |
327 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); | 405 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); |
328 | 406 |
| 407 scoped_refptr<ModelSafeWorker> passive_worker( |
| 408 new FakeModelWorker(GROUP_PASSIVE)); |
329 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); | 409 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); |
330 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); | 410 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); |
| 411 workers_one.push_back(passive_worker); |
331 workers_one.push_back(db_worker); | 412 workers_one.push_back(db_worker); |
| 413 workers_two.push_back(passive_worker); |
332 workers_two.push_back(db_worker); | 414 workers_two.push_back(db_worker); |
333 workers_two.push_back(ui_worker); | 415 workers_two.push_back(ui_worker); |
334 routes_one[syncable::AUTOFILL] = GROUP_DB; | 416 routes_one[syncable::AUTOFILL] = GROUP_DB; |
335 routes_two[syncable::AUTOFILL] = GROUP_UI; | 417 routes_two[syncable::AUTOFILL] = GROUP_DB; |
336 routes_two[syncable::BOOKMARKS] = GROUP_UI; | 418 routes_two[syncable::BOOKMARKS] = GROUP_UI; |
337 SyncSession one(context_.get(), this, source_one, routes_one, workers_one); | 419 SyncSession one(context_.get(), this, source_one, routes_one, workers_one); |
338 SyncSession two(context_.get(), this, source_two, routes_two, workers_two); | 420 SyncSession two(context_.get(), this, source_two, routes_two, workers_two); |
339 | 421 |
340 two.RebaseRoutingInfoWithLatest(&one); | 422 std::set<ModelSafeGroup> expected_enabled_groups_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()); |
341 | 438 |
342 // Make sure the source has not been touched. | 439 // Make sure the source has not been touched. |
343 EXPECT_EQ(two.source().updates_source, | 440 EXPECT_EQ(two.source().updates_source, |
344 sync_pb::GetUpdatesCallerInfo::LOCAL); | 441 sync_pb::GetUpdatesCallerInfo::LOCAL); |
345 | 442 |
346 // Make sure the payload is reduced to one. | 443 // Make sure the payload is reduced to one. |
347 EXPECT_EQ(one_type, two.source().types); | 444 EXPECT_EQ(one_type, two.source().types); |
348 | 445 |
349 // Make sure the workers are udpated. | 446 // Make sure the workers are udpated. |
350 std::vector<ModelSafeWorker*>::const_iterator it_db = | 447 std::vector<ModelSafeWorker*>::const_iterator it_db = |
351 std::find(two.workers().begin(), two.workers().end(), db_worker); | 448 std::find(two.workers().begin(), two.workers().end(), db_worker); |
352 std::vector<ModelSafeWorker*>::const_iterator it_ui = | 449 std::vector<ModelSafeWorker*>::const_iterator it_ui = |
353 std::find(two.workers().begin(), two.workers().end(), ui_worker); | 450 std::find(two.workers().begin(), two.workers().end(), ui_worker); |
354 EXPECT_NE(it_db, two.workers().end()); | 451 EXPECT_NE(it_db, two.workers().end()); |
355 EXPECT_EQ(it_ui, two.workers().end()); | 452 EXPECT_EQ(it_ui, two.workers().end()); |
356 EXPECT_EQ(two.workers().size(), 1U); | 453 EXPECT_EQ(two.workers().size(), 2U); |
357 | 454 |
358 // Make sure the model safe routing info is reduced to one type. | 455 // Make sure the model safe routing info is reduced to one type. |
359 ModelSafeRoutingInfo::const_iterator it = | 456 ModelSafeRoutingInfo::const_iterator it = |
360 two.routing_info().find(syncable::AUTOFILL); | 457 two.routing_info().find(syncable::AUTOFILL); |
361 EXPECT_NE(it, two.routing_info().end()); | 458 EXPECT_NE(it, two.routing_info().end()); |
362 EXPECT_EQ(it->second, GROUP_DB); | 459 EXPECT_EQ(it->second, GROUP_DB); |
363 EXPECT_EQ(two.routing_info().size(), 1U); | 460 EXPECT_EQ(two.routing_info().size(), 1U); |
364 } | 461 } |
365 | 462 |
366 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { | 463 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { |
367 std::vector<ModelSafeWorker*> workers_first, workers_second; | 464 std::vector<ModelSafeWorker*> workers_first, workers_second; |
368 ModelSafeRoutingInfo routes_first, routes_second; | 465 ModelSafeRoutingInfo routes_first, routes_second; |
369 syncable::ModelTypePayloadMap all_types = | 466 syncable::ModelTypePayloadMap all_types = |
370 syncable::ModelTypePayloadMapFromBitSet( | 467 syncable::ModelTypePayloadMapFromBitSet( |
371 ParamsMeaningAllEnabledTypes(), | 468 ParamsMeaningAllEnabledTypes(), |
372 std::string()); | 469 std::string()); |
373 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC, | 470 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC, |
374 all_types); | 471 all_types); |
375 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL, | 472 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL, |
376 all_types); | 473 all_types); |
377 | 474 |
| 475 scoped_refptr<ModelSafeWorker> passive_worker( |
| 476 new FakeModelWorker(GROUP_PASSIVE)); |
378 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB)); | 477 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB)); |
379 scoped_refptr<FakeModelWorker> ui_worker(new FakeModelWorker(GROUP_UI)); | 478 scoped_refptr<FakeModelWorker> ui_worker(new FakeModelWorker(GROUP_UI)); |
| 479 workers_first.push_back(passive_worker); |
380 workers_first.push_back(db_worker); | 480 workers_first.push_back(db_worker); |
381 workers_first.push_back(ui_worker); | 481 workers_first.push_back(ui_worker); |
| 482 workers_second.push_back(passive_worker); |
382 workers_second.push_back(db_worker); | 483 workers_second.push_back(db_worker); |
383 workers_second.push_back(ui_worker); | 484 workers_second.push_back(ui_worker); |
384 routes_first[syncable::AUTOFILL] = GROUP_DB; | 485 routes_first[syncable::AUTOFILL] = GROUP_DB; |
385 routes_first[syncable::BOOKMARKS] = GROUP_UI; | 486 routes_first[syncable::BOOKMARKS] = GROUP_UI; |
386 routes_second[syncable::AUTOFILL] = GROUP_DB; | 487 routes_second[syncable::AUTOFILL] = GROUP_DB; |
387 routes_second[syncable::BOOKMARKS] = GROUP_UI; | 488 routes_second[syncable::BOOKMARKS] = GROUP_UI; |
388 SyncSession first(context_.get(), this, source_first, routes_first, | 489 SyncSession first(context_.get(), this, source_first, routes_first, |
389 workers_first); | 490 workers_first); |
390 SyncSession second(context_.get(), this, source_second, routes_second, | 491 SyncSession second(context_.get(), this, source_second, routes_second, |
391 workers_second); | 492 workers_second); |
392 | 493 |
393 second.RebaseRoutingInfoWithLatest(&first); | 494 std::set<ModelSafeGroup> expected_enabled_groups; |
| 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()); |
394 | 506 |
395 // Make sure the source has not been touched. | 507 // Make sure the source has not been touched. |
396 EXPECT_EQ(second.source().updates_source, | 508 EXPECT_EQ(second.source().updates_source, |
397 sync_pb::GetUpdatesCallerInfo::LOCAL); | 509 sync_pb::GetUpdatesCallerInfo::LOCAL); |
398 | 510 |
399 // Make sure our payload is still the same. | 511 // Make sure our payload is still the same. |
400 EXPECT_EQ(all_types, second.source().types); | 512 EXPECT_EQ(all_types, second.source().types); |
401 | 513 |
402 // Make sure the workers are still the same. | 514 // 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); |
403 std::vector<ModelSafeWorker*>::const_iterator it_db = | 518 std::vector<ModelSafeWorker*>::const_iterator it_db = |
404 std::find(second.workers().begin(), second.workers().end(), db_worker); | 519 std::find(second.workers().begin(), second.workers().end(), db_worker); |
405 std::vector<ModelSafeWorker*>::const_iterator it_ui = | 520 std::vector<ModelSafeWorker*>::const_iterator it_ui = |
406 std::find(second.workers().begin(), second.workers().end(), ui_worker); | 521 std::find(second.workers().begin(), second.workers().end(), ui_worker); |
| 522 EXPECT_NE(it_passive, second.workers().end()); |
407 EXPECT_NE(it_db, second.workers().end()); | 523 EXPECT_NE(it_db, second.workers().end()); |
408 EXPECT_NE(it_ui, second.workers().end()); | 524 EXPECT_NE(it_ui, second.workers().end()); |
409 EXPECT_EQ(second.workers().size(), 2U); | 525 EXPECT_EQ(second.workers().size(), 3U); |
410 | 526 |
411 // Make sure the model safe routing info is reduced to first type. | 527 // Make sure the model safe routing info is reduced to first type. |
412 ModelSafeRoutingInfo::const_iterator it1 = | 528 ModelSafeRoutingInfo::const_iterator it1 = |
413 second.routing_info().find(syncable::AUTOFILL); | 529 second.routing_info().find(syncable::AUTOFILL); |
414 ModelSafeRoutingInfo::const_iterator it2 = | 530 ModelSafeRoutingInfo::const_iterator it2 = |
415 second.routing_info().find(syncable::BOOKMARKS); | 531 second.routing_info().find(syncable::BOOKMARKS); |
416 | 532 |
417 EXPECT_NE(it1, second.routing_info().end()); | 533 EXPECT_NE(it1, second.routing_info().end()); |
418 EXPECT_EQ(it1->second, GROUP_DB); | 534 EXPECT_EQ(it1->second, GROUP_DB); |
419 | 535 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 EXPECT_EQ(empty_payload, original[syncable::BOOKMARKS]); | 594 EXPECT_EQ(empty_payload, original[syncable::BOOKMARKS]); |
479 EXPECT_EQ(payload1, original[syncable::PASSWORDS]); | 595 EXPECT_EQ(payload1, original[syncable::PASSWORDS]); |
480 EXPECT_EQ(payload1, original[syncable::AUTOFILL]); | 596 EXPECT_EQ(payload1, original[syncable::AUTOFILL]); |
481 EXPECT_EQ(payload2, original[syncable::SESSIONS]); | 597 EXPECT_EQ(payload2, original[syncable::SESSIONS]); |
482 EXPECT_EQ(payload3, original[syncable::THEMES]); | 598 EXPECT_EQ(payload3, original[syncable::THEMES]); |
483 } | 599 } |
484 | 600 |
485 } // namespace | 601 } // namespace |
486 } // namespace sessions | 602 } // namespace sessions |
487 } // namespace browser_sync | 603 } // namespace browser_sync |
OLD | NEW |