Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / debugger / live-edit.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="../../http/tests/inspector/live-edit-test.js"></script>
6 <script src="resources/edit-me.js"></script>
7 <script src="resources/edit-me-syntax-error.js"></script>
8 <script src="resources/edit-me-when-paused.js"></script>
9
10 <script>
11
12 function test()
13 {
14     var panel = WebInspector.showPanel("sources");
15
16     InspectorTest.runDebuggerTestSuite([
17         function testLiveEdit(next)
18         {
19             InspectorTest.showScriptSource("edit-me.js", didShowScriptSource);
20
21             function didShowScriptSource(sourceFrame)
22             {
23                 replaceInSource(sourceFrame, "return 0;", "return \"live-edited string\";", didEditScriptSource);
24             }
25
26             function didEditScriptSource()
27             {
28                 InspectorTest.evaluateInPage("f()", didEvaluateInPage)
29             }
30
31             function didEvaluateInPage(result)
32             {
33                 InspectorTest.assertEquals("live-edited string", result.description, "edited function returns wrong result");
34                 InspectorTest.dumpSourceFrameContents(panel.visibleView);
35                 next();
36             }
37         },
38
39         function testLiveEditSyntaxError(next)
40         {
41             InspectorTest.showScriptSource("edit-me-syntax-error.js", didShowScriptSource);
42
43             function didShowScriptSource(sourceFrame)
44             {
45                 InspectorTest.replaceInSource(sourceFrame, ",\"I'm good\"", "\"I'm good\"");
46                 InspectorTest.dumpSourceFrameContents(panel.visibleView);
47                 next();
48             }
49         },
50
51         function testLiveEditWhenPaused(next)
52         {
53             InspectorTest.showScriptSource("edit-me-when-paused.js", didShowScriptSource);
54
55             function didShowScriptSource(sourceFrame)
56             {
57                 InspectorTest.waitUntilPaused(paused);
58                 InspectorTest.evaluateInPage("f1()", didEvaluateInPage);
59             }
60
61             function paused(callFrames)
62             {
63                 replaceInSource(panel.visibleView, "return 1;", "return 2;\n\n\n\n", didEditScriptSource);
64             }
65
66             function didEditScriptSource()
67             {
68                 InspectorTest.resumeExecution();
69             }
70
71             function didEvaluateInPage(result)
72             {
73                 InspectorTest.assertEquals("3", result.description, "edited function returns wrong result");
74                 next();
75             }
76         },
77
78         function testNoCrashWhenOnlyOneFunctionOnStack(next)
79         {
80             InspectorTest.showScriptSource("edit-me-when-paused.js", didShowScriptSource);
81
82             function didShowScriptSource(sourceFrame)
83             {
84                 InspectorTest.waitUntilPaused(paused);
85                 InspectorTest.evaluateInPage("setTimeout(f1, 0)");
86             }
87
88             function paused(callFrames)
89             {
90                 InspectorTest.captureStackTrace(callFrames);
91                 replaceInSource(panel.visibleView, "debugger;", "debugger;\n", didEditScriptSource);
92             }
93
94             function didEditScriptSource()
95             {
96                 InspectorTest.resumeExecution(InspectorTest.waitUntilPaused.bind(InspectorTest, InspectorTest.resumeExecution.bind(InspectorTest, next)));
97             }
98         },
99
100         function testBreakpointsUpdated(next)
101         {
102             InspectorTest.showScriptSource("edit-me.js", didShowScriptSource);
103
104             function didShowScriptSource(sourceFrame)
105             {
106                 InspectorTest.addSniffer(sourceFrame, "_addBreakpointDecoration", breakpointAdded);
107                 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
108             }
109
110             function breakpointAdded()
111             {
112                 replaceInSource(panel.visibleView, "function f()", "function newFunctionCreatedWithLiveEdit()\n{\n}\nfunction f()", didEditScriptSource);
113             }
114
115             function didEditScriptSource()
116             {
117                 var breakpoints = panel.visibleView._breakpoints;
118                 for (var lineNumber in breakpoints)
119                     InspectorTest.assertEquals("5", lineNumber);
120                 next();
121             }
122         }
123     ]);
124
125     function replaceInSource(sourceFrame, string, replacement, callback)
126     {
127         InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", callback);
128         InspectorTest.replaceInSource(sourceFrame, string, replacement);
129         InspectorTest.commitSource(sourceFrame);
130         
131     }
132 };
133
134 </script>
135
136 </head>
137
138 <body onload="runTest()">
139 <p>Tests live edit feature.</p>
140
141 </body>
142 </html>