Chromium Code Reviews| 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 EXPECT_TRUE(password_node.InitByClientTagLookup(syncable::PASSWORDS, | 381 EXPECT_TRUE(password_node.InitByClientTagLookup(syncable::PASSWORDS, |
| 382 "foo")); | 382 "foo")); |
| 383 const sync_pb::PasswordSpecificsData& data = | 383 const sync_pb::PasswordSpecificsData& data = |
| 384 password_node.GetPasswordSpecifics(); | 384 password_node.GetPasswordSpecifics(); |
| 385 EXPECT_EQ("secret", data.password_value()); | 385 EXPECT_EQ("secret", data.password_value()); |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 | 388 |
| 389 namespace { | 389 namespace { |
| 390 | 390 |
| 391 void CheckNodeValue(const BaseNode& node, const DictionaryValue& value) { | 391 void CheckNodeValue(const BaseNode& node, const DictionaryValue& value, |
| 392 bool is_detailed) { | |
| 392 ExpectInt64Value(node.GetId(), value, "id"); | 393 ExpectInt64Value(node.GetId(), value, "id"); |
| 393 ExpectInt64Value(node.GetModificationTime(), value, "modificationTime"); | |
| 394 ExpectInt64Value(node.GetParentId(), value, "parentId"); | |
| 395 { | 394 { |
| 396 bool is_folder = false; | 395 bool is_folder = false; |
| 397 EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder)); | 396 EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder)); |
| 398 EXPECT_EQ(node.GetIsFolder(), is_folder); | 397 EXPECT_EQ(node.GetIsFolder(), is_folder); |
| 399 } | 398 } |
| 400 ExpectDictStringValue(WideToUTF8(node.GetTitle()), value, "title"); | 399 ExpectDictStringValue(WideToUTF8(node.GetTitle()), value, "title"); |
| 401 { | 400 { |
| 402 ModelType expected_model_type = node.GetModelType(); | 401 ModelType expected_model_type = node.GetModelType(); |
| 403 std::string type_str; | 402 std::string type_str; |
| 404 EXPECT_TRUE(value.GetString("type", &type_str)); | 403 EXPECT_TRUE(value.GetString("type", &type_str)); |
| 405 if (expected_model_type >= syncable::FIRST_REAL_MODEL_TYPE) { | 404 if (expected_model_type >= syncable::FIRST_REAL_MODEL_TYPE) { |
| 406 ModelType model_type = | 405 ModelType model_type = |
| 407 syncable::ModelTypeFromString(type_str); | 406 syncable::ModelTypeFromString(type_str); |
| 408 EXPECT_EQ(expected_model_type, model_type); | 407 EXPECT_EQ(expected_model_type, model_type); |
| 409 } else if (expected_model_type == syncable::TOP_LEVEL_FOLDER) { | 408 } else if (expected_model_type == syncable::TOP_LEVEL_FOLDER) { |
| 410 EXPECT_EQ("Top-level folder", type_str); | 409 EXPECT_EQ("Top-level folder", type_str); |
| 411 } else if (expected_model_type == syncable::UNSPECIFIED) { | 410 } else if (expected_model_type == syncable::UNSPECIFIED) { |
| 412 EXPECT_EQ("Unspecified", type_str); | 411 EXPECT_EQ("Unspecified", type_str); |
| 413 } else { | 412 } else { |
| 414 ADD_FAILURE(); | 413 ADD_FAILURE(); |
| 415 } | 414 } |
| 416 } | 415 } |
| 417 ExpectInt64Value(node.GetExternalId(), value, "externalId"); | 416 if (is_detailed) { |
| 418 ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId"); | 417 ExpectInt64Value(node.GetParentId(), value, "parentId"); |
| 419 ExpectInt64Value(node.GetSuccessorId(), value, "successorId"); | 418 ExpectInt64Value(node.GetModificationTime(), value, "modificationTime"); |
| 420 ExpectInt64Value(node.GetFirstChildId(), value, "firstChildId"); | 419 ExpectInt64Value(node.GetExternalId(), value, "externalId"); |
| 421 { | 420 ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId"); |
| 422 scoped_ptr<DictionaryValue> expected_entry(node.GetEntry()->ToValue()); | 421 ExpectInt64Value(node.GetSuccessorId(), value, "successorId"); |
| 423 Value* entry = NULL; | 422 ExpectInt64Value(node.GetFirstChildId(), value, "firstChildId"); |
| 424 EXPECT_TRUE(value.Get("entry", &entry)); | 423 { |
| 425 EXPECT_TRUE(Value::Equals(entry, expected_entry.get())); | 424 scoped_ptr<DictionaryValue> expected_entry(node.GetEntry()->ToValue()); |
| 425 Value* entry = NULL; | |
| 426 EXPECT_TRUE(value.Get("entry", &entry)); | |
| 427 EXPECT_TRUE(Value::Equals(entry, expected_entry.get())); | |
| 428 } | |
| 429 EXPECT_EQ(11u, value.size()); | |
| 430 } else { | |
| 431 EXPECT_EQ(4u, value.size()); | |
| 426 } | 432 } |
| 427 EXPECT_EQ(11u, value.size()); | |
| 428 } | 433 } |
| 429 | 434 |
| 430 } // namespace | 435 } // namespace |
| 431 | 436 |
| 432 TEST_F(SyncApiTest, BaseNodeToValue) { | 437 TEST_F(SyncApiTest, BaseNodeGetSummaryAsValue) { |
| 433 ReadTransaction trans(test_user_share_.user_share()); | 438 ReadTransaction trans(test_user_share_.user_share()); |
| 434 ReadNode node(&trans); | 439 ReadNode node(&trans); |
| 435 node.InitByRootLookup(); | 440 node.InitByRootLookup(); |
| 436 scoped_ptr<DictionaryValue> value(node.ToValue()); | 441 scoped_ptr<DictionaryValue> details(node.GetSummaryAsValue()); |
| 437 if (value.get()) { | 442 if (details.get()) { |
| 438 CheckNodeValue(node, *value); | 443 CheckNodeValue(node, *details, false); |
| 439 } else { | 444 } else { |
| 440 ADD_FAILURE(); | 445 ADD_FAILURE(); |
| 441 } | 446 } |
| 447 } | |
| 448 | |
| 449 TEST_F(SyncApiTest, BaseNodeGetDetailsAsValue) { | |
| 450 ReadTransaction trans(test_user_share_.user_share()); | |
| 451 ReadNode node(&trans); | |
| 452 node.InitByRootLookup(); | |
| 453 scoped_ptr<DictionaryValue> details(node.GetDetailsAsValue()); | |
| 454 if (details.get()) { | |
| 455 CheckNodeValue(node, *details, true); | |
| 456 } else { | |
| 457 ADD_FAILURE(); | |
| 458 } | |
| 442 } | 459 } |
| 443 | 460 |
| 444 namespace { | 461 namespace { |
| 445 | 462 |
| 446 void ExpectChangeRecordActionValue(SyncManager::ChangeRecord::Action | 463 void ExpectChangeRecordActionValue(SyncManager::ChangeRecord::Action |
| 447 expected_value, | 464 expected_value, |
| 448 const DictionaryValue& value, | 465 const DictionaryValue& value, |
| 449 const std::string& key) { | 466 const std::string& key) { |
| 450 std::string str_value; | 467 std::string str_value; |
| 451 EXPECT_TRUE(value.GetString(key, &str_value)); | 468 EXPECT_TRUE(value.GetString(key, &str_value)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 466 } | 483 } |
| 467 | 484 |
| 468 void CheckNonDeleteChangeRecordValue(const SyncManager::ChangeRecord& record, | 485 void CheckNonDeleteChangeRecordValue(const SyncManager::ChangeRecord& record, |
| 469 const DictionaryValue& value, | 486 const DictionaryValue& value, |
| 470 BaseTransaction* trans) { | 487 BaseTransaction* trans) { |
| 471 EXPECT_NE(SyncManager::ChangeRecord::ACTION_DELETE, record.action); | 488 EXPECT_NE(SyncManager::ChangeRecord::ACTION_DELETE, record.action); |
| 472 ExpectChangeRecordActionValue(record.action, value, "action"); | 489 ExpectChangeRecordActionValue(record.action, value, "action"); |
| 473 { | 490 { |
| 474 ReadNode node(trans); | 491 ReadNode node(trans); |
| 475 EXPECT_TRUE(node.InitByIdLookup(record.id)); | 492 EXPECT_TRUE(node.InitByIdLookup(record.id)); |
| 476 scoped_ptr<DictionaryValue> expected_node_value(node.ToValue()); | 493 scoped_ptr<DictionaryValue> expected_details(node.GetDetailsAsValue()); |
| 477 ExpectDictDictionaryValue(*expected_node_value, value, "node"); | 494 ExpectDictDictionaryValue(*expected_details, value, "node"); |
| 478 } | 495 } |
| 479 } | 496 } |
| 480 | 497 |
| 481 void CheckDeleteChangeRecordValue(const SyncManager::ChangeRecord& record, | 498 void CheckDeleteChangeRecordValue(const SyncManager::ChangeRecord& record, |
| 482 const DictionaryValue& value) { | 499 const DictionaryValue& value) { |
| 483 EXPECT_EQ(SyncManager::ChangeRecord::ACTION_DELETE, record.action); | 500 EXPECT_EQ(SyncManager::ChangeRecord::ACTION_DELETE, record.action); |
| 484 ExpectChangeRecordActionValue(record.action, value, "action"); | 501 ExpectChangeRecordActionValue(record.action, value, "action"); |
| 485 DictionaryValue* node_value = NULL; | 502 DictionaryValue* node_value = NULL; |
| 486 EXPECT_TRUE(value.GetDictionary("node", &node_value)); | 503 EXPECT_TRUE(value.GetDictionary("node", &node_value)); |
| 487 if (node_value) { | 504 if (node_value) { |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 830 // dropped. | 847 // dropped. |
| 831 { | 848 { |
| 832 StrictMock<MockJsEventHandler> event_handler; | 849 StrictMock<MockJsEventHandler> event_handler; |
| 833 js_backend->ProcessMessage("unknownMessage", | 850 js_backend->ProcessMessage("unknownMessage", |
| 834 kNoArgs, &event_handler); | 851 kNoArgs, &event_handler); |
| 835 js_backend->ProcessMessage("getNotificationState", | 852 js_backend->ProcessMessage("getNotificationState", |
| 836 kNoArgs, &event_handler); | 853 kNoArgs, &event_handler); |
| 837 } | 854 } |
| 838 } | 855 } |
| 839 | 856 |
| 840 TEST_F(SyncManagerTest, ProcessMessageGetRootNode) { | 857 TEST_F(SyncManagerTest, ProcessMessageGetRootNodeDetails) { |
| 841 const JsArgList kNoArgs; | 858 const JsArgList kNoArgs; |
| 842 | 859 |
| 843 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); | 860 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); |
| 844 | 861 |
| 845 StrictMock<MockJsEventHandler> event_handler; | 862 StrictMock<MockJsEventHandler> event_handler; |
| 846 StrictMock<MockJsEventRouter> event_router; | 863 StrictMock<MockJsEventRouter> event_router; |
| 847 | 864 |
| 848 JsArgList return_args; | 865 JsArgList return_args; |
| 849 | 866 |
| 850 EXPECT_CALL(event_router, | 867 EXPECT_CALL(event_router, |
| 851 RouteJsMessageReply("getRootNode", _, &event_handler)) | 868 RouteJsMessageReply("getRootNodeDetails", _, &event_handler)) |
| 852 .WillOnce(SaveArg<1>(&return_args)); | 869 .WillOnce(SaveArg<1>(&return_args)); |
| 853 | 870 |
| 854 js_backend->SetParentJsEventRouter(&event_router); | 871 js_backend->SetParentJsEventRouter(&event_router); |
| 855 | 872 |
| 856 // Should trigger the reply. | 873 // Should trigger the reply. |
| 857 js_backend->ProcessMessage("getRootNode", kNoArgs, &event_handler); | 874 js_backend->ProcessMessage("getRootNodeDetails", kNoArgs, &event_handler); |
| 858 | 875 |
| 859 EXPECT_EQ(1u, return_args.Get().GetSize()); | 876 EXPECT_EQ(1u, return_args.Get().GetSize()); |
| 860 DictionaryValue* node_info = NULL; | 877 DictionaryValue* node_info = NULL; |
| 861 EXPECT_TRUE(return_args.Get().GetDictionary(0, &node_info)); | 878 EXPECT_TRUE(return_args.Get().GetDictionary(0, &node_info)); |
| 862 if (node_info) { | 879 if (node_info) { |
| 863 ReadTransaction trans(sync_manager_.GetUserShare()); | 880 ReadTransaction trans(sync_manager_.GetUserShare()); |
| 864 ReadNode node(&trans); | 881 ReadNode node(&trans); |
| 865 node.InitByRootLookup(); | 882 node.InitByRootLookup(); |
| 866 CheckNodeValue(node, *node_info); | 883 CheckNodeValue(node, *node_info, true); |
| 867 } else { | 884 } else { |
| 868 ADD_FAILURE(); | 885 ADD_FAILURE(); |
| 869 } | 886 } |
| 870 | 887 |
| 871 js_backend->RemoveParentJsEventRouter(); | 888 js_backend->RemoveParentJsEventRouter(); |
| 872 } | 889 } |
| 873 | 890 |
| 874 void CheckGetNodesByIdReturnArgs(const SyncManager& sync_manager, | 891 void CheckGetNodesByIdReturnArgs(const SyncManager& sync_manager, |
| 875 const JsArgList& return_args, | 892 const JsArgList& return_args, |
| 876 int64 id) { | 893 int64 id, |
| 894 bool is_detailed) { | |
| 877 EXPECT_EQ(1u, return_args.Get().GetSize()); | 895 EXPECT_EQ(1u, return_args.Get().GetSize()); |
| 878 ListValue* nodes = NULL; | 896 ListValue* nodes = NULL; |
| 879 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); | 897 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); |
| 880 ASSERT_TRUE(nodes); | 898 ASSERT_TRUE(nodes); |
| 881 EXPECT_EQ(1u, nodes->GetSize()); | 899 EXPECT_EQ(1u, nodes->GetSize()); |
| 882 DictionaryValue* node_info = NULL; | 900 DictionaryValue* node_info = NULL; |
| 883 EXPECT_TRUE(nodes->GetDictionary(0, &node_info)); | 901 EXPECT_TRUE(nodes->GetDictionary(0, &node_info)); |
| 884 ASSERT_TRUE(node_info); | 902 ASSERT_TRUE(node_info); |
| 885 ReadTransaction trans(sync_manager.GetUserShare()); | 903 ReadTransaction trans(sync_manager.GetUserShare()); |
| 886 ReadNode node(&trans); | 904 ReadNode node(&trans); |
| 887 node.InitByIdLookup(id); | 905 node.InitByIdLookup(id); |
| 888 CheckNodeValue(node, *node_info); | 906 CheckNodeValue(node, *node_info, is_detailed); |
| 889 } | 907 } |
| 890 | 908 |
| 891 TEST_F(SyncManagerTest, ProcessMessageGetNodesById) { | 909 class SyncManagerGetNodesByIdTest : public SyncManagerTest { |
| 892 int64 child_id = | 910 protected: |
| 893 MakeNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, "testtag"); | 911 virtual ~SyncManagerGetNodesByIdTest() {} |
| 894 | 912 |
| 913 void RunGetNodesByIdTest(const char* message_name, bool is_detailed) { | |
| 914 int64 child_id = | |
| 915 MakeNode(sync_manager_.GetUserShare(), | |
| 916 syncable::BOOKMARKS, "testtag"); | |
| 917 | |
| 918 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); | |
| 919 | |
| 920 StrictMock<MockJsEventHandler> event_handler; | |
| 921 StrictMock<MockJsEventRouter> event_router; | |
| 922 | |
| 923 JsArgList return_args; | |
| 924 | |
| 925 EXPECT_CALL(event_router, | |
| 926 RouteJsMessageReply(message_name, _, &event_handler)) | |
| 927 .Times(2).WillRepeatedly(SaveArg<1>(&return_args)); | |
| 928 | |
| 929 js_backend->SetParentJsEventRouter(&event_router); | |
| 930 | |
| 931 // Should trigger the reply. | |
| 932 { | |
| 933 ListValue args; | |
| 934 ListValue* ids = new ListValue(); | |
| 935 args.Append(ids); | |
| 936 ids->Append(Value::CreateStringValue("1")); | |
|
lipalani1
2011/06/02 18:51:52
shouldnt this be child_id?
akalin
2011/06/02 22:13:33
It should be the id of the root, actually. Refact
| |
| 937 js_backend->ProcessMessage(message_name, | |
| 938 JsArgList(&args), &event_handler); | |
| 939 } | |
| 940 | |
| 941 CheckGetNodesByIdReturnArgs(sync_manager_, return_args, 1, is_detailed); | |
| 942 | |
| 943 // Should trigger another reply. | |
| 944 { | |
| 945 ListValue args; | |
| 946 ListValue* ids = new ListValue(); | |
| 947 args.Append(ids); | |
| 948 ids->Append(Value::CreateStringValue(base::Int64ToString(child_id))); | |
| 949 js_backend->ProcessMessage(message_name, | |
| 950 JsArgList(&args), &event_handler); | |
| 951 } | |
| 952 | |
| 953 CheckGetNodesByIdReturnArgs(sync_manager_, return_args, child_id, | |
| 954 is_detailed); | |
| 955 | |
| 956 js_backend->RemoveParentJsEventRouter(); | |
| 957 } | |
| 958 | |
| 959 void RunGetNodesByIdFailureTest(const char* message_name) { | |
| 960 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); | |
| 961 | |
| 962 StrictMock<MockJsEventHandler> event_handler; | |
| 963 StrictMock<MockJsEventRouter> event_router; | |
| 964 | |
| 965 ListValue empty_list_args; | |
| 966 empty_list_args.Append(new ListValue()); | |
| 967 | |
| 968 EXPECT_CALL(event_router, | |
| 969 RouteJsMessageReply(message_name, | |
| 970 HasArgsAsList(empty_list_args), | |
| 971 &event_handler)) | |
| 972 .Times(6); | |
| 973 | |
| 974 js_backend->SetParentJsEventRouter(&event_router); | |
| 975 | |
| 976 { | |
| 977 ListValue args; | |
| 978 js_backend->ProcessMessage(message_name, | |
| 979 JsArgList(&args), &event_handler); | |
| 980 } | |
| 981 | |
| 982 { | |
| 983 ListValue args; | |
| 984 args.Append(new ListValue()); | |
| 985 js_backend->ProcessMessage(message_name, | |
| 986 JsArgList(&args), &event_handler); | |
| 987 } | |
| 988 | |
| 989 { | |
| 990 ListValue args; | |
| 991 ListValue* ids = new ListValue(); | |
| 992 args.Append(ids); | |
| 993 ids->Append(Value::CreateStringValue("")); | |
| 994 js_backend->ProcessMessage(message_name, | |
| 995 JsArgList(&args), &event_handler); | |
| 996 } | |
| 997 | |
| 998 { | |
| 999 ListValue args; | |
| 1000 ListValue* ids = new ListValue(); | |
| 1001 args.Append(ids); | |
| 1002 ids->Append(Value::CreateStringValue("nonsense")); | |
| 1003 js_backend->ProcessMessage(message_name, | |
| 1004 JsArgList(&args), &event_handler); | |
| 1005 } | |
| 1006 | |
| 1007 { | |
| 1008 ListValue args; | |
| 1009 ListValue* ids = new ListValue(); | |
| 1010 args.Append(ids); | |
| 1011 ids->Append(Value::CreateStringValue("0")); | |
| 1012 js_backend->ProcessMessage(message_name, | |
| 1013 JsArgList(&args), &event_handler); | |
| 1014 } | |
| 1015 | |
| 1016 { | |
| 1017 ListValue args; | |
| 1018 ListValue* ids = new ListValue(); | |
| 1019 args.Append(ids); | |
| 1020 ids->Append(Value::CreateStringValue("9999")); | |
| 1021 js_backend->ProcessMessage(message_name, | |
| 1022 JsArgList(&args), &event_handler); | |
| 1023 } | |
| 1024 | |
| 1025 js_backend->RemoveParentJsEventRouter(); | |
| 1026 } | |
| 1027 }; | |
| 1028 | |
| 1029 TEST_F(SyncManagerGetNodesByIdTest, GetNodeSummariesById) { | |
| 1030 RunGetNodesByIdTest("getNodeSummariesById", false); | |
| 1031 } | |
| 1032 | |
| 1033 TEST_F(SyncManagerGetNodesByIdTest, GetNodeDetailsById) { | |
| 1034 RunGetNodesByIdTest("getNodeDetailsById", true); | |
| 1035 } | |
| 1036 | |
| 1037 TEST_F(SyncManagerGetNodesByIdTest, GetNodeSummariesByIdFailure) { | |
| 1038 RunGetNodesByIdFailureTest("getNodeSummariesById"); | |
| 1039 } | |
| 1040 | |
| 1041 TEST_F(SyncManagerGetNodesByIdTest, GetNodeDetailsByIdFailure) { | |
| 1042 RunGetNodesByIdFailureTest("getNodeDetailsById"); | |
| 1043 } | |
| 1044 | |
| 1045 TEST_F(SyncManagerTest, GetChildNodeIds) { | |
| 895 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); | 1046 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); |
| 896 | 1047 |
| 897 StrictMock<MockJsEventHandler> event_handler; | 1048 StrictMock<MockJsEventHandler> event_handler; |
| 898 StrictMock<MockJsEventRouter> event_router; | |
| 899 | |
| 900 JsArgList return_args; | |
| 901 | |
| 902 EXPECT_CALL(event_router, | |
| 903 RouteJsMessageReply("getNodesById", _, &event_handler)) | |
| 904 .Times(2).WillRepeatedly(SaveArg<1>(&return_args)); | |
| 905 | |
| 906 js_backend->SetParentJsEventRouter(&event_router); | |
| 907 | |
| 908 // Should trigger the reply. | |
| 909 { | |
| 910 ListValue args; | |
| 911 ListValue* ids = new ListValue(); | |
| 912 args.Append(ids); | |
| 913 ids->Append(Value::CreateStringValue("1")); | |
| 914 js_backend->ProcessMessage("getNodesById", | |
| 915 JsArgList(&args), &event_handler); | |
| 916 } | |
| 917 | |
| 918 CheckGetNodesByIdReturnArgs(sync_manager_, return_args, 1); | |
| 919 | |
| 920 // Should trigger another reply. | |
| 921 { | |
| 922 ListValue args; | |
| 923 ListValue* ids = new ListValue(); | |
| 924 args.Append(ids); | |
| 925 ids->Append(Value::CreateStringValue(base::Int64ToString(child_id))); | |
| 926 js_backend->ProcessMessage("getNodesById", | |
| 927 JsArgList(&args), &event_handler); | |
| 928 } | |
| 929 | |
| 930 CheckGetNodesByIdReturnArgs(sync_manager_, return_args, child_id); | |
| 931 | |
| 932 js_backend->RemoveParentJsEventRouter(); | |
| 933 } | |
| 934 | |
| 935 TEST_F(SyncManagerTest, ProcessMessageGetNodesByIdFailure) { | |
| 936 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); | |
| 937 | |
| 938 StrictMock<MockJsEventHandler> event_handler; | |
| 939 StrictMock<MockJsEventRouter> event_router; | |
| 940 | |
| 941 ListValue empty_list_args; | |
| 942 empty_list_args.Append(new ListValue()); | |
| 943 | |
| 944 EXPECT_CALL(event_router, | |
| 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; | 1049 StrictMock<MockJsEventRouter> event_router; |
| 1009 | 1050 |
| 1010 JsArgList return_args; | 1051 JsArgList return_args; |
| 1011 | 1052 |
| 1012 EXPECT_CALL(event_router, | 1053 EXPECT_CALL(event_router, |
| 1013 RouteJsMessageReply("getChildNodeIds", _, &event_handler)) | 1054 RouteJsMessageReply("getChildNodeIds", _, &event_handler)) |
| 1014 .Times(1).WillRepeatedly(SaveArg<1>(&return_args)); | 1055 .Times(1).WillRepeatedly(SaveArg<1>(&return_args)); |
| 1015 | 1056 |
| 1016 js_backend->SetParentJsEventRouter(&event_router); | 1057 js_backend->SetParentJsEventRouter(&event_router); |
| 1017 | 1058 |
| 1018 // Should trigger the reply. | 1059 // Should trigger the reply. |
| 1019 { | 1060 { |
| 1020 ListValue args; | 1061 ListValue args; |
| 1021 args.Append(Value::CreateStringValue("1")); | 1062 args.Append(Value::CreateStringValue("1")); |
| 1022 js_backend->ProcessMessage("getChildNodeIds", | 1063 js_backend->ProcessMessage("getChildNodeIds", |
| 1023 JsArgList(&args), &event_handler); | 1064 JsArgList(&args), &event_handler); |
| 1024 } | 1065 } |
| 1025 | 1066 |
| 1026 EXPECT_EQ(1u, return_args.Get().GetSize()); | 1067 EXPECT_EQ(1u, return_args.Get().GetSize()); |
| 1027 ListValue* nodes = NULL; | 1068 ListValue* nodes = NULL; |
| 1028 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); | 1069 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); |
| 1029 ASSERT_TRUE(nodes); | 1070 ASSERT_TRUE(nodes); |
| 1030 EXPECT_EQ(5u, nodes->GetSize()); | 1071 EXPECT_EQ(5u, nodes->GetSize()); |
| 1031 | 1072 |
| 1032 js_backend->RemoveParentJsEventRouter(); | 1073 js_backend->RemoveParentJsEventRouter(); |
| 1033 } | 1074 } |
| 1034 | 1075 |
| 1035 TEST_F(SyncManagerTest, ProcessMessageGetChildNodeIdsFailure) { | 1076 TEST_F(SyncManagerTest, GetChildNodeIdsFailure) { |
| 1036 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); | 1077 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); |
| 1037 | 1078 |
| 1038 StrictMock<MockJsEventHandler> event_handler; | 1079 StrictMock<MockJsEventHandler> event_handler; |
| 1039 StrictMock<MockJsEventRouter> event_router; | 1080 StrictMock<MockJsEventRouter> event_router; |
| 1040 | 1081 |
| 1041 ListValue empty_list_args; | 1082 ListValue empty_list_args; |
| 1042 empty_list_args.Append(new ListValue()); | 1083 empty_list_args.Append(new ListValue()); |
| 1043 | 1084 |
| 1044 EXPECT_CALL(event_router, | 1085 EXPECT_CALL(event_router, |
| 1045 RouteJsMessageReply("getChildNodeIds", | 1086 RouteJsMessageReply("getChildNodeIds", |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1079 { | 1120 { |
| 1080 ListValue args; | 1121 ListValue args; |
| 1081 args.Append(Value::CreateStringValue("9999")); | 1122 args.Append(Value::CreateStringValue("9999")); |
| 1082 js_backend->ProcessMessage("getChildNodeIds", | 1123 js_backend->ProcessMessage("getChildNodeIds", |
| 1083 JsArgList(&args), &event_handler); | 1124 JsArgList(&args), &event_handler); |
| 1084 } | 1125 } |
| 1085 | 1126 |
| 1086 js_backend->RemoveParentJsEventRouter(); | 1127 js_backend->RemoveParentJsEventRouter(); |
| 1087 } | 1128 } |
| 1088 | 1129 |
| 1130 // TODO(akalin): Add unit tests for findNodesContainingString message. | |
| 1131 | |
| 1089 TEST_F(SyncManagerTest, OnNotificationStateChange) { | 1132 TEST_F(SyncManagerTest, OnNotificationStateChange) { |
| 1090 InSequence dummy; | 1133 InSequence dummy; |
| 1091 StrictMock<MockJsEventRouter> event_router; | 1134 StrictMock<MockJsEventRouter> event_router; |
| 1092 | 1135 |
| 1093 DictionaryValue true_details; | 1136 DictionaryValue true_details; |
| 1094 true_details.SetBoolean("enabled", true); | 1137 true_details.SetBoolean("enabled", true); |
| 1095 DictionaryValue false_details; | 1138 DictionaryValue false_details; |
| 1096 false_details.SetBoolean("enabled", false); | 1139 false_details.SetBoolean("enabled", false); |
| 1097 | 1140 |
| 1098 EXPECT_CALL(event_router, | 1141 EXPECT_CALL(event_router, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1235 true /* is encrypted */)); | 1278 true /* is encrypted */)); |
| 1236 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1279 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
| 1237 syncable::THEMES, | 1280 syncable::THEMES, |
| 1238 false /* not encrypted */)); | 1281 false /* not encrypted */)); |
| 1239 } | 1282 } |
| 1240 } | 1283 } |
| 1241 | 1284 |
| 1242 } // namespace | 1285 } // namespace |
| 1243 | 1286 |
| 1244 } // namespace browser_sync | 1287 } // namespace browser_sync |
| OLD | NEW |