Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / sources / debugger / script-formatter-breakpoints.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 <script src="resources/unformatted.js"></script>
6
7 <script>
8
9 function f1()
10 {
11     var a=0;var b=1;var c=3;var d=4;var e=5;
12     var f=0;
13     return 0;
14 }
15
16 var test = function()
17 {
18     WebInspector.breakpointManager._storage._breakpoints = {};
19     var panel = WebInspector.panels.sources;
20     var sourceFrame;
21
22     InspectorTest.runDebuggerTestSuite([
23         function testBreakpointsInOriginalAndFormattedSource(next)
24         {
25             InspectorTest.showScriptSource("script-formatter-breakpoints.html", didShowScriptSource);
26
27             function didShowScriptSource(frame)
28             {
29                 sourceFrame = frame;
30                 InspectorTest.setBreakpoint(sourceFrame, 11, "", true);
31                 InspectorTest.waitUntilPaused(pausedInF1);
32                 InspectorTest.evaluateInPageWithTimeout("f1()");
33             }
34
35             function pausedInF1(callFrames)
36             {
37                 InspectorTest.dumpBreakpointSidebarPane("while paused in raw");
38                 InspectorTest.resumeExecution(resumed);
39             }
40
41             function resumed()
42             {
43                 sourceFrame._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, didFormatPage, this);
44                 sourceFrame._uiSourceCode.setFormatted(true);
45             }
46
47             function didFormatPage()
48             {
49                 sourceFrame._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.FormattedChanged, didFormatPage, this);
50                 // There should be a breakpoint in f1 although script is pretty-printed.
51                 InspectorTest.waitUntilPaused(pausedInF1Again);
52                 InspectorTest.evaluateInPageWithTimeout("f1()");
53             }
54
55             function pausedInF1Again(callFrames)
56             {
57                 InspectorTest.dumpBreakpointSidebarPane("while paused in pretty printed");
58                 sourceFrame._uiSourceCode.setFormatted(false);
59                 InspectorTest.dumpBreakpointSidebarPane("while paused in raw");
60                 InspectorTest.removeBreakpoint(sourceFrame, 11);
61                 InspectorTest.resumeExecution(next);
62             }
63         },
64
65         function testBreakpointSetInOriginalAndRemovedInFormatted(next)
66         {
67             InspectorTest.showScriptSource("script-formatter-breakpoints.html", didShowScriptSource);
68
69             function didShowScriptSource(frame)
70             {
71                 sourceFrame = frame;
72                 InspectorTest.addResult("Adding breakpoint.");
73                 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved);
74                 InspectorTest.setBreakpoint(sourceFrame, 11, "", true);
75             }
76
77             function breakpointResolved()
78             {
79                 InspectorTest.addSniffer(WebInspector.UISourceCode.prototype, "updateLiveLocations", didFormatPage);
80                 InspectorTest.addResult("Formatting.");
81                 sourceFrame._uiSourceCode.setFormatted(true);
82             }
83
84             function didFormatPage()
85             {
86                 InspectorTest.addResult("Removing breakpoint.");
87                 InspectorTest.removeBreakpoint(sourceFrame, 16);
88                 InspectorTest.addResult("Unformatting.");
89                 sourceFrame._uiSourceCode.setFormatted(false);
90                 var breakpoints = WebInspector.breakpointManager._storage._setting.get();
91                 InspectorTest.assertEquals(breakpoints.length, 0, "There should not be any breakpoints in the storage.");
92                 next();
93             }
94         },
95
96         function testBreakpointsSetAndRemoveInFormattedSource(next)
97         {
98             InspectorTest.showScriptSource("unformatted.js", didShowScriptSource);
99
100             function didShowScriptSource(frame)
101             {
102                 sourceFrame = frame;
103                 sourceFrame._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, didFormatPage, this);
104                 sourceFrame._uiSourceCode.setFormatted(true);
105             }
106                 
107             function didFormatPage()
108             {
109                 sourceFrame._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.FormattedChanged, didFormatPage, this);
110                 InspectorTest.setBreakpoint(sourceFrame, 3, "", true);
111                 InspectorTest.waitUntilPaused(pausedInF2);
112                 InspectorTest.evaluateInPageWithTimeout("f2()");
113             }
114
115             function pausedInF2(callFrames)
116             {
117                 InspectorTest.dumpBreakpointSidebarPane("while paused in pretty printed");
118                 InspectorTest.removeBreakpoint(sourceFrame, 3);
119                 sourceFrame._uiSourceCode.setFormatted(false);
120                 InspectorTest.dumpBreakpointSidebarPane("while paused in raw");
121                 InspectorTest.resumeExecution(next);
122             }
123         },
124
125         function testBreakpointsSetInFormattedAndRemoveInOriginalSource(next)
126         {
127             InspectorTest.showScriptSource("unformatted.js", didShowScriptSource);
128
129             function didShowScriptSource(frame)
130             {
131                 sourceFrame = frame;
132                 sourceFrame._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, didFormatPage, this);
133                 sourceFrame._uiSourceCode.setFormatted(true);
134             }
135                 
136             function didFormatPage()
137             {
138                 sourceFrame._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.FormattedChanged, didFormatPage, this);
139                 InspectorTest.setBreakpoint(sourceFrame, 3, "", true);
140                 InspectorTest.waitUntilPaused(pausedInF2);
141                 InspectorTest.evaluateInPageWithTimeout("f2()");
142             }
143
144             function pausedInF2(callFrames)
145             {
146                 InspectorTest.dumpBreakpointSidebarPane("while paused in pretty printed");
147                 sourceFrame._uiSourceCode.setFormatted(false);
148                 InspectorTest.dumpBreakpointSidebarPane("while paused in raw");
149                 InspectorTest.removeBreakpoint(sourceFrame, 2);
150                 InspectorTest.dumpBreakpointSidebarPane("after removed");
151                 InspectorTest.resumeExecution(next);
152             }
153         }
154     ]);
155 }
156
157 </script>
158
159 </head>
160
161 <body onload="runTest()">
162 <p>Tests the script formatting is working fine with breakpoints.
163 </p>
164
165 </body>
166 </html>