3 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
8 function testFunction()
13 function startWorkerAndRunTest()
15 worker
= new Worker("resources/dedicated-worker.js");
16 worker
.onmessage = function(event
) { };
17 worker
.postMessage(1);
18 log("Started worker");
25 var workerRequestId
= 1;
27 function sendCommandToWorker(method
, params
)
29 InspectorTest
.sendCommand("Worker.sendMessageToWorker",
32 "message": JSON
.stringify({ "method": method
,
34 "id": workerRequestId
})
36 return workerRequestId
++;
39 InspectorTest
.sendCommand("Debugger.enable", {});
40 InspectorTest
.eventHandler
["Debugger.paused"] = handleDebuggerPausedInTestFunction
;
41 InspectorTest
.sendCommand("Runtime.evaluate", { "expression": "testFunction()" });
43 function handleDebuggerPausedInTestFunction(messageObject
)
45 InspectorTest
.log("Paused on 'debugger;'");
46 InspectorTest
.sendCommand("Worker.enable", {}, didEnableWorkerDebugging
);
50 function didEnableWorkerDebugging(messageObject
)
52 if ("error" in messageObject
) {
53 InspectorTest
.log("FAIL: Couldn't enable worker debugger: " + messageObject
.error
.message
);
54 InspectorTest
.completeTest();
58 var savedWorkerRequestId
= -1;
59 InspectorTest
.eventHandler
["Worker.workerCreated"] = function(messageObject
)
61 workerId
= messageObject
["params"]["workerId"];
62 InspectorTest
.log("Worker created");
63 InspectorTest
.sendCommand("Worker.connectToWorker", { "workerId": workerId
}, didConnectToWorker
);
65 function didConnectToWorker(messageObject
)
67 InspectorTest
.log("didConnectToWorker");
68 savedWorkerRequestId
= sendCommandToWorker("Runtime.evaluate", { "expression": "1+1"});
72 InspectorTest
.eventHandler
["Worker.dispatchMessageFromWorker"] = function(messageObject
)
74 var message
= JSON
.parse(messageObject
["params"]["message"]);
75 if (message
["id"] === savedWorkerRequestId
) {
76 var value
= message
["result"]["result"]["value"];
77 InspectorTest
.log("Successfully evaluated, result: " + value
);
78 InspectorTest
.completeTest();
84 <body onLoad=
"startWorkerAndRunTest();">