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