| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // 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> |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 using sessions::StatusController; | 94 using sessions::StatusController; |
| 95 using sessions::SyncSessionContext; | 95 using sessions::SyncSessionContext; |
| 96 using sessions::SyncSession; | 96 using sessions::SyncSession; |
| 97 | 97 |
| 98 namespace { | 98 namespace { |
| 99 | 99 |
| 100 // A helper to hold on to the counters emitted by the sync engine. | 100 // A helper to hold on to the counters emitted by the sync engine. |
| 101 class TypeDebugInfoCache : public TypeDebugInfoObserver { | 101 class TypeDebugInfoCache : public TypeDebugInfoObserver { |
| 102 public: | 102 public: |
| 103 TypeDebugInfoCache(); | 103 TypeDebugInfoCache(); |
| 104 virtual ~TypeDebugInfoCache(); | 104 ~TypeDebugInfoCache() override; |
| 105 | 105 |
| 106 CommitCounters GetLatestCommitCounters(ModelType type) const; | 106 CommitCounters GetLatestCommitCounters(ModelType type) const; |
| 107 UpdateCounters GetLatestUpdateCounters(ModelType type) const; | 107 UpdateCounters GetLatestUpdateCounters(ModelType type) const; |
| 108 StatusCounters GetLatestStatusCounters(ModelType type) const; | 108 StatusCounters GetLatestStatusCounters(ModelType type) const; |
| 109 | 109 |
| 110 // TypeDebugInfoObserver implementation. | 110 // TypeDebugInfoObserver implementation. |
| 111 virtual void OnCommitCountersUpdated( | 111 void OnCommitCountersUpdated(syncer::ModelType type, |
| 112 syncer::ModelType type, | 112 const CommitCounters& counters) override; |
| 113 const CommitCounters& counters) override; | 113 void OnUpdateCountersUpdated(syncer::ModelType type, |
| 114 virtual void OnUpdateCountersUpdated( | 114 const UpdateCounters& counters) override; |
| 115 syncer::ModelType type, | 115 void OnStatusCountersUpdated(syncer::ModelType type, |
| 116 const UpdateCounters& counters) override; | 116 const StatusCounters& counters) override; |
| 117 virtual void OnStatusCountersUpdated( | |
| 118 syncer::ModelType type, | |
| 119 const StatusCounters& counters) override; | |
| 120 | 117 |
| 121 private: | 118 private: |
| 122 std::map<ModelType, CommitCounters> commit_counters_map_; | 119 std::map<ModelType, CommitCounters> commit_counters_map_; |
| 123 std::map<ModelType, UpdateCounters> update_counters_map_; | 120 std::map<ModelType, UpdateCounters> update_counters_map_; |
| 124 std::map<ModelType, StatusCounters> status_counters_map_; | 121 std::map<ModelType, StatusCounters> status_counters_map_; |
| 125 }; | 122 }; |
| 126 | 123 |
| 127 TypeDebugInfoCache::TypeDebugInfoCache() {} | 124 TypeDebugInfoCache::TypeDebugInfoCache() {} |
| 128 | 125 |
| 129 TypeDebugInfoCache::~TypeDebugInfoCache() {} | 126 TypeDebugInfoCache::~TypeDebugInfoCache() {} |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 public SyncEngineEventListener { | 183 public SyncEngineEventListener { |
| 187 protected: | 184 protected: |
| 188 SyncerTest() | 185 SyncerTest() |
| 189 : extensions_activity_(new ExtensionsActivity), | 186 : extensions_activity_(new ExtensionsActivity), |
| 190 syncer_(NULL), | 187 syncer_(NULL), |
| 191 saw_syncer_event_(false), | 188 saw_syncer_event_(false), |
| 192 last_client_invalidation_hint_buffer_size_(10) { | 189 last_client_invalidation_hint_buffer_size_(10) { |
| 193 } | 190 } |
| 194 | 191 |
| 195 // SyncSession::Delegate implementation. | 192 // SyncSession::Delegate implementation. |
| 196 virtual void OnThrottled(const base::TimeDelta& throttle_duration) override { | 193 void OnThrottled(const base::TimeDelta& throttle_duration) override { |
| 197 FAIL() << "Should not get silenced."; | 194 FAIL() << "Should not get silenced."; |
| 198 } | 195 } |
| 199 virtual void OnTypesThrottled( | 196 void OnTypesThrottled(ModelTypeSet types, |
| 200 ModelTypeSet types, | 197 const base::TimeDelta& throttle_duration) override { |
| 201 const base::TimeDelta& throttle_duration) override { | |
| 202 FAIL() << "Should not get silenced."; | 198 FAIL() << "Should not get silenced."; |
| 203 } | 199 } |
| 204 virtual bool IsCurrentlyThrottled() override { | 200 bool IsCurrentlyThrottled() override { return false; } |
| 205 return false; | 201 void OnReceivedLongPollIntervalUpdate( |
| 206 } | |
| 207 virtual void OnReceivedLongPollIntervalUpdate( | |
| 208 const base::TimeDelta& new_interval) override { | 202 const base::TimeDelta& new_interval) override { |
| 209 last_long_poll_interval_received_ = new_interval; | 203 last_long_poll_interval_received_ = new_interval; |
| 210 } | 204 } |
| 211 virtual void OnReceivedShortPollIntervalUpdate( | 205 void OnReceivedShortPollIntervalUpdate( |
| 212 const base::TimeDelta& new_interval) override { | 206 const base::TimeDelta& new_interval) override { |
| 213 last_short_poll_interval_received_ = new_interval; | 207 last_short_poll_interval_received_ = new_interval; |
| 214 } | 208 } |
| 215 virtual void OnReceivedCustomNudgeDelays( | 209 void OnReceivedCustomNudgeDelays( |
| 216 const std::map<ModelType, base::TimeDelta>& delay_map) override { | 210 const std::map<ModelType, base::TimeDelta>& delay_map) override { |
| 217 std::map<ModelType, base::TimeDelta>::const_iterator iter = | 211 std::map<ModelType, base::TimeDelta>::const_iterator iter = |
| 218 delay_map.find(SESSIONS); | 212 delay_map.find(SESSIONS); |
| 219 if (iter != delay_map.end() && iter->second > base::TimeDelta()) | 213 if (iter != delay_map.end() && iter->second > base::TimeDelta()) |
| 220 last_sessions_commit_delay_ = iter->second; | 214 last_sessions_commit_delay_ = iter->second; |
| 221 iter = delay_map.find(BOOKMARKS); | 215 iter = delay_map.find(BOOKMARKS); |
| 222 if (iter != delay_map.end() && iter->second > base::TimeDelta()) | 216 if (iter != delay_map.end() && iter->second > base::TimeDelta()) |
| 223 last_bookmarks_commit_delay_ = iter->second; | 217 last_bookmarks_commit_delay_ = iter->second; |
| 224 } | 218 } |
| 225 virtual void OnReceivedClientInvalidationHintBufferSize( | 219 void OnReceivedClientInvalidationHintBufferSize(int size) override { |
| 226 int size) override { | |
| 227 last_client_invalidation_hint_buffer_size_ = size; | 220 last_client_invalidation_hint_buffer_size_ = size; |
| 228 } | 221 } |
| 229 virtual void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override {} | 222 void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override {} |
| 230 virtual void OnReceivedMigrationRequest(ModelTypeSet types) override {} | 223 void OnReceivedMigrationRequest(ModelTypeSet types) override {} |
| 231 virtual void OnProtocolEvent(const ProtocolEvent& event) override {} | 224 void OnProtocolEvent(const ProtocolEvent& event) override {} |
| 232 virtual void OnSyncProtocolError(const SyncProtocolError& error) override {} | 225 void OnSyncProtocolError(const SyncProtocolError& error) override {} |
| 233 | 226 |
| 234 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 227 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
| 235 // We're just testing the sync engine here, so we shunt everything to | 228 // We're just testing the sync engine here, so we shunt everything to |
| 236 // the SyncerThread. Datatypes which aren't enabled aren't in the map. | 229 // the SyncerThread. Datatypes which aren't enabled aren't in the map. |
| 237 for (ModelTypeSet::Iterator it = enabled_datatypes_.First(); | 230 for (ModelTypeSet::Iterator it = enabled_datatypes_.First(); |
| 238 it.Good(); it.Inc()) { | 231 it.Good(); it.Inc()) { |
| 239 (*out)[it.Get()] = GROUP_PASSIVE; | 232 (*out)[it.Get()] = GROUP_PASSIVE; |
| 240 } | 233 } |
| 241 } | 234 } |
| 242 | 235 |
| 243 virtual void OnSyncCycleEvent(const SyncCycleEvent& event) override { | 236 void OnSyncCycleEvent(const SyncCycleEvent& event) override { |
| 244 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; | 237 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; |
| 245 // we only test for entry-specific events, not status changed ones. | 238 // we only test for entry-specific events, not status changed ones. |
| 246 switch (event.what_happened) { | 239 switch (event.what_happened) { |
| 247 case SyncCycleEvent::SYNC_CYCLE_BEGIN: // Fall through. | 240 case SyncCycleEvent::SYNC_CYCLE_BEGIN: // Fall through. |
| 248 case SyncCycleEvent::STATUS_CHANGED: | 241 case SyncCycleEvent::STATUS_CHANGED: |
| 249 case SyncCycleEvent::SYNC_CYCLE_ENDED: | 242 case SyncCycleEvent::SYNC_CYCLE_ENDED: |
| 250 return; | 243 return; |
| 251 default: | 244 default: |
| 252 CHECK(false) << "Handling unknown error type in unit tests!!"; | 245 CHECK(false) << "Handling unknown error type in unit tests!!"; |
| 253 } | 246 } |
| 254 saw_syncer_event_ = true; | 247 saw_syncer_event_ = true; |
| 255 } | 248 } |
| 256 | 249 |
| 257 virtual void OnActionableError(const SyncProtocolError& error) override {} | 250 void OnActionableError(const SyncProtocolError& error) override {} |
| 258 virtual void OnRetryTimeChanged(base::Time retry_time) override {} | 251 void OnRetryTimeChanged(base::Time retry_time) override {} |
| 259 virtual void OnThrottledTypesChanged(ModelTypeSet throttled_types) override {} | 252 void OnThrottledTypesChanged(ModelTypeSet throttled_types) override {} |
| 260 virtual void OnMigrationRequested(ModelTypeSet types) override {} | 253 void OnMigrationRequested(ModelTypeSet types) override {} |
| 261 | 254 |
| 262 void ResetSession() { | 255 void ResetSession() { |
| 263 session_.reset(SyncSession::Build(context_.get(), this)); | 256 session_.reset(SyncSession::Build(context_.get(), this)); |
| 264 } | 257 } |
| 265 | 258 |
| 266 void SyncShareNudge() { | 259 void SyncShareNudge() { |
| 267 ResetSession(); | 260 ResetSession(); |
| 268 | 261 |
| 269 // Pretend we've seen a local change, to make the nudge_tracker look normal. | 262 // Pretend we've seen a local change, to make the nudge_tracker look normal. |
| 270 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 263 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
| (...skipping 4778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5049 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5042 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
| 5050 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5043 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
| 5051 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5044 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
| 5052 } else { | 5045 } else { |
| 5053 EXPECT_TRUE(final_monitor_records.empty()) | 5046 EXPECT_TRUE(final_monitor_records.empty()) |
| 5054 << "Should not restore records after successful bookmark commit."; | 5047 << "Should not restore records after successful bookmark commit."; |
| 5055 } | 5048 } |
| 5056 } | 5049 } |
| 5057 | 5050 |
| 5058 } // namespace syncer | 5051 } // namespace syncer |
| OLD | NEW |