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