| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/tracked.h" |
| 9 #include "chrome/browser/sync/engine/apply_updates_command.h" | 10 #include "chrome/browser/sync/engine/apply_updates_command.h" |
| 10 #include "chrome/browser/sync/engine/syncer.h" | 11 #include "chrome/browser/sync/engine/syncer.h" |
| 11 #include "chrome/browser/sync/engine/syncer_util.h" | 12 #include "chrome/browser/sync/engine/syncer_util.h" |
| 12 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 13 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 13 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 14 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 14 #include "chrome/browser/sync/sessions/sync_session.h" | 15 #include "chrome/browser/sync/sessions/sync_session.h" |
| 15 #include "chrome/browser/sync/syncable/directory_manager.h" | 16 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 16 #include "chrome/browser/sync/syncable/nigori_util.h" | 17 #include "chrome/browser/sync/syncable/nigori_util.h" |
| 17 #include "chrome/browser/sync/syncable/syncable.h" | 18 #include "chrome/browser/sync/syncable/syncable.h" |
| 18 #include "chrome/browser/sync/syncable/syncable_id.h" | 19 #include "chrome/browser/sync/syncable/syncable_id.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 48 (*mutable_routing_info())[syncable::PASSWORDS] = GROUP_PASSIVE; | 49 (*mutable_routing_info())[syncable::PASSWORDS] = GROUP_PASSIVE; |
| 49 (*mutable_routing_info())[syncable::NIGORI] = GROUP_PASSIVE; | 50 (*mutable_routing_info())[syncable::NIGORI] = GROUP_PASSIVE; |
| 50 SyncerCommandTest::SetUp(); | 51 SyncerCommandTest::SetUp(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Create a new unapplied bookmark node with a parent. | 54 // Create a new unapplied bookmark node with a parent. |
| 54 void CreateUnappliedNewItemWithParent(const string& item_id, | 55 void CreateUnappliedNewItemWithParent(const string& item_id, |
| 55 const string& parent_id) { | 56 const string& parent_id) { |
| 56 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 57 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 57 ASSERT_TRUE(dir.good()); | 58 ASSERT_TRUE(dir.good()); |
| 58 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 59 WriteTransaction trans(dir, UNITTEST, FROM_HERE); |
| 59 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 60 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 60 Id::CreateFromServerId(item_id)); | 61 Id::CreateFromServerId(item_id)); |
| 61 ASSERT_TRUE(entry.good()); | 62 ASSERT_TRUE(entry.good()); |
| 62 entry.Put(syncable::SERVER_VERSION, next_revision_++); | 63 entry.Put(syncable::SERVER_VERSION, next_revision_++); |
| 63 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 64 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
| 64 | 65 |
| 65 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); | 66 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); |
| 66 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id)); | 67 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id)); |
| 67 entry.Put(syncable::SERVER_IS_DIR, true); | 68 entry.Put(syncable::SERVER_IS_DIR, true); |
| 68 sync_pb::EntitySpecifics default_bookmark_specifics; | 69 sync_pb::EntitySpecifics default_bookmark_specifics; |
| 69 default_bookmark_specifics.MutableExtension(sync_pb::bookmark); | 70 default_bookmark_specifics.MutableExtension(sync_pb::bookmark); |
| 70 entry.Put(syncable::SERVER_SPECIFICS, default_bookmark_specifics); | 71 entry.Put(syncable::SERVER_SPECIFICS, default_bookmark_specifics); |
| 71 } | 72 } |
| 72 | 73 |
| 73 // Create a new unapplied update without a parent. | 74 // Create a new unapplied update without a parent. |
| 74 void CreateUnappliedNewItem(const string& item_id, | 75 void CreateUnappliedNewItem(const string& item_id, |
| 75 const sync_pb::EntitySpecifics& specifics, | 76 const sync_pb::EntitySpecifics& specifics, |
| 76 bool is_unique) { | 77 bool is_unique) { |
| 77 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 78 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 78 ASSERT_TRUE(dir.good()); | 79 ASSERT_TRUE(dir.good()); |
| 79 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 80 WriteTransaction trans(dir, UNITTEST, FROM_HERE); |
| 80 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 81 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 81 Id::CreateFromServerId(item_id)); | 82 Id::CreateFromServerId(item_id)); |
| 82 ASSERT_TRUE(entry.good()); | 83 ASSERT_TRUE(entry.good()); |
| 83 entry.Put(syncable::SERVER_VERSION, next_revision_++); | 84 entry.Put(syncable::SERVER_VERSION, next_revision_++); |
| 84 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 85 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
| 85 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); | 86 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); |
| 86 entry.Put(syncable::SERVER_PARENT_ID, syncable::kNullId); | 87 entry.Put(syncable::SERVER_PARENT_ID, syncable::kNullId); |
| 87 entry.Put(syncable::SERVER_IS_DIR, false); | 88 entry.Put(syncable::SERVER_IS_DIR, false); |
| 88 entry.Put(syncable::SERVER_SPECIFICS, specifics); | 89 entry.Put(syncable::SERVER_SPECIFICS, specifics); |
| 89 if (is_unique) // For top-level nodes. | 90 if (is_unique) // For top-level nodes. |
| 90 entry.Put(syncable::UNIQUE_SERVER_TAG, item_id); | 91 entry.Put(syncable::UNIQUE_SERVER_TAG, item_id); |
| 91 } | 92 } |
| 92 | 93 |
| 93 // Create an unsynced item in the database. If item_id is a local ID, it | 94 // Create an unsynced item in the database. If item_id is a local ID, it |
| 94 // will be treated as a create-new. Otherwise, if it's a server ID, we'll | 95 // will be treated as a create-new. Otherwise, if it's a server ID, we'll |
| 95 // fake the server data so that it looks like it exists on the server. | 96 // fake the server data so that it looks like it exists on the server. |
| 96 // Returns the methandle of the created item in |metahandle_out| if not NULL. | 97 // Returns the methandle of the created item in |metahandle_out| if not NULL. |
| 97 void CreateUnsyncedItem(const Id& item_id, | 98 void CreateUnsyncedItem(const Id& item_id, |
| 98 const Id& parent_id, | 99 const Id& parent_id, |
| 99 const string& name, | 100 const string& name, |
| 100 bool is_folder, | 101 bool is_folder, |
| 101 syncable::ModelType model_type, | 102 syncable::ModelType model_type, |
| 102 int64* metahandle_out) { | 103 int64* metahandle_out) { |
| 103 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 104 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 104 ASSERT_TRUE(dir.good()); | 105 ASSERT_TRUE(dir.good()); |
| 105 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 106 WriteTransaction trans(dir, UNITTEST, FROM_HERE); |
| 106 Id predecessor_id = dir->GetLastChildId(&trans, parent_id); | 107 Id predecessor_id = dir->GetLastChildId(&trans, parent_id); |
| 107 MutableEntry entry(&trans, syncable::CREATE, parent_id, name); | 108 MutableEntry entry(&trans, syncable::CREATE, parent_id, name); |
| 108 ASSERT_TRUE(entry.good()); | 109 ASSERT_TRUE(entry.good()); |
| 109 entry.Put(syncable::ID, item_id); | 110 entry.Put(syncable::ID, item_id); |
| 110 entry.Put(syncable::BASE_VERSION, | 111 entry.Put(syncable::BASE_VERSION, |
| 111 item_id.ServerKnows() ? next_revision_++ : 0); | 112 item_id.ServerKnows() ? next_revision_++ : 0); |
| 112 entry.Put(syncable::IS_UNSYNCED, true); | 113 entry.Put(syncable::IS_UNSYNCED, true); |
| 113 entry.Put(syncable::IS_DIR, is_folder); | 114 entry.Put(syncable::IS_DIR, is_folder); |
| 114 entry.Put(syncable::IS_DEL, false); | 115 entry.Put(syncable::IS_DEL, false); |
| 115 entry.Put(syncable::PARENT_ID, parent_id); | 116 entry.Put(syncable::PARENT_ID, parent_id); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 215 } |
| 215 | 216 |
| 216 TEST_F(ApplyUpdatesCommandTest, DecryptablePassword) { | 217 TEST_F(ApplyUpdatesCommandTest, DecryptablePassword) { |
| 217 // Decryptable password updates should be applied. | 218 // Decryptable password updates should be applied. |
| 218 Cryptographer* cryptographer; | 219 Cryptographer* cryptographer; |
| 219 { | 220 { |
| 220 // Storing the cryptographer separately is bad, but for this test we | 221 // Storing the cryptographer separately is bad, but for this test we |
| 221 // know it's safe. | 222 // know it's safe. |
| 222 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 223 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 223 ASSERT_TRUE(dir.good()); | 224 ASSERT_TRUE(dir.good()); |
| 224 ReadTransaction trans(dir, __FILE__, __LINE__); | 225 ReadTransaction trans(dir, FROM_HERE); |
| 225 cryptographer = | 226 cryptographer = |
| 226 session()->context()->directory_manager()->GetCryptographer(&trans); | 227 session()->context()->directory_manager()->GetCryptographer(&trans); |
| 227 } | 228 } |
| 228 | 229 |
| 229 browser_sync::KeyParams params = {"localhost", "dummy", "foobar"}; | 230 browser_sync::KeyParams params = {"localhost", "dummy", "foobar"}; |
| 230 cryptographer->AddKey(params); | 231 cryptographer->AddKey(params); |
| 231 | 232 |
| 232 sync_pb::EntitySpecifics specifics; | 233 sync_pb::EntitySpecifics specifics; |
| 233 sync_pb::PasswordSpecificsData data; | 234 sync_pb::PasswordSpecificsData data; |
| 234 data.set_origin("http://example.com"); | 235 data.set_origin("http://example.com"); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 279 |
| 279 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) { | 280 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) { |
| 280 // Only decryptable password updates should be applied. | 281 // Only decryptable password updates should be applied. |
| 281 { | 282 { |
| 282 sync_pb::EntitySpecifics specifics; | 283 sync_pb::EntitySpecifics specifics; |
| 283 sync_pb::PasswordSpecificsData data; | 284 sync_pb::PasswordSpecificsData data; |
| 284 data.set_origin("http://example.com/1"); | 285 data.set_origin("http://example.com/1"); |
| 285 { | 286 { |
| 286 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 287 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 287 ASSERT_TRUE(dir.good()); | 288 ASSERT_TRUE(dir.good()); |
| 288 ReadTransaction trans(dir, __FILE__, __LINE__); | 289 ReadTransaction trans(dir, FROM_HERE); |
| 289 Cryptographer* cryptographer = | 290 Cryptographer* cryptographer = |
| 290 session()->context()->directory_manager()->GetCryptographer(&trans); | 291 session()->context()->directory_manager()->GetCryptographer(&trans); |
| 291 | 292 |
| 292 KeyParams params = {"localhost", "dummy", "foobar"}; | 293 KeyParams params = {"localhost", "dummy", "foobar"}; |
| 293 cryptographer->AddKey(params); | 294 cryptographer->AddKey(params); |
| 294 | 295 |
| 295 cryptographer->Encrypt(data, | 296 cryptographer->Encrypt(data, |
| 296 specifics.MutableExtension(sync_pb::password)->mutable_encrypted()); | 297 specifics.MutableExtension(sync_pb::password)->mutable_encrypted()); |
| 297 } | 298 } |
| 298 CreateUnappliedNewItem("item1", specifics, false); | 299 CreateUnappliedNewItem("item1", specifics, false); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 | 336 |
| 336 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { | 337 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { |
| 337 // Storing the cryptographer separately is bad, but for this test we | 338 // Storing the cryptographer separately is bad, but for this test we |
| 338 // know it's safe. | 339 // know it's safe. |
| 339 Cryptographer* cryptographer; | 340 Cryptographer* cryptographer; |
| 340 syncable::ModelTypeSet encrypted_types; | 341 syncable::ModelTypeSet encrypted_types; |
| 341 encrypted_types.insert(syncable::PASSWORDS); | 342 encrypted_types.insert(syncable::PASSWORDS); |
| 342 { | 343 { |
| 343 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 344 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 344 ASSERT_TRUE(dir.good()); | 345 ASSERT_TRUE(dir.good()); |
| 345 ReadTransaction trans(dir, __FILE__, __LINE__); | 346 ReadTransaction trans(dir, FROM_HERE); |
| 346 cryptographer = | 347 cryptographer = |
| 347 session()->context()->directory_manager()->GetCryptographer(&trans); | 348 session()->context()->directory_manager()->GetCryptographer(&trans); |
| 348 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); | 349 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); |
| 349 } | 350 } |
| 350 | 351 |
| 351 // Nigori node updates should update the Cryptographer. | 352 // Nigori node updates should update the Cryptographer. |
| 352 Cryptographer other_cryptographer; | 353 Cryptographer other_cryptographer; |
| 353 KeyParams params = {"localhost", "dummy", "foobar"}; | 354 KeyParams params = {"localhost", "dummy", "foobar"}; |
| 354 other_cryptographer.AddKey(params); | 355 other_cryptographer.AddKey(params); |
| 355 | 356 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 380 | 381 |
| 381 TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { | 382 TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { |
| 382 // Storing the cryptographer separately is bad, but for this test we | 383 // Storing the cryptographer separately is bad, but for this test we |
| 383 // know it's safe. | 384 // know it's safe. |
| 384 Cryptographer* cryptographer; | 385 Cryptographer* cryptographer; |
| 385 syncable::ModelTypeSet encrypted_types; | 386 syncable::ModelTypeSet encrypted_types; |
| 386 encrypted_types.insert(syncable::PASSWORDS); | 387 encrypted_types.insert(syncable::PASSWORDS); |
| 387 { | 388 { |
| 388 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 389 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 389 ASSERT_TRUE(dir.good()); | 390 ASSERT_TRUE(dir.good()); |
| 390 ReadTransaction trans(dir, __FILE__, __LINE__); | 391 ReadTransaction trans(dir, FROM_HERE); |
| 391 cryptographer = | 392 cryptographer = |
| 392 session()->context()->directory_manager()->GetCryptographer(&trans); | 393 session()->context()->directory_manager()->GetCryptographer(&trans); |
| 393 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); | 394 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); |
| 394 | 395 |
| 395 | 396 |
| 396 // With default encrypted_types, this should be true. | 397 // With default encrypted_types, this should be true. |
| 397 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 398 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| 398 | 399 |
| 399 Syncer::UnsyncedMetaHandles handles; | 400 Syncer::UnsyncedMetaHandles handles; |
| 400 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 401 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 431 encrypted_types.insert(syncable::BOOKMARKS); | 432 encrypted_types.insert(syncable::BOOKMARKS); |
| 432 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), | 433 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), |
| 433 specifics, true); | 434 specifics, true); |
| 434 EXPECT_FALSE(cryptographer->has_pending_keys()); | 435 EXPECT_FALSE(cryptographer->has_pending_keys()); |
| 435 EXPECT_TRUE(cryptographer->is_ready()); | 436 EXPECT_TRUE(cryptographer->is_ready()); |
| 436 | 437 |
| 437 { | 438 { |
| 438 // Ensure we have unsynced nodes that aren't properly encrypted. | 439 // Ensure we have unsynced nodes that aren't properly encrypted. |
| 439 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 440 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 440 ASSERT_TRUE(dir.good()); | 441 ASSERT_TRUE(dir.good()); |
| 441 ReadTransaction trans(dir, __FILE__, __LINE__); | 442 ReadTransaction trans(dir, FROM_HERE); |
| 442 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 443 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| 443 | 444 |
| 444 Syncer::UnsyncedMetaHandles handles; | 445 Syncer::UnsyncedMetaHandles handles; |
| 445 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 446 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| 446 EXPECT_EQ(2*batch_s+1, handles.size()); | 447 EXPECT_EQ(2*batch_s+1, handles.size()); |
| 447 } | 448 } |
| 448 | 449 |
| 449 apply_updates_command_.ExecuteImpl(session()); | 450 apply_updates_command_.ExecuteImpl(session()); |
| 450 | 451 |
| 451 sessions::StatusController* status = session()->status_controller(); | 452 sessions::StatusController* status = session()->status_controller(); |
| 452 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 453 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
| 453 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) | 454 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) |
| 454 << "All updates should have been attempted"; | 455 << "All updates should have been attempted"; |
| 455 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 456 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) |
| 456 << "No updates should be in conflict"; | 457 << "No updates should be in conflict"; |
| 457 EXPECT_EQ(0, status->conflict_progress().NonblockingConflictingItemsSize()) | 458 EXPECT_EQ(0, status->conflict_progress().NonblockingConflictingItemsSize()) |
| 458 << "No updates should be in conflict"; | 459 << "No updates should be in conflict"; |
| 459 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) | 460 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) |
| 460 << "The nigori update should be applied"; | 461 << "The nigori update should be applied"; |
| 461 EXPECT_FALSE(cryptographer->has_pending_keys()); | 462 EXPECT_FALSE(cryptographer->has_pending_keys()); |
| 462 EXPECT_TRUE(cryptographer->is_ready()); | 463 EXPECT_TRUE(cryptographer->is_ready()); |
| 463 { | 464 { |
| 464 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 465 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 465 ASSERT_TRUE(dir.good()); | 466 ASSERT_TRUE(dir.good()); |
| 466 ReadTransaction trans(dir, __FILE__, __LINE__); | 467 ReadTransaction trans(dir, FROM_HERE); |
| 467 | 468 |
| 468 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes | 469 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes |
| 469 // should be encrypted now. | 470 // should be encrypted now. |
| 470 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); | 471 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); |
| 471 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 472 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| 472 | 473 |
| 473 Syncer::UnsyncedMetaHandles handles; | 474 Syncer::UnsyncedMetaHandles handles; |
| 474 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 475 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| 475 EXPECT_EQ(2*batch_s+1, handles.size()); | 476 EXPECT_EQ(2*batch_s+1, handles.size()); |
| 476 } | 477 } |
| 477 } | 478 } |
| 478 | 479 |
| 479 TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { | 480 TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { |
| 480 // Storing the cryptographer separately is bad, but for this test we | 481 // Storing the cryptographer separately is bad, but for this test we |
| 481 // know it's safe. | 482 // know it's safe. |
| 482 Cryptographer* cryptographer; | 483 Cryptographer* cryptographer; |
| 483 syncable::ModelTypeSet encrypted_types; | 484 syncable::ModelTypeSet encrypted_types; |
| 484 encrypted_types.insert(syncable::PASSWORDS); | 485 encrypted_types.insert(syncable::PASSWORDS); |
| 485 { | 486 { |
| 486 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 487 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 487 ASSERT_TRUE(dir.good()); | 488 ASSERT_TRUE(dir.good()); |
| 488 ReadTransaction trans(dir, __FILE__, __LINE__); | 489 ReadTransaction trans(dir, FROM_HERE); |
| 489 cryptographer = | 490 cryptographer = |
| 490 session()->context()->directory_manager()->GetCryptographer(&trans); | 491 session()->context()->directory_manager()->GetCryptographer(&trans); |
| 491 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); | 492 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); |
| 492 | 493 |
| 493 | 494 |
| 494 // With default encrypted_types, this should be true. | 495 // With default encrypted_types, this should be true. |
| 495 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 496 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| 496 | 497 |
| 497 Syncer::UnsyncedMetaHandles handles; | 498 Syncer::UnsyncedMetaHandles handles; |
| 498 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 499 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 nigori->set_encrypt_bookmarks(true); | 532 nigori->set_encrypt_bookmarks(true); |
| 532 encrypted_types.insert(syncable::BOOKMARKS); | 533 encrypted_types.insert(syncable::BOOKMARKS); |
| 533 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), | 534 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), |
| 534 specifics, true); | 535 specifics, true); |
| 535 EXPECT_FALSE(cryptographer->has_pending_keys()); | 536 EXPECT_FALSE(cryptographer->has_pending_keys()); |
| 536 | 537 |
| 537 { | 538 { |
| 538 // Ensure we have unsynced nodes that aren't properly encrypted. | 539 // Ensure we have unsynced nodes that aren't properly encrypted. |
| 539 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 540 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 540 ASSERT_TRUE(dir.good()); | 541 ASSERT_TRUE(dir.good()); |
| 541 ReadTransaction trans(dir, __FILE__, __LINE__); | 542 ReadTransaction trans(dir, FROM_HERE); |
| 542 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 543 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| 543 Syncer::UnsyncedMetaHandles handles; | 544 Syncer::UnsyncedMetaHandles handles; |
| 544 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 545 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| 545 EXPECT_EQ(2*batch_s+1, handles.size()); | 546 EXPECT_EQ(2*batch_s+1, handles.size()); |
| 546 } | 547 } |
| 547 | 548 |
| 548 apply_updates_command_.ExecuteImpl(session()); | 549 apply_updates_command_.ExecuteImpl(session()); |
| 549 | 550 |
| 550 sessions::StatusController* status = session()->status_controller(); | 551 sessions::StatusController* status = session()->status_controller(); |
| 551 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 552 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
| 552 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) | 553 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) |
| 553 << "All updates should have been attempted"; | 554 << "All updates should have been attempted"; |
| 554 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 555 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) |
| 555 << "The unsynced changes don't trigger a blocking conflict with the " | 556 << "The unsynced changes don't trigger a blocking conflict with the " |
| 556 << "nigori update."; | 557 << "nigori update."; |
| 557 EXPECT_EQ(1, status->conflict_progress().NonblockingConflictingItemsSize()) | 558 EXPECT_EQ(1, status->conflict_progress().NonblockingConflictingItemsSize()) |
| 558 << "The unsynced changes trigger a non-blocking conflict with the " | 559 << "The unsynced changes trigger a non-blocking conflict with the " |
| 559 << "nigori update."; | 560 << "nigori update."; |
| 560 EXPECT_EQ(0, status->update_progress().SuccessfullyAppliedUpdateCount()) | 561 EXPECT_EQ(0, status->update_progress().SuccessfullyAppliedUpdateCount()) |
| 561 << "The nigori update should not be applied"; | 562 << "The nigori update should not be applied"; |
| 562 EXPECT_FALSE(cryptographer->is_ready()); | 563 EXPECT_FALSE(cryptographer->is_ready()); |
| 563 EXPECT_TRUE(cryptographer->has_pending_keys()); | 564 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 564 { | 565 { |
| 565 // Ensure the unsynced nodes are still not encrypted. | 566 // Ensure the unsynced nodes are still not encrypted. |
| 566 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 567 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 567 ASSERT_TRUE(dir.good()); | 568 ASSERT_TRUE(dir.good()); |
| 568 ReadTransaction trans(dir, __FILE__, __LINE__); | 569 ReadTransaction trans(dir, FROM_HERE); |
| 569 | 570 |
| 570 // Since we're in conflict, the specifics don't reflect the unapplied | 571 // Since we're in conflict, the specifics don't reflect the unapplied |
| 571 // changes. | 572 // changes. |
| 572 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 573 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| 573 encrypted_types.clear(); | 574 encrypted_types.clear(); |
| 574 encrypted_types.insert(syncable::PASSWORDS); | 575 encrypted_types.insert(syncable::PASSWORDS); |
| 575 encrypted_types.insert(syncable::BOOKMARKS); | 576 encrypted_types.insert(syncable::BOOKMARKS); |
| 576 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); | 577 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); |
| 577 | 578 |
| 578 Syncer::UnsyncedMetaHandles handles; | 579 Syncer::UnsyncedMetaHandles handles; |
| 579 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 580 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| 580 EXPECT_EQ(2*batch_s+1, handles.size()); | 581 EXPECT_EQ(2*batch_s+1, handles.size()); |
| 581 } | 582 } |
| 582 } | 583 } |
| 583 | 584 |
| 584 } // namespace browser_sync | 585 } // namespace browser_sync |
| OLD | NEW |