Skip to content

Commit 6428614

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[sdk] Run DebuggerModel.test.ts also in Node.js
Requires some changes to the underlying CDP types. We also add 2 more helpers to the MockCDPConnection. Adding handlers one-by-one gives actual type-saftey, which we can't do for an array of them. R=alexrudenko@chromium.org Bug: 451502260 Change-Id: I97186af694609032e3f1cea9ae7776082c7671b5 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7156127 Reviewed-by: Alex Rudenko <alexrudenko@chromium.org> Commit-Queue: Simon Zünd <szuend@chromium.org>
1 parent 420d5d6 commit 6428614

4 files changed

Lines changed: 126 additions & 126 deletions

File tree

front_end/core/sdk/BUILD.gn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ ts_library("unittests") {
155155
"CookieModel.test.ts",
156156
"CookieParser.test.ts",
157157
"DOMModel.test.ts",
158-
"DebuggerModel.test.ts",
159158
"EmulationModel.test.ts",
160159
"EnhancedTracesParser.test.ts",
161160
"FrameManager.test.ts",
@@ -207,13 +206,17 @@ devtools_foundation_module("foundation_unittests") {
207206
testonly = true
208207

209208
sources = [
209+
"DebuggerModel.test.ts",
210210
"RuntimeModel.test.ts",
211211
"Target.test.ts",
212212
"TargetManager.test.ts",
213213
]
214214

215215
deps = [
216216
":bundle",
217+
"../../generated",
218+
"../../models/bindings:bundle",
219+
"../../models/workspace:bundle",
217220
"../../testing",
218221
"../host:bundle",
219222
"../platform:bundle",

front_end/core/sdk/DebuggerModel.test.ts

Lines changed: 118 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import * as Protocol from '../../generated/protocol.js';
66
import * as Bindings from '../../models/bindings/bindings.js';
77
import * as Workspace from '../../models/workspace/workspace.js';
88
import {createTarget} from '../../testing/EnvironmentHelpers.js';
9-
import {
10-
describeWithMockConnection,
11-
dispatchEvent,
12-
setMockConnectionResponseHandler,
13-
} from '../../testing/MockConnection.js';
14-
import {MockProtocolBackend} from '../../testing/MockScopeChain.js';
9+
import {describeWithLocale} from '../../testing/LocaleHelpers.js';
10+
import {MockCDPConnection} from '../../testing/MockCDPConnection.js';
11+
import {setupRuntimeHooks} from '../../testing/RuntimeHelpers.js';
12+
import {setupSettingsHooks} from '../../testing/SettingsHelpers.js';
1513
import * as Common from '../common/common.js';
1614
import * as Platform from '../platform/platform.js';
1715

@@ -21,56 +19,36 @@ const {urlString} = Platform.DevToolsPath;
2119
const SCRIPT_ID_ONE = '1' as Protocol.Runtime.ScriptId;
2220
const SCRIPT_ID_TWO = '2' as Protocol.Runtime.ScriptId;
2321

24-
describeWithMockConnection('DebuggerModel', () => {
25-
describe('breakpoint activation', () => {
26-
beforeEach(() => {
27-
// Dummy handlers for unblocking target suspension.
28-
setMockConnectionResponseHandler('Debugger.setAsyncCallStackDepth', () => ({}));
29-
setMockConnectionResponseHandler('Debugger.disable', () => ({}));
30-
setMockConnectionResponseHandler('DOM.disable', () => ({}));
31-
setMockConnectionResponseHandler('CSS.disable', () => ({}));
32-
setMockConnectionResponseHandler('Overlay.disable', () => ({}));
33-
setMockConnectionResponseHandler('Animation.disable', () => ({}));
34-
setMockConnectionResponseHandler('Overlay.setShowGridOverlays', () => ({}));
35-
setMockConnectionResponseHandler('Overlay.setShowFlexOverlays', () => ({}));
36-
setMockConnectionResponseHandler('Overlay.setShowScrollSnapOverlays', () => ({}));
37-
setMockConnectionResponseHandler('Overlay.setShowContainerQueryOverlays', () => ({}));
38-
setMockConnectionResponseHandler('Overlay.setShowIsolatedElements', () => ({}));
39-
setMockConnectionResponseHandler('Overlay.setShowViewportSizeOnResize', () => ({}));
40-
setMockConnectionResponseHandler('Target.setAutoAttach', () => ({}));
41-
42-
// Dummy handlers for unblocking target resumption.
43-
setMockConnectionResponseHandler('Debugger.enable', () => ({} as Protocol.Debugger.EnableResponse));
44-
setMockConnectionResponseHandler('Debugger.setPauseOnExceptions', () => ({}));
45-
setMockConnectionResponseHandler('DOM.enable', () => ({}));
46-
setMockConnectionResponseHandler('Overlay.enable', () => ({}));
47-
setMockConnectionResponseHandler('CSS.enable', () => ({}));
48-
setMockConnectionResponseHandler('Animation.enable', () => ({}));
49-
});
22+
describe('DebuggerModel', () => {
23+
setupRuntimeHooks();
24+
setupSettingsHooks();
5025

26+
describe('breakpoint activation', () => {
5127
it('deactivates breakpoints on construction with inactive breakpoints', async () => {
28+
const connection = new MockCDPConnection();
5229
let breakpointsDeactivated = false;
53-
setMockConnectionResponseHandler('Debugger.setBreakpointsActive', request => {
30+
connection.setHandler('Debugger.setBreakpointsActive', request => {
5431
if (request.active === false) {
5532
breakpointsDeactivated = true;
5633
}
57-
return {};
34+
return {result: {}};
5835
});
5936
Common.Settings.Settings.instance().moduleSetting('breakpoints-active').set(false);
60-
createTarget();
37+
createTarget({connection});
6138
assert.isTrue(breakpointsDeactivated);
6239
});
6340

6441
it('deactivates breakpoints for suspended target', async () => {
42+
const connection = new MockCDPConnection();
6543
let breakpointsDeactivated = false;
66-
setMockConnectionResponseHandler('Debugger.setBreakpointsActive', request => {
44+
connection.setHandler('Debugger.setBreakpointsActive', request => {
6745
if (request.active === false) {
6846
breakpointsDeactivated = true;
6947
}
70-
return {};
48+
return {result: {}};
7149
});
7250

73-
const target = createTarget();
51+
const target = createTarget({connection});
7452

7553
await target.suspend();
7654

@@ -88,20 +66,21 @@ describeWithMockConnection('DebuggerModel', () => {
8866
});
8967

9068
it('activates breakpoints for suspended target', async () => {
69+
const connection = new MockCDPConnection();
9170
let breakpointsDeactivated = false;
9271
let breakpointsActivated = false;
93-
setMockConnectionResponseHandler('Debugger.setBreakpointsActive', request => {
72+
connection.setHandler('Debugger.setBreakpointsActive', request => {
9473
if (request.active) {
9574
breakpointsActivated = true;
9675
} else {
9776
breakpointsDeactivated = true;
9877
}
99-
return {};
78+
return {result: {}};
10079
});
10180

10281
// Deactivate breakpoints befroe the target is created.
10382
Common.Settings.Settings.instance().moduleSetting('breakpoints-active').set(false);
104-
const target = createTarget();
83+
const target = createTarget({connection});
10584
assert.isTrue(breakpointsDeactivated);
10685

10786
await target.suspend();
@@ -116,39 +95,44 @@ describeWithMockConnection('DebuggerModel', () => {
11695

11796
describe('createRawLocationFromURL', () => {
11897
it('yields correct location in the presence of multiple scripts with the same URL', async () => {
119-
const target = createTarget();
98+
const connection = new MockCDPConnection();
99+
const target = createTarget({connection});
120100
const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel);
121101
const url = 'http://localhost/index.html';
122-
dispatchEvent(target, 'Debugger.scriptParsed', {
123-
scriptId: SCRIPT_ID_ONE,
124-
url,
125-
startLine: 0,
126-
startColumn: 0,
127-
endLine: 1,
128-
endColumn: 10,
129-
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
130-
hash: '',
131-
buildId: '',
132-
isLiveEdit: false,
133-
sourceMapURL: undefined,
134-
hasSourceURL: false,
135-
length: 10,
136-
});
137-
dispatchEvent(target, 'Debugger.scriptParsed', {
138-
scriptId: SCRIPT_ID_TWO,
139-
url,
140-
startLine: 20,
141-
startColumn: 0,
142-
endLine: 21,
143-
endColumn: 10,
144-
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
145-
hash: '',
146-
buildId: '',
147-
isLiveEdit: false,
148-
sourceMapURL: undefined,
149-
hasSourceURL: false,
150-
length: 10,
151-
});
102+
connection.dispatchEvent(
103+
'Debugger.scriptParsed', {
104+
scriptId: SCRIPT_ID_ONE,
105+
url,
106+
startLine: 0,
107+
startColumn: 0,
108+
endLine: 1,
109+
endColumn: 10,
110+
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
111+
hash: '',
112+
buildId: '',
113+
isLiveEdit: false,
114+
sourceMapURL: undefined,
115+
hasSourceURL: false,
116+
length: 10,
117+
},
118+
target.sessionId);
119+
connection.dispatchEvent(
120+
'Debugger.scriptParsed', {
121+
scriptId: SCRIPT_ID_TWO,
122+
url,
123+
startLine: 20,
124+
startColumn: 0,
125+
endLine: 21,
126+
endColumn: 10,
127+
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
128+
hash: '',
129+
buildId: '',
130+
isLiveEdit: false,
131+
sourceMapURL: undefined,
132+
hasSourceURL: false,
133+
length: 10,
134+
},
135+
target.sessionId);
152136
assert.strictEqual(debuggerModel?.createRawLocationByURL(url, 0)?.scriptId, SCRIPT_ID_ONE);
153137
assert.strictEqual(debuggerModel?.createRawLocationByURL(url, 20, 1)?.scriptId, SCRIPT_ID_TWO);
154138
assert.isNull(debuggerModel?.createRawLocationByURL(url, 5, 5));
@@ -160,26 +144,25 @@ describeWithMockConnection('DebuggerModel', () => {
160144

161145
describe('setBreakpointByURL', () => {
162146
it('correctly sets only a single breakpoint in Node.js internal scripts', async () => {
163-
setMockConnectionResponseHandler('Debugger.setBreakpointByUrl', ({url}) => {
147+
const connection = new MockCDPConnection();
148+
connection.setHandler('Debugger.setBreakpointByUrl', ({url}) => {
164149
if (url === 'fs.js') {
165150
return {
166-
breakpointId: breakpointId1,
167-
locations: [],
168-
getError() {
169-
return undefined;
170-
},
151+
result: {
152+
breakpointId: breakpointId1,
153+
locations: [],
154+
}
171155
};
172156
}
173157
return {
174-
breakpointId: breakpointId2,
175-
locations: [],
176-
getError() {
177-
return undefined;
178-
},
158+
result: {
159+
breakpointId: breakpointId2,
160+
locations: [],
161+
}
179162
};
180163
});
181164

182-
const target = createTarget();
165+
const target = createTarget({connection});
183166
target.markAsNodeJSForTest();
184167
const model = new SDK.DebuggerModel.DebuggerModel(target);
185168
const {breakpointId} = await model.setBreakpointByURL(urlString`fs.js`, 1);
@@ -189,38 +172,43 @@ describeWithMockConnection('DebuggerModel', () => {
189172

190173
describe('scriptsForSourceURL', () => {
191174
it('returns the latest script at the front of the result for scripts with the same URL', () => {
192-
const target = createTarget();
175+
const connection = new MockCDPConnection();
176+
const target = createTarget({connection});
193177
const url = 'http://localhost/index.html';
194-
dispatchEvent(target, 'Debugger.scriptParsed', {
195-
scriptId: SCRIPT_ID_ONE,
196-
url,
197-
startLine: 0,
198-
startColumn: 0,
199-
endLine: 1,
200-
endColumn: 10,
201-
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
202-
hash: '',
203-
buildId: '',
204-
isLiveEdit: false,
205-
sourceMapURL: undefined,
206-
hasSourceURL: false,
207-
length: 10,
208-
});
209-
dispatchEvent(target, 'Debugger.scriptParsed', {
210-
scriptId: SCRIPT_ID_TWO,
211-
url,
212-
startLine: 20,
213-
startColumn: 0,
214-
endLine: 21,
215-
endColumn: 10,
216-
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
217-
buildId: '',
218-
hash: '',
219-
isLiveEdit: false,
220-
sourceMapURL: undefined,
221-
hasSourceURL: false,
222-
length: 10,
223-
});
178+
connection.dispatchEvent(
179+
'Debugger.scriptParsed', {
180+
scriptId: SCRIPT_ID_ONE,
181+
url,
182+
startLine: 0,
183+
startColumn: 0,
184+
endLine: 1,
185+
endColumn: 10,
186+
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
187+
hash: '',
188+
buildId: '',
189+
isLiveEdit: false,
190+
sourceMapURL: undefined,
191+
hasSourceURL: false,
192+
length: 10,
193+
},
194+
target.sessionId);
195+
connection.dispatchEvent(
196+
'Debugger.scriptParsed', {
197+
scriptId: SCRIPT_ID_TWO,
198+
url,
199+
startLine: 20,
200+
startColumn: 0,
201+
endLine: 21,
202+
endColumn: 10,
203+
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
204+
buildId: '',
205+
hash: '',
206+
isLiveEdit: false,
207+
sourceMapURL: undefined,
208+
hasSourceURL: false,
209+
length: 10,
210+
},
211+
target.sessionId);
224212

225213
const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel);
226214
const scripts = debuggerModel?.scriptsForSourceURL(url) || [];
@@ -230,7 +218,7 @@ describeWithMockConnection('DebuggerModel', () => {
230218
});
231219
});
232220

233-
describe('Scope', () => {
221+
describeWithLocale('Scope', () => {
234222
it('Scope.typeName covers every enum value', async () => {
235223
const target = createTarget();
236224
const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel) as SDK.DebuggerModel.DebuggerModel;
@@ -277,12 +265,8 @@ describeWithMockConnection('DebuggerModel', () => {
277265
});
278266

279267
describe('pause', () => {
280-
let target: SDK.Target.Target;
281-
let backend: MockProtocolBackend;
282-
283268
beforeEach(() => {
284-
target = createTarget({id: 'main' as Protocol.Target.TargetID, name: 'main', type: SDK.Target.Type.FRAME});
285-
const targetManager = target.targetManager();
269+
const targetManager = SDK.TargetManager.TargetManager.instance();
286270
const workspace = Workspace.Workspace.WorkspaceImpl.instance();
287271
const resourceMapping = new Bindings.ResourceMapping.ResourceMapping(targetManager, workspace);
288272
const ignoreListManager = Workspace.IgnoreListManager.IgnoreListManager.instance({forceNew: true});
@@ -293,17 +277,26 @@ describeWithMockConnection('DebuggerModel', () => {
293277
ignoreListManager,
294278
workspace,
295279
});
296-
backend = new MockProtocolBackend();
297280
});
298281

299282
it('with empty call frame list will invoke plain step-into', async () => {
283+
const connection = new MockCDPConnection();
284+
const target =
285+
createTarget({id: 'main' as Protocol.Target.TargetID, name: 'main', type: SDK.Target.Type.FRAME, connection});
300286
const stepIntoRequestPromise = new Promise<void>(resolve => {
301-
setMockConnectionResponseHandler('Debugger.stepInto', () => {
287+
connection.setHandler('Debugger.stepInto', () => {
302288
resolve();
303-
return {};
289+
return {result: {}};
304290
});
305291
});
306-
backend.dispatchDebuggerPauseWithNoCallFrames(target, Protocol.Debugger.PausedEventReason.Other);
292+
293+
connection.dispatchEvent(
294+
'Debugger.paused', {
295+
callFrames: [],
296+
reason: Protocol.Debugger.PausedEventReason.Other,
297+
},
298+
target.sessionId);
299+
307300
await stepIntoRequestPromise;
308301
});
309302
});

front_end/models/bindings/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ devtools_entrypoint("bundle") {
5050

5151
visibility = [
5252
":*",
53+
"../../core/sdk:foundation_unittests",
54+
"../../core/sdk:foundation_unittests_node_typecheck",
5355
"../../core/sdk:unittests",
5456
"../../entrypoints/main/*",
5557
"../../foundation/*",

front_end/models/workspace/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ devtools_entrypoint("bundle") {
3434

3535
visibility = [
3636
":*",
37+
"../../core/sdk:foundation_unittests",
38+
"../../core/sdk:foundation_unittests_node_typecheck",
3739
"../../core/sdk:unittests",
3840
"../../entrypoints/main/*",
3941
"../../foundation/*",

0 commit comments

Comments
 (0)