Commit d05203d1 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

DevTools: Fix tests that rely on onceAttachedToTarget

onceAttachedToTarget needs to be run before the thing that causes the
target creation otherwise it will race with the creation, which
could occur after e.g. the evaluate() call and before the onceAttached()
call.

Change-Id: I26cd5d9d6fdd993fcb0a38c28923870b0e5c8e69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1944467
Auto-Submit: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: default avatarMathias Bynens <mathias@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720184}
parent 8dd52f5b
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
await session.navigate('resources/repeat-fetch-service-worker.html'); await session.navigate('resources/repeat-fetch-service-worker.html');
const attachedPromise = dp.Target.onceAttachedToTarget();
swHelper.installSWAndWaitForActivated('/inspector-protocol/service-worker/resources/repeat-fetch-service-worker.js'); swHelper.installSWAndWaitForActivated('/inspector-protocol/service-worker/resources/repeat-fetch-service-worker.js');
const attachedToTarget = await dp.Target.onceAttachedToTarget(); const attachedToTarget = await attachedPromise;
const swdp = session.createChild(attachedToTarget.params.sessionId).protocol; const swdp = session.createChild(attachedToTarget.params.sessionId).protocol;
await swdp.Network.enable(); await swdp.Network.enable();
......
...@@ -6,30 +6,33 @@ ...@@ -6,30 +6,33 @@
await dp.Page.onceLoadEventFired(); await dp.Page.onceLoadEventFired();
testRunner.log('Enabling auto-discovery...'); testRunner.log('Enabling auto-discovery...');
dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false}); const attachedPromise = dp.Target.onceAttachedToTarget();
await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false});
let attachedEvent = (await dp.Target.onceAttachedToTarget()).params; const attachedEvent = (await attachedPromise).params;
testRunner.log('Got auto-attached.'); testRunner.log('Got auto-attached.');
let frameId = attachedEvent.targetInfo.targetId; const frameId = attachedEvent.targetInfo.targetId;
testRunner.log('Navigating to in-process iframe...'); testRunner.log('Navigating to in-process iframe...');
let navigatePromise = dp.Page.navigate({frameId, url: testRunner.url('../resources/iframe.html')}); const navigatePromise = dp.Page.navigate({frameId, url: testRunner.url('../resources/iframe.html')});
let detachedPromise = dp.Target.onceDetachedFromTarget(); const detachedPromise = dp.Target.onceDetachedFromTarget();
await Promise.all([navigatePromise, detachedPromise]); await Promise.all([navigatePromise, detachedPromise]);
let detachedEvent = (await detachedPromise).params; const detachedEvent = (await detachedPromise).params;
testRunner.log('Session id should match: ' + (attachedEvent.sessionId === detachedEvent.sessionId)); testRunner.log('Session id should match: ' + (attachedEvent.sessionId === detachedEvent.sessionId));
testRunner.log('Target id should match: ' + (attachedEvent.targetInfo.targetId === detachedEvent.targetId)); testRunner.log('Target id should match: ' + (attachedEvent.targetInfo.targetId === detachedEvent.targetId));
testRunner.log('Navigating back to out-of-process iframe...'); testRunner.log('Navigating back to out-of-process iframe...');
const attachedPromise2 = dp.Target.onceAttachedToTarget();
dp.Page.navigate({frameId, url: 'http://devtools.oopif.test:8000/inspector-protocol/resources/iframe.html'}); dp.Page.navigate({frameId, url: 'http://devtools.oopif.test:8000/inspector-protocol/resources/iframe.html'});
let attachedEvent2 = (await dp.Target.onceAttachedToTarget()).params; const attachedEvent2 = (await attachedPromise2).params;
testRunner.log('Target ids should match: ' + (attachedEvent.targetInfo.targetId === attachedEvent2.targetInfo.targetId)); testRunner.log('Target ids should match: ' + (attachedEvent.targetInfo.targetId === attachedEvent2.targetInfo.targetId));
dp.Target.setAutoAttach({autoAttach: false, waitForDebuggerOnStart: false}); const detachedPromise2 = dp.Target.onceDetachedFromTarget();
let detachedEvent2 = (await dp.Target.onceDetachedFromTarget()).params; await dp.Target.setAutoAttach({autoAttach: false, waitForDebuggerOnStart: false});
const detachedEvent2 = (await detachedPromise2).params;
testRunner.log('Session id should match: ' + (attachedEvent2.sessionId === detachedEvent2.sessionId)); testRunner.log('Session id should match: ' + (attachedEvent2.sessionId === detachedEvent2.sessionId));
testRunner.log('Target id should match: ' + (attachedEvent2.targetInfo.targetId === detachedEvent2.targetId)); testRunner.log('Target id should match: ' + (attachedEvent2.targetInfo.targetId === detachedEvent2.targetId));
......
...@@ -6,25 +6,28 @@ ...@@ -6,25 +6,28 @@
await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: true, flatten: true, windowOpen: true}); await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: true, flatten: true, windowOpen: true});
const attachedPromise = dp.Target.onceAttachedToTarget();
session.evaluate(` session.evaluate(`
window.myWindow = window.open('../resources/inspector-protocol-page.html'); undefined; window.myWindow = window.open('../resources/inspector-protocol-page.html'); undefined;
`); `);
testRunner.log('Opened the window'); testRunner.log('Opened the window');
await dp.Target.onceAttachedToTarget(); await attachedPromise;
testRunner.log('Attached to window'); testRunner.log('Attached to window');
const changedPromise = dp.Target.onceTargetInfoChanged();
session.evaluate(` session.evaluate(`
window.myWindow.location.assign('../resources/inspector-protocol-page.html?foo'); undefined; window.myWindow.location.assign('../resources/inspector-protocol-page.html?foo'); undefined;
`); `);
testRunner.log('Navigated the window'); testRunner.log('Navigated the window');
await dp.Target.onceTargetInfoChanged(); await changedPromise;
testRunner.log('Target info changed'); testRunner.log('Target info changed');
const detachedPromise = dp.Target.onceDetachedFromTarget();
session.evaluate(` session.evaluate(`
window.myWindow.close(); undefined; window.myWindow.close(); undefined;
`); `);
testRunner.log('Closed the window'); testRunner.log('Closed the window');
await dp.Target.onceDetachedFromTarget(); await detachedPromise;
testRunner.log('Detached from window'); testRunner.log('Detached from window');
testRunner.completeTest(); testRunner.completeTest();
......
...@@ -9,21 +9,25 @@ ...@@ -9,21 +9,25 @@
dp.Network.enable() dp.Network.enable()
]); ]);
await dp.Network.setUserAgentOverride({userAgent: 'test'}); await dp.Network.setUserAgentOverride({userAgent: 'test'});
const requestSentPromise = dp.Network.onceRequestWillBeSent();
const attachedPromise = dp.Target.onceAttachedToTarget();
session.evaluate(` session.evaluate(`
var iframe = document.createElement('iframe'); var iframe = document.createElement('iframe');
iframe.src = 'http://devtools.oopif.test:8000/inspector-protocol/network/resources/echo-headers.php?headers=HTTP_USER_AGENT'; iframe.src = 'http://devtools.oopif.test:8000/inspector-protocol/network/resources/echo-headers.php?headers=HTTP_USER_AGENT';
document.body.appendChild(iframe); document.body.appendChild(iframe);
`); `);
let params = (await dp.Network.onceRequestWillBeSent()).params; const params = (await requestSentPromise).params;
let sessionId = (await dp.Target.onceAttachedToTarget()).params.sessionId; const sessionId = (await attachedPromise).params.sessionId;
let dp1 = session.createChild(sessionId).protocol; const dp1 = session.createChild(sessionId).protocol;
await dp1.Network.enable(); await dp1.Network.enable();
await dp1.Network.setUserAgentOverride({userAgent: 'test (subframe)'}); await dp1.Network.setUserAgentOverride({userAgent: 'test (subframe)'});
const loadingFinishedPromise = dp1.Network.onceLoadingFinished();
await dp1.Runtime.runIfWaitingForDebugger(); await dp1.Runtime.runIfWaitingForDebugger();
testRunner.log(`User-Agent = ${params.request.headers['User-Agent']}`); testRunner.log(`User-Agent = ${params.request.headers['User-Agent']}`);
await dp1.Network.onceLoadingFinished(); await loadingFinishedPromise;
let content = (await dp1.Network.getResponseBody({requestId: params.requestId})).result.body; const content = (await dp1.Network.getResponseBody({requestId: params.requestId})).result.body;
testRunner.log(`content (should have user-agent header overriden): ${content}`); testRunner.log(`content (should have user-agent header overriden): ${content}`);
testRunner.completeTest(); testRunner.completeTest();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
await dp.Target.setAutoAttach({autoAttach: true, await dp.Target.setAutoAttach({autoAttach: true,
waitForDebuggerOnStart: false, waitForDebuggerOnStart: false,
flatten: true}); flatten: true});
const attachedPromise = dp.Target.onceAttachedToTarget();
await session.evaluate(` await session.evaluate(`
window.worker = new Worker('${testRunner.url('resources/dedicated-worker-loop.js')}'); window.worker = new Worker('${testRunner.url('resources/dedicated-worker-loop.js')}');
var resolve; var resolve;
...@@ -16,7 +17,7 @@ ...@@ -16,7 +17,7 @@
`); `);
testRunner.log('Started worker'); testRunner.log('Started worker');
const sessionId = (await dp.Target.onceAttachedToTarget()).params.sessionId; const sessionId = (await attachedPromise).params.sessionId;
testRunner.log('Worker created'); testRunner.log('Worker created');
testRunner.log('didConnectToWorker'); testRunner.log('didConnectToWorker');
......
...@@ -9,10 +9,11 @@ ...@@ -9,10 +9,11 @@
`); `);
testRunner.log('Started worker'); testRunner.log('Started worker');
dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false, const attachedPromise = dp.Target.onceAttachedToTarget();
await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false,
flatten: true}); flatten: true});
const event = await dp.Target.onceAttachedToTarget(); const event = await attachedPromise;
const childSession = session.createChild(event.params.sessionId); const childSession = session.createChild(event.params.sessionId);
testRunner.log('Worker created'); testRunner.log('Worker created');
testRunner.log('didConnectToWorker'); testRunner.log('didConnectToWorker');
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
const {page, session, dp} = await testRunner.startBlank( const {page, session, dp} = await testRunner.startBlank(
'Tests sourceURL in setTimeout from worker.'); 'Tests sourceURL in setTimeout from worker.');
dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false, await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false,
flatten: true}); flatten: true});
const attachedPromise = dp.Target.onceAttachedToTarget();
await session.evaluate(` await session.evaluate(`
window.worker = new Worker('${testRunner.url('resources/dedicated-worker-string-setTimeout.js')}'); window.worker = new Worker('${testRunner.url('resources/dedicated-worker-string-setTimeout.js')}');
window.worker.onmessage = function(event) { }; window.worker.onmessage = function(event) { };
...@@ -12,7 +13,7 @@ ...@@ -12,7 +13,7 @@
`); `);
testRunner.log('Started worker'); testRunner.log('Started worker');
const messageObject = await dp.Target.onceAttachedToTarget(); const messageObject = await attachedPromise;
const childSession = session.createChild(messageObject.params.sessionId); const childSession = session.createChild(messageObject.params.sessionId);
testRunner.log('Worker created'); testRunner.log('Worker created');
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: true, await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: true,
flatten: true}); flatten: true});
const attachedPromise = dp.Target.onceAttachedToTarget();
await session.evaluate(` await session.evaluate(`
window.worker = new Worker('${testRunner.url('resources/dedicated-worker-step-into.js')}'); window.worker = new Worker('${testRunner.url('resources/dedicated-worker-step-into.js')}');
window.worker.onmessage = function(event) { }; window.worker.onmessage = function(event) { };
...@@ -11,7 +12,7 @@ ...@@ -11,7 +12,7 @@
`); `);
testRunner.log('Started worker'); testRunner.log('Started worker');
const sessionId = (await dp.Target.onceAttachedToTarget()).params.sessionId; const sessionId = (await attachedPromise).params.sessionId;
testRunner.log('Worker created'); testRunner.log('Worker created');
const childSession = session.createChild(sessionId); const childSession = session.createChild(sessionId);
......
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false, dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false,
flatten: true}); flatten: true});
const attachedPromise = dp.Target.onceAttachedToTarget();
await session.evaluate(` await session.evaluate(`
window.worker = new Worker('${testRunner.url('resources/dedicated-worker.js')}'); window.worker = new Worker('${testRunner.url('resources/dedicated-worker.js')}');
window.worker.onmessage = function(event) { }; window.worker.onmessage = function(event) { };
window.worker.postMessage(1); window.worker.postMessage(1);
`); `);
testRunner.log('Started worker'); testRunner.log('Started worker');
const sessionId = (await dp.Target.onceAttachedToTarget()).params.sessionId; const sessionId = (await attachedPromise).params.sessionId;
const childSession = session.createChild(sessionId); const childSession = session.createChild(sessionId);
testRunner.log('Worker created'); testRunner.log('Worker created');
testRunner.log('didConnectToWorker'); testRunner.log('didConnectToWorker');
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: true, await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: true,
flatten: true}); flatten: true});
const attachedPromise = dp.Target.onceAttachedToTarget();
await session.evaluate(` await session.evaluate(`
const workerScript = \` const workerScript = \`
self.count = 0; self.count = 0;
...@@ -22,7 +23,7 @@ ...@@ -22,7 +23,7 @@
worker.postMessage(1); worker.postMessage(1);
`); `);
const event = await dp.Target.onceAttachedToTarget(); const event = await attachedPromise;
const childSession = session.createChild(event.params.sessionId); const childSession = session.createChild(event.params.sessionId);
testRunner.log('Worker created'); testRunner.log('Worker created');
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false, await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false,
flatten: true}); flatten: true});
const attachedPromise = dp.Target.onceAttachedToTarget();
session.evaluate(` session.evaluate(`
window.worker1 = new Worker('${testRunner.url('../resources/worker-with-throw.js')}'); window.worker1 = new Worker('${testRunner.url('../resources/worker-with-throw.js')}');
window.worker1.onerror = function(e) { window.worker1.onerror = function(e) {
...@@ -12,24 +13,27 @@ ...@@ -12,24 +13,27 @@
worker1.terminate(); worker1.terminate();
} }
`); `);
let event = await dp.Target.onceAttachedToTarget(); let event = await attachedPromise;
const childSession = session.createChild(event.params.sessionId); const childSession = session.createChild(event.params.sessionId);
testRunner.log('Worker created'); testRunner.log('Worker created');
await childSession.protocol.Runtime.enable(); await childSession.protocol.Runtime.enable();
const detachedPromise = dp.Target.onceDetachedFromTarget();
session.evaluate('worker1.postMessage(239);'); session.evaluate('worker1.postMessage(239);');
await dp.Target.onceDetachedFromTarget(); await detachedPromise;
testRunner.log('Worker destroyed'); testRunner.log('Worker destroyed');
const attachedPromise2 = dp.Target.onceAttachedToTarget();
session.evaluate(` session.evaluate(`
window.worker2 = new Worker('${testRunner.url('../resources/worker-with-throw.js')}'); window.worker2 = new Worker('${testRunner.url('../resources/worker-with-throw.js')}');
`); `);
event = await dp.Target.onceAttachedToTarget(); event = await attachedPromise2;
const childSession2 = session.createChild(event.params.sessionId); const childSession2 = session.createChild(event.params.sessionId);
testRunner.log('\nWorker created'); testRunner.log('\nWorker created');
await childSession2.protocol.Runtime.enable(); await childSession2.protocol.Runtime.enable();
const thrownPromise = childSession2.protocol.Runtime.onceExceptionThrown();
session.evaluate('worker2.postMessage(42);'); session.evaluate('worker2.postMessage(42);');
event = await childSession2.protocol.Runtime.onceExceptionThrown(); event = await thrownPromise;
const callFrames = event.params.exceptionDetails.stackTrace ? event.params.exceptionDetails.stackTrace.callFrames : []; const callFrames = event.params.exceptionDetails.stackTrace ? event.params.exceptionDetails.stackTrace.callFrames : [];
testRunner.log(callFrames.length > 0 ? 'Message with stack trace received.' : '[FAIL] Message contains empty stack trace'); testRunner.log(callFrames.length > 0 ? 'Message with stack trace received.' : '[FAIL] Message contains empty stack trace');
......
...@@ -98,10 +98,11 @@ ...@@ -98,10 +98,11 @@
// an event that we're attached; which we receive below to create the // an event that we're attached; which we receive below to create the
// childSession instance. // childSession instance.
clientLog.push('Starting autoattach'); clientLog.push('Starting autoattach');
dp.Target.setAutoAttach({ const attachedPromise = dp.Target.onceAttachedToTarget();
await dp.Target.setAutoAttach({
autoAttach: true, waitForDebuggerOnStart: false, flatten: true}); autoAttach: true, waitForDebuggerOnStart: false, flatten: true});
const childSession = session.createChild( const childSession = session.createChild(
(await dp.Target.onceAttachedToTarget()).params.sessionId); (await attachedPromise).params.sessionId);
childSession.protocol.Runtime.onConsoleAPICalled((event) => { childSession.protocol.Runtime.onConsoleAPICalled((event) => {
consoleLog.push(event.params.args[0].value); consoleLog.push(event.params.args[0].value);
}); });
...@@ -139,13 +140,14 @@ ...@@ -139,13 +140,14 @@
// This time we start the worker only after Target.setAutoAttach, so // This time we start the worker only after Target.setAutoAttach, so
// we may await the autoattach response. // we may await the autoattach response.
clientLog.push('Starting autoattach'); clientLog.push('Starting autoattach');
const attachedPromise = dp.Target.onceAttachedToTarget();
await dp.Target.setAutoAttach({ await dp.Target.setAutoAttach({
autoAttach: true, waitForDebuggerOnStart: false, flatten: true}); autoAttach: true, waitForDebuggerOnStart: false, flatten: true});
clientLog.push('Starting worker'); clientLog.push('Starting worker');
session.evaluate('startWorker()'); session.evaluate('startWorker()');
const childSession = session.createChild( const childSession = session.createChild(
(await dp.Target.onceAttachedToTarget()).params.sessionId); (await attachedPromise).params.sessionId);
childSession.protocol.Runtime.onConsoleAPICalled((event) => { childSession.protocol.Runtime.onConsoleAPICalled((event) => {
consoleLog.push(event.params.args[0].value); consoleLog.push(event.params.args[0].value);
}); });
...@@ -172,9 +174,10 @@ ...@@ -172,9 +174,10 @@
clientLog.push( clientLog.push(
'\n=== New worker, with auto-attach still enabled. ==='); '\n=== New worker, with auto-attach still enabled. ===');
clientLog.push('Starting worker'); clientLog.push('Starting worker');
const attachedPromise = dp.Target.onceAttachedToTarget();
session.evaluate('startWorker()'); session.evaluate('startWorker()');
const childSession = session.createChild( const childSession = session.createChild(
(await dp.Target.onceAttachedToTarget()).params.sessionId); (await attachedPromise).params.sessionId);
childSession.protocol.Runtime.onConsoleAPICalled((event) => { childSession.protocol.Runtime.onConsoleAPICalled((event) => {
consoleLog.push(event.params.args[0].value); consoleLog.push(event.params.args[0].value);
}); });
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
testRunner.log('Set breakpoint before worker created'); testRunner.log('Set breakpoint before worker created');
await dp.Debugger.setBreakpointByUrl( await dp.Debugger.setBreakpointByUrl(
{url: 'test.js', lineNumber: 2, columnNumber: 13}); {url: 'test.js', lineNumber: 2, columnNumber: 13});
const attachedPromise = dp.Target.onceAttachedToTarget();
session.evaluate(` session.evaluate(`
var blob = new Blob(['console.log(239);//# sourceURL=worker.js'], {type: 'application/javascript'}); var blob = new Blob(['console.log(239);//# sourceURL=worker.js'], {type: 'application/javascript'});
var worker = new Worker(URL.createObjectURL(blob)); var worker = new Worker(URL.createObjectURL(blob));
...@@ -24,7 +25,7 @@ var worker = new Worker(URL.createObjectURL(blob)); ...@@ -24,7 +25,7 @@ var worker = new Worker(URL.createObjectURL(blob));
testRunner.log('Setup worker session'); testRunner.log('Setup worker session');
const childSession = session.createChild( const childSession = session.createChild(
(await dp.Target.onceAttachedToTarget()).params.sessionId); (await attachedPromise).params.sessionId);
const workerDebuggerId = const workerDebuggerId =
(await childSession.protocol.Debugger.enable()).debuggerId; (await childSession.protocol.Debugger.enable()).debuggerId;
......
...@@ -6,15 +6,15 @@ ...@@ -6,15 +6,15 @@
name: 'the name' name: 'the name'
}); });
`); `);
let workerCallback; const attachedPromise = dp.Target.onceAttachedToTarget();
const workerPromise = new Promise(x => workerCallback = x); await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false,
dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: false,
flatten: true}); flatten: true});
const {params: {sessionId, targetInfo}} = await dp.Target.onceAttachedToTarget(); const {params: {sessionId, targetInfo}} = await attachedPromise;
testRunner.log(`target title: "${targetInfo.title}"`); testRunner.log(`target title: "${targetInfo.title}"`);
const childSession = session.createChild(sessionId); const childSession = session.createChild(sessionId);
childSession.protocol.Runtime.enable({}); const contextPromise = childSession.protocol.Runtime.onceExecutionContextCreated();
const event = await childSession.protocol.Runtime.onceExecutionContextCreated(); await childSession.protocol.Runtime.enable({});
const event = await contextPromise;
testRunner.log(`execution context name: "${event.params.context.name}"`); testRunner.log(`execution context name: "${event.params.context.name}"`);
testRunner.completeTest(); testRunner.completeTest();
}) })
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
const pageDebuggerId = (await dp.Debugger.enable()).result.debuggerId; const pageDebuggerId = (await dp.Debugger.enable()).result.debuggerId;
debuggers.set(pageDebuggerId, dp.Debugger); debuggers.set(pageDebuggerId, dp.Debugger);
await dp.Debugger.setAsyncCallStackDepth({maxDepth: 32}); await dp.Debugger.setAsyncCallStackDepth({maxDepth: 32});
const attachedPromise = dp.Target.onceAttachedToTarget();
session.evaluate(` session.evaluate(`
var blob = new Blob(['postMessage(239);//# sourceURL=worker.js'], {type: 'application/javascript'}); var blob = new Blob(['postMessage(239);//# sourceURL=worker.js'], {type: 'application/javascript'});
var worker = new Worker(URL.createObjectURL(blob)); var worker = new Worker(URL.createObjectURL(blob));
...@@ -17,8 +18,7 @@ worker.onmessage = (e) => console.log(e.data); ...@@ -17,8 +18,7 @@ worker.onmessage = (e) => console.log(e.data);
//# sourceURL=test.js`); //# sourceURL=test.js`);
testRunner.log('Setup worker session'); testRunner.log('Setup worker session');
const childSession = session.createChild( const childSession = session.createChild((await attachedPromise).params.sessionId);
(await dp.Target.onceAttachedToTarget()).params.sessionId);
const workerDebuggerId = const workerDebuggerId =
(await childSession.protocol.Debugger.enable()).result.debuggerId; (await childSession.protocol.Debugger.enable()).result.debuggerId;
debuggers.set(workerDebuggerId, childSession.protocol.Debugger); debuggers.set(workerDebuggerId, childSession.protocol.Debugger);
...@@ -29,14 +29,16 @@ worker.onmessage = (e) => console.log(e.data); ...@@ -29,14 +29,16 @@ worker.onmessage = (e) => console.log(e.data);
{url: 'worker.js', lineNumber: 0, columnNumber: 0}); {url: 'worker.js', lineNumber: 0, columnNumber: 0});
testRunner.log('Run worker'); testRunner.log('Run worker');
const pausedPromise = childSession.protocol.Debugger.oncePaused();
await childSession.protocol.Runtime.runIfWaitingForDebugger(); await childSession.protocol.Runtime.runIfWaitingForDebugger();
testRunner.log('Run stepInto with breakOnAsyncCall flag'); testRunner.log('Run stepInto with breakOnAsyncCall flag');
await childSession.protocol.Debugger.oncePaused(); await pausedPromise;
const pausedOnBreakPromise = dp.Debugger.oncePaused();
await childSession.protocol.Debugger.stepInto({breakOnAsyncCall: true}); await childSession.protocol.Debugger.stepInto({breakOnAsyncCall: true});
const {callFrames, asyncStackTraceId} = (await dp.Debugger.oncePaused()).params; const {callFrames, asyncStackTraceId} = (await pausedOnBreakPromise).params;
await testRunner.logStackTrace( await testRunner.logStackTrace(
debuggers, {callFrames, parentId: asyncStackTraceId}, pageDebuggerId); debuggers, {callFrames, parentId: asyncStackTraceId}, pageDebuggerId);
testRunner.completeTest(); testRunner.completeTest();
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
testRunner.log('Set breakpoint before postMessage'); testRunner.log('Set breakpoint before postMessage');
await dp.Debugger.setBreakpointByUrl( await dp.Debugger.setBreakpointByUrl(
{url: 'test.js', lineNumber: 3, columnNumber: 7}); {url: 'test.js', lineNumber: 3, columnNumber: 7});
const attachedPromise = dp.Target.onceAttachedToTarget();
session.evaluate(` session.evaluate(`
var blob = new Blob(['onmessage = (e) => console.log(e.data);//# sourceURL=worker.js'], {type: 'application/javascript'}); var blob = new Blob(['onmessage = (e) => console.log(e.data);//# sourceURL=worker.js'], {type: 'application/javascript'});
var worker = new Worker(URL.createObjectURL(blob)); var worker = new Worker(URL.createObjectURL(blob));
...@@ -25,7 +26,7 @@ worker.postMessage(42); ...@@ -25,7 +26,7 @@ worker.postMessage(42);
testRunner.log('Setup worker session'); testRunner.log('Setup worker session');
const childSession = session.createChild( const childSession = session.createChild(
(await dp.Target.onceAttachedToTarget()).params.sessionId); (await attachedPromise).params.sessionId);
const workerDebuggerId = const workerDebuggerId =
(await childSession.protocol.Debugger.enable()).result.debuggerId; (await childSession.protocol.Debugger.enable()).result.debuggerId;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment