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

Unified Diff: runtime/vm/service_test.cc

Issue 184653003: Support displaying of types in the observatory (back-end only for now): (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/service_test.cc
===================================================================
--- runtime/vm/service_test.cc (revision 34138)
+++ runtime/vm/service_test.cc (working copy)
@@ -744,6 +744,95 @@
}
+TEST_CASE(Service_Types) {
+ const char* kScript =
+ "var port;\n" // Set to our mock port by C++.
+ "\n"
+ "class A<T> { }\n"
+ "\n"
+ "main() {\n"
+ " new A<A<bool>>();\n"
+ "}";
+
+ Isolate* isolate = Isolate::Current();
+ Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
+ EXPECT_VALID(h_lib);
+ Library& lib = Library::Handle();
+ lib ^= Api::UnwrapHandle(h_lib);
+ EXPECT(!lib.IsNull());
+ Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
+ EXPECT_VALID(result);
+ const Class& class_a = Class::Handle(GetClass(lib, "A"));
+ EXPECT(!class_a.IsNull());
+ intptr_t cid = class_a.id();
+
+ // Build a mock message handler and wrap it in a dart port.
+ ServiceTestMessageHandler handler;
+ Dart_Port port_id = PortMap::CreatePort(&handler);
+ Dart_Handle port =
+ Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id));
+ EXPECT_VALID(port);
+ EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port));
+
+ Instance& service_msg = Instance::Handle();
+
+ // Request the class A over the service.
+ service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "'], [], []]", cid);
+ Service::HandleIsolateMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg());
+ ExpectSubstringF(handler.msg(),
+ "\"id\":\"classes\\/%" Pd "\",\"name\":\"A\",", cid);
+
+ // Request canonical type 0 from class A.
+ service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'types', '0'],"
+ "[], []]", cid);
+ Service::HandleIsolateMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ EXPECT_SUBSTRING("\"type\":\"Type\"", handler.msg());
+ ExpectSubstringF(handler.msg(),
+ "\"id\":\"classes\\/%" Pd "\\/types\\/0\","
+ "\"name\":\"A<bool>\",", cid);
+
+ // Request canonical type 1 from class A.
+ service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'types', '1'],"
+ "[], []]", cid);
+ Service::HandleIsolateMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ EXPECT_SUBSTRING("\"type\":\"Type\"", handler.msg());
+ ExpectSubstringF(handler.msg(),
+ "\"id\":\"classes\\/%" Pd "\\/types\\/1\","
+ "\"name\":\"A<A<bool>>\",", cid);
+
+ // Request for non-existent canonical type from class A.
+ service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'types', '42'],"
+ "[], []]", cid);
+ Service::HandleIsolateMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ ExpectSubstringF(handler.msg(),
+ "{\"type\":\"Error\",\"id\":\"\","
+ "\"message\":\"Canonical type 42 not found\""
+ ",\"request\":"
+ "{\"arguments\":[\"classes\",\"%" Pd "\",\"types\",\"42\"],"
+ "\"option_keys\":[],\"option_values\":[]}}", cid);
+
+ // Request canonical type arguments. Expect <A<bool>> to be listed.
+ service_msg = EvalF(h_lib, "[port, ['typearguments'],"
+ "[], []]");
+ Service::HandleIsolateMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ EXPECT_SUBSTRING("\"type\":\"TypeArgumentsList\"", handler.msg());
+ ExpectSubstringF(handler.msg(), "\"name\":\"<A<bool>>\",");
+
+ // Request canonical type arguments with instantiations.
+ service_msg = EvalF(h_lib, "[port, ['typearguments', 'withinstantiations'],"
+ "[], []]");
+ Service::HandleIsolateMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ EXPECT_SUBSTRING("\"type\":\"TypeArgumentsList\"", handler.msg());
+}
+
+
TEST_CASE(Service_Code) {
const char* kScript =
"var port;\n" // Set to our mock port by C++.
« 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