| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 const base::TimeDelta& new_delay) OVERRIDE { | 139 const base::TimeDelta& new_delay) OVERRIDE { |
| 140 last_sessions_commit_delay_seconds_ = new_delay; | 140 last_sessions_commit_delay_seconds_ = new_delay; |
| 141 } | 141 } |
| 142 virtual void OnShouldStopSyncingPermanently() OVERRIDE { | 142 virtual void OnShouldStopSyncingPermanently() OVERRIDE { |
| 143 } | 143 } |
| 144 virtual void OnSyncProtocolError( | 144 virtual void OnSyncProtocolError( |
| 145 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE { | 145 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE { |
| 146 } | 146 } |
| 147 | 147 |
| 148 void GetWorkers(std::vector<ModelSafeWorker*>* out) { | 148 void GetWorkers(std::vector<ModelSafeWorker*>* out) { |
| 149 out->push_back(worker_.get()); | 149 out->push_back(control_worker_.get()); |
| 150 out->push_back(passive_worker_.get()); |
| 150 } | 151 } |
| 151 | 152 |
| 152 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 153 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
| 153 // We're just testing the sync engine here, so we shunt everything to | 154 // We're just testing the sync engine here, so we shunt everything to |
| 154 // the SyncerThread. Datatypes which aren't enabled aren't in the map. | 155 // the SyncerThread. Datatypes which aren't enabled aren't in the map. |
| 155 for (ModelTypeSet::Iterator it = enabled_datatypes_.First(); | 156 for (ModelTypeSet::Iterator it = enabled_datatypes_.First(); |
| 156 it.Good(); it.Inc()) { | 157 it.Good(); it.Inc()) { |
| 157 (*out)[it.Get()] = GROUP_PASSIVE; | 158 if (!IsControlType(it.Get())) { |
| 159 (*out)[it.Get()] = GROUP_PASSIVE; |
| 160 } else { |
| 161 (*out)[it.Get()] = GROUP_CONTROL; |
| 162 } |
| 158 } | 163 } |
| 159 } | 164 } |
| 160 | 165 |
| 161 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE { | 166 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE { |
| 162 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; | 167 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; |
| 163 // we only test for entry-specific events, not status changed ones. | 168 // we only test for entry-specific events, not status changed ones. |
| 164 switch (event.what_happened) { | 169 switch (event.what_happened) { |
| 165 case SyncEngineEvent::SYNC_CYCLE_BEGIN: // Fall through. | 170 case SyncEngineEvent::SYNC_CYCLE_BEGIN: // Fall through. |
| 166 case SyncEngineEvent::STATUS_CHANGED: | 171 case SyncEngineEvent::STATUS_CHANGED: |
| 167 case SyncEngineEvent::SYNC_CYCLE_ENDED: | 172 case SyncEngineEvent::SYNC_CYCLE_ENDED: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } while (should_loop); | 220 } while (should_loop); |
| 216 } | 221 } |
| 217 | 222 |
| 218 virtual void SetUp() { | 223 virtual void SetUp() { |
| 219 dir_maker_.SetUp(); | 224 dir_maker_.SetUp(); |
| 220 mock_server_.reset(new MockConnectionManager(directory())); | 225 mock_server_.reset(new MockConnectionManager(directory())); |
| 221 EnableDatatype(BOOKMARKS); | 226 EnableDatatype(BOOKMARKS); |
| 222 EnableDatatype(NIGORI); | 227 EnableDatatype(NIGORI); |
| 223 EnableDatatype(PREFERENCES); | 228 EnableDatatype(PREFERENCES); |
| 224 EnableDatatype(NIGORI); | 229 EnableDatatype(NIGORI); |
| 225 worker_ = new FakeModelWorker(GROUP_PASSIVE); | 230 passive_worker_ = new FakeModelWorker(GROUP_PASSIVE); |
| 231 control_worker_ = new FakeModelWorker(GROUP_CONTROL); |
| 226 std::vector<SyncEngineEventListener*> listeners; | 232 std::vector<SyncEngineEventListener*> listeners; |
| 227 listeners.push_back(this); | 233 listeners.push_back(this); |
| 228 | 234 |
| 229 ModelSafeRoutingInfo routing_info; | 235 ModelSafeRoutingInfo routing_info; |
| 230 std::vector<ModelSafeWorker*> workers; | 236 std::vector<ModelSafeWorker*> workers; |
| 231 | 237 |
| 232 GetModelSafeRoutingInfo(&routing_info); | 238 GetModelSafeRoutingInfo(&routing_info); |
| 233 GetWorkers(&workers); | 239 GetWorkers(&workers); |
| 234 | 240 |
| 235 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); | 241 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 scoped_ptr<MockConnectionManager> mock_server_; | 560 scoped_ptr<MockConnectionManager> mock_server_; |
| 555 | 561 |
| 556 Syncer* syncer_; | 562 Syncer* syncer_; |
| 557 | 563 |
| 558 scoped_ptr<SyncSession> session_; | 564 scoped_ptr<SyncSession> session_; |
| 559 scoped_ptr<SyncSessionContext> context_; | 565 scoped_ptr<SyncSessionContext> context_; |
| 560 bool saw_syncer_event_; | 566 bool saw_syncer_event_; |
| 561 base::TimeDelta last_short_poll_interval_received_; | 567 base::TimeDelta last_short_poll_interval_received_; |
| 562 base::TimeDelta last_long_poll_interval_received_; | 568 base::TimeDelta last_long_poll_interval_received_; |
| 563 base::TimeDelta last_sessions_commit_delay_seconds_; | 569 base::TimeDelta last_sessions_commit_delay_seconds_; |
| 564 scoped_refptr<ModelSafeWorker> worker_; | 570 scoped_refptr<ModelSafeWorker> passive_worker_; |
| 571 scoped_refptr<ModelSafeWorker> control_worker_; |
| 565 | 572 |
| 566 ModelTypeSet enabled_datatypes_; | 573 ModelTypeSet enabled_datatypes_; |
| 567 TrafficRecorder traffic_recorder_; | 574 TrafficRecorder traffic_recorder_; |
| 568 | 575 |
| 569 DISALLOW_COPY_AND_ASSIGN(SyncerTest); | 576 DISALLOW_COPY_AND_ASSIGN(SyncerTest); |
| 570 }; | 577 }; |
| 571 | 578 |
| 572 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { | 579 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { |
| 573 { | 580 { |
| 574 Syncer::UnsyncedMetaHandles handles; | 581 Syncer::UnsyncedMetaHandles handles; |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 // Data for testing encryption/decryption. | 994 // Data for testing encryption/decryption. |
| 988 Cryptographer other_cryptographer(&encryptor_); | 995 Cryptographer other_cryptographer(&encryptor_); |
| 989 other_cryptographer.AddKey(old_key); | 996 other_cryptographer.AddKey(old_key); |
| 990 sync_pb::EntitySpecifics other_encrypted_specifics; | 997 sync_pb::EntitySpecifics other_encrypted_specifics; |
| 991 other_encrypted_specifics.mutable_bookmark()->set_title("title"); | 998 other_encrypted_specifics.mutable_bookmark()->set_title("title"); |
| 992 other_cryptographer.Encrypt( | 999 other_cryptographer.Encrypt( |
| 993 other_encrypted_specifics, | 1000 other_encrypted_specifics, |
| 994 other_encrypted_specifics.mutable_encrypted()); | 1001 other_encrypted_specifics.mutable_encrypted()); |
| 995 sync_pb::EntitySpecifics our_encrypted_specifics; | 1002 sync_pb::EntitySpecifics our_encrypted_specifics; |
| 996 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); | 1003 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); |
| 997 ModelTypeSet encrypted_types = ModelTypeSet::All(); | 1004 ModelTypeSet encrypted_types = syncer::EncryptableTypes(); |
| 998 | 1005 |
| 999 | 1006 |
| 1000 // Receive the initial nigori node. | 1007 // Receive the initial nigori node. |
| 1001 sync_pb::EntitySpecifics initial_nigori_specifics; | 1008 sync_pb::EntitySpecifics initial_nigori_specifics; |
| 1002 initial_nigori_specifics.mutable_nigori(); | 1009 initial_nigori_specifics.mutable_nigori(); |
| 1003 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); | 1010 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); |
| 1004 SyncShareNudge(); | 1011 SyncShareNudge(); |
| 1005 | 1012 |
| 1006 { | 1013 { |
| 1007 // Set up the current nigori node (containing both keys and encrypt | 1014 // Set up the current nigori node (containing both keys and encrypt |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 sync_pb::EntitySpecifics other_encrypted_specifics; | 1086 sync_pb::EntitySpecifics other_encrypted_specifics; |
| 1080 other_encrypted_specifics.mutable_bookmark()->set_title("title"); | 1087 other_encrypted_specifics.mutable_bookmark()->set_title("title"); |
| 1081 other_cryptographer.Encrypt( | 1088 other_cryptographer.Encrypt( |
| 1082 other_encrypted_specifics, | 1089 other_encrypted_specifics, |
| 1083 other_encrypted_specifics.mutable_encrypted()); | 1090 other_encrypted_specifics.mutable_encrypted()); |
| 1084 sync_pb::EntitySpecifics our_encrypted_specifics; | 1091 sync_pb::EntitySpecifics our_encrypted_specifics; |
| 1085 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); | 1092 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); |
| 1086 | 1093 |
| 1087 // Receive the initial nigori node. | 1094 // Receive the initial nigori node. |
| 1088 SyncShareNudge(); | 1095 SyncShareNudge(); |
| 1089 encrypted_types = ModelTypeSet::All(); | 1096 encrypted_types = syncer::EncryptableTypes(); |
| 1090 { | 1097 { |
| 1091 // Local changes with different passphrase, different types. | 1098 // Local changes with different passphrase, different types. |
| 1092 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1099 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 1093 sync_pb::EntitySpecifics specifics; | 1100 sync_pb::EntitySpecifics specifics; |
| 1094 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1101 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 1095 cryptographer(&wtrans)->AddKey(local_key_params); | 1102 cryptographer(&wtrans)->AddKey(local_key_params); |
| 1096 cryptographer(&wtrans)->Encrypt( | 1103 cryptographer(&wtrans)->Encrypt( |
| 1097 our_encrypted_specifics, | 1104 our_encrypted_specifics, |
| 1098 our_encrypted_specifics.mutable_encrypted()); | 1105 our_encrypted_specifics.mutable_encrypted()); |
| 1099 cryptographer(&wtrans)->GetKeys( | 1106 cryptographer(&wtrans)->GetKeys( |
| (...skipping 3757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4857 | 4864 |
| 4858 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4865 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
| 4859 Add(mid_id_); | 4866 Add(mid_id_); |
| 4860 Add(low_id_); | 4867 Add(low_id_); |
| 4861 Add(high_id_); | 4868 Add(high_id_); |
| 4862 SyncShareNudge(); | 4869 SyncShareNudge(); |
| 4863 ExpectLocalOrderIsByServerId(); | 4870 ExpectLocalOrderIsByServerId(); |
| 4864 } | 4871 } |
| 4865 | 4872 |
| 4866 } // namespace syncer | 4873 } // namespace syncer |
| OLD | NEW |