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 // 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 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 sync_manager_.UpdateEnabledTypes(); | 911 sync_manager_.UpdateEnabledTypes(); |
912 EXPECT_EQ(2, update_enabled_types_call_count_); | 912 EXPECT_EQ(2, update_enabled_types_call_count_); |
913 } | 913 } |
914 | 914 |
915 TEST_F(SyncManagerTest, ProcessJsMessage) { | 915 TEST_F(SyncManagerTest, ProcessJsMessage) { |
916 const JsArgList kNoArgs; | 916 const JsArgList kNoArgs; |
917 | 917 |
918 StrictMock<MockJsReplyHandler> reply_handler; | 918 StrictMock<MockJsReplyHandler> reply_handler; |
919 | 919 |
920 ListValue false_args; | 920 ListValue false_args; |
921 false_args.Append(Value::CreateBooleanValue(false)); | 921 false_args.Append(base::FalseValue()); |
922 | 922 |
923 EXPECT_CALL(reply_handler, | 923 EXPECT_CALL(reply_handler, |
924 HandleJsReply("getNotificationState", | 924 HandleJsReply("getNotificationState", |
925 HasArgsAsList(false_args))); | 925 HasArgsAsList(false_args))); |
926 | 926 |
927 // This message should be dropped. | 927 // This message should be dropped. |
928 SendJsMessage("unknownMessage", kNoArgs, reply_handler.AsWeakHandle()); | 928 SendJsMessage("unknownMessage", kNoArgs, reply_handler.AsWeakHandle()); |
929 | 929 |
930 SendJsMessage("getNotificationState", kNoArgs, reply_handler.AsWeakHandle()); | 930 SendJsMessage("getNotificationState", kNoArgs, reply_handler.AsWeakHandle()); |
931 } | 931 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 const int64 ids[] = { root_id, child_id }; | 998 const int64 ids[] = { root_id, child_id }; |
999 | 999 |
1000 EXPECT_CALL(reply_handler, | 1000 EXPECT_CALL(reply_handler, |
1001 HandleJsReply(message_name, _)) | 1001 HandleJsReply(message_name, _)) |
1002 .Times(arraysize(ids)).WillRepeatedly(SaveArg<1>(&return_args)); | 1002 .Times(arraysize(ids)).WillRepeatedly(SaveArg<1>(&return_args)); |
1003 | 1003 |
1004 for (size_t i = 0; i < arraysize(ids); ++i) { | 1004 for (size_t i = 0; i < arraysize(ids); ++i) { |
1005 ListValue args; | 1005 ListValue args; |
1006 ListValue* id_values = new ListValue(); | 1006 ListValue* id_values = new ListValue(); |
1007 args.Append(id_values); | 1007 args.Append(id_values); |
1008 id_values->Append(Value::CreateStringValue(base::Int64ToString(ids[i]))); | 1008 id_values->Append(base::StringValue::New(base::Int64ToString(ids[i]))); |
1009 SendJsMessage(message_name, | 1009 SendJsMessage(message_name, |
1010 JsArgList(&args), reply_handler.AsWeakHandle()); | 1010 JsArgList(&args), reply_handler.AsWeakHandle()); |
1011 | 1011 |
1012 CheckGetNodesByIdReturnArgs(sync_manager_, return_args, | 1012 CheckGetNodesByIdReturnArgs(sync_manager_, return_args, |
1013 ids[i], is_detailed); | 1013 ids[i], is_detailed); |
1014 } | 1014 } |
1015 } | 1015 } |
1016 | 1016 |
1017 void RunGetNodesByIdFailureTest(const char* message_name) { | 1017 void RunGetNodesByIdFailureTest(const char* message_name) { |
1018 StrictMock<MockJsReplyHandler> reply_handler; | 1018 StrictMock<MockJsReplyHandler> reply_handler; |
(...skipping 16 matching lines...) Expand all Loading... |
1035 ListValue args; | 1035 ListValue args; |
1036 args.Append(new ListValue()); | 1036 args.Append(new ListValue()); |
1037 SendJsMessage(message_name, | 1037 SendJsMessage(message_name, |
1038 JsArgList(&args), reply_handler.AsWeakHandle()); | 1038 JsArgList(&args), reply_handler.AsWeakHandle()); |
1039 } | 1039 } |
1040 | 1040 |
1041 { | 1041 { |
1042 ListValue args; | 1042 ListValue args; |
1043 ListValue* ids = new ListValue(); | 1043 ListValue* ids = new ListValue(); |
1044 args.Append(ids); | 1044 args.Append(ids); |
1045 ids->Append(Value::CreateStringValue("")); | 1045 ids->Append(base::StringValue::New("")); |
1046 SendJsMessage(message_name, | 1046 SendJsMessage(message_name, |
1047 JsArgList(&args), reply_handler.AsWeakHandle()); | 1047 JsArgList(&args), reply_handler.AsWeakHandle()); |
1048 } | 1048 } |
1049 | 1049 |
1050 { | 1050 { |
1051 ListValue args; | 1051 ListValue args; |
1052 ListValue* ids = new ListValue(); | 1052 ListValue* ids = new ListValue(); |
1053 args.Append(ids); | 1053 args.Append(ids); |
1054 ids->Append(Value::CreateStringValue("nonsense")); | 1054 ids->Append(base::StringValue::New("nonsense")); |
1055 SendJsMessage(message_name, | 1055 SendJsMessage(message_name, |
1056 JsArgList(&args), reply_handler.AsWeakHandle()); | 1056 JsArgList(&args), reply_handler.AsWeakHandle()); |
1057 } | 1057 } |
1058 | 1058 |
1059 { | 1059 { |
1060 ListValue args; | 1060 ListValue args; |
1061 ListValue* ids = new ListValue(); | 1061 ListValue* ids = new ListValue(); |
1062 args.Append(ids); | 1062 args.Append(ids); |
1063 ids->Append(Value::CreateStringValue("0")); | 1063 ids->Append(base::StringValue::New("0")); |
1064 SendJsMessage(message_name, | 1064 SendJsMessage(message_name, |
1065 JsArgList(&args), reply_handler.AsWeakHandle()); | 1065 JsArgList(&args), reply_handler.AsWeakHandle()); |
1066 } | 1066 } |
1067 | 1067 |
1068 { | 1068 { |
1069 ListValue args; | 1069 ListValue args; |
1070 ListValue* ids = new ListValue(); | 1070 ListValue* ids = new ListValue(); |
1071 args.Append(ids); | 1071 args.Append(ids); |
1072 ids->Append(Value::CreateStringValue("9999")); | 1072 ids->Append(base::StringValue::New("9999")); |
1073 SendJsMessage(message_name, | 1073 SendJsMessage(message_name, |
1074 JsArgList(&args), reply_handler.AsWeakHandle()); | 1074 JsArgList(&args), reply_handler.AsWeakHandle()); |
1075 } | 1075 } |
1076 } | 1076 } |
1077 }; | 1077 }; |
1078 | 1078 |
1079 TEST_F(SyncManagerGetNodesByIdTest, GetNodeSummariesById) { | 1079 TEST_F(SyncManagerGetNodesByIdTest, GetNodeSummariesById) { |
1080 RunGetNodesByIdTest("getNodeSummariesById", false); | 1080 RunGetNodesByIdTest("getNodeSummariesById", false); |
1081 } | 1081 } |
1082 | 1082 |
(...skipping 13 matching lines...) Expand all Loading... |
1096 StrictMock<MockJsReplyHandler> reply_handler; | 1096 StrictMock<MockJsReplyHandler> reply_handler; |
1097 | 1097 |
1098 JsArgList return_args; | 1098 JsArgList return_args; |
1099 | 1099 |
1100 EXPECT_CALL(reply_handler, | 1100 EXPECT_CALL(reply_handler, |
1101 HandleJsReply("getChildNodeIds", _)) | 1101 HandleJsReply("getChildNodeIds", _)) |
1102 .Times(1).WillRepeatedly(SaveArg<1>(&return_args)); | 1102 .Times(1).WillRepeatedly(SaveArg<1>(&return_args)); |
1103 | 1103 |
1104 { | 1104 { |
1105 ListValue args; | 1105 ListValue args; |
1106 args.Append(Value::CreateStringValue("1")); | 1106 args.Append(base::StringValue::New("1")); |
1107 SendJsMessage("getChildNodeIds", | 1107 SendJsMessage("getChildNodeIds", |
1108 JsArgList(&args), reply_handler.AsWeakHandle()); | 1108 JsArgList(&args), reply_handler.AsWeakHandle()); |
1109 } | 1109 } |
1110 | 1110 |
1111 EXPECT_EQ(1u, return_args.Get().GetSize()); | 1111 EXPECT_EQ(1u, return_args.Get().GetSize()); |
1112 ListValue* nodes = NULL; | 1112 ListValue* nodes = NULL; |
1113 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); | 1113 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); |
1114 ASSERT_TRUE(nodes); | 1114 ASSERT_TRUE(nodes); |
1115 EXPECT_EQ(5u, nodes->GetSize()); | 1115 EXPECT_EQ(5u, nodes->GetSize()); |
1116 } | 1116 } |
(...skipping 10 matching lines...) Expand all Loading... |
1127 .Times(5); | 1127 .Times(5); |
1128 | 1128 |
1129 { | 1129 { |
1130 ListValue args; | 1130 ListValue args; |
1131 SendJsMessage("getChildNodeIds", | 1131 SendJsMessage("getChildNodeIds", |
1132 JsArgList(&args), reply_handler.AsWeakHandle()); | 1132 JsArgList(&args), reply_handler.AsWeakHandle()); |
1133 } | 1133 } |
1134 | 1134 |
1135 { | 1135 { |
1136 ListValue args; | 1136 ListValue args; |
1137 args.Append(Value::CreateStringValue("")); | 1137 args.Append(base::StringValue::New("")); |
1138 SendJsMessage("getChildNodeIds", | 1138 SendJsMessage("getChildNodeIds", |
1139 JsArgList(&args), reply_handler.AsWeakHandle()); | 1139 JsArgList(&args), reply_handler.AsWeakHandle()); |
1140 } | 1140 } |
1141 | 1141 |
1142 { | 1142 { |
1143 ListValue args; | 1143 ListValue args; |
1144 args.Append(Value::CreateStringValue("nonsense")); | 1144 args.Append(base::StringValue::New("nonsense")); |
1145 SendJsMessage("getChildNodeIds", | 1145 SendJsMessage("getChildNodeIds", |
1146 JsArgList(&args), reply_handler.AsWeakHandle()); | 1146 JsArgList(&args), reply_handler.AsWeakHandle()); |
1147 } | 1147 } |
1148 | 1148 |
1149 { | 1149 { |
1150 ListValue args; | 1150 ListValue args; |
1151 args.Append(Value::CreateStringValue("0")); | 1151 args.Append(base::StringValue::New("0")); |
1152 SendJsMessage("getChildNodeIds", | 1152 SendJsMessage("getChildNodeIds", |
1153 JsArgList(&args), reply_handler.AsWeakHandle()); | 1153 JsArgList(&args), reply_handler.AsWeakHandle()); |
1154 } | 1154 } |
1155 | 1155 |
1156 { | 1156 { |
1157 ListValue args; | 1157 ListValue args; |
1158 args.Append(Value::CreateStringValue("9999")); | 1158 args.Append(base::StringValue::New("9999")); |
1159 SendJsMessage("getChildNodeIds", | 1159 SendJsMessage("getChildNodeIds", |
1160 JsArgList(&args), reply_handler.AsWeakHandle()); | 1160 JsArgList(&args), reply_handler.AsWeakHandle()); |
1161 } | 1161 } |
1162 } | 1162 } |
1163 | 1163 |
1164 // TODO(akalin): Add unit tests for findNodesContainingString message. | 1164 // TODO(akalin): Add unit tests for findNodesContainingString message. |
1165 | 1165 |
1166 TEST_F(SyncManagerTest, OnNotificationStateChange) { | 1166 TEST_F(SyncManagerTest, OnNotificationStateChange) { |
1167 InSequence dummy; | 1167 InSequence dummy; |
1168 StrictMock<MockJsEventHandler> event_handler; | 1168 StrictMock<MockJsEventHandler> event_handler; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 // Build expected_args to have a single argument with the string | 1205 // Build expected_args to have a single argument with the string |
1206 // equivalents of model_types. | 1206 // equivalents of model_types. |
1207 DictionaryValue expected_details; | 1207 DictionaryValue expected_details; |
1208 { | 1208 { |
1209 ListValue* model_type_list = new ListValue(); | 1209 ListValue* model_type_list = new ListValue(); |
1210 expected_details.Set("changedTypes", model_type_list); | 1210 expected_details.Set("changedTypes", model_type_list); |
1211 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 1211 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
1212 i < syncable::MODEL_TYPE_COUNT; ++i) { | 1212 i < syncable::MODEL_TYPE_COUNT; ++i) { |
1213 if (model_types[i]) { | 1213 if (model_types[i]) { |
1214 model_type_list->Append( | 1214 model_type_list->Append( |
1215 Value::CreateStringValue( | 1215 base::StringValue::New( |
1216 syncable::ModelTypeToString( | 1216 syncable::ModelTypeToString( |
1217 syncable::ModelTypeFromInt(i)))); | 1217 syncable::ModelTypeFromInt(i)))); |
1218 } | 1218 } |
1219 } | 1219 } |
1220 } | 1220 } |
1221 | 1221 |
1222 EXPECT_CALL(event_handler, | 1222 EXPECT_CALL(event_handler, |
1223 HandleJsEvent("onIncomingNotification", | 1223 HandleJsEvent("onIncomingNotification", |
1224 HasDetailsAsDictionary(expected_details))); | 1224 HasDetailsAsDictionary(expected_details))); |
1225 | 1225 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1423 { | 1423 { |
1424 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1424 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
1425 ReadNode password_node(&trans); | 1425 ReadNode password_node(&trans); |
1426 EXPECT_FALSE(password_node.InitByIdLookup(node_id)); | 1426 EXPECT_FALSE(password_node.InitByIdLookup(node_id)); |
1427 } | 1427 } |
1428 } | 1428 } |
1429 | 1429 |
1430 } // namespace | 1430 } // namespace |
1431 | 1431 |
1432 } // namespace browser_sync | 1432 } // namespace browser_sync |
OLD | NEW |