Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector-protocol / debugger / debugger-pause-dedicated-worker-loop.html
blobe0d98882200a559b968ae4d39eea6f70aa73f88a
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script>
6 var worker;
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");
16 runTest();
19 function test()
21 var workerId;
22 var workerRequestId = 1;
23 function sendCommandToWorker(method, params)
25 InspectorTest.sendCommand("Worker.sendMessageToWorker",
27 "workerId": workerId,
28 "message": JSON.stringify({ "method": method,
29 "params": params,
30 "id": workerRequestId })
31 });
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"];
79 if (value === true)
80 InspectorTest.log("SUCCESS: evaluated, result: " + value);
81 else
82 InspectorTest.log("FAIL: evaluated, result: " + value);
83 InspectorTest.completeTest();
87 </script>
88 </head>
89 <body onLoad="startWorkerAndRunTest();">
90 </body>
91 </html>