3 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
7 function startWorkerAndRunTest()
9 worker
= new Worker("resources/dedicated-worker-loop.js");
10 worker
.onmessage = function(event
)
12 if (event
.data
=== "WorkerMessageReceived")
13 evaluateInFrontend("InspectorTest.workerMessageReceived()");
15 log("Started worker");
22 var workerRequestId
= 1;
23 function sendCommandToWorker(method
, params
)
25 InspectorTest
.sendCommand("Worker.sendMessageToWorker",
28 "message": JSON
.stringify({ "method": method
,
30 "id": workerRequestId
})
32 return workerRequestId
++;
35 function didEnableWorkerDebugging(messageObject
)
37 if ("error" in messageObject
) {
38 InspectorTest
.log("FAIL: Couldn't enable worker debugger: " + messageObject
.error
.message
);
39 InspectorTest
.completeTest();
42 InspectorTest
.sendCommand("Worker.enable", {}, didEnableWorkerDebugging
);
44 var evaluateRequestId
= -1;
45 var debuggerEnableRequestId
= -1;
46 InspectorTest
.eventHandler
["Worker.workerCreated"] = function(messageObject
)
48 workerId
= messageObject
["params"]["workerId"];
49 InspectorTest
.log("Worker created");
50 InspectorTest
.sendCommand("Worker.connectToWorker", { "workerId": workerId
}, didConnectToWorker
);
52 function didConnectToWorker(messageObject
)
54 InspectorTest
.log("didConnectToWorker");
55 // Enable debugger so that V8 can interrupt and handle inspector commands while there is a script running in a tight loop.
56 debuggerEnableRequestId
= sendCommandToWorker("Debugger.enable", {});
60 InspectorTest
.workerMessageReceived = function()
62 evaluateRequestId
= sendCommandToWorker("Runtime.evaluate", { "expression": "message_id > 1"});
65 InspectorTest
.eventHandler
["Worker.dispatchMessageFromWorker"] = function(messageObject
)
67 var message
= JSON
.parse(messageObject
["params"]["message"]);
68 if (message
["id"] === debuggerEnableRequestId
) {
69 InspectorTest
.log("Did enable debugger");
70 // Start tight loop in the worker.
71 InspectorTest
.sendCommand("Runtime.evaluate", { "expression": "worker.postMessage(1)" }, didPostMessageToWorker
);
72 function didPostMessageToWorker()
74 InspectorTest
.log("Did post message to worker");
77 if (message
["id"] === evaluateRequestId
) {
78 var value
= message
["result"]["result"]["value"];
80 InspectorTest
.log("SUCCESS: evaluated, result: " + value
);
82 InspectorTest
.log("FAIL: evaluated, result: " + value
);
83 InspectorTest
.completeTest();
89 <body onLoad=
"startWorkerAndRunTest();">