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 <map> | 9 #include <map> |
10 | 10 |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 ReadNode node(&trans); | 864 ReadNode node(&trans); |
865 node.InitByRootLookup(); | 865 node.InitByRootLookup(); |
866 CheckNodeValue(node, *node_info); | 866 CheckNodeValue(node, *node_info); |
867 } else { | 867 } else { |
868 ADD_FAILURE(); | 868 ADD_FAILURE(); |
869 } | 869 } |
870 | 870 |
871 js_backend->RemoveParentJsEventRouter(); | 871 js_backend->RemoveParentJsEventRouter(); |
872 } | 872 } |
873 | 873 |
874 void CheckGetNodeByIdReturnArgs(const SyncManager& sync_manager, | 874 void CheckGetNodesByIdReturnArgs(const SyncManager& sync_manager, |
875 const JsArgList& return_args, | 875 const JsArgList& return_args, |
876 int64 id) { | 876 int64 id) { |
877 EXPECT_EQ(1u, return_args.Get().GetSize()); | 877 EXPECT_EQ(1u, return_args.Get().GetSize()); |
| 878 ListValue* nodes = NULL; |
| 879 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); |
| 880 ASSERT_TRUE(nodes); |
| 881 EXPECT_EQ(1u, nodes->GetSize()); |
878 DictionaryValue* node_info = NULL; | 882 DictionaryValue* node_info = NULL; |
879 EXPECT_TRUE(return_args.Get().GetDictionary(0, &node_info)); | 883 EXPECT_TRUE(nodes->GetDictionary(0, &node_info)); |
880 if (node_info) { | 884 ASSERT_TRUE(node_info); |
881 ReadTransaction trans(sync_manager.GetUserShare()); | 885 ReadTransaction trans(sync_manager.GetUserShare()); |
882 ReadNode node(&trans); | 886 ReadNode node(&trans); |
883 node.InitByIdLookup(id); | 887 node.InitByIdLookup(id); |
884 CheckNodeValue(node, *node_info); | 888 CheckNodeValue(node, *node_info); |
885 } else { | |
886 ADD_FAILURE(); | |
887 } | |
888 } | 889 } |
889 | 890 |
890 TEST_F(SyncManagerTest, ProcessMessageGetNodeById) { | 891 TEST_F(SyncManagerTest, ProcessMessageGetNodesById) { |
891 int64 child_id = | 892 int64 child_id = |
892 MakeNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, "testtag"); | 893 MakeNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, "testtag"); |
893 | 894 |
894 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); | 895 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); |
895 | 896 |
896 StrictMock<MockJsEventHandler> event_handler; | 897 StrictMock<MockJsEventHandler> event_handler; |
897 StrictMock<MockJsEventRouter> event_router; | 898 StrictMock<MockJsEventRouter> event_router; |
898 | 899 |
899 JsArgList return_args; | 900 JsArgList return_args; |
900 | 901 |
901 EXPECT_CALL(event_router, | 902 EXPECT_CALL(event_router, |
902 RouteJsMessageReply("getNodeById", _, &event_handler)) | 903 RouteJsMessageReply("getNodesById", _, &event_handler)) |
903 .Times(2).WillRepeatedly(SaveArg<1>(&return_args)); | 904 .Times(2).WillRepeatedly(SaveArg<1>(&return_args)); |
904 | 905 |
905 js_backend->SetParentJsEventRouter(&event_router); | 906 js_backend->SetParentJsEventRouter(&event_router); |
906 | 907 |
907 // Should trigger the reply. | 908 // Should trigger the reply. |
908 { | 909 { |
909 ListValue args; | 910 ListValue args; |
910 args.Append(Value::CreateStringValue("1")); | 911 ListValue* ids = new ListValue(); |
911 js_backend->ProcessMessage("getNodeById", JsArgList(&args), &event_handler); | 912 args.Append(ids); |
| 913 ids->Append(Value::CreateStringValue("1")); |
| 914 js_backend->ProcessMessage("getNodesById", |
| 915 JsArgList(&args), &event_handler); |
912 } | 916 } |
913 | 917 |
914 CheckGetNodeByIdReturnArgs(sync_manager_, return_args, 1); | 918 CheckGetNodesByIdReturnArgs(sync_manager_, return_args, 1); |
915 | 919 |
916 // Should trigger another reply. | 920 // Should trigger another reply. |
917 { | 921 { |
918 ListValue args; | 922 ListValue args; |
919 args.Append(Value::CreateStringValue(base::Int64ToString(child_id))); | 923 ListValue* ids = new ListValue(); |
920 js_backend->ProcessMessage("getNodeById", JsArgList(&args), &event_handler); | 924 args.Append(ids); |
| 925 ids->Append(Value::CreateStringValue(base::Int64ToString(child_id))); |
| 926 js_backend->ProcessMessage("getNodesById", |
| 927 JsArgList(&args), &event_handler); |
921 } | 928 } |
922 | 929 |
923 CheckGetNodeByIdReturnArgs(sync_manager_, return_args, child_id); | 930 CheckGetNodesByIdReturnArgs(sync_manager_, return_args, child_id); |
924 | 931 |
925 js_backend->RemoveParentJsEventRouter(); | 932 js_backend->RemoveParentJsEventRouter(); |
926 } | 933 } |
927 | 934 |
928 TEST_F(SyncManagerTest, ProcessMessageGetNodeByIdFailure) { | 935 TEST_F(SyncManagerTest, ProcessMessageGetNodesByIdFailure) { |
929 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); | 936 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); |
930 | 937 |
931 StrictMock<MockJsEventHandler> event_handler; | 938 StrictMock<MockJsEventHandler> event_handler; |
932 StrictMock<MockJsEventRouter> event_router; | 939 StrictMock<MockJsEventRouter> event_router; |
933 | 940 |
934 ListValue null_args; | 941 ListValue empty_list_args; |
935 null_args.Append(Value::CreateNullValue()); | 942 empty_list_args.Append(new ListValue()); |
936 | 943 |
937 EXPECT_CALL(event_router, | 944 EXPECT_CALL(event_router, |
938 RouteJsMessageReply("getNodeById", HasArgsAsList(null_args), | 945 RouteJsMessageReply("getNodesById", |
| 946 HasArgsAsList(empty_list_args), |
| 947 &event_handler)) |
| 948 .Times(6); |
| 949 |
| 950 js_backend->SetParentJsEventRouter(&event_router); |
| 951 |
| 952 { |
| 953 ListValue args; |
| 954 js_backend->ProcessMessage("getNodesById", |
| 955 JsArgList(&args), &event_handler); |
| 956 } |
| 957 |
| 958 { |
| 959 ListValue args; |
| 960 args.Append(new ListValue()); |
| 961 js_backend->ProcessMessage("getNodesById", |
| 962 JsArgList(&args), &event_handler); |
| 963 } |
| 964 |
| 965 { |
| 966 ListValue args; |
| 967 ListValue* ids = new ListValue(); |
| 968 args.Append(ids); |
| 969 ids->Append(Value::CreateStringValue("")); |
| 970 js_backend->ProcessMessage("getNodesById", |
| 971 JsArgList(&args), &event_handler); |
| 972 } |
| 973 |
| 974 { |
| 975 ListValue args; |
| 976 ListValue* ids = new ListValue(); |
| 977 args.Append(ids); |
| 978 ids->Append(Value::CreateStringValue("nonsense")); |
| 979 js_backend->ProcessMessage("getNodesById", |
| 980 JsArgList(&args), &event_handler); |
| 981 } |
| 982 |
| 983 { |
| 984 ListValue args; |
| 985 ListValue* ids = new ListValue(); |
| 986 args.Append(ids); |
| 987 ids->Append(Value::CreateStringValue("0")); |
| 988 js_backend->ProcessMessage("getNodesById", |
| 989 JsArgList(&args), &event_handler); |
| 990 } |
| 991 |
| 992 { |
| 993 ListValue args; |
| 994 ListValue* ids = new ListValue(); |
| 995 args.Append(ids); |
| 996 ids->Append(Value::CreateStringValue("9999")); |
| 997 js_backend->ProcessMessage("getNodesById", |
| 998 JsArgList(&args), &event_handler); |
| 999 } |
| 1000 |
| 1001 js_backend->RemoveParentJsEventRouter(); |
| 1002 } |
| 1003 |
| 1004 TEST_F(SyncManagerTest, ProcessMessageGetChildNodeIds) { |
| 1005 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); |
| 1006 |
| 1007 StrictMock<MockJsEventHandler> event_handler; |
| 1008 StrictMock<MockJsEventRouter> event_router; |
| 1009 |
| 1010 JsArgList return_args; |
| 1011 |
| 1012 EXPECT_CALL(event_router, |
| 1013 RouteJsMessageReply("getChildNodeIds", _, &event_handler)) |
| 1014 .Times(1).WillRepeatedly(SaveArg<1>(&return_args)); |
| 1015 |
| 1016 js_backend->SetParentJsEventRouter(&event_router); |
| 1017 |
| 1018 // Should trigger the reply. |
| 1019 { |
| 1020 ListValue args; |
| 1021 args.Append(Value::CreateStringValue("1")); |
| 1022 js_backend->ProcessMessage("getChildNodeIds", |
| 1023 JsArgList(&args), &event_handler); |
| 1024 } |
| 1025 |
| 1026 EXPECT_EQ(1u, return_args.Get().GetSize()); |
| 1027 ListValue* nodes = NULL; |
| 1028 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); |
| 1029 ASSERT_TRUE(nodes); |
| 1030 EXPECT_EQ(5u, nodes->GetSize()); |
| 1031 |
| 1032 js_backend->RemoveParentJsEventRouter(); |
| 1033 } |
| 1034 |
| 1035 TEST_F(SyncManagerTest, ProcessMessageGetChildNodeIdsFailure) { |
| 1036 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); |
| 1037 |
| 1038 StrictMock<MockJsEventHandler> event_handler; |
| 1039 StrictMock<MockJsEventRouter> event_router; |
| 1040 |
| 1041 ListValue empty_list_args; |
| 1042 empty_list_args.Append(new ListValue()); |
| 1043 |
| 1044 EXPECT_CALL(event_router, |
| 1045 RouteJsMessageReply("getChildNodeIds", |
| 1046 HasArgsAsList(empty_list_args), |
939 &event_handler)) | 1047 &event_handler)) |
940 .Times(5); | 1048 .Times(5); |
941 | 1049 |
942 js_backend->SetParentJsEventRouter(&event_router); | 1050 js_backend->SetParentJsEventRouter(&event_router); |
943 | 1051 |
944 { | 1052 { |
945 ListValue args; | 1053 ListValue args; |
946 js_backend->ProcessMessage("getNodeById", JsArgList(&args), &event_handler); | 1054 js_backend->ProcessMessage("getChildNodeIds", |
| 1055 JsArgList(&args), &event_handler); |
947 } | 1056 } |
948 | 1057 |
949 { | 1058 { |
950 ListValue args; | 1059 ListValue args; |
951 args.Append(Value::CreateStringValue("")); | 1060 args.Append(Value::CreateStringValue("")); |
952 js_backend->ProcessMessage("getNodeById", JsArgList(&args), &event_handler); | 1061 js_backend->ProcessMessage("getChildNodeIds", |
| 1062 JsArgList(&args), &event_handler); |
953 } | 1063 } |
954 | 1064 |
955 { | 1065 { |
956 ListValue args; | 1066 ListValue args; |
957 args.Append(Value::CreateStringValue("nonsense")); | 1067 args.Append(Value::CreateStringValue("nonsense")); |
958 js_backend->ProcessMessage("getNodeById", JsArgList(&args), &event_handler); | 1068 js_backend->ProcessMessage("getChildNodeIds", |
959 } | 1069 JsArgList(&args), &event_handler); |
960 | |
961 { | |
962 ListValue args; | |
963 args.Append(Value::CreateStringValue("nonsense")); | |
964 js_backend->ProcessMessage("getNodeById", JsArgList(&args), &event_handler); | |
965 } | 1070 } |
966 | 1071 |
967 { | 1072 { |
968 ListValue args; | 1073 ListValue args; |
969 args.Append(Value::CreateStringValue("0")); | 1074 args.Append(Value::CreateStringValue("0")); |
970 js_backend->ProcessMessage("getNodeById", JsArgList(&args), &event_handler); | 1075 js_backend->ProcessMessage("getChildNodeIds", |
| 1076 JsArgList(&args), &event_handler); |
971 } | 1077 } |
972 | 1078 |
973 // TODO(akalin): Figure out how to test InitByIdLookup() failure. | 1079 { |
| 1080 ListValue args; |
| 1081 args.Append(Value::CreateStringValue("9999")); |
| 1082 js_backend->ProcessMessage("getChildNodeIds", |
| 1083 JsArgList(&args), &event_handler); |
| 1084 } |
974 | 1085 |
975 js_backend->RemoveParentJsEventRouter(); | 1086 js_backend->RemoveParentJsEventRouter(); |
976 } | 1087 } |
977 | 1088 |
978 TEST_F(SyncManagerTest, OnNotificationStateChange) { | 1089 TEST_F(SyncManagerTest, OnNotificationStateChange) { |
979 InSequence dummy; | 1090 InSequence dummy; |
980 StrictMock<MockJsEventRouter> event_router; | 1091 StrictMock<MockJsEventRouter> event_router; |
981 | 1092 |
982 DictionaryValue true_details; | 1093 DictionaryValue true_details; |
983 true_details.SetBoolean("enabled", true); | 1094 true_details.SetBoolean("enabled", true); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 true /* is encrypted */)); | 1235 true /* is encrypted */)); |
1125 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1236 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
1126 syncable::THEMES, | 1237 syncable::THEMES, |
1127 false /* not encrypted */)); | 1238 false /* not encrypted */)); |
1128 } | 1239 } |
1129 } | 1240 } |
1130 | 1241 |
1131 } // namespace | 1242 } // namespace |
1132 | 1243 |
1133 } // namespace browser_sync | 1244 } // namespace browser_sync |
OLD | NEW |