sourcemap_header.js (1922B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 "use strict"; 6 7 (async () => { 8 SimpleTest.waitForExplicitFinish(); 9 10 const HTTP_BASE_URL = "http://mochi.test:8888/tests/dom/workers/test/"; 11 const IFRAME_URL = HTTP_BASE_URL + "sourcemap_header_iframe.html"; 12 const WORKER_URL = HTTP_BASE_URL + "sourcemap_header_worker.js"; 13 const DEBUGGER_URL = BASE_URL + "sourcemap_header_debugger.js"; 14 15 const workerFrame = document.getElementById("worker-frame"); 16 ok(workerFrame, "has frame"); 17 18 await new Promise(r => { 19 workerFrame.onload = r; 20 workerFrame.src = IFRAME_URL; 21 }); 22 23 info("Start worker and watch for registration"); 24 const workerLoadedChannel = new MessageChannel(); 25 26 const loadDebuggerAndWorker = Promise.all([ 27 waitForRegister(WORKER_URL, DEBUGGER_URL), 28 // We need to wait for the worker to load so a Debugger.Source will be 29 // guaranteed to exist. 30 new Promise(r => { 31 workerLoadedChannel.port1.onmessage = r; 32 }), 33 ]); 34 workerFrame.contentWindow.postMessage(WORKER_URL, "*", [ 35 workerLoadedChannel.port2, 36 ]); 37 const [dbg] = await loadDebuggerAndWorker; 38 39 // Wait for the debugger server to reply with the sourceMapURL of the 40 // loaded worker scripts. 41 info("Querying for the sourceMapURL of the worker script"); 42 const urls = await new Promise(res => { 43 dbg.addListener({ 44 onMessage(msg) { 45 const data = JSON.parse(msg); 46 if (data.type !== "response-sourceMapURL") { 47 return; 48 } 49 dbg.removeListener(this); 50 res(data.value); 51 }, 52 }); 53 dbg.postMessage( 54 JSON.stringify({ 55 type: "request-sourceMapURL", 56 url: WORKER_URL, 57 }) 58 ); 59 }); 60 61 ok(Array.isArray(urls) && urls.length === 1, "has a single source actor"); 62 is(urls[0], "worker-header.js.map", "has the right map URL"); 63 64 SimpleTest.finish(); 65 })();