@@ -6,12 +6,10 @@ import * as Protocol from '../../generated/protocol.js';
66import * as Bindings from '../../models/bindings/bindings.js' ;
77import * as Workspace from '../../models/workspace/workspace.js' ;
88import { 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' ;
1513import * as Common from '../common/common.js' ;
1614import * as Platform from '../platform/platform.js' ;
1715
@@ -21,56 +19,36 @@ const {urlString} = Platform.DevToolsPath;
2119const SCRIPT_ID_ONE = '1' as Protocol . Runtime . ScriptId ;
2220const 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 } ) ;
0 commit comments