LayoutTest inspector/worker/debugger-pause.html sometimes times out
[WebKit-https.git] / LayoutTests / inspector / worker / debugger-pause.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script src="../debugger/resources/log-pause-location.js"></script>
6 <script src="resources/worker-utilities.js"></script>
7 <script>
8 TestPage.allowUncaughtExceptions = true;
9 TestPage.needToSanitizeUncaughtExceptionURLs = true;
10
11 let worker = new Worker("resources/worker-debugger-pause.js");
12
13 function test()
14 {
15     let workerTarget = Array.from(WI.targets).find((target) => target.type === WI.Target.Type.Worker);
16     let workerDebuggerData = WI.debuggerManager.dataForTarget(workerTarget);
17     if (!workerTarget) {
18         InspectorTest.fail("Missing Worker Target");
19         InspectorTest.completeTest();
20         return;
21     }
22
23     // In each test, the Worker pauses and the Main Thread is waiting to
24     // pause on the next statement. Do an InspectorTest.log, which evaluates
25     // JavaScript in the page and should pause. Then later run work.
26     // In WebKit1, because the VM is shared between the inspector and
27     // inspected page we need to put an artificial break between our
28     // Inspector JavaScript, the Page JavaScript, and back to the Inspector.
29     function pauseTheMainThread() {
30         return new Promise((resolve, reject) => {
31             setTimeout(() => {
32                 InspectorTest.log("");
33                 setTimeout(resolve);
34             });
35         });
36     }
37
38     WI.debuggerManager.allUncaughtExceptionsBreakpoint.disabled = false;
39     WI.debuggerManager.assertionsBreakpoint.disabled = false;
40
41
42     let suite = InspectorTest.createAsyncSuite("Worker.Debugger.Pause");
43
44     suite.addTestCase({
45         name: "Worker.Debugger.Pause.DebuggerStatement",
46         description: "Worker should pause on debugger statement.",
47         test(resolve, reject) {
48             InspectorTest.evaluateInPage(`worker.postMessage("triggerDebuggerStatement")`);
49             WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
50                 pauseTheMainThread().then(() => {
51                     InspectorTest.pass("Paused");
52                     InspectorTest.expectEqual(WI.debuggerManager.activeCallFrame.target, workerTarget, "Should be paused in a Worker CallFrame.");
53                     InspectorTest.expectEqual(workerDebuggerData.pauseReason, WI.DebuggerManager.PauseReason.DebuggerStatement, "Pause reason should be a debugger statement.");
54                     logPauseLocation();
55                     WI.debuggerManager.resume().then(resolve, reject);
56                 });
57             });
58         }
59     });
60
61     suite.addTestCase({
62         name: "Worker.Debugger.Pause.Breakpoint",
63         description: "Worker should pause on breakpoint.",
64         test(resolve, reject) {
65             let location = workerTarget.mainResource.createSourceCodeLocation(8, 0);
66             let breakpoint = new WI.Breakpoint(location);
67             WI.debuggerManager.addBreakpoint(breakpoint);
68             InspectorTest.evaluateInPage(`worker.postMessage("triggerBreakpoint")`);
69             WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
70                 pauseTheMainThread().then(() => {
71                     InspectorTest.pass("Paused");
72                     InspectorTest.expectEqual(WI.debuggerManager.activeCallFrame.target, workerTarget, "Should be paused in a Worker CallFrame.");
73                     InspectorTest.expectEqual(workerDebuggerData.pauseReason, WI.DebuggerManager.PauseReason.Breakpoint, "Pause reason should be a breakpoint.");
74                     logPauseLocation();
75                     WI.debuggerManager.resume().then(resolve, reject);
76                 });
77             });
78         }
79     });
80
81     suite.addTestCase({
82         name: "Worker.Debugger.Pause.Exception",
83         description: "Worker should pause on exception.",
84         test(resolve, reject) {
85             InspectorTest.evaluateInPage(`worker.postMessage("triggerException")`);
86             WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
87                 pauseTheMainThread().then(() => {
88                     InspectorTest.pass("Paused");
89                     InspectorTest.expectEqual(WI.debuggerManager.activeCallFrame.target, workerTarget, "Should be paused in a Worker CallFrame.");
90                     InspectorTest.expectEqual(workerDebuggerData.pauseReason, WI.DebuggerManager.PauseReason.Exception, "Pause reason should be an exception.");
91                     logPauseLocation();
92                     WI.debuggerManager.resume().then(resolve, reject);
93                 });
94             });
95         }
96     });
97
98     suite.addTestCase({
99         name: "Worker.Debugger.Pause.Assert",
100         description: "Worker should pause on assert.",
101         test(resolve, reject) {
102             InspectorTest.evaluateInPage(`worker.postMessage("triggerAssertion")`);
103             WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
104                 pauseTheMainThread().then(() => {
105                     InspectorTest.pass("Paused");
106                     InspectorTest.expectEqual(WI.debuggerManager.activeCallFrame.target, workerTarget, "Should be paused in a Worker CallFrame.");
107                     InspectorTest.expectEqual(workerDebuggerData.pauseReason, WI.DebuggerManager.PauseReason.Assertion, "Pause reason should be an exception.");
108                     logPauseLocation();
109                     WI.debuggerManager.resume().then(resolve, reject);
110                 });
111             });
112         }
113     });
114
115     awaitTargetMainResource(workerTarget).then(() => {
116         window.loadLinesFromSourceCode(workerTarget.mainResource).then(() => {
117             suite.runTestCasesAndFinish();
118         });
119     });
120 }
121 </script>
122 </head>
123 <body onload="runTest()">
124 <p>Ensure we can pause in Workers.</p>
125 </body>
126 </html>