Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector-protocol / debugger / debugger-pause-in-tight-loop.html
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script>
5
6 function testFunction()
7 {
8     setTimeout(hotFunction, 0);
9 }
10
11 var terminated = false;
12 function hotFunction() {
13   evaluateInFrontend("InspectorTest.didFireTimer()");
14
15   var message_id = 1;
16   var ts = Date.now();
17   while (!terminated) {
18       // Without this try/catch v8 will optimize the function and break will not work.
19       try {
20           if (Date.now() - ts > 1000) {
21               ts = Date.now();
22               console.error("Message #" + message_id++);
23           }
24       } catch (e) {
25       }
26   }
27 }
28
29 function test()
30 {
31     InspectorTest.sendCommand("Inspector.enable", {});
32     InspectorTest.sendCommand("Debugger.enable", {}, didEnableDebugger);
33     function didEnableDebugger()
34     {
35         // Start tight loop in page.
36         InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunction()" }, didEval);
37         function didEval()
38         {
39             InspectorTest.log("didEval");
40         }
41     }
42
43     InspectorTest.didFireTimer = function()
44     {
45         InspectorTest.log("didFireTimer");
46         InspectorTest.sendCommand("Debugger.pause", { });
47     }
48
49     InspectorTest.eventHandler["Debugger.paused"] = function(messageObject)
50     {
51         var message = messageObject["params"]["message"];
52         InspectorTest.log("SUCCESS: Paused");
53         InspectorTest.sendCommand("Runtime.evaluate", { "expression": "terminated = true;" });
54         InspectorTest.sendCommand("Debugger.resume", { });
55         InspectorTest.completeTest();
56     }
57 }
58 </script>
59 </head>
60 <body onLoad="runTest();">
61 </body>
62 </html>