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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 ModelSafeRoutingInfoToPayloadMap(info, std::string()); | 181 ModelSafeRoutingInfoToPayloadMap(info, std::string()); |
182 return new SyncSession(context_.get(), this, | 182 return new SyncSession(context_.get(), this, |
183 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), | 183 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), |
184 info, workers); | 184 info, workers); |
185 } | 185 } |
186 | 186 |
187 bool SyncShareAsDelegate( | 187 bool SyncShareAsDelegate( |
188 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) { | 188 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) { |
189 SyncerStep start; | 189 SyncerStep start; |
190 SyncerStep end; | 190 SyncerStep end; |
191 SyncScheduler::SetSyncerStepsForPurpose(purpose, &start, &end); | 191 SyncScheduler::SetSyncerStepsForPurpose(purpose, |
| 192 &start, |
| 193 &end); |
192 | 194 |
193 session_.reset(MakeSession()); | 195 session_.reset(MakeSession()); |
194 syncer_->SyncShare(session_.get(), start, end); | 196 syncer_->SyncShare(session_.get(), start, end); |
195 return session_->HasMoreToSync(); | 197 return session_->HasMoreToSync(); |
196 } | 198 } |
197 | 199 |
198 bool SyncShareNudge() { | 200 bool SyncShareNudge() { |
199 session_.reset(MakeSession()); | 201 session_.reset(MakeSession()); |
200 return SyncShareAsDelegate(SyncScheduler::SyncSessionJob::NUDGE); | 202 return SyncShareAsDelegate(SyncScheduler::SyncSessionJob::NUDGE); |
201 } | 203 } |
(...skipping 28 matching lines...) Expand all Loading... |
230 | 232 |
231 GetModelSafeRoutingInfo(&routing_info); | 233 GetModelSafeRoutingInfo(&routing_info); |
232 GetWorkers(&workers); | 234 GetWorkers(&workers); |
233 | 235 |
234 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); | 236 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); |
235 | 237 |
236 context_.reset( | 238 context_.reset( |
237 new SyncSessionContext( | 239 new SyncSessionContext( |
238 mock_server_.get(), directory(), routing_info, workers, | 240 mock_server_.get(), directory(), routing_info, workers, |
239 &extensions_activity_monitor_, throttled_data_type_tracker_.get(), | 241 &extensions_activity_monitor_, throttled_data_type_tracker_.get(), |
240 listeners, NULL, &traffic_recorder_)); | 242 listeners, NULL, &traffic_recorder_, |
| 243 true /* enable keystore encryption */)); |
241 ASSERT_FALSE(context_->resolver()); | 244 ASSERT_FALSE(context_->resolver()); |
242 syncer_ = new Syncer(); | 245 syncer_ = new Syncer(); |
243 session_.reset(MakeSession()); | 246 session_.reset(MakeSession()); |
244 | 247 |
245 syncable::ReadTransaction trans(FROM_HERE, directory()); | 248 syncable::ReadTransaction trans(FROM_HERE, directory()); |
246 syncable::Directory::ChildHandles children; | 249 syncable::Directory::ChildHandles children; |
247 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); | 250 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); |
248 ASSERT_EQ(0u, children.size()); | 251 ASSERT_EQ(0u, children.size()); |
249 saw_syncer_event_ = false; | 252 saw_syncer_event_ = false; |
250 root_id_ = TestIdFactory::root(); | 253 root_id_ = TestIdFactory::root(); |
251 parent_id_ = ids_.MakeServer("parent id"); | 254 parent_id_ = ids_.MakeServer("parent id"); |
252 child_id_ = ids_.MakeServer("child id"); | 255 child_id_ = ids_.MakeServer("child id"); |
| 256 directory()->set_store_birthday(mock_server_->store_birthday()); |
| 257 mock_server_->SetKeystoreKey("encryption_key"); |
253 } | 258 } |
254 | 259 |
255 virtual void TearDown() { | 260 virtual void TearDown() { |
256 mock_server_.reset(); | 261 mock_server_.reset(); |
257 delete syncer_; | 262 delete syncer_; |
258 syncer_ = NULL; | 263 syncer_ = NULL; |
259 dir_maker_.TearDown(); | 264 dir_maker_.TearDown(); |
260 } | 265 } |
261 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { | 266 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { |
262 EXPECT_FALSE(entry->Get(IS_DIR)); | 267 EXPECT_FALSE(entry->Get(IS_DIR)); |
(...skipping 2036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2299 MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID), | 2304 MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID), |
2300 "bob"); | 2305 "bob"); |
2301 CHECK(entry2.good()); | 2306 CHECK(entry2.good()); |
2302 entry2.Put(syncable::IS_DIR, true); | 2307 entry2.Put(syncable::IS_DIR, true); |
2303 entry2.Put(syncable::IS_UNSYNCED, true); | 2308 entry2.Put(syncable::IS_UNSYNCED, true); |
2304 entry2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 2309 entry2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
2305 } | 2310 } |
2306 }; | 2311 }; |
2307 | 2312 |
2308 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { | 2313 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { |
2309 directory()->set_store_birthday(mock_server_->store_birthday()); | |
2310 { | 2314 { |
2311 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2315 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2312 MutableEntry entry(&trans, syncable::CREATE, trans.root_id(), | 2316 MutableEntry entry(&trans, syncable::CREATE, trans.root_id(), |
2313 "bob"); | 2317 "bob"); |
2314 ASSERT_TRUE(entry.good()); | 2318 ASSERT_TRUE(entry.good()); |
2315 entry.Put(syncable::IS_DIR, true); | 2319 entry.Put(syncable::IS_DIR, true); |
2316 entry.Put(syncable::IS_UNSYNCED, true); | 2320 entry.Put(syncable::IS_UNSYNCED, true); |
2317 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 2321 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
2318 } | 2322 } |
2319 | 2323 |
(...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4159 // The second node was not downloaded. | 4163 // The second node was not downloaded. |
4160 Entry n2(&trans, GET_BY_ID, node2); | 4164 Entry n2(&trans, GET_BY_ID, node2); |
4161 EXPECT_FALSE(n2.good()); | 4165 EXPECT_FALSE(n2.good()); |
4162 | 4166 |
4163 // One update remains undownloaded. | 4167 // One update remains undownloaded. |
4164 mock_server_->ClearUpdatesQueue(); | 4168 mock_server_->ClearUpdatesQueue(); |
4165 | 4169 |
4166 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS)); | 4170 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS)); |
4167 } | 4171 } |
4168 | 4172 |
| 4173 TEST_F(SyncerTest, GetKeySuccess) { |
| 4174 { |
| 4175 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
| 4176 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey()); |
| 4177 } |
| 4178 |
| 4179 SyncShareConfigure(); |
| 4180 |
| 4181 EXPECT_EQ(session_->status_controller().last_get_key_result(), SYNCER_OK); |
| 4182 { |
| 4183 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
| 4184 EXPECT_TRUE(cryptographer(&rtrans)->HasKeystoreKey()); |
| 4185 } |
| 4186 } |
| 4187 |
| 4188 TEST_F(SyncerTest, GetKeyEmpty) { |
| 4189 { |
| 4190 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
| 4191 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey()); |
| 4192 } |
| 4193 |
| 4194 mock_server_->SetKeystoreKey(""); |
| 4195 SyncShareConfigure(); |
| 4196 |
| 4197 EXPECT_NE(session_->status_controller().last_get_key_result(), SYNCER_OK); |
| 4198 { |
| 4199 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
| 4200 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey()); |
| 4201 } |
| 4202 } |
| 4203 |
4169 // Test what happens if a client deletes, then recreates, an object very | 4204 // Test what happens if a client deletes, then recreates, an object very |
4170 // quickly. It is possible that the deletion gets sent as a commit, and | 4205 // quickly. It is possible that the deletion gets sent as a commit, and |
4171 // the undelete happens during the commit request. The principle here | 4206 // the undelete happens during the commit request. The principle here |
4172 // is that with a single committing client, conflicts should never | 4207 // is that with a single committing client, conflicts should never |
4173 // be encountered, and a client encountering its past actions during | 4208 // be encountered, and a client encountering its past actions during |
4174 // getupdates should never feed back to override later actions. | 4209 // getupdates should never feed back to override later actions. |
4175 // | 4210 // |
4176 // In cases of ordering A-F below, the outcome should be the same. | 4211 // In cases of ordering A-F below, the outcome should be the same. |
4177 // Exercised by UndeleteDuringCommit: | 4212 // Exercised by UndeleteDuringCommit: |
4178 // A. Delete - commit - undelete - commitresponse. | 4213 // A. Delete - commit - undelete - commitresponse. |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4823 | 4858 |
4824 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4859 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
4825 Add(mid_id_); | 4860 Add(mid_id_); |
4826 Add(low_id_); | 4861 Add(low_id_); |
4827 Add(high_id_); | 4862 Add(high_id_); |
4828 SyncShareNudge(); | 4863 SyncShareNudge(); |
4829 ExpectLocalOrderIsByServerId(); | 4864 ExpectLocalOrderIsByServerId(); |
4830 } | 4865 } |
4831 | 4866 |
4832 } // namespace syncer | 4867 } // namespace syncer |
OLD | NEW |