Web Inspector: Remove recompileAllJSFunctions timer in ScriptDebugServer
[WebKit-https.git] / LayoutTests / inspector-protocol / debugger / setPauseOnExceptions-all.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
4 <script src="resources/exception.js"></script>
5 <script>
6 function test()
7 {
8     var expectPause = true;
9
10     var statementsWithoutExceptions = [
11         "1+1;",
12         "noException();",
13         "catchNested(noException, 7);"
14     ];
15
16     var currentCaughtExceptionStatement = 0;
17     var statementsWithCaughtExceptions = [
18         "try{ ({}).a.b.c.d } catch (e) { console.log('caught inline: ' + JSON.stringify(e)); }",
19         "catchNested(exceptionBasic, 1);",
20         "catchNested(exceptionDOM, 2);",
21         "catchNested(exceptionInHostFunction, 3);",
22         "catchNested(throwString, 10);",
23         "catchNested(throwParam, 5, new Error('error message'));"
24     ];
25
26     var currentUncaughtExceptionStatement = 0;
27     var statementsWithUncaughtExceptions = [
28         "({}).a.b.c.d;",
29         "exceptionBasic();",
30         "exceptionDOM();",
31         "exceptionInHostFunction();",
32         "throwString();",
33         "throwParam({x:1});",
34         "throwParam(new Error('error message'));"
35     ];
36
37     // FIXME: <https://webkit.org/b/121108> Web Inspector gets paused twice when there is an exception in host function
38     var extraCaughtExceptionPauses = 1;
39     var extraUncaughtExceptionPauses = 1;
40
41     function evaluateStatements(list, callback)
42     {
43         for (var i = 0; i < list.length; ++i) {
44             var statement = list[i];
45             var last = i === list.length - 1;
46             var responseCallback = last ? function() { setTimeout(callback, 10); } : function(){};
47             InspectorTest.sendCommand("Runtime.evaluate", {expression: "setTimeout(function() { " + statement + " }, 0);"}, responseCallback);
48         }
49     }
50
51     function evaluateExpectedNoPauses(callback)
52     {
53         var statements = statementsWithoutExceptions;
54         evaluateStatements(statements, function() {
55             InspectorTest.log("PASS - did not pause on non-exception statements");
56             callback();
57         });
58     }
59
60
61     var triggerNext = triggerNextCaughtException;
62
63     function triggerNextCaughtException()
64     {
65         // Evaluate statement and expect to pause.
66         if (currentCaughtExceptionStatement < statementsWithCaughtExceptions.length) {
67             var statement = statementsWithCaughtExceptions[currentCaughtExceptionStatement++];
68             InspectorTest.sendCommand("Runtime.evaluate", {expression: "setTimeout(function() { " + statement + " }, 0);"});
69             return;
70         }
71
72         // FIXME: <https://webkit.org/b/121108> Web Inspector gets paused twice when there is an exception in host function
73         if (extraCaughtExceptionPauses-- > 0)
74             return;
75
76         // Done evaluating caught exceptions statements. Move on to uncaught exceptions.
77         InspectorTest.log("PASS - paused for each caught exception");
78         triggerNext = triggerNextUncaughtException;
79         triggerNext();
80     }
81
82     function triggerNextUncaughtException()
83     {
84         // Evaluate statement and expect to pause.
85         if (currentUncaughtExceptionStatement < statementsWithUncaughtExceptions.length) {
86             var statement = statementsWithUncaughtExceptions[currentUncaughtExceptionStatement++];
87             InspectorTest.sendCommand("Runtime.evaluate", {expression: "setTimeout(function() { " + statement + " }, 0);"});
88             return;
89         }
90
91         // FIXME: <https://webkit.org/b/121108> Web Inspector gets paused twice when there is an exception in host function
92         if (extraUncaughtExceptionPauses-- > 0)
93             return;
94
95         // Done evaluating statements to pause. Evaluate some more we do not expect to pause.
96         InspectorTest.log("PASS - paused for each uncaught exception");
97         expectPause = false;
98         evaluateExpectedNoPauses(function() {
99             InspectorTest.completeTest();
100         });
101     }
102
103
104     InspectorTest.sendCommand("Debugger.enable", {});
105     InspectorTest.sendCommand("Debugger.setPauseOnExceptions", {state: "all"}, function(responseObject) {
106         InspectorTest.checkForError(responseObject);
107         InspectorTest.log("Debugger.setPauseOnExceptions - all");
108         evaluateExpectedNoPauses(function() {
109             expectPause = true;
110             triggerNext();
111         });
112     });
113
114     InspectorTest.eventHandler["Debugger.paused"] = function(messageObject)
115     {
116         InspectorTest.log("Paused!");
117
118         if (!expectPause) {
119             InspectorTest.log("FAIL - debugger paused when we did not expect to");
120             InspectorTest.completeTest();
121             return;
122         }
123
124         InspectorTest.sendCommand("Debugger.resume", {});
125     }
126
127     InspectorTest.eventHandler["Debugger.resumed"] = function(messageObject)
128     {
129         InspectorTest.log("Resumed");
130         triggerNext();
131     }
132 }
133 </script>
134 </head>
135 <body onload="runTest()">
136 <p>Debugger.setPauseOnExceptions all</p>
137 </body>
138 </html>