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

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

Issue 199363002: Rework library and class view pages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/service.cc ('k') | tests/standalone/vmservice/isolate_code_test.dart » ('j') | 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 "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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 "['expr'], ['this+99']]"); 490 "['expr'], ['this+99']]");
491 Service::HandleIsolateMessage(isolate, service_msg); 491 Service::HandleIsolateMessage(isolate, service_msg);
492 handler.HandleNextMessage(); 492 handler.HandleNextMessage();
493 handler.filterMsg("name"); 493 handler.filterMsg("name");
494 EXPECT_STREQ( 494 EXPECT_STREQ(
495 "{\"type\":\"@Smi\",\"id\":\"objects\\/int-222\"," 495 "{\"type\":\"@Smi\",\"id\":\"objects\\/int-222\","
496 "\"class\":{\"type\":\"@Class\",\"id\":\"classes\\/42\"," 496 "\"class\":{\"type\":\"@Class\",\"id\":\"classes\\/42\","
497 "\"user_name\":\"int\"},\"preview\":\"222\"}", 497 "\"user_name\":\"int\"},\"preview\":\"222\"}",
498 handler.msg()); 498 handler.msg());
499 499
500 // eval returning null works
501 service_msg = Eval(lib,
502 "[port, ['objects', 'int-123', 'eval'], "
503 "['expr'], ['null']]");
504 Service::HandleIsolateMessage(isolate, service_msg);
505 handler.HandleNextMessage();
506 handler.filterMsg("name");
507 EXPECT_STREQ(
508 "{\"type\":\"@Null\",\"id\":\"objects\\/null\",\"preview\":\"null\"}",
509 handler.msg());
510
500 // object id ring / invalid => expired 511 // object id ring / invalid => expired
501 service_msg = Eval(lib, "[port, ['objects', '99999999', 'eval'], " 512 service_msg = Eval(lib, "[port, ['objects', '99999999', 'eval'], "
502 "['expr'], ['this']]"); 513 "['expr'], ['this']]");
503 Service::HandleIsolateMessage(isolate, service_msg); 514 Service::HandleIsolateMessage(isolate, service_msg);
504 handler.HandleNextMessage(); 515 handler.HandleNextMessage();
505 handler.filterMsg("name"); 516 handler.filterMsg("name");
506 EXPECT_STREQ( 517 EXPECT_STREQ(
507 "{\"type\":\"Error\",\"id\":\"\",\"kind\":\"EvalExpired\"," 518 "{\"type\":\"Error\",\"id\":\"\",\"kind\":\"EvalExpired\","
508 "\"message\":\"attempt to evaluate against expired object\\n\"," 519 "\"message\":\"attempt to evaluate against expired object\\n\","
509 "\"request\":{\"arguments\":[\"objects\",\"99999999\",\"eval\"]," 520 "\"request\":{\"arguments\":[\"objects\",\"99999999\",\"eval\"],"
510 "\"option_keys\":[\"expr\"],\"option_values\":[\"this\"]}}", 521 "\"option_keys\":[\"expr\"],\"option_values\":[\"this\"]}}",
511 handler.msg()); 522 handler.msg());
512 523
513 // Extra arg to eval. 524 // Extra arg to eval.
514 service_msg = Eval(lib, 525 service_msg = Eval(lib,
515 "[port, ['objects', 'int-123', 'eval', 'foo'], " 526 "[port, ['objects', 'int-123', 'eval', 'foo'], "
516 "['expr'], ['this+99']]"); 527 "['expr'], ['this+99']]");
517 Service::HandleIsolateMessage(isolate, service_msg); 528 Service::HandleIsolateMessage(isolate, service_msg);
518 handler.HandleNextMessage(); 529 handler.HandleNextMessage();
519 handler.filterMsg("name"); 530 handler.filterMsg("name");
520 EXPECT_STREQ( 531 EXPECT_STREQ(
521 "{\"type\":\"Error\",\"id\":\"\"," 532 "{\"type\":\"Error\",\"id\":\"\","
522 "\"message\":\"expected at most 3 arguments but found 4\\n\"," 533 "\"message\":\"expected at most 3 arguments but found 4\\n\","
523 "\"request\":{\"arguments\":[\"objects\",\"int-123\",\"eval\",\"foo\"]," 534 "\"request\":{\"arguments\":[\"objects\",\"int-123\",\"eval\",\"foo\"],"
524 "\"option_keys\":[\"expr\"],\"option_values\":[\"this+99\"]}}", 535 "\"option_keys\":[\"expr\"],\"option_values\":[\"this+99\"]}}",
525 handler.msg()); 536 handler.msg());
526 } 537 }
527 538
528 539
540 TEST_CASE(Service_Libraries) {
541 const char* kScript =
542 "var port;\n" // Set to our mock port by C++.
543 "var libVar = 54321;\n"
544 "\n"
545 "main() {\n"
546 "}";
547
548 Isolate* isolate = Isolate::Current();
549 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
550 EXPECT_VALID(h_lib);
551 Library& lib = Library::Handle();
552 lib ^= Api::UnwrapHandle(h_lib);
553 EXPECT(!lib.IsNull());
554
555 // Find the current library.
556 intptr_t lib_id = -1;
557 const GrowableObjectArray& libs =
558 GrowableObjectArray::Handle(isolate->object_store()->libraries());
559 for (intptr_t i = 0; i < libs.Length(); i++) {
560 if (libs.At(i) == lib.raw()) {
561 lib_id = i;
562 }
563 }
564 ASSERT(lib_id > 0);
565
566 // Build a mock message handler and wrap it in a dart port.
567 ServiceTestMessageHandler handler;
568 Dart_Port port_id = PortMap::CreatePort(&handler);
569 Dart_Handle port =
570 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id));
571 EXPECT_VALID(port);
572 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port));
573
574 Instance& service_msg = Instance::Handle();
575
576 // Request library.
577 service_msg = EvalF(h_lib,
578 "[port, ['libraries', '%" Pd "'], [], []]", lib_id);
579 Service::HandleIsolateMessage(isolate, service_msg);
580 handler.HandleNextMessage();
581 EXPECT_SUBSTRING("\"type\":\"Library\"", handler.msg());
582 EXPECT_SUBSTRING("\"url\":\"dart:test-lib\"", handler.msg());
583
584 // Evaluate an expression from a library.
585 service_msg = EvalF(h_lib,
586 "[port, ['libraries', '%" Pd "', 'eval'], "
587 "['expr'], ['libVar - 1']]", lib_id);
588 Service::HandleIsolateMessage(isolate, service_msg);
589 handler.HandleNextMessage();
590 handler.filterMsg("name");
591 EXPECT_STREQ(
592 "{\"type\":\"@Smi\",\"id\":\"objects\\/int-54320\","
593 "\"class\":{\"type\":\"@Class\",\"id\":\"classes\\/42\","
594 "\"user_name\":\"int\"},\"preview\":\"54320\"}",
595 handler.msg());
596 }
597
529 598
530 TEST_CASE(Service_Classes) { 599 TEST_CASE(Service_Classes) {
531 const char* kScript = 600 const char* kScript =
532 "var port;\n" // Set to our mock port by C++. 601 "var port;\n" // Set to our mock port by C++.
533 "\n" 602 "\n"
534 "class A {\n" 603 "class A {\n"
535 " var a;\n" 604 " var a;\n"
605 " static var cobra = 11235;\n"
536 " dynamic b() {}\n" 606 " dynamic b() {}\n"
537 " dynamic c() {\n" 607 " dynamic c() {\n"
538 " var d = () { b(); };\n" 608 " var d = () { b(); };\n"
539 " return d;\n" 609 " return d;\n"
540 " }\n" 610 " }\n"
541 "}\n" 611 "}\n"
542 "main() {\n" 612 "main() {\n"
543 " var z = new A();\n" 613 " var z = new A();\n"
544 " var x = z.c();\n" 614 " var x = z.c();\n"
545 " x();\n" 615 " x();\n"
(...skipping 28 matching lines...) Expand all
574 EXPECT_STREQ( 644 EXPECT_STREQ(
575 "{\"type\":\"Error\",\"id\":\"\"," 645 "{\"type\":\"Error\",\"id\":\"\","
576 "\"message\":\"999999 is not a valid class id.\"," 646 "\"message\":\"999999 is not a valid class id.\","
577 "\"request\":{\"arguments\":[\"classes\",\"999999\"]," 647 "\"request\":{\"arguments\":[\"classes\",\"999999\"],"
578 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); 648 "\"option_keys\":[],\"option_values\":[]}}", handler.msg());
579 649
580 // Request the class A over the service. 650 // Request the class A over the service.
581 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "'], [], []]", cid); 651 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "'], [], []]", cid);
582 Service::HandleIsolateMessage(isolate, service_msg); 652 Service::HandleIsolateMessage(isolate, service_msg);
583 handler.HandleNextMessage(); 653 handler.HandleNextMessage();
584
585 EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg()); 654 EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg());
586 ExpectSubstringF(handler.msg(), 655 ExpectSubstringF(handler.msg(),
587 "\"id\":\"classes\\/%" Pd "\",\"name\":\"A\",", cid); 656 "\"id\":\"classes\\/%" Pd "\",\"name\":\"A\",", cid);
588 657
658 // Evaluate an expression from class A.
659 service_msg = EvalF(h_lib,
660 "[port, ['classes', '%" Pd "', 'eval'], "
661 "['expr'], ['cobra + 100000']]", cid);
662 Service::HandleIsolateMessage(isolate, service_msg);
663 handler.HandleNextMessage();
664 handler.filterMsg("name");
665 EXPECT_STREQ(
666 "{\"type\":\"@Smi\",\"id\":\"objects\\/int-111235\","
667 "\"class\":{\"type\":\"@Class\",\"id\":\"classes\\/42\","
668 "\"user_name\":\"int\"},\"preview\":\"111235\"}",
669 handler.msg());
670
671 // Request function 0 from class A.
589 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '0']," 672 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '0'],"
590 "[], []]", cid); 673 "[], []]", cid);
591 Service::HandleIsolateMessage(isolate, service_msg); 674 Service::HandleIsolateMessage(isolate, service_msg);
592 handler.HandleNextMessage(); 675 handler.HandleNextMessage();
593 EXPECT_SUBSTRING("\"type\":\"Function\"", handler.msg()); 676 EXPECT_SUBSTRING("\"type\":\"Function\"", handler.msg());
594 ExpectSubstringF(handler.msg(), 677 ExpectSubstringF(handler.msg(),
595 "\"id\":\"classes\\/%" Pd "\\/functions\\/0\"," 678 "\"id\":\"classes\\/%" Pd "\\/functions\\/0\","
596 "\"name\":\"get:a\",", cid); 679 "\"name\":\"get:a\",", cid);
597 680
598 // Request field 0 from class A. 681 // Request field 0 from class A.
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 Service::HandleIsolateMessage(isolate, service_msg); 1101 Service::HandleIsolateMessage(isolate, service_msg);
1019 handler.HandleNextMessage(); 1102 handler.HandleNextMessage();
1020 EXPECT_STREQ("alpha", handler.msg()); 1103 EXPECT_STREQ("alpha", handler.msg());
1021 service_msg = Eval(lib, "[port, ['beta'], [], []]"); 1104 service_msg = Eval(lib, "[port, ['beta'], [], []]");
1022 Service::HandleIsolateMessage(isolate, service_msg); 1105 Service::HandleIsolateMessage(isolate, service_msg);
1023 handler.HandleNextMessage(); 1106 handler.HandleNextMessage();
1024 EXPECT_STREQ("beta", handler.msg()); 1107 EXPECT_STREQ("beta", handler.msg());
1025 } 1108 }
1026 1109
1027 } // namespace dart 1110 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service.cc ('k') | tests/standalone/vmservice/isolate_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698