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

Unified Diff: sync/engine/apply_updates_command_unittest.cc

Issue 10559104: sync: Process 'control' data separately (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename, cleanup, fix tests Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/engine/apply_updates_command.cc ('k') | sync/engine/conflict_resolver.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/engine/apply_updates_command_unittest.cc
diff --git a/sync/engine/apply_updates_command_unittest.cc b/sync/engine/apply_updates_command_unittest.cc
index f334bf11924d9e2f054ddc6b0a74b9cd1fa4d835..5487243e055dc4a29ae5d4f7989e221dd6380142 100644
--- a/sync/engine/apply_updates_command_unittest.cc
+++ b/sync/engine/apply_updates_command_unittest.cc
@@ -4,16 +4,13 @@
#include <string>
-#include "base/format_macros.h"
#include "base/location.h"
-#include "base/stringprintf.h"
+#include "base/memory/scoped_ptr.h"
#include "sync/engine/apply_updates_command.h"
-#include "sync/engine/nigori_util.h"
#include "sync/engine/syncer.h"
#include "sync/engine/syncer_util.h"
#include "sync/protocol/bookmark_specifics.pb.h"
#include "sync/protocol/password_specifics.pb.h"
-#include "sync/sessions/sync_session.h"
#include "sync/syncable/mutable_entry.h"
#include "sync/syncable/read_transaction.h"
#include "sync/syncable/syncable_id.h"
@@ -22,12 +19,12 @@
#include "sync/test/engine/syncer_command_test.h"
#include "sync/test/engine/test_id_factory.h"
#include "sync/test/fake_encryptor.h"
+#include "sync/test/test_entry_factory.h"
#include "sync/util/cryptographer.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace csync {
-using sessions::SyncSession;
using std::string;
using syncable::Id;
using syncable::MutableEntry;
@@ -46,7 +43,7 @@ sync_pb::EntitySpecifics DefaultBookmarkSpecifics() {
class ApplyUpdatesCommandTest : public SyncerCommandTest {
public:
protected:
- ApplyUpdatesCommandTest() : next_revision_(1) {}
+ ApplyUpdatesCommandTest() {}
virtual ~ApplyUpdatesCommandTest() {}
virtual void SetUp() {
@@ -58,172 +55,27 @@ class ApplyUpdatesCommandTest : public SyncerCommandTest {
make_scoped_refptr(new FakeModelWorker(GROUP_PASSWORD)));
(*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_UI;
(*mutable_routing_info())[syncable::PASSWORDS] = GROUP_PASSWORD;
- (*mutable_routing_info())[syncable::NIGORI] = GROUP_PASSIVE;
+ (*mutable_routing_info())[syncable::NIGORI] = GROUP_CONTROL;
SyncerCommandTest::SetUp();
+ entry_factory_.reset(new TestEntryFactory(directory()));
ExpectNoGroupsToChange(apply_updates_command_);
}
- // Create a new unapplied folder node with a parent.
- void CreateUnappliedNewItemWithParent(
- const string& item_id,
- const sync_pb::EntitySpecifics& specifics,
- const string& parent_id) {
- WriteTransaction trans(FROM_HERE, UNITTEST, directory());
- MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
- Id::CreateFromServerId(item_id));
- ASSERT_TRUE(entry.good());
- entry.Put(syncable::SERVER_VERSION, next_revision_++);
- entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
-
- entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id);
- entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id));
- entry.Put(syncable::SERVER_IS_DIR, true);
- entry.Put(syncable::SERVER_SPECIFICS, specifics);
- }
-
- // Create a new unapplied update without a parent.
- void CreateUnappliedNewItem(const string& item_id,
- const sync_pb::EntitySpecifics& specifics,
- bool is_unique) {
- WriteTransaction trans(FROM_HERE, UNITTEST, directory());
- MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
- Id::CreateFromServerId(item_id));
- ASSERT_TRUE(entry.good());
- entry.Put(syncable::SERVER_VERSION, next_revision_++);
- entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
- entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id);
- entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId());
- entry.Put(syncable::SERVER_IS_DIR, false);
- entry.Put(syncable::SERVER_SPECIFICS, specifics);
- if (is_unique) // For top-level nodes.
- entry.Put(syncable::UNIQUE_SERVER_TAG, item_id);
- }
-
- // Create an unsynced item in the database. If item_id is a local ID, it
- // will be treated as a create-new. Otherwise, if it's a server ID, we'll
- // fake the server data so that it looks like it exists on the server.
- // Returns the methandle of the created item in |metahandle_out| if not NULL.
- void CreateUnsyncedItem(const Id& item_id,
- const Id& parent_id,
- const string& name,
- bool is_folder,
- syncable::ModelType model_type,
- int64* metahandle_out) {
- WriteTransaction trans(FROM_HERE, UNITTEST, directory());
- Id predecessor_id;
- ASSERT_TRUE(
- directory()->GetLastChildIdForTest(&trans, parent_id, &predecessor_id));
- MutableEntry entry(&trans, syncable::CREATE, parent_id, name);
- ASSERT_TRUE(entry.good());
- entry.Put(syncable::ID, item_id);
- entry.Put(syncable::BASE_VERSION,
- item_id.ServerKnows() ? next_revision_++ : 0);
- entry.Put(syncable::IS_UNSYNCED, true);
- entry.Put(syncable::IS_DIR, is_folder);
- entry.Put(syncable::IS_DEL, false);
- entry.Put(syncable::PARENT_ID, parent_id);
- CHECK(entry.PutPredecessor(predecessor_id));
- sync_pb::EntitySpecifics default_specifics;
- syncable::AddDefaultFieldValue(model_type, &default_specifics);
- entry.Put(syncable::SPECIFICS, default_specifics);
- if (item_id.ServerKnows()) {
- entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
- entry.Put(syncable::SERVER_IS_DIR, is_folder);
- entry.Put(syncable::SERVER_PARENT_ID, parent_id);
- entry.Put(syncable::SERVER_IS_DEL, false);
- }
- if (metahandle_out)
- *metahandle_out = entry.Get(syncable::META_HANDLE);
- }
-
- // Creates an item that is both unsynced an an unapplied update. Returns the
- // metahandle of the created item.
- int64 CreateUnappliedAndUnsyncedItem(const string& name,
- syncable::ModelType model_type) {
- int64 metahandle = 0;
- CreateUnsyncedItem(id_factory_.MakeServer(name), id_factory_.root(), name,
- false, model_type, &metahandle);
-
- WriteTransaction trans(FROM_HERE, UNITTEST, directory());
- MutableEntry entry(&trans, syncable::GET_BY_HANDLE, metahandle);
- if (!entry.good()) {
- ADD_FAILURE();
- return syncable::kInvalidMetaHandle;
- }
-
- entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
- entry.Put(syncable::SERVER_VERSION, GetNextRevision());
-
- return metahandle;
- }
-
-
- // Creates an item that has neither IS_UNSYNED or IS_UNAPPLIED_UPDATE. The
- // item is known to both the server and client. Returns the metahandle of
- // the created item.
- int64 CreateSyncedItem(const std::string& name, syncable::ModelType
- model_type, bool is_folder) {
- WriteTransaction trans(FROM_HERE, UNITTEST, directory());
-
- syncable::Id parent_id(id_factory_.root());
- syncable::Id item_id(id_factory_.MakeServer(name));
- int64 version = GetNextRevision();
-
- sync_pb::EntitySpecifics default_specifics;
- syncable::AddDefaultFieldValue(model_type, &default_specifics);
-
- MutableEntry entry(&trans, syncable::CREATE, parent_id, name);
- if (!entry.good()) {
- ADD_FAILURE();
- return syncable::kInvalidMetaHandle;
- }
-
- entry.Put(syncable::ID, item_id);
- entry.Put(syncable::BASE_VERSION, version);
- entry.Put(syncable::IS_UNSYNCED, false);
- entry.Put(syncable::NON_UNIQUE_NAME, name);
- entry.Put(syncable::IS_DIR, is_folder);
- entry.Put(syncable::IS_DEL, false);
- entry.Put(syncable::PARENT_ID, parent_id);
-
- if (!entry.PutPredecessor(id_factory_.root())) {
- ADD_FAILURE();
- return syncable::kInvalidMetaHandle;
- }
- entry.Put(syncable::SPECIFICS, default_specifics);
-
- entry.Put(syncable::SERVER_VERSION, GetNextRevision());
- entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
- entry.Put(syncable::SERVER_NON_UNIQUE_NAME, "X");
- entry.Put(syncable::SERVER_PARENT_ID, id_factory_.MakeServer("Y"));
- entry.Put(syncable::SERVER_IS_DIR, is_folder);
- entry.Put(syncable::SERVER_IS_DEL, false);
- entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
- entry.Put(syncable::SERVER_PARENT_ID, parent_id);
-
- return entry.Get(syncable::META_HANDLE);
- }
-
- int64 GetNextRevision() {
- return next_revision_++;
- }
-
ApplyUpdatesCommand apply_updates_command_;
FakeEncryptor encryptor_;
- TestIdFactory id_factory_;
+ scoped_ptr<TestEntryFactory> entry_factory_;
private:
- int64 next_revision_;
DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesCommandTest);
};
TEST_F(ApplyUpdatesCommandTest, Simple) {
string root_server_id = syncable::GetNullId().GetServerId();
- CreateUnappliedNewItemWithParent("parent",
- DefaultBookmarkSpecifics(),
- root_server_id);
- CreateUnappliedNewItemWithParent("child",
- DefaultBookmarkSpecifics(),
- "parent");
+ entry_factory_->CreateUnappliedNewItemWithParent("parent",
+ DefaultBookmarkSpecifics(),
+ root_server_id);
+ entry_factory_->CreateUnappliedNewItemWithParent("child",
+ DefaultBookmarkSpecifics(),
+ "parent");
ExpectGroupToChange(apply_updates_command_, GROUP_UI);
apply_updates_command_.ExecuteImpl(session());
@@ -249,21 +101,16 @@ TEST_F(ApplyUpdatesCommandTest, UpdateWithChildrenBeforeParents) {
// Set a bunch of updates which are difficult to apply in the order
// they're received due to dependencies on other unseen items.
string root_server_id = syncable::GetNullId().GetServerId();
- CreateUnappliedNewItemWithParent("a_child_created_first",
- DefaultBookmarkSpecifics(),
- "parent");
- CreateUnappliedNewItemWithParent("x_child_created_first",
- DefaultBookmarkSpecifics(),
- "parent");
- CreateUnappliedNewItemWithParent("parent",
- DefaultBookmarkSpecifics(),
- root_server_id);
- CreateUnappliedNewItemWithParent("a_child_created_second",
- DefaultBookmarkSpecifics(),
- "parent");
- CreateUnappliedNewItemWithParent("x_child_created_second",
- DefaultBookmarkSpecifics(),
- "parent");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "a_child_created_first", DefaultBookmarkSpecifics(), "parent");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "x_child_created_first", DefaultBookmarkSpecifics(), "parent");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "parent", DefaultBookmarkSpecifics(), root_server_id);
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "a_child_created_second", DefaultBookmarkSpecifics(), "parent");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "x_child_created_second", DefaultBookmarkSpecifics(), "parent");
ExpectGroupToChange(apply_updates_command_, GROUP_UI);
apply_updates_command_.ExecuteImpl(session());
@@ -285,7 +132,8 @@ TEST_F(ApplyUpdatesCommandTest, UpdateWithChildrenBeforeParents) {
// to detect that this update can't be applied because it is in a CONFLICT
// state.
TEST_F(ApplyUpdatesCommandTest, SimpleConflict) {
- CreateUnappliedAndUnsyncedItem("item", syncable::BOOKMARKS);
+ entry_factory_->CreateUnappliedAndUnsyncedItem(
+ "item", syncable::BOOKMARKS);
ExpectGroupToChange(apply_updates_command_, GROUP_UI);
apply_updates_command_.ExecuteImpl(session());
@@ -304,8 +152,8 @@ TEST_F(ApplyUpdatesCommandTest, SimpleConflict) {
// simple conflict processing logic; it is in a CONFLICT_HIERARCHY state.
TEST_F(ApplyUpdatesCommandTest, HierarchyAndSimpleConflict) {
// Create a simply-conflicting item. It will start with valid parent ids.
- int64 handle = CreateUnappliedAndUnsyncedItem("orphaned_by_server",
- syncable::BOOKMARKS);
+ int64 handle = entry_factory_->CreateUnappliedAndUnsyncedItem(
+ "orphaned_by_server", syncable::BOOKMARKS);
{
// Manually set the SERVER_PARENT_ID to bad value.
// A bad parent indicates a hierarchy conflict.
@@ -314,7 +162,7 @@ TEST_F(ApplyUpdatesCommandTest, HierarchyAndSimpleConflict) {
ASSERT_TRUE(entry.good());
entry.Put(syncable::SERVER_PARENT_ID,
- id_factory_.MakeServer("bogus_parent"));
+ TestIdFactory::MakeServer("bogus_parent"));
}
ExpectGroupToChange(apply_updates_command_, GROUP_UI);
@@ -342,21 +190,23 @@ TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDirectoryLoop) {
// parent of 'Y'.
{
// Create it as a child of root node.
- int64 handle = CreateSyncedItem("X", syncable::BOOKMARKS, true);
+ int64 handle = entry_factory_->CreateSyncedItem(
+ "X", syncable::BOOKMARKS, true);
WriteTransaction trans(FROM_HERE, UNITTEST, directory());
MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle);
ASSERT_TRUE(entry.good());
// Re-parent from root to "Y"
- entry.Put(syncable::SERVER_VERSION, GetNextRevision());
+ entry.Put(syncable::SERVER_VERSION, entry_factory_->GetNextRevision());
entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
- entry.Put(syncable::SERVER_PARENT_ID, id_factory_.MakeServer("Y"));
+ entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::MakeServer("Y"));
}
// Item 'Y' is child of 'X'.
- CreateUnsyncedItem(id_factory_.MakeServer("Y"), id_factory_.MakeServer("X"),
- "Y", true, syncable::BOOKMARKS, NULL);
+ entry_factory_->CreateUnsyncedItem(
+ TestIdFactory::MakeServer("Y"), TestIdFactory::MakeServer("X"), "Y", true,
+ syncable::BOOKMARKS, NULL);
// If the server's update were applied, we would have X be a child of Y, and Y
// as a child of X. That's a directory loop. The UpdateApplicator should
@@ -384,8 +234,9 @@ TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDirectoryLoop) {
TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDeletedParent) {
// Create a locally deleted parent item.
int64 parent_handle;
- CreateUnsyncedItem(Id::CreateFromServerId("parent"), id_factory_.root(),
- "parent", true, syncable::BOOKMARKS, &parent_handle);
+ entry_factory_->CreateUnsyncedItem(
+ Id::CreateFromServerId("parent"), TestIdFactory::root(),
+ "parent", true, syncable::BOOKMARKS, &parent_handle);
{
WriteTransaction trans(FROM_HERE, UNITTEST, directory());
MutableEntry entry(&trans, syncable::GET_BY_HANDLE, parent_handle);
@@ -393,8 +244,8 @@ TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDeletedParent) {
}
// Create an incoming child from the server.
- CreateUnappliedNewItemWithParent("child", DefaultBookmarkSpecifics(),
- "parent");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "child", DefaultBookmarkSpecifics(), "parent");
// The server's update may seem valid to some other client, but on this client
// that new item's parent no longer exists. The update should not be applied
@@ -420,23 +271,24 @@ TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDeleteNonEmptyDirectory) {
// Create a server-deleted directory.
{
// Create it as a child of root node.
- int64 handle = CreateSyncedItem("parent", syncable::BOOKMARKS, true);
+ int64 handle = entry_factory_->CreateSyncedItem(
+ "parent", syncable::BOOKMARKS, true);
WriteTransaction trans(FROM_HERE, UNITTEST, directory());
MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle);
ASSERT_TRUE(entry.good());
// Delete it on the server.
- entry.Put(syncable::SERVER_VERSION, GetNextRevision());
+ entry.Put(syncable::SERVER_VERSION, entry_factory_->GetNextRevision());
entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
- entry.Put(syncable::SERVER_PARENT_ID, id_factory_.root());
+ entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::root());
entry.Put(syncable::SERVER_IS_DEL, true);
}
// Create a local child of the server-deleted directory.
- CreateUnsyncedItem(id_factory_.MakeServer("child"),
- id_factory_.MakeServer("parent"), "child", false,
- syncable::BOOKMARKS, NULL);
+ entry_factory_->CreateUnsyncedItem(
+ TestIdFactory::MakeServer("child"), TestIdFactory::MakeServer("parent"),
+ "child", false, syncable::BOOKMARKS, NULL);
// The server's request to delete the directory must be ignored, otherwise our
// unsynced new child would be orphaned. This is a hierarchy conflict.
@@ -458,12 +310,10 @@ TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDeleteNonEmptyDirectory) {
// item is in a CONFLICT_HIERARCHY state.
TEST_F(ApplyUpdatesCommandTest, HierarchyConflictUnknownParent) {
// We shouldn't be able to do anything with either of these items.
- CreateUnappliedNewItemWithParent("some_item",
- DefaultBookmarkSpecifics(),
- "unknown_parent");
- CreateUnappliedNewItemWithParent("some_other_item",
- DefaultBookmarkSpecifics(),
- "some_item");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "some_item", DefaultBookmarkSpecifics(), "unknown_parent");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "some_other_item", DefaultBookmarkSpecifics(), "some_item");
ExpectGroupToChange(apply_updates_command_, GROUP_UI);
apply_updates_command_.ExecuteImpl(session());
@@ -486,24 +336,18 @@ TEST_F(ApplyUpdatesCommandTest, HierarchyConflictUnknownParent) {
TEST_F(ApplyUpdatesCommandTest, ItemsBothKnownAndUnknown) {
// See what happens when there's a mixture of good and bad updates.
string root_server_id = syncable::GetNullId().GetServerId();
- CreateUnappliedNewItemWithParent("first_unknown_item",
- DefaultBookmarkSpecifics(),
- "unknown_parent");
- CreateUnappliedNewItemWithParent("first_known_item",
- DefaultBookmarkSpecifics(),
- root_server_id);
- CreateUnappliedNewItemWithParent("second_unknown_item",
- DefaultBookmarkSpecifics(),
- "unknown_parent");
- CreateUnappliedNewItemWithParent("second_known_item",
- DefaultBookmarkSpecifics(),
- "first_known_item");
- CreateUnappliedNewItemWithParent("third_known_item",
- DefaultBookmarkSpecifics(),
- "fourth_known_item");
- CreateUnappliedNewItemWithParent("fourth_known_item",
- DefaultBookmarkSpecifics(),
- root_server_id);
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "first_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "first_known_item", DefaultBookmarkSpecifics(), root_server_id);
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "second_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "second_known_item", DefaultBookmarkSpecifics(), "first_known_item");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "third_known_item", DefaultBookmarkSpecifics(), "fourth_known_item");
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "fourth_known_item", DefaultBookmarkSpecifics(), root_server_id);
ExpectGroupToChange(apply_updates_command_, GROUP_UI);
apply_updates_command_.ExecuteImpl(session());
@@ -539,7 +383,7 @@ TEST_F(ApplyUpdatesCommandTest, DecryptablePassword) {
cryptographer->Encrypt(data,
specifics.mutable_password()->mutable_encrypted());
- CreateUnappliedNewItem("item", specifics, false);
+ entry_factory_->CreateUnappliedNewItem("item", specifics, false);
ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD);
apply_updates_command_.ExecuteImpl(session());
@@ -562,13 +406,12 @@ TEST_F(ApplyUpdatesCommandTest, UndecryptableData) {
encrypted_bookmark.mutable_encrypted();
AddDefaultFieldValue(syncable::BOOKMARKS, &encrypted_bookmark);
string root_server_id = syncable::GetNullId().GetServerId();
- CreateUnappliedNewItemWithParent("folder",
- encrypted_bookmark,
- root_server_id);
- CreateUnappliedNewItem("item2", encrypted_bookmark, false);
+ entry_factory_->CreateUnappliedNewItemWithParent(
+ "folder", encrypted_bookmark, root_server_id);
+ entry_factory_->CreateUnappliedNewItem("item2", encrypted_bookmark, false);
sync_pb::EntitySpecifics encrypted_password;
encrypted_password.mutable_password();
- CreateUnappliedNewItem("item3", encrypted_password, false);
+ entry_factory_->CreateUnappliedNewItem("item3", encrypted_password, false);
ExpectGroupsToChange(apply_updates_command_, GROUP_UI, GROUP_PASSWORD);
apply_updates_command_.ExecuteImpl(session());
@@ -597,7 +440,7 @@ TEST_F(ApplyUpdatesCommandTest, UndecryptableData) {
ASSERT_TRUE(status->update_progress());
EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
<< "All updates should have been attempted";
- ASSERT_TRUE(status->conflict_progress());
+ ASSERT_TRUE(status->conflict_progress());
EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
<< "The updates that can't be decrypted should not be in regular "
<< "conflict";
@@ -625,7 +468,7 @@ TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) {
cryptographer->Encrypt(data,
specifics.mutable_password()->mutable_encrypted());
}
- CreateUnappliedNewItem("item1", specifics, false);
+ entry_factory_->CreateUnappliedNewItem("item1", specifics, false);
}
{
// Create a new cryptographer, independent of the one in the session.
@@ -639,7 +482,7 @@ TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) {
cryptographer.Encrypt(data,
specifics.mutable_password()->mutable_encrypted());
- CreateUnappliedNewItem("item2", specifics, false);
+ entry_factory_->CreateUnappliedNewItem("item2", specifics, false);
}
ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD);
@@ -666,342 +509,4 @@ TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) {
}
}
-TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) {
- // Storing the cryptographer separately is bad, but for this test we
- // know it's safe.
- Cryptographer* cryptographer;
- syncable::ModelTypeSet encrypted_types;
- encrypted_types.Put(syncable::PASSWORDS);
- encrypted_types.Put(syncable::NIGORI);
- {
- syncable::ReadTransaction trans(FROM_HERE, directory());
- cryptographer = directory()->GetCryptographer(&trans);
- EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types));
- }
-
- // Nigori node updates should update the Cryptographer.
- Cryptographer other_cryptographer(&encryptor_);
- KeyParams params = {"localhost", "dummy", "foobar"};
- other_cryptographer.AddKey(params);
-
- sync_pb::EntitySpecifics specifics;
- sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
- other_cryptographer.GetKeys(nigori->mutable_encrypted());
- nigori->set_encrypt_bookmarks(true);
- encrypted_types.Put(syncable::BOOKMARKS);
- CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
- specifics, true);
- EXPECT_FALSE(cryptographer->has_pending_keys());
-
- ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
- apply_updates_command_.ExecuteImpl(session());
-
- sessions::StatusController* status = session()->mutable_status_controller();
- sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
- ASSERT_TRUE(status->update_progress());
- EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
- << "All updates should have been attempted";
- ASSERT_TRUE(status->conflict_progress());
- EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
- << "The nigori update shouldn't be in conflict";
- EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
- << "The nigori update should be applied";
-
- EXPECT_FALSE(cryptographer->is_ready());
- EXPECT_TRUE(cryptographer->has_pending_keys());
- EXPECT_TRUE(
- cryptographer->GetEncryptedTypes()
- .Equals(syncable::ModelTypeSet::All()));
-}
-
-TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) {
- // Storing the cryptographer separately is bad, but for this test we
- // know it's safe.
- Cryptographer* cryptographer;
- syncable::ModelTypeSet encrypted_types;
- encrypted_types.Put(syncable::PASSWORDS);
- encrypted_types.Put(syncable::NIGORI);
- {
- syncable::ReadTransaction trans(FROM_HERE, directory());
- cryptographer = directory()->GetCryptographer(&trans);
- EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types));
- }
-
- // Nigori node updates should update the Cryptographer.
- Cryptographer other_cryptographer(&encryptor_);
- KeyParams params = {"localhost", "dummy", "foobar"};
- other_cryptographer.AddKey(params);
-
- sync_pb::EntitySpecifics specifics;
- sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
- other_cryptographer.GetKeys(nigori->mutable_encrypted());
- nigori->set_encrypt_sessions(true);
- nigori->set_encrypt_themes(true);
- encrypted_types.Put(syncable::SESSIONS);
- encrypted_types.Put(syncable::THEMES);
- CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
- specifics, true);
- EXPECT_FALSE(cryptographer->has_pending_keys());
-
- ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
- apply_updates_command_.ExecuteImpl(session());
-
- sessions::StatusController* status = session()->mutable_status_controller();
- sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
- ASSERT_TRUE(status->update_progress());
- EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
- << "All updates should have been attempted";
- ASSERT_TRUE(status->conflict_progress());
- EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
- << "The nigori update shouldn't be in conflict";
- EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
- << "The nigori update should be applied";
-
- EXPECT_FALSE(cryptographer->is_ready());
- EXPECT_TRUE(cryptographer->has_pending_keys());
- EXPECT_TRUE(
- cryptographer->GetEncryptedTypes()
- .Equals(syncable::ModelTypeSet::All()));
-}
-
-// Create some local unsynced and unencrypted data. Apply a nigori update that
-// turns on encryption for the unsynced data. Ensure we properly encrypt the
-// data as part of the nigori update. Apply another nigori update with no
-// changes. Ensure we ignore already-encrypted unsynced data and that nothing
-// breaks.
-TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) {
- // Storing the cryptographer separately is bad, but for this test we
- // know it's safe.
- Cryptographer* cryptographer;
- syncable::ModelTypeSet encrypted_types;
- encrypted_types.Put(syncable::PASSWORDS);
- encrypted_types.Put(syncable::NIGORI);
- {
- syncable::ReadTransaction trans(FROM_HERE, directory());
- cryptographer = directory()->GetCryptographer(&trans);
- EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types));
-
- // With default encrypted_types, this should be true.
- EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
-
- Syncer::UnsyncedMetaHandles handles;
- SyncerUtil::GetUnsyncedEntries(&trans, &handles);
- EXPECT_TRUE(handles.empty());
- }
-
- // Create unsynced bookmarks without encryption.
- // First item is a folder
- Id folder_id = id_factory_.NewLocalId();
- CreateUnsyncedItem(folder_id, id_factory_.root(), "folder",
- true, syncable::BOOKMARKS, NULL);
- // Next five items are children of the folder
- size_t i;
- size_t batch_s = 5;
- for (i = 0; i < batch_s; ++i) {
- CreateUnsyncedItem(id_factory_.NewLocalId(), folder_id,
- base::StringPrintf("Item %"PRIuS"", i), false,
- syncable::BOOKMARKS, NULL);
- }
- // Next five items are children of the root.
- for (; i < 2*batch_s; ++i) {
- CreateUnsyncedItem(id_factory_.NewLocalId(), id_factory_.root(),
- base::StringPrintf("Item %"PRIuS"", i), false,
- syncable::BOOKMARKS, NULL);
- }
-
- KeyParams params = {"localhost", "dummy", "foobar"};
- cryptographer->AddKey(params);
- sync_pb::EntitySpecifics specifics;
- sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
- cryptographer->GetKeys(nigori->mutable_encrypted());
- nigori->set_encrypt_bookmarks(true);
- encrypted_types.Put(syncable::BOOKMARKS);
- CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
- specifics, true);
- EXPECT_FALSE(cryptographer->has_pending_keys());
- EXPECT_TRUE(cryptographer->is_ready());
-
- {
- // Ensure we have unsynced nodes that aren't properly encrypted.
- syncable::ReadTransaction trans(FROM_HERE, directory());
- EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
-
- Syncer::UnsyncedMetaHandles handles;
- SyncerUtil::GetUnsyncedEntries(&trans, &handles);
- EXPECT_EQ(2*batch_s+1, handles.size());
- }
-
- ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
- apply_updates_command_.ExecuteImpl(session());
-
- {
- sessions::StatusController* status = session()->mutable_status_controller();
- sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
- ASSERT_TRUE(status->update_progress());
- EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
- << "All updates should have been attempted";
- ASSERT_TRUE(status->conflict_progress());
- EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
- << "No updates should be in conflict";
- EXPECT_EQ(0, status->conflict_progress()->EncryptionConflictingItemsSize())
- << "No updates should be in conflict";
- EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
- << "The nigori update should be applied";
- }
- EXPECT_FALSE(cryptographer->has_pending_keys());
- EXPECT_TRUE(cryptographer->is_ready());
- {
- syncable::ReadTransaction trans(FROM_HERE, directory());
-
- // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes
- // should be encrypted now.
- EXPECT_TRUE(syncable::ModelTypeSet::All().Equals(
- cryptographer->GetEncryptedTypes()));
- EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
-
- Syncer::UnsyncedMetaHandles handles;
- SyncerUtil::GetUnsyncedEntries(&trans, &handles);
- EXPECT_EQ(2*batch_s+1, handles.size());
- }
-
- // Simulate another nigori update that doesn't change anything.
- {
- WriteTransaction trans(FROM_HERE, UNITTEST, directory());
- MutableEntry entry(&trans, syncable::GET_BY_SERVER_TAG,
- syncable::ModelTypeToRootTag(syncable::NIGORI));
- ASSERT_TRUE(entry.good());
- entry.Put(syncable::SERVER_VERSION, GetNextRevision());
- entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
- }
- ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
- apply_updates_command_.ExecuteImpl(session());
- {
- sessions::StatusController* status = session()->mutable_status_controller();
- sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
- ASSERT_TRUE(status->update_progress());
- EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize())
- << "All updates should have been attempted";
- ASSERT_TRUE(status->conflict_progress());
- EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
- << "No updates should be in conflict";
- EXPECT_EQ(0, status->conflict_progress()->EncryptionConflictingItemsSize())
- << "No updates should be in conflict";
- EXPECT_EQ(2, status->update_progress()->SuccessfullyAppliedUpdateCount())
- << "The nigori update should be applied";
- }
- EXPECT_FALSE(cryptographer->has_pending_keys());
- EXPECT_TRUE(cryptographer->is_ready());
- {
- syncable::ReadTransaction trans(FROM_HERE, directory());
-
- // All our changes should still be encrypted.
- EXPECT_TRUE(syncable::ModelTypeSet::All().Equals(
- cryptographer->GetEncryptedTypes()));
- EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
-
- Syncer::UnsyncedMetaHandles handles;
- SyncerUtil::GetUnsyncedEntries(&trans, &handles);
- EXPECT_EQ(2*batch_s+1, handles.size());
- }
-}
-
-TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) {
- // Storing the cryptographer separately is bad, but for this test we
- // know it's safe.
- Cryptographer* cryptographer;
- syncable::ModelTypeSet encrypted_types;
- encrypted_types.Put(syncable::PASSWORDS);
- encrypted_types.Put(syncable::NIGORI);
- {
- syncable::ReadTransaction trans(FROM_HERE, directory());
- cryptographer = directory()->GetCryptographer(&trans);
- EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types));
-
- // With default encrypted_types, this should be true.
- EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
-
- Syncer::UnsyncedMetaHandles handles;
- SyncerUtil::GetUnsyncedEntries(&trans, &handles);
- EXPECT_TRUE(handles.empty());
- }
-
- // Create unsynced bookmarks without encryption.
- // First item is a folder
- Id folder_id = id_factory_.NewLocalId();
- CreateUnsyncedItem(folder_id, id_factory_.root(), "folder", true,
- syncable::BOOKMARKS, NULL);
- // Next five items are children of the folder
- size_t i;
- size_t batch_s = 5;
- for (i = 0; i < batch_s; ++i) {
- CreateUnsyncedItem(id_factory_.NewLocalId(), folder_id,
- base::StringPrintf("Item %"PRIuS"", i), false,
- syncable::BOOKMARKS, NULL);
- }
- // Next five items are children of the root.
- for (; i < 2*batch_s; ++i) {
- CreateUnsyncedItem(id_factory_.NewLocalId(), id_factory_.root(),
- base::StringPrintf("Item %"PRIuS"", i), false,
- syncable::BOOKMARKS, NULL);
- }
-
- // We encrypt with new keys, triggering the local cryptographer to be unready
- // and unable to decrypt data (once updated).
- Cryptographer other_cryptographer(&encryptor_);
- KeyParams params = {"localhost", "dummy", "foobar"};
- other_cryptographer.AddKey(params);
- sync_pb::EntitySpecifics specifics;
- sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
- other_cryptographer.GetKeys(nigori->mutable_encrypted());
- nigori->set_encrypt_bookmarks(true);
- encrypted_types.Put(syncable::BOOKMARKS);
- CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
- specifics, true);
- EXPECT_FALSE(cryptographer->has_pending_keys());
-
- {
- // Ensure we have unsynced nodes that aren't properly encrypted.
- syncable::ReadTransaction trans(FROM_HERE, directory());
- EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
- Syncer::UnsyncedMetaHandles handles;
- SyncerUtil::GetUnsyncedEntries(&trans, &handles);
- EXPECT_EQ(2*batch_s+1, handles.size());
- }
-
- ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
- apply_updates_command_.ExecuteImpl(session());
-
- sessions::StatusController* status = session()->mutable_status_controller();
- sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
- ASSERT_TRUE(status->update_progress());
- EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
- << "All updates should have been attempted";
- ASSERT_TRUE(status->conflict_progress());
- EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
- << "The unsynced changes don't trigger a blocking conflict with the "
- << "nigori update.";
- EXPECT_EQ(0, status->conflict_progress()->EncryptionConflictingItemsSize())
- << "The unsynced changes don't trigger an encryption conflict with the "
- << "nigori update.";
- EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
- << "The nigori update should be applied";
- EXPECT_FALSE(cryptographer->is_ready());
- EXPECT_TRUE(cryptographer->has_pending_keys());
- {
- syncable::ReadTransaction trans(FROM_HERE, directory());
-
- // Since we have pending keys, we would have failed to encrypt, but the
- // cryptographer should be updated.
- EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
- EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(
- syncable::ModelTypeSet().All()));
- EXPECT_FALSE(cryptographer->is_ready());
- EXPECT_TRUE(cryptographer->has_pending_keys());
-
- Syncer::UnsyncedMetaHandles handles;
- SyncerUtil::GetUnsyncedEntries(&trans, &handles);
- EXPECT_EQ(2*batch_s+1, handles.size());
- }
-}
-
} // namespace csync
« no previous file with comments | « sync/engine/apply_updates_command.cc ('k') | sync/engine/conflict_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698