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