Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / sources / debugger / set-conditional-breakpoint.html
1 <html>
2 <head>
3 <script src="../../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../../http/tests/inspector/debugger-test.js"></script>
5
6 <script>
7 function oneLineTestFunction() { return 0; }
8 </script>
9
10 <script>
11 function oneLineTestFunction2() { return 0; }</script>
12
13 <script>
14
15 function testFunction()
16 {
17     var x = Math.sqrt(10);
18     console.log("Done.");
19     return x;
20 }
21
22 var test = function()
23 {
24     var currentSourceFrame;
25     InspectorTest.setQuiet(true);
26     InspectorTest.runDebuggerTestSuite([
27         function testSetConditionalBreakpointThatBreaks(next)
28         {
29             InspectorTest.showScriptSource("set-conditional-breakpoint.html", didShowScriptSource);
30
31             function didShowScriptSource(sourceFrame)
32             {
33                 currentSourceFrame = sourceFrame;
34                 InspectorTest.addResult("Script source was shown.");
35                 setBreakpointAndWaitUntilPaused(currentSourceFrame, 16, "true", didPause);
36                 InspectorTest.runTestFunction();
37             }
38
39             function didPause(callFrames)
40             {
41                 InspectorTest.addResult("Script execution paused.");
42                 InspectorTest.captureStackTrace(callFrames);
43                 InspectorTest.dumpBreakpointSidebarPane();
44                 InspectorTest.addSniffer(currentSourceFrame, "_removeBreakpointDecoration", breakpointRemoved);
45                 InspectorTest.removeBreakpoint(currentSourceFrame, 16);
46             }
47
48             function breakpointRemoved()
49             {
50                 InspectorTest.resumeExecution(didResume);
51             }
52
53             function didResume()
54             {
55                 InspectorTest.dumpBreakpointSidebarPane()
56                 InspectorTest.addResult("Script execution resumed.");
57                 next();
58             }
59         },
60
61         function testSetConditionalBreakpointThatDoesNotBreak(next)
62         {
63             InspectorTest.showScriptSource("set-conditional-breakpoint.html", didShowScriptSource);
64
65             function didShowScriptSource(sourceFrame)
66             {
67                 currentSourceFrame = sourceFrame;
68                 InspectorTest.addResult("Script source was shown.");
69                 setBreakpoint(currentSourceFrame, 16, "false");
70                 InspectorTest.runTestFunction();
71                 InspectorTest.addConsoleSniffer(testFunctionFinished);
72                 
73             }
74
75             function testFunctionFinished(callFrames)
76             {
77                 InspectorTest.addResult("Test function finished.");
78                 InspectorTest.dumpBreakpointSidebarPane();
79                 InspectorTest.addSniffer(currentSourceFrame, "_removeBreakpointDecoration", breakpointRemoved);
80                 InspectorTest.removeBreakpoint(currentSourceFrame, 16);
81             }
82
83             function breakpointRemoved()
84             {
85                 InspectorTest.addResult("Breakpoints removed.");
86                 InspectorTest.dumpBreakpointSidebarPane();
87                 next();
88             }
89         },
90     ]);
91
92     function setBreakpoint(sourceFrame, lineNumber, condition, callback)
93     {
94         var expectedBreakpointId;
95         InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", didSetBreakpointInDebugger);
96         InspectorTest.setBreakpoint(sourceFrame, lineNumber, condition, true);
97
98         function didSetBreakpointInDebugger(breakpointManagerCallback, breakpointId)
99         {
100             if (callback)
101                 callback(breakpointId);
102         }
103     }
104
105     function setBreakpointAndWaitUntilPaused(sourceFrame, lineNumber, condition, pausedCallback)
106     {
107         setBreakpoint(sourceFrame, lineNumber, condition, didSetBreakpointInDebugger);
108         var expectedBreakpointId;
109
110         function didSetBreakpointInDebugger(breakpointId)
111         {
112             expectedBreakpointId = breakpointId;
113             InspectorTest.waitUntilPaused(didPause);
114         }
115
116         function didPause(callFrames, reason, breakpointIds)
117         {
118             InspectorTest.assertEquals(breakpointIds.length, 1);
119             InspectorTest.assertEquals(breakpointIds[0], expectedBreakpointId);
120             InspectorTest.assertEquals(reason, "other");
121
122             pausedCallback(callFrames);
123         }
124     }
125 }
126
127 </script>
128 </head>
129
130 <body onload="runTest()">
131 <p>
132 Tests setting breakpoints.
133 </p>
134
135 </body>
136 </html>