OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 | 993 |
994 JsArgList return_args; | 994 JsArgList return_args; |
995 | 995 |
996 EXPECT_CALL(reply_handler, | 996 EXPECT_CALL(reply_handler, |
997 HandleJsReply("getRootNodeDetails", _)) | 997 HandleJsReply("getRootNodeDetails", _)) |
998 .WillOnce(SaveArg<1>(&return_args)); | 998 .WillOnce(SaveArg<1>(&return_args)); |
999 | 999 |
1000 SendJsMessage("getRootNodeDetails", kNoArgs, reply_handler.AsWeakHandle()); | 1000 SendJsMessage("getRootNodeDetails", kNoArgs, reply_handler.AsWeakHandle()); |
1001 | 1001 |
1002 EXPECT_EQ(1u, return_args.Get().GetSize()); | 1002 EXPECT_EQ(1u, return_args.Get().GetSize()); |
1003 DictionaryValue* node_info = NULL; | 1003 const DictionaryValue* node_info = NULL; |
1004 EXPECT_TRUE(return_args.Get().GetDictionary(0, &node_info)); | 1004 EXPECT_TRUE(return_args.Get().GetDictionary(0, &node_info)); |
1005 if (node_info) { | 1005 if (node_info) { |
1006 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1006 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
1007 ReadNode node(&trans); | 1007 ReadNode node(&trans); |
1008 node.InitByRootLookup(); | 1008 node.InitByRootLookup(); |
1009 CheckNodeValue(node, *node_info, true); | 1009 CheckNodeValue(node, *node_info, true); |
1010 } else { | 1010 } else { |
1011 ADD_FAILURE(); | 1011 ADD_FAILURE(); |
1012 } | 1012 } |
1013 } | 1013 } |
1014 | 1014 |
1015 void CheckGetNodesByIdReturnArgs(SyncManager* sync_manager, | 1015 void CheckGetNodesByIdReturnArgs(SyncManager* sync_manager, |
1016 const JsArgList& return_args, | 1016 const JsArgList& return_args, |
1017 int64 id, | 1017 int64 id, |
1018 bool is_detailed) { | 1018 bool is_detailed) { |
1019 EXPECT_EQ(1u, return_args.Get().GetSize()); | 1019 EXPECT_EQ(1u, return_args.Get().GetSize()); |
1020 ListValue* nodes = NULL; | 1020 const ListValue* nodes = NULL; |
1021 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); | 1021 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); |
1022 ASSERT_TRUE(nodes); | 1022 ASSERT_TRUE(nodes); |
1023 EXPECT_EQ(1u, nodes->GetSize()); | 1023 EXPECT_EQ(1u, nodes->GetSize()); |
1024 DictionaryValue* node_info = NULL; | 1024 const DictionaryValue* node_info = NULL; |
1025 EXPECT_TRUE(nodes->GetDictionary(0, &node_info)); | 1025 EXPECT_TRUE(nodes->GetDictionary(0, &node_info)); |
1026 ASSERT_TRUE(node_info); | 1026 ASSERT_TRUE(node_info); |
1027 ReadTransaction trans(FROM_HERE, sync_manager->GetUserShare()); | 1027 ReadTransaction trans(FROM_HERE, sync_manager->GetUserShare()); |
1028 ReadNode node(&trans); | 1028 ReadNode node(&trans); |
1029 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); | 1029 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); |
1030 CheckNodeValue(node, *node_info, is_detailed); | 1030 CheckNodeValue(node, *node_info, is_detailed); |
1031 } | 1031 } |
1032 | 1032 |
1033 class SyncManagerGetNodesByIdTest : public SyncManagerTest { | 1033 class SyncManagerGetNodesByIdTest : public SyncManagerTest { |
1034 protected: | 1034 protected: |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 .Times(1).WillRepeatedly(SaveArg<1>(&return_args)); | 1157 .Times(1).WillRepeatedly(SaveArg<1>(&return_args)); |
1158 | 1158 |
1159 { | 1159 { |
1160 ListValue args; | 1160 ListValue args; |
1161 args.Append(Value::CreateStringValue("1")); | 1161 args.Append(Value::CreateStringValue("1")); |
1162 SendJsMessage("getChildNodeIds", | 1162 SendJsMessage("getChildNodeIds", |
1163 JsArgList(&args), reply_handler.AsWeakHandle()); | 1163 JsArgList(&args), reply_handler.AsWeakHandle()); |
1164 } | 1164 } |
1165 | 1165 |
1166 EXPECT_EQ(1u, return_args.Get().GetSize()); | 1166 EXPECT_EQ(1u, return_args.Get().GetSize()); |
1167 ListValue* nodes = NULL; | 1167 const ListValue* nodes = NULL; |
1168 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); | 1168 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); |
1169 ASSERT_TRUE(nodes); | 1169 ASSERT_TRUE(nodes); |
1170 EXPECT_EQ(6u, nodes->GetSize()); | 1170 EXPECT_EQ(6u, nodes->GetSize()); |
1171 } | 1171 } |
1172 | 1172 |
1173 TEST_F(SyncManagerTest, GetChildNodeIdsFailure) { | 1173 TEST_F(SyncManagerTest, GetChildNodeIdsFailure) { |
1174 StrictMock<MockJsReplyHandler> reply_handler; | 1174 StrictMock<MockJsReplyHandler> reply_handler; |
1175 | 1175 |
1176 ListValue empty_list_args; | 1176 ListValue empty_list_args; |
1177 empty_list_args.Append(new ListValue()); | 1177 empty_list_args.Append(new ListValue()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 } | 1231 } |
1232 | 1232 |
1233 // There's not much value in verifying every attribute on every node here. | 1233 // There's not much value in verifying every attribute on every node here. |
1234 // Most of the value of this test has already been achieved: we've verified we | 1234 // Most of the value of this test has already been achieved: we've verified we |
1235 // can call the above function without crashing or leaking memory. | 1235 // can call the above function without crashing or leaking memory. |
1236 // | 1236 // |
1237 // Let's just check the list size and a few of its elements. Anything more | 1237 // Let's just check the list size and a few of its elements. Anything more |
1238 // would make this test brittle without greatly increasing our chances of | 1238 // would make this test brittle without greatly increasing our chances of |
1239 // catching real bugs. | 1239 // catching real bugs. |
1240 | 1240 |
1241 ListValue* node_list; | 1241 const ListValue* node_list; |
1242 DictionaryValue* first_result; | 1242 const DictionaryValue* first_result; |
1243 | 1243 |
1244 // The resulting argument list should have one argument, a list of nodes. | 1244 // The resulting argument list should have one argument, a list of nodes. |
1245 ASSERT_EQ(1U, return_args.Get().GetSize()); | 1245 ASSERT_EQ(1U, return_args.Get().GetSize()); |
1246 ASSERT_TRUE(return_args.Get().GetList(0, &node_list)); | 1246 ASSERT_TRUE(return_args.Get().GetList(0, &node_list)); |
1247 | 1247 |
1248 // The database creation logic depends on the routing info. | 1248 // The database creation logic depends on the routing info. |
1249 // Refer to setup methods for more information. | 1249 // Refer to setup methods for more information. |
1250 ModelSafeRoutingInfo routes; | 1250 ModelSafeRoutingInfo routes; |
1251 GetModelSafeRoutingInfo(&routes); | 1251 GetModelSafeRoutingInfo(&routes); |
1252 size_t directory_size = routes.size() + 1; | 1252 size_t directory_size = routes.size() + 1; |
(...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2782 | 2782 |
2783 // Verify only the non-disabled types remain after cleanup. | 2783 // Verify only the non-disabled types remain after cleanup. |
2784 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2784 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
2785 EXPECT_TRUE(new_enabled_types.Equals( | 2785 EXPECT_TRUE(new_enabled_types.Equals( |
2786 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2786 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
2787 EXPECT_TRUE(disabled_types.Equals( | 2787 EXPECT_TRUE(disabled_types.Equals( |
2788 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2788 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
2789 } | 2789 } |
2790 | 2790 |
2791 } // namespace | 2791 } // namespace |
OLD | NEW |