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

Unified Diff: sync/engine/process_updates_command_unittest.cc

Issue 11636006: WIP: The Bookmark Position Megapatch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Various updates, including switch suffix to unique_client_tag style Created 8 years 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/process_updates_command.cc ('k') | sync/engine/syncer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/engine/process_updates_command_unittest.cc
diff --git a/sync/engine/process_updates_command_unittest.cc b/sync/engine/process_updates_command_unittest.cc
index f4cc583dc29c38ccf8f9eb82c5db6c505c16e888..362e7b2766913aee0d361f75dda90290fa5c240c 100644
--- a/sync/engine/process_updates_command_unittest.cc
+++ b/sync/engine/process_updates_command_unittest.cc
@@ -5,15 +5,20 @@
#include "base/basictypes.h"
#include "sync/engine/process_updates_command.h"
#include "sync/internal_api/public/base/model_type.h"
+#include "sync/internal_api/public/test/test_entry_factory.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"
+#include "sync/syncable/syncable_proto_util.h"
+#include "sync/syncable/write_transaction.h"
#include "sync/test/engine/fake_model_worker.h"
#include "sync/test/engine/syncer_command_test.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
+using sync_pb::SyncEntity;
using syncable::Id;
using syncable::MutableEntry;
using syncable::UNITTEST;
@@ -35,6 +40,7 @@ class ProcessUpdatesCommandTest : public SyncerCommandTest {
(*mutable_routing_info())[BOOKMARKS] = GROUP_UI;
(*mutable_routing_info())[AUTOFILL] = GROUP_DB;
SyncerCommandTest::SetUp();
+ test_entry_factory_.reset(new TestEntryFactory(directory()));
}
void CreateLocalItem(const std::string& item_id,
@@ -54,18 +60,21 @@ class ProcessUpdatesCommandTest : public SyncerCommandTest {
entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
}
- void AddUpdate(sync_pb::GetUpdatesResponse* updates,
+ SyncEntity* AddUpdate(sync_pb::GetUpdatesResponse* updates,
const std::string& id, const std::string& parent,
const ModelType& type) {
sync_pb::SyncEntity* e = updates->add_entries();
- e->set_id_string("b1");
+ e->set_id_string(id);
e->set_parent_id_string(parent);
- e->set_non_unique_name("b1");
- e->set_name("b1");
+ e->set_non_unique_name(id);
+ e->set_name(id);
+ e->set_version(1000);
AddDefaultFieldValue(type, e->mutable_specifics());
+ return e;
}
ProcessUpdatesCommand command_;
+ scoped_ptr<TestEntryFactory> test_entry_factory_;
private:
DISALLOW_COPY_AND_ASSIGN(ProcessUpdatesCommandTest);
@@ -74,8 +83,6 @@ class ProcessUpdatesCommandTest : public SyncerCommandTest {
TEST_F(ProcessUpdatesCommandTest, GroupsToChange) {
std::string root = syncable::GetNullId().GetServerId();
- CreateLocalItem("b1", root, BOOKMARKS);
- CreateLocalItem("b2", root, BOOKMARKS);
CreateLocalItem("p1", root, PREFERENCES);
CreateLocalItem("a1", root, AUTOFILL);
@@ -84,8 +91,6 @@ TEST_F(ProcessUpdatesCommandTest, GroupsToChange) {
sync_pb::GetUpdatesResponse* updates =
session()->mutable_status_controller()->
mutable_updates_response()->mutable_get_updates();
- AddUpdate(updates, "b1", root, BOOKMARKS);
- AddUpdate(updates, "b2", root, BOOKMARKS);
AddUpdate(updates, "p1", root, PREFERENCES);
AddUpdate(updates, "a1", root, AUTOFILL);
@@ -94,6 +99,74 @@ TEST_F(ProcessUpdatesCommandTest, GroupsToChange) {
command_.ExecuteImpl(session());
}
+static const char kCacheGuid[] = "tuiWdG8hV+8y4RT9N5Aikg==";
+
+// Test that the bookmark tag is set on newly created items.
+TEST_F(ProcessUpdatesCommandTest, NewBookmarkTag) {
+ std::string root = syncable::GetNullId().GetServerId();
+ sync_pb::GetUpdatesResponse* updates =
+ session()->mutable_status_controller()->
+ mutable_updates_response()->mutable_get_updates();
+ Id server_id = Id::CreateFromServerId("b1");
+ SyncEntity* e =
+ AddUpdate(updates, SyncableIdToProto(server_id), root, BOOKMARKS);
+
+ e->set_originator_cache_guid(
+ std::string(kCacheGuid, arraysize(kCacheGuid)-1));
+ Id client_id = Id::CreateFromClientString("-42");
+ e->set_originator_client_item_id(client_id.value());
+ e->set_position_in_parent(0);
+
+ command_.ExecuteImpl(session());
+
+ syncable::ReadTransaction trans(FROM_HERE, directory());
+ syncable::Entry entry(&trans, syncable::GET_BY_ID, server_id);
+ ASSERT_TRUE(entry.good());
+ EXPECT_TRUE(
+ UniquePosition::IsValidSuffix(entry.Get(syncable::UNIQUE_BOOKMARK_TAG)));
+}
+
+// Test that the bookmark tag is updated on existing items.
+TEST_F(ProcessUpdatesCommandTest, UpdeateExistingBookmarkTag) {
+ int64 handle = test_entry_factory_->CreateSyncedBookmarkItem("b1", false);
+
+ Id server_id;
+ std::string original_suffix;
+ {
+ syncable::ReadTransaction trans(FROM_HERE, directory());
+ syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, handle);
+ ASSERT_TRUE(entry.good());
+ original_suffix = entry.Get(syncable::UNIQUE_BOOKMARK_TAG);
+ EXPECT_TRUE(UniquePosition::IsValidSuffix(
+ entry.Get(syncable::UNIQUE_BOOKMARK_TAG)));
+ server_id = entry.Get(syncable::ID);
+ }
+
+ std::string root = syncable::GetNullId().GetServerId();
+ sync_pb::GetUpdatesResponse* updates =
+ session()->mutable_status_controller()->
+ mutable_updates_response()->mutable_get_updates();
+ SyncEntity* e =
+ AddUpdate(updates, SyncableIdToProto(server_id), root, BOOKMARKS);
+
+ e->set_originator_cache_guid(
+ std::string(kCacheGuid, arraysize(kCacheGuid)-1));
+ Id client_id = Id::CreateFromClientString("-42");
+ e->set_originator_client_item_id(client_id.value());
+ e->set_position_in_parent(0);
+
+ command_.ExecuteImpl(session());
+
+ {
+ syncable::ReadTransaction trans(FROM_HERE, directory());
+ syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, handle);
+ ASSERT_TRUE(entry.good());
+ std::string new_suffix = entry.Get(syncable::UNIQUE_BOOKMARK_TAG);
+ EXPECT_TRUE(UniquePosition::IsValidSuffix(new_suffix));
+ EXPECT_NE(original_suffix, new_suffix);
+ }
+}
+
} // namespace
} // namespace syncer
« no previous file with comments | « sync/engine/process_updates_command.cc ('k') | sync/engine/syncer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698