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