OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto
r-protocol-test.js"></script> | 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto
r-protocol-test.js"></script> |
4 <script> | 4 <script> |
5 | 5 |
6 var worker; | 6 var worker; |
7 | |
8 function testFunction() | |
9 { | |
10 debugger; | |
11 } | |
12 | |
13 function startWorkerAndRunTest() | 7 function startWorkerAndRunTest() |
14 { | 8 { |
15 worker = new Worker("resources/dedicated-worker.js"); | 9 worker = new Worker("resources/dedicated-worker-loop.js"); |
16 worker.onmessage = function(event) { }; | 10 worker.onmessage = function(event) { }; |
17 worker.postMessage(1); | |
18 log("Started worker"); | 11 log("Started worker"); |
19 runTest(); | 12 runTest(); |
20 } | 13 } |
21 | 14 |
22 function test() | 15 function test() |
23 { | 16 { |
24 var workerId; | 17 var workerId; |
25 var workerRequestId = 1; | 18 var workerRequestId = 1; |
26 | |
27 function sendCommandToWorker(method, params) | 19 function sendCommandToWorker(method, params) |
28 { | 20 { |
29 InspectorTest.sendCommand("Worker.sendMessageToWorker", | 21 InspectorTest.sendCommand("Worker.sendMessageToWorker", |
30 { | 22 { |
31 "workerId": workerId, | 23 "workerId": workerId, |
32 "message": { "method": method, | 24 "message": { "method": method, |
33 "params": params, | 25 "params": params, |
34 "id": workerRequestId } | 26 "id": workerRequestId } |
35 }); | 27 }); |
36 return workerRequestId++; | 28 return workerRequestId++; |
37 } | 29 } |
38 | 30 |
39 InspectorTest.sendCommand("Debugger.enable", {}); | |
40 InspectorTest.eventHandler["Debugger.paused"] = handleDebuggerPausedInTestFu
nction; | |
41 InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunction(
)" }); | |
42 | |
43 function handleDebuggerPausedInTestFunction(messageObject) | |
44 { | |
45 InspectorTest.log("Paused on 'debugger;'"); | |
46 InspectorTest.sendCommand("Worker.enable", {}, didEnableWorkerDebugging)
; | |
47 | |
48 } | |
49 | |
50 function didEnableWorkerDebugging(messageObject) | 31 function didEnableWorkerDebugging(messageObject) |
51 { | 32 { |
52 if ("error" in messageObject) { | 33 if ("error" in messageObject) { |
53 InspectorTest.log("FAIL: Couldn't enable worker debugger: " + messag
eObject.error.message); | 34 InspectorTest.log("FAIL: Couldn't enable worker debugger: " + messag
eObject.error.message); |
54 InspectorTest.completeTest(); | 35 InspectorTest.completeTest(); |
55 } | 36 } |
56 } | 37 } |
| 38 InspectorTest.sendCommand("Worker.enable", {}, didEnableWorkerDebugging); |
57 | 39 |
58 var savedWorkerRequestId = -1; | 40 var evaluateRequestId = -1; |
| 41 var debuggerEnableRequestId = -1; |
59 InspectorTest.eventHandler["Worker.workerCreated"] = function(messageObject) | 42 InspectorTest.eventHandler["Worker.workerCreated"] = function(messageObject) |
60 { | 43 { |
61 workerId = messageObject["params"]["workerId"]; | 44 workerId = messageObject["params"]["workerId"]; |
62 InspectorTest.log("Worker created"); | 45 InspectorTest.log("Worker created"); |
63 InspectorTest.sendCommand("Worker.connectToWorker", { "workerId": worker
Id }, didConnectToWorker); | 46 InspectorTest.sendCommand("Worker.connectToWorker", { "workerId": worker
Id }, didConnectToWorker); |
64 | 47 |
65 function didConnectToWorker(messageObject) | 48 function didConnectToWorker(messageObject) |
66 { | 49 { |
67 InspectorTest.log("didConnectToWorker"); | 50 InspectorTest.log("didConnectToWorker"); |
68 savedWorkerRequestId = sendCommandToWorker("Runtime.evaluate", { "ex
pression": "1+1"}); | 51 // Enable debugger so that V8 can interrupt and handle inspector com
mands while there is a script running in a tight loop. |
| 52 debuggerEnableRequestId = sendCommandToWorker("Debugger.enable", {})
; |
69 } | 53 } |
70 } | 54 } |
71 | 55 |
72 InspectorTest.eventHandler["Worker.dispatchMessageFromWorker"] = function(me
ssageObject) | 56 InspectorTest.eventHandler["Worker.dispatchMessageFromWorker"] = function(me
ssageObject) |
73 { | 57 { |
74 var message = messageObject["params"]["message"]; | 58 var message = messageObject["params"]["message"]; |
75 if (message["id"] === savedWorkerRequestId) { | 59 if (message["id"] === debuggerEnableRequestId) { |
| 60 InspectorTest.log("Did enable debugger"); |
| 61 // Start tight loop in the worker. |
| 62 InspectorTest.sendCommand("Runtime.evaluate", { "expression": "worke
r.postMessage(1)" }, didPostMessageToWorker); |
| 63 function didPostMessageToWorker() |
| 64 { |
| 65 InspectorTest.log("Did post message to worker"); |
| 66 evaluateRequestId = sendCommandToWorker("Runtime.evaluate", { "e
xpression": "message_id > 1"}); |
| 67 } |
| 68 } |
| 69 if (message["id"] === evaluateRequestId) { |
76 var value = message["result"]["result"]["value"]; | 70 var value = message["result"]["result"]["value"]; |
77 InspectorTest.log("Successfully evaluated, result: " + value); | 71 if (value === true) |
| 72 InspectorTest.log("SUCCESS: evaluated, result: " + value); |
| 73 else |
| 74 InspectorTest.log("FAIL: evaluated, result: " + value); |
78 InspectorTest.completeTest(); | 75 InspectorTest.completeTest(); |
79 } | 76 } |
80 } | 77 } |
81 } | 78 } |
82 </script> | 79 </script> |
83 </head> | 80 </head> |
84 <body onLoad="startWorkerAndRunTest();"> | 81 <body onLoad="startWorkerAndRunTest();"> |
85 </body> | 82 </body> |
86 </html> | 83 </html> |
OLD | NEW |