Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 10455012: [Sync] Add support for performing a GetKey on startup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 ConfigurationParams config_params;
192 if (purpose == SyncScheduler::SyncSessionJob::CONFIGURATION) {
193 config_params.keystore_key_status =
194 ConfigurationParams::KEYSTORE_KEY_NEEDED;
195 config_params.types_to_download = ModelTypeSet(BOOKMARKS);
196 }
197 SyncScheduler::SetSyncerStepsForPurpose(purpose,
198 config_params,
199 &start,
200 &end);
192 201
193 session_.reset(MakeSession()); 202 session_.reset(MakeSession());
194 syncer_->SyncShare(session_.get(), start, end); 203 syncer_->SyncShare(session_.get(), start, end);
195 return session_->HasMoreToSync(); 204 return session_->HasMoreToSync();
196 } 205 }
197 206
198 bool SyncShareNudge() { 207 bool SyncShareNudge() {
199 session_.reset(MakeSession()); 208 session_.reset(MakeSession());
200 return SyncShareAsDelegate(SyncScheduler::SyncSessionJob::NUDGE); 209 return SyncShareAsDelegate(SyncScheduler::SyncSessionJob::NUDGE);
201 } 210 }
(...skipping 28 matching lines...) Expand all
230 239
231 GetModelSafeRoutingInfo(&routing_info); 240 GetModelSafeRoutingInfo(&routing_info);
232 GetWorkers(&workers); 241 GetWorkers(&workers);
233 242
234 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); 243 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL));
235 244
236 context_.reset( 245 context_.reset(
237 new SyncSessionContext( 246 new SyncSessionContext(
238 mock_server_.get(), directory(), routing_info, workers, 247 mock_server_.get(), directory(), routing_info, workers,
239 &extensions_activity_monitor_, throttled_data_type_tracker_.get(), 248 &extensions_activity_monitor_, throttled_data_type_tracker_.get(),
240 listeners, NULL, &traffic_recorder_)); 249 listeners, NULL, &traffic_recorder_,
250 true /* enable keystore encryption */));
241 ASSERT_FALSE(context_->resolver()); 251 ASSERT_FALSE(context_->resolver());
242 syncer_ = new Syncer(); 252 syncer_ = new Syncer();
243 session_.reset(MakeSession()); 253 session_.reset(MakeSession());
244 254
245 syncable::ReadTransaction trans(FROM_HERE, directory()); 255 syncable::ReadTransaction trans(FROM_HERE, directory());
246 syncable::Directory::ChildHandles children; 256 syncable::Directory::ChildHandles children;
247 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); 257 directory()->GetChildHandlesById(&trans, trans.root_id(), &children);
248 ASSERT_EQ(0u, children.size()); 258 ASSERT_EQ(0u, children.size());
249 saw_syncer_event_ = false; 259 saw_syncer_event_ = false;
250 root_id_ = TestIdFactory::root(); 260 root_id_ = TestIdFactory::root();
251 parent_id_ = ids_.MakeServer("parent id"); 261 parent_id_ = ids_.MakeServer("parent id");
252 child_id_ = ids_.MakeServer("child id"); 262 child_id_ = ids_.MakeServer("child id");
263 directory()->set_store_birthday(mock_server_->store_birthday());
264 mock_server_->SetKeystoreKey("encryption_key");
253 } 265 }
254 266
255 virtual void TearDown() { 267 virtual void TearDown() {
256 mock_server_.reset(); 268 mock_server_.reset();
257 delete syncer_; 269 delete syncer_;
258 syncer_ = NULL; 270 syncer_ = NULL;
259 dir_maker_.TearDown(); 271 dir_maker_.TearDown();
260 } 272 }
261 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { 273 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) {
262 EXPECT_FALSE(entry->Get(IS_DIR)); 274 EXPECT_FALSE(entry->Get(IS_DIR));
(...skipping 2036 matching lines...) Expand 10 before | Expand all | Expand 10 after
2299 MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID), 2311 MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID),
2300 "bob"); 2312 "bob");
2301 CHECK(entry2.good()); 2313 CHECK(entry2.good());
2302 entry2.Put(syncable::IS_DIR, true); 2314 entry2.Put(syncable::IS_DIR, true);
2303 entry2.Put(syncable::IS_UNSYNCED, true); 2315 entry2.Put(syncable::IS_UNSYNCED, true);
2304 entry2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2316 entry2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2305 } 2317 }
2306 }; 2318 };
2307 2319
2308 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { 2320 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) {
2309 directory()->set_store_birthday(mock_server_->store_birthday());
2310 { 2321 {
2311 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2322 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2312 MutableEntry entry(&trans, syncable::CREATE, trans.root_id(), 2323 MutableEntry entry(&trans, syncable::CREATE, trans.root_id(),
2313 "bob"); 2324 "bob");
2314 ASSERT_TRUE(entry.good()); 2325 ASSERT_TRUE(entry.good());
2315 entry.Put(syncable::IS_DIR, true); 2326 entry.Put(syncable::IS_DIR, true);
2316 entry.Put(syncable::IS_UNSYNCED, true); 2327 entry.Put(syncable::IS_UNSYNCED, true);
2317 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2328 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2318 } 2329 }
2319 2330
(...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after
4130 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) { 4141 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) {
4131 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS)); 4142 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS));
4132 4143
4133 syncable::Id node1 = ids_.NewServerId(); 4144 syncable::Id node1 = ids_.NewServerId();
4134 syncable::Id node2 = ids_.NewServerId(); 4145 syncable::Id node2 = ids_.NewServerId();
4135 4146
4136 // The scenario: we have two batches of updates with one update each. A 4147 // The scenario: we have two batches of updates with one update each. A
4137 // normal confgure step would download all the updates one batch at a time and 4148 // normal confgure step would download all the updates one batch at a time and
4138 // apply them. This configure will succeed in downloading the first batch 4149 // apply them. This configure will succeed in downloading the first batch
4139 // then fail when downloading the second. 4150 // then fail when downloading the second.
4140 mock_server_->FailNthPostBufferToPathCall(2); 4151 mock_server_->FailNthPostBufferToPathCall(3);
4141 4152
4142 // Construct the first GetUpdates response. 4153 // Construct the first GetUpdates response.
4143 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10); 4154 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10);
4144 mock_server_->SetChangesRemaining(1); 4155 mock_server_->SetChangesRemaining(1);
4145 mock_server_->NextUpdateBatch(); 4156 mock_server_->NextUpdateBatch();
4146 4157
4147 // Consutrct the second GetUpdates response. 4158 // Consutrct the second GetUpdates response.
4148 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20); 4159 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20);
4149 4160
4150 SyncShareConfigure(); 4161 SyncShareConfigure();
4151 4162
4152 syncable::ReadTransaction trans(FROM_HERE, directory()); 4163 syncable::ReadTransaction trans(FROM_HERE, directory());
4153 4164
4154 // The first node was downloaded, but not applied. 4165 // The first node was downloaded, but not applied.
4155 Entry n1(&trans, GET_BY_ID, node1); 4166 Entry n1(&trans, GET_BY_ID, node1);
4156 ASSERT_TRUE(n1.good()); 4167 ASSERT_TRUE(n1.good());
4157 EXPECT_TRUE(n1.Get(IS_UNAPPLIED_UPDATE)); 4168 EXPECT_TRUE(n1.Get(IS_UNAPPLIED_UPDATE));
4158 4169
4159 // The second node was not downloaded. 4170 // The second node was not downloaded.
4160 Entry n2(&trans, GET_BY_ID, node2); 4171 Entry n2(&trans, GET_BY_ID, node2);
4161 EXPECT_FALSE(n2.good()); 4172 EXPECT_FALSE(n2.good());
4162 4173
4163 // One update remains undownloaded. 4174 // One update remains undownloaded.
4164 mock_server_->ClearUpdatesQueue(); 4175 mock_server_->ClearUpdatesQueue();
4165 4176
4166 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS)); 4177 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS));
4167 } 4178 }
4168 4179
4180 TEST_F(SyncerTest, GetKeySuccess) {
4181 {
4182 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4183 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey());
4184 }
4185
4186 SyncShareConfigure();
4187
4188 EXPECT_EQ(session_->status_controller().last_get_key_result(), SYNCER_OK);
4189 {
4190 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4191 EXPECT_TRUE(cryptographer(&rtrans)->HasKeystoreKey());
4192 }
4193 }
4194
4195 TEST_F(SyncerTest, GetKeyError) {
4196 {
4197 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4198 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey());
4199 }
4200
4201 mock_server_->SetGetKeyResponseStatus(sync_pb::SyncEnums::TRANSIENT_ERROR);
4202 SyncShareConfigure();
4203
4204 EXPECT_NE(session_->status_controller().last_get_key_result(), SYNCER_OK);
4205 {
4206 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4207 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey());
4208 }
4209 }
4210
4211 TEST_F(SyncerTest, GetKeyEmpty) {
4212 {
4213 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4214 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey());
4215 }
4216
4217 mock_server_->SetKeystoreKey("");
4218 SyncShareConfigure();
4219
4220 EXPECT_NE(session_->status_controller().last_get_key_result(), SYNCER_OK);
4221 {
4222 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4223 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey());
4224 }
4225 }
4226
4169 // Test what happens if a client deletes, then recreates, an object very 4227 // 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 4228 // quickly. It is possible that the deletion gets sent as a commit, and
4171 // the undelete happens during the commit request. The principle here 4229 // the undelete happens during the commit request. The principle here
4172 // is that with a single committing client, conflicts should never 4230 // is that with a single committing client, conflicts should never
4173 // be encountered, and a client encountering its past actions during 4231 // be encountered, and a client encountering its past actions during
4174 // getupdates should never feed back to override later actions. 4232 // getupdates should never feed back to override later actions.
4175 // 4233 //
4176 // In cases of ordering A-F below, the outcome should be the same. 4234 // In cases of ordering A-F below, the outcome should be the same.
4177 // Exercised by UndeleteDuringCommit: 4235 // Exercised by UndeleteDuringCommit:
4178 // A. Delete - commit - undelete - commitresponse. 4236 // A. Delete - commit - undelete - commitresponse.
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
4823 4881
4824 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4882 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4825 Add(mid_id_); 4883 Add(mid_id_);
4826 Add(low_id_); 4884 Add(low_id_);
4827 Add(high_id_); 4885 Add(high_id_);
4828 SyncShareNudge(); 4886 SyncShareNudge();
4829 ExpectLocalOrderIsByServerId(); 4887 ExpectLocalOrderIsByServerId();
4830 } 4888 }
4831 4889
4832 } // namespace syncer 4890 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698