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

Side by Side Diff: runtime/observatory/tests/service/get_source_report_test.dart

Issue 1566793002: Expose the new _getSourceReport api in the service protocol. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code rev Created 4 years, 11 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/observatory/tests/service/coverage_test.dart ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4 // VMOptions=--error_on_bad_type --error_on_bad_override
5
6 import 'package:observatory/service_io.dart';
7 import 'package:unittest/unittest.dart';
8 import 'test_helper.dart';
9 import 'dart:developer';
10
11 int globalVar = 100;
12
13 class MyClass {
14 static void myFunction(int value) {
15 if (value < 0) {
16 print("negative");
17 } else {
18 print("positive");
19 }
20 debugger();
21 }
22
23 static void otherFunction(int value) {
24 if (value < 0) {
25 print("otherFunction <");
26 } else {
27 print("otherFunction >=");
28 }
29 }
30 }
31
32 void testFunction() {
33 MyClass.otherFunction(-100);
34 MyClass.myFunction(10000);
35 }
36
37 var tests = [
38
39 hasStoppedAtBreakpoint,
40
41 (Isolate isolate) async {
42 var stack = await isolate.getStack();
43
44 // Make sure we are in the right place.
45 expect(stack.type, equals('Stack'));
46 expect(stack['frames'].length, greaterThanOrEqualTo(2));
47 expect(stack['frames'][0].function.name, equals('myFunction'));
48 expect(stack['frames'][0].function.dartOwner.name, equals('MyClass'));
49
50 var func = stack['frames'][0].function;
51 expect(func.name, equals('myFunction'));
52 await func.load();
53
54 var expectedRange = {
55 'scriptIndex': 0,
56 'startPos': 33,
57 'endPos': 82,
58 'compiled': true,
59 'coverage': {'hits': [48, 66, 76], 'misses': [54]}
60 };
61
62 // Full script
63 var params = { 'reports' : ['Coverage'],
64 'scriptId' : func.location.script.id };
65 var coverage = await isolate.invokeRpcNoUpgrade('_getSourceReport', params);
66 expect(coverage['type'], equals('SourceReport'));
67 expect(coverage['ranges'].length, 5);
68 expect(coverage['ranges'][0], equals(expectedRange));
69 expect(coverage['scripts'].length, 1);
70 expect(coverage['scripts'][0]['uri'],
71 endsWith('get_source_report_test.dart'));
72
73 // One function
74 params = { 'reports' : ['Coverage'],
75 'scriptId' : func.location.script.id,
76 'tokenPos' : func.location.tokenPos,
77 'endTokenPos' : func.location.endTokenPos };
78 coverage = await isolate.invokeRpcNoUpgrade('_getSourceReport', params);
79 expect(coverage['type'], equals('SourceReport'));
80 expect(coverage['ranges'].length, 1);
81 expect(coverage['ranges'][0], equals(expectedRange));
82 expect(coverage['scripts'].length, 1);
83 expect(coverage['scripts'][0]['uri'],
84 endsWith('get_source_report_test.dart'));
85
86 // Full isolate
87 params = { 'reports' : ['Coverage'] };
88 coverage = await isolate.invokeRpcNoUpgrade('_getSourceReport', params);
89 expect(coverage['type'], equals('SourceReport'));
90 expect(coverage['ranges'].length, greaterThan(1));
91 expect(coverage['scripts'].length, greaterThan(1));
92
93 // Multiple reports (make sure enum list parameter parsing works).
94 params = { 'reports' : ['CallSites', 'Coverage'],
95 'scriptId' : func.location.script.id,
96 'tokenPos' : func.location.tokenPos,
97 'endTokenPos' : func.location.endTokenPos };
98 coverage = await isolate.invokeRpcNoUpgrade('_getSourceReport', params);
99 expect(coverage['type'], equals('SourceReport'));
100 expect(coverage['ranges'].length, 1);
101 var range = coverage['ranges'][0];
102 expect(range.containsKey('callSites'), isTrue);
103 expect(range.containsKey('coverage'), isTrue);
104
105 // missing scriptId with tokenPos.
106 bool caughtException = false;
107 try {
108 params = { 'reports' : ['Coverage'],
109 'tokenPos' : func.location.tokenPos };
110 coverage = await isolate.invokeRpcNoUpgrade('_getSourceReport', params);
111 } on ServerRpcException catch(e) {
112 caughtException = true;
113 expect(e.code, equals(ServerRpcException.kInvalidParams));
114 expect(e.message,
115 "_getSourceReport: the 'tokenPos' parameter requires the "
116 "\'scriptId\' parameter");
117 }
118 expect(caughtException, isTrue);
119
120 // missing scriptId with endTokenPos.
121 caughtException = false;
122 try {
123 params = { 'reports' : ['Coverage'],
124 'endTokenPos' : func.location.endTokenPos };
125 coverage = await isolate.invokeRpcNoUpgrade('_getSourceReport', params);
126 } on ServerRpcException catch(e) {
127 caughtException = true;
128 expect(e.code, equals(ServerRpcException.kInvalidParams));
129 expect(e.message,
130 "_getSourceReport: the 'endTokenPos' parameter requires the "
131 "\'scriptId\' parameter");
132 }
133 expect(caughtException, isTrue);
134 },
135
136 ];
137
138 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction);
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/coverage_test.dart ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698