Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: runtime/vm/service_test.cc

Issue 2041293003: Allow embedder service request handlers to return JSON-RPC errors. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "include/dart_tools_api.h" 7 #include "include/dart_tools_api.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/debugger.h" 10 #include "vm/debugger.h"
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 "['address'], ['7']]"); 564 "['address'], ['7']]");
565 Service::HandleIsolateMessage(isolate, service_msg); 565 Service::HandleIsolateMessage(isolate, service_msg);
566 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 566 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
567 // TODO(turnidge): Should this be a ServiceException instead? 567 // TODO(turnidge): Should this be a ServiceException instead?
568 EXPECT_SUBSTRING("{\"type\":\"Sentinel\",\"kind\":\"Free\"," 568 EXPECT_SUBSTRING("{\"type\":\"Sentinel\",\"kind\":\"Free\","
569 "\"valueAsString\":\"<free>\"", 569 "\"valueAsString\":\"<free>\"",
570 handler.msg()); 570 handler.msg());
571 } 571 }
572 572
573 573
574 static const char* alpha_callback( 574 static bool alpha_callback(
575 const char* name, 575 const char* name,
576 const char** option_keys, 576 const char** option_keys,
577 const char** option_values, 577 const char** option_values,
578 intptr_t num_options, 578 intptr_t num_options,
579 void* user_data) { 579 void* user_data,
580 return strdup("alpha"); 580 const char** result) {
581 *result = strdup("alpha");
582 return true;
581 } 583 }
582 584
583 585
584 static const char* beta_callback( 586 static bool beta_callback(
585 const char* name, 587 const char* name,
586 const char** option_keys, 588 const char** option_keys,
587 const char** option_values, 589 const char** option_values,
588 intptr_t num_options, 590 intptr_t num_options,
589 void* user_data) { 591 void* user_data,
590 return strdup("beta"); 592 const char** result) {
593 *result = strdup("beta");
594 return false;
591 } 595 }
592 596
593 597
594 TEST_CASE(Service_EmbedderRootHandler) { 598 TEST_CASE(Service_EmbedderRootHandler) {
595 const char* kScript = 599 const char* kScript =
596 "var port;\n" // Set to our mock port by C++. 600 "var port;\n" // Set to our mock port by C++.
597 "\n" 601 "\n"
598 "var x = 7;\n" 602 "var x = 7;\n"
599 "main() {\n" 603 "main() {\n"
600 " x = x * x;\n" 604 " x = x * x;\n"
(...skipping 18 matching lines...) Expand all
619 623
620 Array& service_msg = Array::Handle(); 624 Array& service_msg = Array::Handle();
621 service_msg = Eval(lib, "[0, port, '\"', 'alpha', [], []]"); 625 service_msg = Eval(lib, "[0, port, '\"', 'alpha', [], []]");
622 Service::HandleRootMessage(service_msg); 626 Service::HandleRootMessage(service_msg);
623 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 627 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
624 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"\\\"\"}", 628 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"\\\"\"}",
625 handler.msg()); 629 handler.msg());
626 service_msg = Eval(lib, "[0, port, 1, 'beta', [], []]"); 630 service_msg = Eval(lib, "[0, port, 1, 'beta', [], []]");
627 Service::HandleRootMessage(service_msg); 631 Service::HandleRootMessage(service_msg);
628 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 632 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
629 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":beta,\"id\":1}", 633 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"error\":beta,\"id\":1}",
630 handler.msg()); 634 handler.msg());
631 } 635 }
632 636
633 637
634 TEST_CASE(Service_EmbedderIsolateHandler) { 638 TEST_CASE(Service_EmbedderIsolateHandler) {
635 const char* kScript = 639 const char* kScript =
636 "var port;\n" // Set to our mock port by C++. 640 "var port;\n" // Set to our mock port by C++.
637 "\n" 641 "\n"
638 "var x = 7;\n" 642 "var x = 7;\n"
639 "main() {\n" 643 "main() {\n"
(...skipping 19 matching lines...) Expand all
659 663
660 Array& service_msg = Array::Handle(); 664 Array& service_msg = Array::Handle();
661 service_msg = Eval(lib, "[0, port, '0', 'alpha', [], []]"); 665 service_msg = Eval(lib, "[0, port, '0', 'alpha', [], []]");
662 Service::HandleIsolateMessage(isolate, service_msg); 666 Service::HandleIsolateMessage(isolate, service_msg);
663 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 667 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
664 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"0\"}", 668 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"0\"}",
665 handler.msg()); 669 handler.msg());
666 service_msg = Eval(lib, "[0, port, '0', 'beta', [], []]"); 670 service_msg = Eval(lib, "[0, port, '0', 'beta', [], []]");
667 Service::HandleIsolateMessage(isolate, service_msg); 671 Service::HandleIsolateMessage(isolate, service_msg);
668 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 672 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
669 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":beta,\"id\":\"0\"}", 673 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"error\":beta,\"id\":\"0\"}",
670 handler.msg()); 674 handler.msg());
671 } 675 }
672 676
673 // TODO(zra): Remove when tests are ready to enable. 677 // TODO(zra): Remove when tests are ready to enable.
674 #if !defined(TARGET_ARCH_ARM64) 678 #if !defined(TARGET_ARCH_ARM64)
675 679
676 TEST_CASE(Service_Profile) { 680 TEST_CASE(Service_Profile) {
677 const char* kScript = 681 const char* kScript =
678 "var port;\n" // Set to our mock port by C++. 682 "var port;\n" // Set to our mock port by C++.
679 "\n" 683 "\n"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 721 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
718 // Expect error. 722 // Expect error.
719 EXPECT_SUBSTRING("\"error\"", handler.msg()); 723 EXPECT_SUBSTRING("\"error\"", handler.msg());
720 } 724 }
721 725
722 #endif // !defined(TARGET_ARCH_ARM64) 726 #endif // !defined(TARGET_ARCH_ARM64)
723 727
724 #endif // !PRODUCT 728 #endif // !PRODUCT
725 729
726 } // namespace dart 730 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698