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 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <list> | 10 #include <list> |
11 #include <map> | 11 #include <map> |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/compiler_specific.h" |
16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
17 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
18 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
19 #include "base/tracked.h" | 20 #include "base/tracked.h" |
20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
21 #include "chrome/browser/sync/engine/conflict_resolver.h" | 22 #include "chrome/browser/sync/engine/conflict_resolver.h" |
22 #include "chrome/browser/sync/engine/get_commit_ids_command.h" | 23 #include "chrome/browser/sync/engine/get_commit_ids_command.h" |
23 #include "chrome/browser/sync/engine/model_safe_worker.h" | 24 #include "chrome/browser/sync/engine/model_safe_worker.h" |
24 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 25 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
25 #include "chrome/browser/sync/engine/process_updates_command.h" | 26 #include "chrome/browser/sync/engine/process_updates_command.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 using sessions::SyncSession; | 100 using sessions::SyncSession; |
100 | 101 |
101 class SyncerTest : public testing::Test, | 102 class SyncerTest : public testing::Test, |
102 public SyncSession::Delegate, | 103 public SyncSession::Delegate, |
103 public ModelSafeWorkerRegistrar, | 104 public ModelSafeWorkerRegistrar, |
104 public SyncEngineEventListener { | 105 public SyncEngineEventListener { |
105 protected: | 106 protected: |
106 SyncerTest() : syncer_(NULL), saw_syncer_event_(false) {} | 107 SyncerTest() : syncer_(NULL), saw_syncer_event_(false) {} |
107 | 108 |
108 // SyncSession::Delegate implementation. | 109 // SyncSession::Delegate implementation. |
109 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) { | 110 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) OVERRIDE { |
110 FAIL() << "Should not get silenced."; | 111 FAIL() << "Should not get silenced."; |
111 } | 112 } |
112 virtual bool IsSyncingCurrentlySilenced() { | 113 virtual bool IsSyncingCurrentlySilenced() OVERRIDE { |
113 return false; | 114 return false; |
114 } | 115 } |
115 virtual void OnReceivedLongPollIntervalUpdate( | 116 virtual void OnReceivedLongPollIntervalUpdate( |
116 const base::TimeDelta& new_interval) { | 117 const base::TimeDelta& new_interval) OVERRIDE { |
117 last_long_poll_interval_received_ = new_interval; | 118 last_long_poll_interval_received_ = new_interval; |
118 } | 119 } |
119 virtual void OnReceivedShortPollIntervalUpdate( | 120 virtual void OnReceivedShortPollIntervalUpdate( |
120 const base::TimeDelta& new_interval) { | 121 const base::TimeDelta& new_interval) OVERRIDE { |
121 last_short_poll_interval_received_ = new_interval; | 122 last_short_poll_interval_received_ = new_interval; |
122 } | 123 } |
123 virtual void OnShouldStopSyncingPermanently() { | 124 virtual void OnReceivedSessionsCommitDelay( |
| 125 const base::TimeDelta& new_delay) OVERRIDE { |
| 126 last_sessions_commit_delay_seconds_ = new_delay; |
| 127 } |
| 128 virtual void OnShouldStopSyncingPermanently() OVERRIDE { |
124 } | 129 } |
125 | 130 |
126 // ModelSafeWorkerRegistrar implementation. | 131 // ModelSafeWorkerRegistrar implementation. |
127 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) { | 132 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) OVERRIDE { |
128 out->push_back(worker_.get()); | 133 out->push_back(worker_.get()); |
129 } | 134 } |
130 | 135 |
131 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 136 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) OVERRIDE { |
132 // We're just testing the sync engine here, so we shunt everything to | 137 // We're just testing the sync engine here, so we shunt everything to |
133 // the SyncerThread. Datatypes which aren't enabled aren't in the map. | 138 // the SyncerThread. Datatypes which aren't enabled aren't in the map. |
134 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 139 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
135 if (enabled_datatypes_[i]) { | 140 if (enabled_datatypes_[i]) { |
136 (*out)[syncable::ModelTypeFromInt(i)] = GROUP_PASSIVE; | 141 (*out)[syncable::ModelTypeFromInt(i)] = GROUP_PASSIVE; |
137 } | 142 } |
138 } | 143 } |
139 } | 144 } |
140 | 145 |
141 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) { | 146 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE { |
142 VLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; | 147 VLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; |
143 // we only test for entry-specific events, not status changed ones. | 148 // we only test for entry-specific events, not status changed ones. |
144 switch (event.what_happened) { | 149 switch (event.what_happened) { |
145 case SyncEngineEvent::STATUS_CHANGED: | 150 case SyncEngineEvent::STATUS_CHANGED: |
146 // fall through | 151 // fall through |
147 case SyncEngineEvent::SYNC_CYCLE_ENDED: | 152 case SyncEngineEvent::SYNC_CYCLE_ENDED: |
148 return; | 153 return; |
149 default: | 154 default: |
150 CHECK(false) << "Handling unknown error type in unit tests!!"; | 155 CHECK(false) << "Handling unknown error type in unit tests!!"; |
151 } | 156 } |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 TestDirectorySetterUpper syncdb_; | 474 TestDirectorySetterUpper syncdb_; |
470 scoped_ptr<MockConnectionManager> mock_server_; | 475 scoped_ptr<MockConnectionManager> mock_server_; |
471 | 476 |
472 Syncer* syncer_; | 477 Syncer* syncer_; |
473 | 478 |
474 scoped_ptr<SyncSession> session_; | 479 scoped_ptr<SyncSession> session_; |
475 scoped_ptr<SyncSessionContext> context_; | 480 scoped_ptr<SyncSessionContext> context_; |
476 bool saw_syncer_event_; | 481 bool saw_syncer_event_; |
477 base::TimeDelta last_short_poll_interval_received_; | 482 base::TimeDelta last_short_poll_interval_received_; |
478 base::TimeDelta last_long_poll_interval_received_; | 483 base::TimeDelta last_long_poll_interval_received_; |
| 484 base::TimeDelta last_sessions_commit_delay_seconds_; |
479 scoped_refptr<ModelSafeWorker> worker_; | 485 scoped_refptr<ModelSafeWorker> worker_; |
480 | 486 |
481 syncable::ModelTypeBitSet enabled_datatypes_; | 487 syncable::ModelTypeBitSet enabled_datatypes_; |
482 | 488 |
483 DISALLOW_COPY_AND_ASSIGN(SyncerTest); | 489 DISALLOW_COPY_AND_ASSIGN(SyncerTest); |
484 }; | 490 }; |
485 | 491 |
486 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { | 492 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { |
487 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 493 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
488 ASSERT_TRUE(dir.good()); | 494 ASSERT_TRUE(dir.good()); |
(...skipping 3359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3848 } | 3854 } |
3849 | 3855 |
3850 TEST_F(SyncerTest, TestClientCommand) { | 3856 TEST_F(SyncerTest, TestClientCommand) { |
3851 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3857 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
3852 CHECK(dir.good()); | 3858 CHECK(dir.good()); |
3853 using sync_pb::ClientCommand; | 3859 using sync_pb::ClientCommand; |
3854 | 3860 |
3855 ClientCommand* command = mock_server_->GetNextClientCommand(); | 3861 ClientCommand* command = mock_server_->GetNextClientCommand(); |
3856 command->set_set_sync_poll_interval(8); | 3862 command->set_set_sync_poll_interval(8); |
3857 command->set_set_sync_long_poll_interval(800); | 3863 command->set_set_sync_long_poll_interval(800); |
| 3864 command->set_sessions_commit_delay_seconds(3141); |
3858 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1); | 3865 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1); |
3859 SyncShareAsDelegate(); | 3866 SyncShareAsDelegate(); |
3860 | 3867 |
3861 EXPECT_TRUE(TimeDelta::FromSeconds(8) == | 3868 EXPECT_TRUE(TimeDelta::FromSeconds(8) == |
3862 last_short_poll_interval_received_); | 3869 last_short_poll_interval_received_); |
3863 EXPECT_TRUE(TimeDelta::FromSeconds(800) == | 3870 EXPECT_TRUE(TimeDelta::FromSeconds(800) == |
3864 last_long_poll_interval_received_); | 3871 last_long_poll_interval_received_); |
| 3872 EXPECT_TRUE(TimeDelta::FromSeconds(3141) == |
| 3873 last_sessions_commit_delay_seconds_); |
3865 | 3874 |
3866 command = mock_server_->GetNextClientCommand(); | 3875 command = mock_server_->GetNextClientCommand(); |
3867 command->set_set_sync_poll_interval(180); | 3876 command->set_set_sync_poll_interval(180); |
3868 command->set_set_sync_long_poll_interval(190); | 3877 command->set_set_sync_long_poll_interval(190); |
| 3878 command->set_sessions_commit_delay_seconds(2718); |
3869 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1); | 3879 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1); |
3870 SyncShareAsDelegate(); | 3880 SyncShareAsDelegate(); |
3871 | 3881 |
3872 EXPECT_TRUE(TimeDelta::FromSeconds(180) == | 3882 EXPECT_TRUE(TimeDelta::FromSeconds(180) == |
3873 last_short_poll_interval_received_); | 3883 last_short_poll_interval_received_); |
3874 EXPECT_TRUE(TimeDelta::FromSeconds(190) == | 3884 EXPECT_TRUE(TimeDelta::FromSeconds(190) == |
3875 last_long_poll_interval_received_); | 3885 last_long_poll_interval_received_); |
| 3886 EXPECT_TRUE(TimeDelta::FromSeconds(2718) == |
| 3887 last_sessions_commit_delay_seconds_); |
3876 } | 3888 } |
3877 | 3889 |
3878 TEST_F(SyncerTest, EnsureWeSendUpOldParent) { | 3890 TEST_F(SyncerTest, EnsureWeSendUpOldParent) { |
3879 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3891 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
3880 CHECK(dir.good()); | 3892 CHECK(dir.good()); |
3881 | 3893 |
3882 syncable::Id folder_one_id = ids_.FromNumber(1); | 3894 syncable::Id folder_one_id = ids_.FromNumber(1); |
3883 syncable::Id folder_two_id = ids_.FromNumber(2); | 3895 syncable::Id folder_two_id = ids_.FromNumber(2); |
3884 | 3896 |
3885 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(), | 3897 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(), |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5177 Add(low_id_); | 5189 Add(low_id_); |
5178 Add(high_id_); | 5190 Add(high_id_); |
5179 SyncShareAsDelegate(); | 5191 SyncShareAsDelegate(); |
5180 ExpectLocalOrderIsByServerId(); | 5192 ExpectLocalOrderIsByServerId(); |
5181 } | 5193 } |
5182 | 5194 |
5183 const SyncerTest::CommitOrderingTest | 5195 const SyncerTest::CommitOrderingTest |
5184 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; | 5196 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; |
5185 | 5197 |
5186 } // namespace browser_sync | 5198 } // namespace browser_sync |
OLD | NEW |