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

Side by Side Diff: chrome/browser/sync/engine/apply_updates_command_unittest.cc

Issue 6465005: [Sync] Initial support for encrypting any datatype (no UI hookup yet). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review Created 9 years, 10 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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 #include "chrome/browser/sync/engine/apply_updates_command.h" 5 #include "chrome/browser/sync/engine/apply_updates_command.h"
6 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" 6 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
7 #include "chrome/browser/sync/sessions/sync_session.h" 7 #include "chrome/browser/sync/sessions/sync_session.h"
8 #include "chrome/browser/sync/syncable/directory_manager.h" 8 #include "chrome/browser/sync/syncable/directory_manager.h"
9 #include "chrome/browser/sync/syncable/syncable.h" 9 #include "chrome/browser/sync/syncable/syncable.h"
10 #include "chrome/browser/sync/syncable/syncable_id.h" 10 #include "chrome/browser/sync/syncable/syncable_id.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); 248 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
249 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize()) 249 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize())
250 << "All updates should have been attempted"; 250 << "All updates should have been attempted";
251 EXPECT_EQ(1, status->conflict_progress().ConflictingItemsSize()) 251 EXPECT_EQ(1, status->conflict_progress().ConflictingItemsSize())
252 << "The decryptable password update should be applied"; 252 << "The decryptable password update should be applied";
253 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) 253 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount())
254 << "The undecryptable password update shouldn't be applied"; 254 << "The undecryptable password update shouldn't be applied";
255 } 255 }
256 256
257 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { 257 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) {
258 syncable::ModelTypeSet encrypted_types;
259 {
260 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
261 ASSERT_TRUE(dir.good());
262 ReadTransaction trans(dir, __FILE__, __LINE__);
263 EXPECT_EQ(encrypted_types, trans.GetEncryptedDatatypes());
264 }
265
258 // Nigori node updates should update the Cryptographer. 266 // Nigori node updates should update the Cryptographer.
259 Cryptographer other_cryptographer; 267 Cryptographer other_cryptographer;
260 KeyParams params = {"localhost", "dummy", "foobar"}; 268 KeyParams params = {"localhost", "dummy", "foobar"};
261 other_cryptographer.AddKey(params); 269 other_cryptographer.AddKey(params);
262 270
263 sync_pb::EntitySpecifics specifics; 271 sync_pb::EntitySpecifics specifics;
264 other_cryptographer.GetKeys( 272 sync_pb::NigoriSpecifics* nigori =
265 specifics.MutableExtension(sync_pb::nigori)->mutable_encrypted()); 273 specifics.MutableExtension(sync_pb::nigori);
274 other_cryptographer.GetKeys(nigori->mutable_encrypted());
275 nigori->set_encrypt_bookmarks(true);
276 encrypted_types.insert(syncable::BOOKMARKS);
277 encrypted_types.insert(syncable::PASSWORDS); // Will get set by default.
266 278
267 CreateUnappliedNewItem("item", specifics); 279 CreateUnappliedNewItem("item", specifics);
268 280
269 Cryptographer* cryptographer = 281 Cryptographer* cryptographer =
270 session()->context()->directory_manager()->cryptographer(); 282 session()->context()->directory_manager()->cryptographer();
271 EXPECT_FALSE(cryptographer->has_pending_keys()); 283 EXPECT_FALSE(cryptographer->has_pending_keys());
272 284
273 apply_updates_command_.ExecuteImpl(session()); 285 apply_updates_command_.ExecuteImpl(session());
274 286
275 sessions::StatusController* status = session()->status_controller(); 287 sessions::StatusController* status = session()->status_controller();
276 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); 288 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
277 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) 289 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize())
278 << "All updates should have been attempted"; 290 << "All updates should have been attempted";
279 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) 291 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize())
280 << "The nigori update shouldn't be in conflict"; 292 << "The nigori update shouldn't be in conflict";
281 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) 293 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount())
282 << "The nigori update should be applied"; 294 << "The nigori update should be applied";
283 295
284 EXPECT_FALSE(cryptographer->is_ready()); 296 EXPECT_FALSE(cryptographer->is_ready());
285 EXPECT_TRUE(cryptographer->has_pending_keys()); 297 EXPECT_TRUE(cryptographer->has_pending_keys());
286 } 298 }
287 299
300 TEST_F(ApplyUpdatesCommandTest, NigoriUpdateWithUnsyncedChange) {
301 syncable::ModelTypeSet encrypted_types;
302 {
303 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
304 ASSERT_TRUE(dir.good());
305 ReadTransaction trans(dir, __FILE__, __LINE__);
306 EXPECT_EQ(encrypted_types, trans.GetEncryptedDatatypes());
307 }
308
309 // Create an unapplied bookmark node without encryption.
310 string root_server_id = syncable::kNullId.GetServerId();
311 CreateUnappliedNewItemWithParent("parent", root_server_id);
312
313 // Nigori node updates should update the Cryptographer.
314 Cryptographer other_cryptographer;
315 KeyParams params = {"localhost", "dummy", "foobar"};
316 other_cryptographer.AddKey(params);
317
318 sync_pb::EntitySpecifics specifics;
319 sync_pb::NigoriSpecifics* nigori =
320 specifics.MutableExtension(sync_pb::nigori);
321 other_cryptographer.GetKeys(nigori->mutable_encrypted());
322 nigori->set_encrypt_bookmarks(true);
323 encrypted_types.insert(syncable::BOOKMARKS);
324 encrypted_types.insert(syncable::PASSWORDS); // Will get set by default.
325
326 CreateUnappliedNewItem("item", specifics);
327
328 Cryptographer* cryptographer =
329 session()->context()->directory_manager()->cryptographer();
330 EXPECT_FALSE(cryptographer->has_pending_keys());
331
332 apply_updates_command_.ExecuteImpl(session());
333
334 sessions::StatusController* status = session()->status_controller();
335 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
336 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize())
337 << "All updates should have been attempted";
338 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize())
339 << "The nigori update shouldn't be in conflict";
340 EXPECT_EQ(2, status->update_progress().SuccessfullyAppliedUpdateCount())
341 << "The nigori update should be applied";
342
343 EXPECT_FALSE(cryptographer->is_ready());
344 EXPECT_TRUE(cryptographer->has_pending_keys());
345 }
346
288 } // namespace browser_sync 347 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/engine/change_reorder_buffer.h » ('j') | chrome/browser/sync/engine/syncapi.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698