| OLD | NEW |
| 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 "include/dart_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
| 6 #include "vm/dart_api_impl.h" | 6 #include "vm/dart_api_impl.h" |
| 7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/message_handler.h" | 10 #include "vm/message_handler.h" |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 Service::HandleIsolateMessage(isolate, service_msg); | 607 Service::HandleIsolateMessage(isolate, service_msg); |
| 608 handler.HandleNextMessage(); | 608 handler.HandleNextMessage(); |
| 609 EXPECT_SUBSTRING( | 609 EXPECT_SUBSTRING( |
| 610 "{\"source\":\"dart:test-lib\",\"script\":{" | 610 "{\"source\":\"dart:test-lib\",\"script\":{" |
| 611 "\"type\":\"@Script\",\"id\":\"scripts\\/dart%3Atest-lib\"," | 611 "\"type\":\"@Script\",\"id\":\"scripts\\/dart%3Atest-lib\"," |
| 612 "\"name\":\"dart:test-lib\",\"user_name\":\"dart:test-lib\"," | 612 "\"name\":\"dart:test-lib\",\"user_name\":\"dart:test-lib\"," |
| 613 "\"kind\":\"script\"},\"hits\":" | 613 "\"kind\":\"script\"},\"hits\":" |
| 614 "[3,0,3,1,5,1,5,1,5,1,6,1,6,1]}", handler.msg()); | 614 "[3,0,3,1,5,1,5,1,5,1,6,1,6,1]}", handler.msg()); |
| 615 } | 615 } |
| 616 | 616 |
| 617 |
| 618 static const char* alpha_callback( |
| 619 const char* name, |
| 620 const char** arguments, |
| 621 intptr_t num_arguments, |
| 622 const char** option_keys, |
| 623 const char** option_values, |
| 624 intptr_t num_options, |
| 625 void* user_data) { |
| 626 return strdup("alpha"); |
| 627 } |
| 628 |
| 629 |
| 630 static const char* beta_callback( |
| 631 const char* name, |
| 632 const char** arguments, |
| 633 intptr_t num_arguments, |
| 634 const char** option_keys, |
| 635 const char** option_values, |
| 636 intptr_t num_options, |
| 637 void* user_data) { |
| 638 return strdup("beta"); |
| 639 } |
| 640 |
| 641 |
| 642 TEST_CASE(Service_EmbedderRootHandler) { |
| 643 const char* kScript = |
| 644 "var port;\n" // Set to our mock port by C++. |
| 645 "\n" |
| 646 "var x = 7;\n" |
| 647 "main() {\n" |
| 648 " x = x * x;\n" |
| 649 " x = x / 13;\n" |
| 650 "}"; |
| 651 |
| 652 Dart_RegisterRootServiceRequestCallback("alpha", alpha_callback, NULL); |
| 653 Dart_RegisterRootServiceRequestCallback("beta", beta_callback, NULL); |
| 654 |
| 655 Isolate* isolate = Isolate::Current(); |
| 656 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
| 657 EXPECT_VALID(lib); |
| 658 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 659 EXPECT_VALID(result); |
| 660 |
| 661 // Build a mock message handler and wrap it in a dart port. |
| 662 ServiceTestMessageHandler handler; |
| 663 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 664 Dart_Handle port = |
| 665 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); |
| 666 EXPECT_VALID(port); |
| 667 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 668 |
| 669 |
| 670 Instance& service_msg = Instance::Handle(); |
| 671 service_msg = Eval(lib, "[port, ['alpha'], [], []]"); |
| 672 Service::HandleRootMessage(service_msg); |
| 673 handler.HandleNextMessage(); |
| 674 EXPECT_STREQ("alpha", handler.msg()); |
| 675 service_msg = Eval(lib, "[port, ['beta'], [], []]"); |
| 676 Service::HandleRootMessage(service_msg); |
| 677 handler.HandleNextMessage(); |
| 678 EXPECT_STREQ("beta", handler.msg()); |
| 679 } |
| 680 |
| 681 TEST_CASE(Service_EmbedderIsolateHandler) { |
| 682 const char* kScript = |
| 683 "var port;\n" // Set to our mock port by C++. |
| 684 "\n" |
| 685 "var x = 7;\n" |
| 686 "main() {\n" |
| 687 " x = x * x;\n" |
| 688 " x = x / 13;\n" |
| 689 "}"; |
| 690 |
| 691 Dart_RegisterIsolateServiceRequestCallback("alpha", alpha_callback, NULL); |
| 692 Dart_RegisterIsolateServiceRequestCallback("beta", beta_callback, NULL); |
| 693 |
| 694 Isolate* isolate = Isolate::Current(); |
| 695 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
| 696 EXPECT_VALID(lib); |
| 697 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 698 EXPECT_VALID(result); |
| 699 |
| 700 // Build a mock message handler and wrap it in a dart port. |
| 701 ServiceTestMessageHandler handler; |
| 702 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 703 Dart_Handle port = |
| 704 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); |
| 705 EXPECT_VALID(port); |
| 706 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 707 |
| 708 Instance& service_msg = Instance::Handle(); |
| 709 service_msg = Eval(lib, "[port, ['alpha'], [], []]"); |
| 710 Service::HandleIsolateMessage(isolate, service_msg); |
| 711 handler.HandleNextMessage(); |
| 712 EXPECT_STREQ("alpha", handler.msg()); |
| 713 service_msg = Eval(lib, "[port, ['beta'], [], []]"); |
| 714 Service::HandleIsolateMessage(isolate, service_msg); |
| 715 handler.HandleNextMessage(); |
| 716 EXPECT_STREQ("beta", handler.msg()); |
| 717 } |
| 718 |
| 617 } // namespace dart | 719 } // namespace dart |
| OLD | NEW |