forked from dart-lang/webdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugger_test.dart
216 lines (192 loc) · 6.63 KB
/
debugger_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@TestOn('vm')
@Timeout(Duration(minutes: 2))
library;
import 'dart:async';
import 'package:dwds/src/debugging/debugger.dart';
import 'package:dwds/src/debugging/frame_computer.dart';
import 'package:dwds/src/debugging/inspector.dart';
import 'package:dwds/src/debugging/location.dart';
import 'package:dwds/src/debugging/skip_list.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';
import 'package:vm_service/vm_service.dart' hide LogRecord;
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
show CallFrame, DebuggerPausedEvent, StackTrace, WipCallFrame, WipScript;
import 'fixtures/debugger_data.dart';
import 'fixtures/fakes.dart';
import 'fixtures/utilities.dart';
late AppInspector inspector;
late Debugger debugger;
late FakeWebkitDebugger webkitDebugger;
late StreamController<DebuggerPausedEvent> pausedController;
late Locations locations;
late SkipLists skipLists;
class TestStrategy extends FakeStrategy {
TestStrategy(super.assetReader);
@override
Future<String> moduleForServerPath(String entrypoint, String appUri) async =>
'foo.ddc.js';
@override
Future<String> serverPathForModule(String entrypoint, String module) async =>
'foo/ddc';
}
final sourceMapContents =
'{"version":3,"sourceRoot":"","sources":["main.dart"],"names":[],'
'"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUwB,IAAtB,WAAM;AAKJ,'
'IAHF,4BAAkB,aAAa,SAAC,GAAG;AACb,MAApB,WAAM;AACN,YAAgC,+CAAO,AAAK,oBAAO,'
'yCAAC,WAAW;IAChE;AAC0D,IAA3D,AAAS,AAAK,0DAAO;AAAe,kBAAO;;;AAEvC,gBAAQ;'
'AAGV,IAFI,kCAAqC,QAAC;AACX,MAA/B,WAAM,AAAwB,0BAAP,QAAF,AAAE,KAAK,GAAP;'
';EAEzB","file":"main.ddc.js"}';
final sampleSyncFrame = WipCallFrame({
'callFrameId': '{"ordinal":0,"injectedScriptId":2}',
'functionName': '',
'functionLocation': {
'scriptId': '69',
'lineNumber': 88,
'columnNumber': 72,
},
'location': {'scriptId': '69', 'lineNumber': 37, 'columnNumber': 0},
'url': '',
'scopeChain': [],
'this': {'type': 'undefined'},
});
final sampleAsyncFrame = CallFrame({
'functionName': 'myFunc',
'url': '',
'scriptId': '71',
'lineNumber': 40,
'columnNumber': 1,
});
final Map<String, WipScript> scripts = {
'69': WipScript(<String, dynamic>{
'url': 'http://127.0.0.1:8081/foo.ddc.js',
}),
'71': WipScript(<String, dynamic>{
'url': 'http://127.0.0.1:8081/bar.ddc.js',
}),
};
void main() async {
setUpAll(() async {
webkitDebugger = FakeWebkitDebugger(scripts: scripts);
pausedController = StreamController<DebuggerPausedEvent>();
webkitDebugger.onPaused = pausedController.stream;
final toolConfiguration = TestToolConfiguration.withLoadStrategy(
loadStrategy: TestStrategy(FakeAssetReader()),
);
setGlobalsForTesting(
toolConfiguration: toolConfiguration,
);
final root = 'fakeRoot';
locations = Locations(
FakeAssetReader(sourceMap: sourceMapContents),
FakeModules(),
root,
);
locations.initialize('fake_entrypoint');
skipLists = SkipLists();
debugger = await Debugger.create(
webkitDebugger,
(_, __) {},
locations,
skipLists,
root,
);
inspector = FakeInspector(webkitDebugger, fakeIsolate: simpleIsolate);
debugger.updateInspector(inspector);
});
/// Test that we get expected variable values from a hard-coded
/// stack frame.
test('frames 1', () async {
final stackComputer = FrameComputer(debugger, frames1);
final frames = await stackComputer.calculateFrames();
expect(frames, isNotNull);
expect(frames, isNotEmpty);
final firstFrameVars = frames[0].vars!;
final frame1Variables = firstFrameVars.map((each) => each.name).toList();
expect(frame1Variables, ['a', 'b']);
});
test('creates async frames', () async {
final stackComputer = FrameComputer(
debugger,
[sampleSyncFrame],
asyncStackTrace: StackTrace({
'callFrames': [sampleAsyncFrame.json],
'parent': StackTrace({
'callFrames': [sampleAsyncFrame.json],
}).json,
}),
);
final frames = await stackComputer.calculateFrames();
expect(frames, hasLength(5));
expect(frames[0].kind, FrameKind.kRegular);
expect(frames[1].kind, FrameKind.kAsyncSuspensionMarker);
expect(frames[2].kind, FrameKind.kAsyncCausal);
expect(frames[3].kind, FrameKind.kAsyncSuspensionMarker);
expect(frames[4].kind, FrameKind.kAsyncCausal);
});
test('elides multiple async frames', () async {
final stackComputer = FrameComputer(
debugger,
[sampleSyncFrame],
asyncStackTrace: StackTrace({
'callFrames': [sampleAsyncFrame.json],
'parent': StackTrace({
'callFrames': [],
'parent': StackTrace({
'callFrames': [sampleAsyncFrame.json],
'parent': StackTrace({
'callFrames': [],
}).json,
}).json,
}).json,
}),
);
final frames = await stackComputer.calculateFrames();
expect(frames, hasLength(5));
expect(frames[0].kind, FrameKind.kRegular);
expect(frames[1].kind, FrameKind.kAsyncSuspensionMarker);
expect(frames[2].kind, FrameKind.kAsyncCausal);
expect(frames[3].kind, FrameKind.kAsyncSuspensionMarker);
expect(frames[4].kind, FrameKind.kAsyncCausal);
});
setUp(() {
// We need to provide an Isolate so that the code doesn't bail out on a null
// check before it has a chance to throw.
inspector = FakeInspector(webkitDebugger, fakeIsolate: simpleIsolate);
debugger.updateInspector(inspector);
});
group('errors', () {
setUp(() {
// We need to provide an Isolate so that the code doesn't bail out on a null
// check before it has a chance to throw.
inspector = FakeInspector(webkitDebugger, fakeIsolate: simpleIsolate);
debugger.updateInspector(inspector);
});
test('errors in the zone are caught and logged', () async {
// Add a DebuggerPausedEvent with a null parameter to provoke an error.
pausedController.sink.add(
DebuggerPausedEvent({
'method': '',
'params': {
'reason': 'other',
'callFrames': [
{'callFrameId': '', 'functionName': ''},
],
},
}),
);
expect(
Debugger.logger.onRecord,
emitsThrough(
predicate(
(LogRecord log) =>
log.message.contains('Error calculating sync frame'),
),
),
);
});
});
}