summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/sync_manager_impl_unittest.cc
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-16 20:59:01 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-16 20:59:01 +0000
commit34da86a6d837a137631c4d9c98d0d8e6709edb01 (patch)
tree24789fd85d009a4712cea24abf936745a066babb /sync/internal_api/sync_manager_impl_unittest.cc
parentb4f5dae6842567d21ca5eedca1f1aedcb5387a60 (diff)
downloadchromium_src-34da86a6d837a137631c4d9c98d0d8e6709edb01.zip
chromium_src-34da86a6d837a137631c4d9c98d0d8e6709edb01.tar.gz
chromium_src-34da86a6d837a137631c4d9c98d0d8e6709edb01.tar.bz2
sync: Remove some WebUI debug functions
This CL removes a number of functions from the sync debugging framework in order to prepare for some upcoming changes to sync debugging (due to 328606). This CL removes the following functions: - GetRootNodeDetails - GetNodeSummaries - GetNodeDetails - GetChildNodeIds It also adds the function 'getListOfKnownTypes' to help replace some old functionality required by the 'data' tab and to fix issue 329013. Rather than having that tab fetch a list of children of the root node, it now asks for a list of all known data types. This is a better solution, since it does not require sync to be fully initialized in order to properly populate the set of checkboxes. The most significant user of the removed functionality is the node browser. Its javascript code has been modified in order to transition it to relying on the getAllNodes function. Rather than fetching node data on demand by a series of asynchronous callbacks, the tab now fetches a list of all known sync nodes at once. This has the advantage of providing a more consistent (though more stale) snapshot. This CL adds a refresh button to the node browser tab in order to give users some control over its staleness. This change had some minor side-effects. The node browser now relies on items' string-based IDs rather than their metahandles when determining the nodes' hierarchy. We've also had to add a 'positionIndex' field to the output of getAllNodes to make it easier for the node browser to sort its entries. In part to make it easier to fetch this field, most of the code associated with getAllNodes has been moved into the syncable::Directory. In addition to all these changes, this CL adds some webui tests to help prevent regressions in about:sync functionality. For now, they only cover the node browser. More tests will be added in future CLs. BUG=110517,329013,328606 Review URL: https://codereview.chromium.org/134443004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245313 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api/sync_manager_impl_unittest.cc')
-rw-r--r--sync/internal_api/sync_manager_impl_unittest.cc347
1 files changed, 8 insertions, 339 deletions
diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc
index 57e2a5b..f97b62d 100644
--- a/sync/internal_api/sync_manager_impl_unittest.cc
+++ b/sync/internal_api/sync_manager_impl_unittest.cc
@@ -97,24 +97,6 @@ using syncable::kEncryptedString;
namespace {
-void ExpectInt64Value(int64 expected_value,
- const base::DictionaryValue& value,
- const std::string& key) {
- std::string int64_str;
- EXPECT_TRUE(value.GetString(key, &int64_str));
- int64 val = 0;
- EXPECT_TRUE(base::StringToInt64(int64_str, &val));
- EXPECT_EQ(expected_value, val);
-}
-
-void ExpectTimeValue(const base::Time& expected_value,
- const base::DictionaryValue& value,
- const std::string& key) {
- std::string time_str;
- EXPECT_TRUE(value.GetString(key, &time_str));
- EXPECT_EQ(GetTimeDebugString(expected_value), time_str);
-}
-
// Makes a non-folder child of the root node. Returns the id of the
// newly-created node.
int64 MakeNode(UserShare* share,
@@ -526,91 +508,6 @@ TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) {
EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty());
}
-namespace {
-
-void CheckNodeValue(const BaseNode& node, const base::DictionaryValue& value,
- bool is_detailed) {
- size_t expected_field_count = 4;
-
- ExpectInt64Value(node.GetId(), value, "id");
- {
- bool is_folder = false;
- EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder));
- EXPECT_EQ(node.GetIsFolder(), is_folder);
- }
- ExpectDictStringValue(node.GetTitle(), value, "title");
-
- ModelType expected_model_type = node.GetModelType();
- std::string type_str;
- EXPECT_TRUE(value.GetString("type", &type_str));
- if (expected_model_type >= FIRST_REAL_MODEL_TYPE) {
- ModelType model_type = ModelTypeFromString(type_str);
- EXPECT_EQ(expected_model_type, model_type);
- } else if (expected_model_type == TOP_LEVEL_FOLDER) {
- EXPECT_EQ("Top-level folder", type_str);
- } else if (expected_model_type == UNSPECIFIED) {
- EXPECT_EQ("Unspecified", type_str);
- } else {
- ADD_FAILURE();
- }
-
- if (is_detailed) {
- {
- scoped_ptr<base::DictionaryValue> expected_entry(
- node.GetEntry()->ToValue(NULL));
- const base::Value* entry = NULL;
- EXPECT_TRUE(value.Get("entry", &entry));
- EXPECT_TRUE(base::Value::Equals(entry, expected_entry.get()));
- }
-
- ExpectInt64Value(node.GetParentId(), value, "parentId");
- ExpectTimeValue(node.GetModificationTime(), value, "modificationTime");
- ExpectInt64Value(node.GetExternalId(), value, "externalId");
- expected_field_count += 4;
-
- if (value.HasKey("predecessorId")) {
- ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId");
- expected_field_count++;
- }
- if (value.HasKey("successorId")) {
- ExpectInt64Value(node.GetSuccessorId(), value, "successorId");
- expected_field_count++;
- }
- if (value.HasKey("firstChildId")) {
- ExpectInt64Value(node.GetFirstChildId(), value, "firstChildId");
- expected_field_count++;
- }
- }
-
- EXPECT_EQ(expected_field_count, value.size());
-}
-
-} // namespace
-
-TEST_F(SyncApiTest, BaseNodeGetSummaryAsValue) {
- ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
- ReadNode node(&trans);
- node.InitByRootLookup();
- scoped_ptr<base::DictionaryValue> details(node.GetSummaryAsValue());
- if (details) {
- CheckNodeValue(node, *details, false);
- } else {
- ADD_FAILURE();
- }
-}
-
-TEST_F(SyncApiTest, BaseNodeGetDetailsAsValue) {
- ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
- ReadNode node(&trans);
- node.InitByRootLookup();
- scoped_ptr<base::DictionaryValue> details(node.GetDetailsAsValue());
- if (details) {
- CheckNodeValue(node, *details, true);
- } else {
- ADD_FAILURE();
- }
-}
-
TEST_F(SyncApiTest, EmptyTags) {
WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
ReadNode root_node(&trans);
@@ -877,6 +774,12 @@ class SyncManagerTest : public testing::Test,
(*out)[PRIORITY_PREFERENCES] = GROUP_PASSIVE;
}
+ ModelTypeSet GetEnabledTypes() {
+ ModelSafeRoutingInfo routing_info;
+ GetModelSafeRoutingInfo(&routing_info);
+ return GetRoutingInfoTypes(routing_info);
+ }
+
virtual void OnChangesApplied(
ModelType model_type,
int64 model_version,
@@ -1039,247 +942,13 @@ TEST_F(SyncManagerTest, ProcessJsMessage) {
StrictMock<MockJsReplyHandler> reply_handler;
- base::ListValue disabled_args;
- disabled_args.Append(new base::StringValue("TRANSIENT_INVALIDATION_ERROR"));
-
EXPECT_CALL(reply_handler,
- HandleJsReply("getNotificationState",
- HasArgsAsList(disabled_args)));
+ HandleJsReply("getNotificationInfo", _));
// This message should be dropped.
SendJsMessage("unknownMessage", kNoArgs, reply_handler.AsWeakHandle());
- SendJsMessage("getNotificationState", kNoArgs, reply_handler.AsWeakHandle());
-}
-
-TEST_F(SyncManagerTest, ProcessJsMessageGetRootNodeDetails) {
- const JsArgList kNoArgs;
-
- StrictMock<MockJsReplyHandler> reply_handler;
-
- JsArgList return_args;
-
- EXPECT_CALL(reply_handler,
- HandleJsReply("getRootNodeDetails", _))
- .WillOnce(SaveArg<1>(&return_args));
-
- SendJsMessage("getRootNodeDetails", kNoArgs, reply_handler.AsWeakHandle());
-
- EXPECT_EQ(1u, return_args.Get().GetSize());
- const base::DictionaryValue* node_info = NULL;
- EXPECT_TRUE(return_args.Get().GetDictionary(0, &node_info));
- if (node_info) {
- ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
- ReadNode node(&trans);
- node.InitByRootLookup();
- CheckNodeValue(node, *node_info, true);
- } else {
- ADD_FAILURE();
- }
-}
-
-void CheckGetNodesByIdReturnArgs(SyncManager* sync_manager,
- const JsArgList& return_args,
- int64 id,
- bool is_detailed) {
- EXPECT_EQ(1u, return_args.Get().GetSize());
- const base::ListValue* nodes = NULL;
- ASSERT_TRUE(return_args.Get().GetList(0, &nodes));
- ASSERT_TRUE(nodes);
- EXPECT_EQ(1u, nodes->GetSize());
- const base::DictionaryValue* node_info = NULL;
- EXPECT_TRUE(nodes->GetDictionary(0, &node_info));
- ASSERT_TRUE(node_info);
- ReadTransaction trans(FROM_HERE, sync_manager->GetUserShare());
- ReadNode node(&trans);
- EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
- CheckNodeValue(node, *node_info, is_detailed);
-}
-
-class SyncManagerGetNodesByIdTest : public SyncManagerTest {
- protected:
- virtual ~SyncManagerGetNodesByIdTest() {}
-
- void RunGetNodesByIdTest(const char* message_name, bool is_detailed) {
- int64 root_id = kInvalidId;
- {
- ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
- ReadNode root_node(&trans);
- root_node.InitByRootLookup();
- root_id = root_node.GetId();
- }
-
- int64 child_id =
- MakeNode(sync_manager_.GetUserShare(), BOOKMARKS, "testtag");
-
- StrictMock<MockJsReplyHandler> reply_handler;
-
- JsArgList return_args;
-
- const int64 ids[] = { root_id, child_id };
-
- EXPECT_CALL(reply_handler,
- HandleJsReply(message_name, _))
- .Times(arraysize(ids)).WillRepeatedly(SaveArg<1>(&return_args));
-
- for (size_t i = 0; i < arraysize(ids); ++i) {
- base::ListValue args;
- base::ListValue* id_values = new base::ListValue();
- args.Append(id_values);
- id_values->Append(new base::StringValue(base::Int64ToString(ids[i])));
- SendJsMessage(message_name,
- JsArgList(&args), reply_handler.AsWeakHandle());
-
- CheckGetNodesByIdReturnArgs(&sync_manager_, return_args,
- ids[i], is_detailed);
- }
- }
-
- void RunGetNodesByIdFailureTest(const char* message_name) {
- StrictMock<MockJsReplyHandler> reply_handler;
-
- base::ListValue empty_list_args;
- empty_list_args.Append(new base::ListValue());
-
- EXPECT_CALL(reply_handler,
- HandleJsReply(message_name,
- HasArgsAsList(empty_list_args)))
- .Times(6);
-
- {
- base::ListValue args;
- SendJsMessage(message_name,
- JsArgList(&args), reply_handler.AsWeakHandle());
- }
-
- {
- base::ListValue args;
- args.Append(new base::ListValue());
- SendJsMessage(message_name,
- JsArgList(&args), reply_handler.AsWeakHandle());
- }
-
- {
- base::ListValue args;
- base::ListValue* ids = new base::ListValue();
- args.Append(ids);
- ids->Append(new base::StringValue(std::string()));
- SendJsMessage(
- message_name, JsArgList(&args), reply_handler.AsWeakHandle());
- }
-
- {
- base::ListValue args;
- base::ListValue* ids = new base::ListValue();
- args.Append(ids);
- ids->Append(new base::StringValue("nonsense"));
- SendJsMessage(message_name,
- JsArgList(&args), reply_handler.AsWeakHandle());
- }
-
- {
- base::ListValue args;
- base::ListValue* ids = new base::ListValue();
- args.Append(ids);
- ids->Append(new base::StringValue("0"));
- SendJsMessage(message_name,
- JsArgList(&args), reply_handler.AsWeakHandle());
- }
-
- {
- base::ListValue args;
- base::ListValue* ids = new base::ListValue();
- args.Append(ids);
- ids->Append(new base::StringValue("9999"));
- SendJsMessage(message_name,
- JsArgList(&args), reply_handler.AsWeakHandle());
- }
- }
-};
-
-TEST_F(SyncManagerGetNodesByIdTest, GetNodeSummariesById) {
- RunGetNodesByIdTest("getNodeSummariesById", false);
-}
-
-TEST_F(SyncManagerGetNodesByIdTest, GetNodeDetailsById) {
- RunGetNodesByIdTest("getNodeDetailsById", true);
-}
-
-TEST_F(SyncManagerGetNodesByIdTest, GetNodeSummariesByIdFailure) {
- RunGetNodesByIdFailureTest("getNodeSummariesById");
-}
-
-TEST_F(SyncManagerGetNodesByIdTest, GetNodeDetailsByIdFailure) {
- RunGetNodesByIdFailureTest("getNodeDetailsById");
-}
-
-TEST_F(SyncManagerTest, GetChildNodeIds) {
- StrictMock<MockJsReplyHandler> reply_handler;
-
- JsArgList return_args;
-
- EXPECT_CALL(reply_handler,
- HandleJsReply("getChildNodeIds", _))
- .Times(1).WillRepeatedly(SaveArg<1>(&return_args));
-
- {
- base::ListValue args;
- args.Append(new base::StringValue("1"));
- SendJsMessage("getChildNodeIds",
- JsArgList(&args), reply_handler.AsWeakHandle());
- }
-
- EXPECT_EQ(1u, return_args.Get().GetSize());
- const base::ListValue* nodes = NULL;
- ASSERT_TRUE(return_args.Get().GetList(0, &nodes));
- ASSERT_TRUE(nodes);
- EXPECT_EQ(9u, nodes->GetSize());
-}
-
-TEST_F(SyncManagerTest, GetChildNodeIdsFailure) {
- StrictMock<MockJsReplyHandler> reply_handler;
-
- base::ListValue empty_list_args;
- empty_list_args.Append(new base::ListValue());
-
- EXPECT_CALL(reply_handler,
- HandleJsReply("getChildNodeIds",
- HasArgsAsList(empty_list_args)))
- .Times(5);
-
- {
- base::ListValue args;
- SendJsMessage("getChildNodeIds",
- JsArgList(&args), reply_handler.AsWeakHandle());
- }
-
- {
- base::ListValue args;
- args.Append(new base::StringValue(std::string()));
- SendJsMessage(
- "getChildNodeIds", JsArgList(&args), reply_handler.AsWeakHandle());
- }
-
- {
- base::ListValue args;
- args.Append(new base::StringValue("nonsense"));
- SendJsMessage("getChildNodeIds",
- JsArgList(&args), reply_handler.AsWeakHandle());
- }
-
- {
- base::ListValue args;
- args.Append(new base::StringValue("0"));
- SendJsMessage("getChildNodeIds",
- JsArgList(&args), reply_handler.AsWeakHandle());
- }
-
- {
- base::ListValue args;
- args.Append(new base::StringValue("9999"));
- SendJsMessage("getChildNodeIds",
- JsArgList(&args), reply_handler.AsWeakHandle());
- }
+ SendJsMessage("getNotificationInfo", kNoArgs, reply_handler.AsWeakHandle());
}
TEST_F(SyncManagerTest, GetAllNodesTest) {