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

Side by Side Diff: sync/internal_api/sync_manager_impl_unittest.cc

Issue 134443004: sync: Remove some WebUI debug functions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/js/js_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 // Unit tests for the SyncApi. Note that a lot of the underlying 5 // Unit tests for the SyncApi. Note that a lot of the underlying
6 // functionality is provided by the Syncable layer, which has its own 6 // functionality is provided by the Syncable layer, which has its own
7 // unit tests. We'll test SyncApi specific things in this harness. 7 // unit tests. We'll test SyncApi specific things in this harness.
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 using sessions::SyncSessionSnapshot; 90 using sessions::SyncSessionSnapshot;
91 using syncable::GET_BY_HANDLE; 91 using syncable::GET_BY_HANDLE;
92 using syncable::IS_DEL; 92 using syncable::IS_DEL;
93 using syncable::IS_UNSYNCED; 93 using syncable::IS_UNSYNCED;
94 using syncable::NON_UNIQUE_NAME; 94 using syncable::NON_UNIQUE_NAME;
95 using syncable::SPECIFICS; 95 using syncable::SPECIFICS;
96 using syncable::kEncryptedString; 96 using syncable::kEncryptedString;
97 97
98 namespace { 98 namespace {
99 99
100 void ExpectInt64Value(int64 expected_value,
101 const base::DictionaryValue& value,
102 const std::string& key) {
103 std::string int64_str;
104 EXPECT_TRUE(value.GetString(key, &int64_str));
105 int64 val = 0;
106 EXPECT_TRUE(base::StringToInt64(int64_str, &val));
107 EXPECT_EQ(expected_value, val);
108 }
109
110 void ExpectTimeValue(const base::Time& expected_value,
111 const base::DictionaryValue& value,
112 const std::string& key) {
113 std::string time_str;
114 EXPECT_TRUE(value.GetString(key, &time_str));
115 EXPECT_EQ(GetTimeDebugString(expected_value), time_str);
116 }
117
118 // Makes a non-folder child of the root node. Returns the id of the 100 // Makes a non-folder child of the root node. Returns the id of the
119 // newly-created node. 101 // newly-created node.
120 int64 MakeNode(UserShare* share, 102 int64 MakeNode(UserShare* share,
121 ModelType model_type, 103 ModelType model_type,
122 const std::string& client_tag) { 104 const std::string& client_tag) {
123 WriteTransaction trans(FROM_HERE, share); 105 WriteTransaction trans(FROM_HERE, share);
124 ReadNode root_node(&trans); 106 ReadNode root_node(&trans);
125 root_node.InitByRootLookup(); 107 root_node.InitByRootLookup();
126 WriteNode node(&trans); 108 WriteNode node(&trans);
127 WriteNode::InitUniqueByCreationResult result = 109 WriteNode::InitUniqueByCreationResult result =
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); 501 entity_specifics.mutable_bookmark()->set_url("http://www.google.com");
520 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); 502 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100);
521 node.SetEntitySpecifics(entity_specifics); 503 node.SetEntitySpecifics(entity_specifics);
522 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); 504 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty());
523 505
524 entity_specifics.mutable_unknown_fields()->Clear(); 506 entity_specifics.mutable_unknown_fields()->Clear();
525 node.SetEntitySpecifics(entity_specifics); 507 node.SetEntitySpecifics(entity_specifics);
526 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); 508 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty());
527 } 509 }
528 510
529 namespace {
530
531 void CheckNodeValue(const BaseNode& node, const base::DictionaryValue& value,
532 bool is_detailed) {
533 size_t expected_field_count = 4;
534
535 ExpectInt64Value(node.GetId(), value, "id");
536 {
537 bool is_folder = false;
538 EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder));
539 EXPECT_EQ(node.GetIsFolder(), is_folder);
540 }
541 ExpectDictStringValue(node.GetTitle(), value, "title");
542
543 ModelType expected_model_type = node.GetModelType();
544 std::string type_str;
545 EXPECT_TRUE(value.GetString("type", &type_str));
546 if (expected_model_type >= FIRST_REAL_MODEL_TYPE) {
547 ModelType model_type = ModelTypeFromString(type_str);
548 EXPECT_EQ(expected_model_type, model_type);
549 } else if (expected_model_type == TOP_LEVEL_FOLDER) {
550 EXPECT_EQ("Top-level folder", type_str);
551 } else if (expected_model_type == UNSPECIFIED) {
552 EXPECT_EQ("Unspecified", type_str);
553 } else {
554 ADD_FAILURE();
555 }
556
557 if (is_detailed) {
558 {
559 scoped_ptr<base::DictionaryValue> expected_entry(
560 node.GetEntry()->ToValue(NULL));
561 const base::Value* entry = NULL;
562 EXPECT_TRUE(value.Get("entry", &entry));
563 EXPECT_TRUE(base::Value::Equals(entry, expected_entry.get()));
564 }
565
566 ExpectInt64Value(node.GetParentId(), value, "parentId");
567 ExpectTimeValue(node.GetModificationTime(), value, "modificationTime");
568 ExpectInt64Value(node.GetExternalId(), value, "externalId");
569 expected_field_count += 4;
570
571 if (value.HasKey("predecessorId")) {
572 ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId");
573 expected_field_count++;
574 }
575 if (value.HasKey("successorId")) {
576 ExpectInt64Value(node.GetSuccessorId(), value, "successorId");
577 expected_field_count++;
578 }
579 if (value.HasKey("firstChildId")) {
580 ExpectInt64Value(node.GetFirstChildId(), value, "firstChildId");
581 expected_field_count++;
582 }
583 }
584
585 EXPECT_EQ(expected_field_count, value.size());
586 }
587
588 } // namespace
589
590 TEST_F(SyncApiTest, BaseNodeGetSummaryAsValue) {
591 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
592 ReadNode node(&trans);
593 node.InitByRootLookup();
594 scoped_ptr<base::DictionaryValue> details(node.GetSummaryAsValue());
595 if (details) {
596 CheckNodeValue(node, *details, false);
597 } else {
598 ADD_FAILURE();
599 }
600 }
601
602 TEST_F(SyncApiTest, BaseNodeGetDetailsAsValue) {
603 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
604 ReadNode node(&trans);
605 node.InitByRootLookup();
606 scoped_ptr<base::DictionaryValue> details(node.GetDetailsAsValue());
607 if (details) {
608 CheckNodeValue(node, *details, true);
609 } else {
610 ADD_FAILURE();
611 }
612 }
613
614 TEST_F(SyncApiTest, EmptyTags) { 511 TEST_F(SyncApiTest, EmptyTags) {
615 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 512 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
616 ReadNode root_node(&trans); 513 ReadNode root_node(&trans);
617 root_node.InitByRootLookup(); 514 root_node.InitByRootLookup();
618 WriteNode node(&trans); 515 WriteNode node(&trans);
619 std::string empty_tag; 516 std::string empty_tag;
620 WriteNode::InitUniqueByCreationResult result = 517 WriteNode::InitUniqueByCreationResult result =
621 node.InitUniqueByCreation(TYPED_URLS, root_node, empty_tag); 518 node.InitUniqueByCreation(TYPED_URLS, root_node, empty_tag);
622 EXPECT_NE(WriteNode::INIT_SUCCESS, result); 519 EXPECT_NE(WriteNode::INIT_SUCCESS, result);
623 EXPECT_EQ(BaseNode::INIT_FAILED_PRECONDITION, 520 EXPECT_EQ(BaseNode::INIT_FAILED_PRECONDITION,
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 (*out)[DEVICE_INFO] = GROUP_PASSIVE; 767 (*out)[DEVICE_INFO] = GROUP_PASSIVE;
871 (*out)[EXPERIMENTS] = GROUP_PASSIVE; 768 (*out)[EXPERIMENTS] = GROUP_PASSIVE;
872 (*out)[BOOKMARKS] = GROUP_PASSIVE; 769 (*out)[BOOKMARKS] = GROUP_PASSIVE;
873 (*out)[THEMES] = GROUP_PASSIVE; 770 (*out)[THEMES] = GROUP_PASSIVE;
874 (*out)[SESSIONS] = GROUP_PASSIVE; 771 (*out)[SESSIONS] = GROUP_PASSIVE;
875 (*out)[PASSWORDS] = GROUP_PASSIVE; 772 (*out)[PASSWORDS] = GROUP_PASSIVE;
876 (*out)[PREFERENCES] = GROUP_PASSIVE; 773 (*out)[PREFERENCES] = GROUP_PASSIVE;
877 (*out)[PRIORITY_PREFERENCES] = GROUP_PASSIVE; 774 (*out)[PRIORITY_PREFERENCES] = GROUP_PASSIVE;
878 } 775 }
879 776
777 ModelTypeSet GetEnabledTypes() {
778 ModelSafeRoutingInfo routing_info;
779 GetModelSafeRoutingInfo(&routing_info);
780 return GetRoutingInfoTypes(routing_info);
781 }
782
880 virtual void OnChangesApplied( 783 virtual void OnChangesApplied(
881 ModelType model_type, 784 ModelType model_type,
882 int64 model_version, 785 int64 model_version,
883 const BaseTransaction* trans, 786 const BaseTransaction* trans,
884 const ImmutableChangeRecordList& changes) OVERRIDE {} 787 const ImmutableChangeRecordList& changes) OVERRIDE {}
885 788
886 virtual void OnChangesComplete(ModelType model_type) OVERRIDE {} 789 virtual void OnChangesComplete(ModelType model_type) OVERRIDE {}
887 790
888 // Helper methods. 791 // Helper methods.
889 bool SetUpEncryption(NigoriStatus nigori_status, 792 bool SetUpEncryption(NigoriStatus nigori_status,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 StrictMock<SyncManagerObserverMock> manager_observer_; 935 StrictMock<SyncManagerObserverMock> manager_observer_;
1033 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; 936 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_;
1034 InternalComponentsFactory::Switches switches_; 937 InternalComponentsFactory::Switches switches_;
1035 }; 938 };
1036 939
1037 TEST_F(SyncManagerTest, ProcessJsMessage) { 940 TEST_F(SyncManagerTest, ProcessJsMessage) {
1038 const JsArgList kNoArgs; 941 const JsArgList kNoArgs;
1039 942
1040 StrictMock<MockJsReplyHandler> reply_handler; 943 StrictMock<MockJsReplyHandler> reply_handler;
1041 944
1042 base::ListValue disabled_args;
1043 disabled_args.Append(new base::StringValue("TRANSIENT_INVALIDATION_ERROR"));
1044
1045 EXPECT_CALL(reply_handler, 945 EXPECT_CALL(reply_handler,
1046 HandleJsReply("getNotificationState", 946 HandleJsReply("getNotificationInfo", _));
1047 HasArgsAsList(disabled_args)));
1048 947
1049 // This message should be dropped. 948 // This message should be dropped.
1050 SendJsMessage("unknownMessage", kNoArgs, reply_handler.AsWeakHandle()); 949 SendJsMessage("unknownMessage", kNoArgs, reply_handler.AsWeakHandle());
1051 950
1052 SendJsMessage("getNotificationState", kNoArgs, reply_handler.AsWeakHandle()); 951 SendJsMessage("getNotificationInfo", kNoArgs, reply_handler.AsWeakHandle());
1053 }
1054
1055 TEST_F(SyncManagerTest, ProcessJsMessageGetRootNodeDetails) {
1056 const JsArgList kNoArgs;
1057
1058 StrictMock<MockJsReplyHandler> reply_handler;
1059
1060 JsArgList return_args;
1061
1062 EXPECT_CALL(reply_handler,
1063 HandleJsReply("getRootNodeDetails", _))
1064 .WillOnce(SaveArg<1>(&return_args));
1065
1066 SendJsMessage("getRootNodeDetails", kNoArgs, reply_handler.AsWeakHandle());
1067
1068 EXPECT_EQ(1u, return_args.Get().GetSize());
1069 const base::DictionaryValue* node_info = NULL;
1070 EXPECT_TRUE(return_args.Get().GetDictionary(0, &node_info));
1071 if (node_info) {
1072 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1073 ReadNode node(&trans);
1074 node.InitByRootLookup();
1075 CheckNodeValue(node, *node_info, true);
1076 } else {
1077 ADD_FAILURE();
1078 }
1079 }
1080
1081 void CheckGetNodesByIdReturnArgs(SyncManager* sync_manager,
1082 const JsArgList& return_args,
1083 int64 id,
1084 bool is_detailed) {
1085 EXPECT_EQ(1u, return_args.Get().GetSize());
1086 const base::ListValue* nodes = NULL;
1087 ASSERT_TRUE(return_args.Get().GetList(0, &nodes));
1088 ASSERT_TRUE(nodes);
1089 EXPECT_EQ(1u, nodes->GetSize());
1090 const base::DictionaryValue* node_info = NULL;
1091 EXPECT_TRUE(nodes->GetDictionary(0, &node_info));
1092 ASSERT_TRUE(node_info);
1093 ReadTransaction trans(FROM_HERE, sync_manager->GetUserShare());
1094 ReadNode node(&trans);
1095 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
1096 CheckNodeValue(node, *node_info, is_detailed);
1097 }
1098
1099 class SyncManagerGetNodesByIdTest : public SyncManagerTest {
1100 protected:
1101 virtual ~SyncManagerGetNodesByIdTest() {}
1102
1103 void RunGetNodesByIdTest(const char* message_name, bool is_detailed) {
1104 int64 root_id = kInvalidId;
1105 {
1106 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1107 ReadNode root_node(&trans);
1108 root_node.InitByRootLookup();
1109 root_id = root_node.GetId();
1110 }
1111
1112 int64 child_id =
1113 MakeNode(sync_manager_.GetUserShare(), BOOKMARKS, "testtag");
1114
1115 StrictMock<MockJsReplyHandler> reply_handler;
1116
1117 JsArgList return_args;
1118
1119 const int64 ids[] = { root_id, child_id };
1120
1121 EXPECT_CALL(reply_handler,
1122 HandleJsReply(message_name, _))
1123 .Times(arraysize(ids)).WillRepeatedly(SaveArg<1>(&return_args));
1124
1125 for (size_t i = 0; i < arraysize(ids); ++i) {
1126 base::ListValue args;
1127 base::ListValue* id_values = new base::ListValue();
1128 args.Append(id_values);
1129 id_values->Append(new base::StringValue(base::Int64ToString(ids[i])));
1130 SendJsMessage(message_name,
1131 JsArgList(&args), reply_handler.AsWeakHandle());
1132
1133 CheckGetNodesByIdReturnArgs(&sync_manager_, return_args,
1134 ids[i], is_detailed);
1135 }
1136 }
1137
1138 void RunGetNodesByIdFailureTest(const char* message_name) {
1139 StrictMock<MockJsReplyHandler> reply_handler;
1140
1141 base::ListValue empty_list_args;
1142 empty_list_args.Append(new base::ListValue());
1143
1144 EXPECT_CALL(reply_handler,
1145 HandleJsReply(message_name,
1146 HasArgsAsList(empty_list_args)))
1147 .Times(6);
1148
1149 {
1150 base::ListValue args;
1151 SendJsMessage(message_name,
1152 JsArgList(&args), reply_handler.AsWeakHandle());
1153 }
1154
1155 {
1156 base::ListValue args;
1157 args.Append(new base::ListValue());
1158 SendJsMessage(message_name,
1159 JsArgList(&args), reply_handler.AsWeakHandle());
1160 }
1161
1162 {
1163 base::ListValue args;
1164 base::ListValue* ids = new base::ListValue();
1165 args.Append(ids);
1166 ids->Append(new base::StringValue(std::string()));
1167 SendJsMessage(
1168 message_name, JsArgList(&args), reply_handler.AsWeakHandle());
1169 }
1170
1171 {
1172 base::ListValue args;
1173 base::ListValue* ids = new base::ListValue();
1174 args.Append(ids);
1175 ids->Append(new base::StringValue("nonsense"));
1176 SendJsMessage(message_name,
1177 JsArgList(&args), reply_handler.AsWeakHandle());
1178 }
1179
1180 {
1181 base::ListValue args;
1182 base::ListValue* ids = new base::ListValue();
1183 args.Append(ids);
1184 ids->Append(new base::StringValue("0"));
1185 SendJsMessage(message_name,
1186 JsArgList(&args), reply_handler.AsWeakHandle());
1187 }
1188
1189 {
1190 base::ListValue args;
1191 base::ListValue* ids = new base::ListValue();
1192 args.Append(ids);
1193 ids->Append(new base::StringValue("9999"));
1194 SendJsMessage(message_name,
1195 JsArgList(&args), reply_handler.AsWeakHandle());
1196 }
1197 }
1198 };
1199
1200 TEST_F(SyncManagerGetNodesByIdTest, GetNodeSummariesById) {
1201 RunGetNodesByIdTest("getNodeSummariesById", false);
1202 }
1203
1204 TEST_F(SyncManagerGetNodesByIdTest, GetNodeDetailsById) {
1205 RunGetNodesByIdTest("getNodeDetailsById", true);
1206 }
1207
1208 TEST_F(SyncManagerGetNodesByIdTest, GetNodeSummariesByIdFailure) {
1209 RunGetNodesByIdFailureTest("getNodeSummariesById");
1210 }
1211
1212 TEST_F(SyncManagerGetNodesByIdTest, GetNodeDetailsByIdFailure) {
1213 RunGetNodesByIdFailureTest("getNodeDetailsById");
1214 }
1215
1216 TEST_F(SyncManagerTest, GetChildNodeIds) {
1217 StrictMock<MockJsReplyHandler> reply_handler;
1218
1219 JsArgList return_args;
1220
1221 EXPECT_CALL(reply_handler,
1222 HandleJsReply("getChildNodeIds", _))
1223 .Times(1).WillRepeatedly(SaveArg<1>(&return_args));
1224
1225 {
1226 base::ListValue args;
1227 args.Append(new base::StringValue("1"));
1228 SendJsMessage("getChildNodeIds",
1229 JsArgList(&args), reply_handler.AsWeakHandle());
1230 }
1231
1232 EXPECT_EQ(1u, return_args.Get().GetSize());
1233 const base::ListValue* nodes = NULL;
1234 ASSERT_TRUE(return_args.Get().GetList(0, &nodes));
1235 ASSERT_TRUE(nodes);
1236 EXPECT_EQ(9u, nodes->GetSize());
1237 }
1238
1239 TEST_F(SyncManagerTest, GetChildNodeIdsFailure) {
1240 StrictMock<MockJsReplyHandler> reply_handler;
1241
1242 base::ListValue empty_list_args;
1243 empty_list_args.Append(new base::ListValue());
1244
1245 EXPECT_CALL(reply_handler,
1246 HandleJsReply("getChildNodeIds",
1247 HasArgsAsList(empty_list_args)))
1248 .Times(5);
1249
1250 {
1251 base::ListValue args;
1252 SendJsMessage("getChildNodeIds",
1253 JsArgList(&args), reply_handler.AsWeakHandle());
1254 }
1255
1256 {
1257 base::ListValue args;
1258 args.Append(new base::StringValue(std::string()));
1259 SendJsMessage(
1260 "getChildNodeIds", JsArgList(&args), reply_handler.AsWeakHandle());
1261 }
1262
1263 {
1264 base::ListValue args;
1265 args.Append(new base::StringValue("nonsense"));
1266 SendJsMessage("getChildNodeIds",
1267 JsArgList(&args), reply_handler.AsWeakHandle());
1268 }
1269
1270 {
1271 base::ListValue args;
1272 args.Append(new base::StringValue("0"));
1273 SendJsMessage("getChildNodeIds",
1274 JsArgList(&args), reply_handler.AsWeakHandle());
1275 }
1276
1277 {
1278 base::ListValue args;
1279 args.Append(new base::StringValue("9999"));
1280 SendJsMessage("getChildNodeIds",
1281 JsArgList(&args), reply_handler.AsWeakHandle());
1282 }
1283 } 952 }
1284 953
1285 TEST_F(SyncManagerTest, GetAllNodesTest) { 954 TEST_F(SyncManagerTest, GetAllNodesTest) {
1286 StrictMock<MockJsReplyHandler> reply_handler; 955 StrictMock<MockJsReplyHandler> reply_handler;
1287 JsArgList return_args; 956 JsArgList return_args;
1288 957
1289 EXPECT_CALL(reply_handler, 958 EXPECT_CALL(reply_handler,
1290 HandleJsReply("getAllNodes", _)) 959 HandleJsReply("getAllNodes", _))
1291 .Times(1).WillRepeatedly(SaveArg<1>(&return_args)); 960 .Times(1).WillRepeatedly(SaveArg<1>(&return_args));
1292 961
(...skipping 2218 matching lines...) Expand 10 before | Expand all | Expand 10 after
3511 // SyncManagerInitInvalidStorageTest::GetFactory will return 3180 // SyncManagerInitInvalidStorageTest::GetFactory will return
3512 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. 3181 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails.
3513 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's 3182 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's
3514 // task is to ensure that SyncManagerImpl reported initialization failure in 3183 // task is to ensure that SyncManagerImpl reported initialization failure in
3515 // OnInitializationComplete callback. 3184 // OnInitializationComplete callback.
3516 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { 3185 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) {
3517 EXPECT_FALSE(initialization_succeeded_); 3186 EXPECT_FALSE(initialization_succeeded_);
3518 } 3187 }
3519 3188
3520 } // namespace 3189 } // namespace
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/js/js_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698