OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 using sessions::SyncSession; | 96 using sessions::SyncSession; |
97 | 97 |
98 namespace { | 98 namespace { |
99 const char* kTestData = "Hello World!"; | 99 const char* kTestData = "Hello World!"; |
100 const int kTestDataLen = 12; | 100 const int kTestDataLen = 12; |
101 const int64 kTestLogRequestTimestamp = 123456; | 101 const int64 kTestLogRequestTimestamp = 123456; |
102 } // namespace | 102 } // namespace |
103 | 103 |
104 class SyncerTest : public testing::Test, | 104 class SyncerTest : public testing::Test, |
105 public SyncSession::Delegate, | 105 public SyncSession::Delegate, |
106 public ModelSafeWorkerRegistrar { | 106 public ModelSafeWorkerRegistrar, |
| 107 public ChannelEventHandler<SyncerEvent> { |
107 protected: | 108 protected: |
108 SyncerTest() : syncer_(NULL) {} | 109 SyncerTest() : syncer_(NULL) {} |
109 | 110 |
110 // SyncSession::Delegate implementation. | 111 // SyncSession::Delegate implementation. |
111 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) { | 112 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) { |
112 FAIL() << "Should not get silenced."; | 113 FAIL() << "Should not get silenced."; |
113 } | 114 } |
114 virtual bool IsSyncingCurrentlySilenced() { | 115 virtual bool IsSyncingCurrentlySilenced() { |
115 return false; | 116 return false; |
116 } | 117 } |
(...skipping 14 matching lines...) Expand all Loading... |
131 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 132 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
132 // We're just testing the sync engine here, so we shunt everything to | 133 // 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. | 134 // the SyncerThread. Datatypes which aren't enabled aren't in the map. |
134 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 135 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
135 if (enabled_datatypes_[i]) { | 136 if (enabled_datatypes_[i]) { |
136 (*out)[syncable::ModelTypeFromInt(i)] = GROUP_PASSIVE; | 137 (*out)[syncable::ModelTypeFromInt(i)] = GROUP_PASSIVE; |
137 } | 138 } |
138 } | 139 } |
139 } | 140 } |
140 | 141 |
141 void HandleSyncerEvent(SyncerEvent event) { | 142 void HandleChannelEvent(const SyncerEvent& event) { |
142 LOG(INFO) << "HandleSyncerEvent in unittest " << event.what_happened; | 143 LOG(INFO) << "HandleSyncerEvent in unittest " << event.what_happened; |
143 // we only test for entry-specific events, not status changed ones. | 144 // we only test for entry-specific events, not status changed ones. |
144 switch (event.what_happened) { | 145 switch (event.what_happened) { |
145 case SyncerEvent::STATUS_CHANGED: | 146 case SyncerEvent::STATUS_CHANGED: |
146 // fall through | 147 // fall through |
147 case SyncerEvent::SYNC_CYCLE_ENDED: | 148 case SyncerEvent::SYNC_CYCLE_ENDED: |
148 // fall through | 149 // fall through |
149 case SyncerEvent::COMMITS_SUCCEEDED: | 150 case SyncerEvent::COMMITS_SUCCEEDED: |
150 return; | 151 return; |
151 case SyncerEvent::SHUTDOWN_USE_WITH_CARE: | 152 case SyncerEvent::SHUTDOWN_USE_WITH_CARE: |
(...skipping 26 matching lines...) Expand all Loading... |
178 context_.reset(new SyncSessionContext(mock_server_.get(), NULL, | 179 context_.reset(new SyncSessionContext(mock_server_.get(), NULL, |
179 syncdb_.manager(), this)); | 180 syncdb_.manager(), this)); |
180 context_->set_account_name(syncdb_.name()); | 181 context_->set_account_name(syncdb_.name()); |
181 ASSERT_FALSE(context_->syncer_event_channel()); | 182 ASSERT_FALSE(context_->syncer_event_channel()); |
182 ASSERT_FALSE(context_->resolver()); | 183 ASSERT_FALSE(context_->resolver()); |
183 syncer_ = new Syncer(context_.get()); | 184 syncer_ = new Syncer(context_.get()); |
184 // The Syncer installs some components on the context. | 185 // The Syncer installs some components on the context. |
185 ASSERT_TRUE(context_->syncer_event_channel()); | 186 ASSERT_TRUE(context_->syncer_event_channel()); |
186 ASSERT_TRUE(context_->resolver()); | 187 ASSERT_TRUE(context_->resolver()); |
187 | 188 |
188 hookup_.reset(NewEventListenerHookup(context_->syncer_event_channel(), this, | 189 hookup_.reset(context_->syncer_event_channel()->AddObserver(this)); |
189 &SyncerTest::HandleSyncerEvent)); | |
190 session_.reset(new SyncSession(context_.get(), this)); | 190 session_.reset(new SyncSession(context_.get(), this)); |
191 | 191 |
192 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 192 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
193 CHECK(dir.good()); | 193 CHECK(dir.good()); |
194 ReadTransaction trans(dir, __FILE__, __LINE__); | 194 ReadTransaction trans(dir, __FILE__, __LINE__); |
195 syncable::Directory::ChildHandles children; | 195 syncable::Directory::ChildHandles children; |
196 dir->GetChildHandles(&trans, trans.root_id(), &children); | 196 dir->GetChildHandles(&trans, trans.root_id(), &children); |
197 ASSERT_TRUE(0 == children.size()); | 197 ASSERT_TRUE(0 == children.size()); |
198 syncer_events_.clear(); | 198 syncer_events_.clear(); |
199 root_id_ = TestIdFactory::root(); | 199 root_id_ = TestIdFactory::root(); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 // TODO(chron): Get rid of these inbuilt IDs. They only make it | 414 // TODO(chron): Get rid of these inbuilt IDs. They only make it |
415 // more confusing. | 415 // more confusing. |
416 syncable::Id root_id_; | 416 syncable::Id root_id_; |
417 syncable::Id parent_id_; | 417 syncable::Id parent_id_; |
418 syncable::Id child_id_; | 418 syncable::Id child_id_; |
419 | 419 |
420 TestIdFactory ids_; | 420 TestIdFactory ids_; |
421 | 421 |
422 TestDirectorySetterUpper syncdb_; | 422 TestDirectorySetterUpper syncdb_; |
423 scoped_ptr<MockConnectionManager> mock_server_; | 423 scoped_ptr<MockConnectionManager> mock_server_; |
424 scoped_ptr<EventListenerHookup> hookup_; | 424 scoped_ptr<ChannelHookup<SyncerEvent> > hookup_; |
425 | 425 |
426 Syncer* syncer_; | 426 Syncer* syncer_; |
427 | 427 |
428 scoped_ptr<SyncSession> session_; | 428 scoped_ptr<SyncSession> session_; |
429 scoped_ptr<SyncSessionContext> context_; | 429 scoped_ptr<SyncSessionContext> context_; |
430 std::set<SyncerEvent> syncer_events_; | 430 std::set<SyncerEvent> syncer_events_; |
431 base::TimeDelta last_short_poll_interval_received_; | 431 base::TimeDelta last_short_poll_interval_received_; |
432 base::TimeDelta last_long_poll_interval_received_; | 432 base::TimeDelta last_long_poll_interval_received_; |
433 scoped_refptr<ModelSafeWorker> worker_; | 433 scoped_refptr<ModelSafeWorker> worker_; |
434 | 434 |
(...skipping 3978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4413 Add(low_id_); | 4413 Add(low_id_); |
4414 Add(high_id_); | 4414 Add(high_id_); |
4415 syncer_->SyncShare(this); | 4415 syncer_->SyncShare(this); |
4416 ExpectLocalOrderIsByServerId(); | 4416 ExpectLocalOrderIsByServerId(); |
4417 } | 4417 } |
4418 | 4418 |
4419 const SyncerTest::CommitOrderingTest | 4419 const SyncerTest::CommitOrderingTest |
4420 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; | 4420 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; |
4421 | 4421 |
4422 } // namespace browser_sync | 4422 } // namespace browser_sync |
OLD | NEW |