Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / sources / debugger / source-url-comment.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>
6 function keepAliveInInlineScript() { }
7
8 //# sourceURL=inlineScriptURL.js
9 </script>
10 <script>
11 function doEval()
12 {
13     eval("function keepAlive() {}\n//# sourceURL=evalURL.js");
14 }
15
16 function doDeprecatedEval()
17 {
18     eval("function keepAlive() {}\n//@ sourceURL=deprecatedEvalURL.js");
19 }
20
21 function doEvalWithNonRelativeURL()
22 {
23     eval("function relativeURLScript() {}\n//# sourceURL=/js/nonRelativeURL.js");
24 }
25
26 function doDynamicScript()
27 {
28     var scriptElement = document.createElement("script");
29     scriptElement.textContent = "function keepAliveInDynamicScript() {}\n//# sourceURL=dynamicScriptURL.js";
30     document.body.appendChild(scriptElement);
31 }
32
33 function doURLAndMappingURL()
34 {
35     eval("function keepAlive() {}\n//# sourceMappingURL=sourceMappingURL.map\n//# sourceURL=sourceURL.js");
36 }
37
38 function addScriptWithURL()
39 {
40     var script = document.createElement("script");
41     script.src = "resources/script-with-url.js";
42     document.head.appendChild(script);
43 }
44
45 function addScriptWithPoorURL()
46 {
47     var script = document.createElement("script");
48     script.src = "resources/script-with-poor-url.js";
49     document.head.appendChild(script);
50 }
51
52 function test()
53
54 {
55     function forEachScriptMatchingURL(url, handler)
56     {
57         var scripts = WebInspector.debuggerModel._scripts;
58         for (var id in scripts) {
59             if (scripts[id].sourceURL.indexOf(url) !== -1)
60                 handler(scripts[id]);
61         }
62     }
63
64     InspectorTest.runDebuggerTestSuite([
65         function testSourceURLCommentInInlineScript(next)
66         {
67             InspectorTest.showScriptSource("source-url-comment.html", didShowScriptSource);
68
69             function didShowScriptSource(sourceFrame)
70             {
71                 var panel = WebInspector.inspectorView.panel("sources");
72                 var uiSourceCodes = panel._workspace.uiSourceCodes();
73                 var ignored = true;
74                 for (var i = 0; i < uiSourceCodes.length && ignored; ++i) {
75                     if (uiSourceCodes[i].originURL().indexOf("inlineScriptURL.js") !== -1)
76                         ignored = false;
77                 }
78                 if (ignored)
79                     InspectorTest.addResult("FAILED: sourceURL comment in inline script was ignored");
80                 next();
81             }
82         },
83
84         function testSourceURLCommentInScript(next)
85         {
86             InspectorTest.showScriptSource("scriptWithSourceURL.js", didShowScriptSource);
87             InspectorTest.evaluateInPage("setTimeout(addScriptWithURL, 0)");
88
89             function didShowScriptSource(sourceFrame)
90             {
91                 InspectorTest.addResult(sourceFrame.textEditor.text().trim());
92                 forEachScriptMatchingURL("scriptWithSourceURL.js", checkScriptSourceURL);
93                 next();
94             }
95         },
96
97         function testPoorSourceURLCommentInScript(next)
98         {
99             InspectorTest.showScriptSource("source-url-comment.html", didShowScriptSource);
100             InspectorTest.evaluateInPage("setTimeout(addScriptWithPoorURL, 0)");
101
102             function didShowScriptSource(sourceFrame)
103             {
104                 var panel = WebInspector.inspectorView.panel("sources");
105                 var uiSourceCodes = panel._workspace.uiSourceCodes();
106                 for (var i = 0; i < uiSourceCodes.length; ++i) {
107                     if (uiSourceCodes[i].originURL().indexOf("scriptWithPoorSourceURL.js") !== -1)
108                         InspectorTest.addResult("FAILED: poor sourceURL comment in script was used as a script name");
109                 }
110                 next();
111             }
112         },
113
114         function testSourceURLComment(next)
115         {
116             InspectorTest.showScriptSource("evalURL.js", didShowScriptSource);
117             InspectorTest.evaluateInPage("setTimeout(doEval, 0)");
118
119             function didShowScriptSource(sourceFrame)
120             {
121                 InspectorTest.addResult(sourceFrame.textEditor.text());
122                 forEachScriptMatchingURL("evalURL.js", checkScriptSourceURL);
123                 next();
124             }
125         },
126
127         function testDeprecatedSourceURLComment(next)
128         {
129             InspectorTest.showScriptSource("deprecatedEvalURL.js", didShowScriptSource);
130             InspectorTest.evaluateInPage("setTimeout(doDeprecatedEval, 0)");
131
132             function didShowScriptSource(sourceFrame)
133             {
134                 InspectorTest.addResult(sourceFrame.textEditor.text());
135                 forEachScriptMatchingURL("deprecatedEvalURL.js", checkScriptSourceURL);
136                 next();
137             }
138         },
139
140         function testSourceURLAndMappingURLComment(next)
141         {
142             InspectorTest.showScriptSource("sourceURL.js", didShowScriptSource);
143             InspectorTest.evaluateInPage("setTimeout(doURLAndMappingURL, 0)");
144
145             function didShowScriptSource(sourceFrame)
146             {
147                 function checkScriptSourceURLAndMappingURL(script)
148                 {
149                     InspectorTest.addResult("hasSourceURL: " + script.hasSourceURL);
150                     InspectorTest.addResult("sourceMapURL: " + script.sourceMapURL);
151                 }
152
153                 InspectorTest.addResult(sourceFrame.textEditor.text());
154                 forEachScriptMatchingURL("sourceURL.js", checkScriptSourceURLAndMappingURL);
155                 next();
156             }
157         },
158
159         function testSourceURLCommentInDynamicScript(next)
160         {
161             InspectorTest.showScriptSource("dynamicScriptURL.js", didShowScriptSource);
162             InspectorTest.evaluateInPage("setTimeout(doDynamicScript, 0)");
163
164             function didShowScriptSource(sourceFrame)
165             {
166                 InspectorTest.addResult(sourceFrame.textEditor.text());
167                 forEachScriptMatchingURL("dynamicScriptURL.js", checkScriptSourceURL);
168                 next();
169             }
170         },
171
172         function testNonRelativeURL(next)
173         {
174             InspectorTest.showScriptSource("/js/nonRelativeURL.js", didShowScriptSource);
175             InspectorTest.evaluateInPage("setTimeout(doEvalWithNonRelativeURL, 0)");
176
177             function didShowScriptSource(sourceFrame)
178             {
179                 InspectorTest.addResult(sourceFrame.textEditor.text());
180                 forEachScriptMatchingURL("nonRelativeURL.js", checkScriptSourceURL);
181                 next();
182             }
183         }
184     ]);
185
186     function checkScriptSourceURL(script)
187     {
188         InspectorTest.addResult("hasSourceURL: " + script.hasSourceURL);
189     }    
190 };
191
192 </script>
193
194 </head>
195
196 <body onload="runTest()">
197 <p>Tests that evals with sourceURL comment are shown in scripts panel.</p>
198 </body>
199 </html>