Upstream version 7.35.139.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                 for (var i = 0; i < uiSourceCodes.length; ++i) {
74                     if (uiSourceCodes[i].originURL().indexOf("inlineScriptURL.js") !== -1)
75                         InspectorTest.addResult("FAILED: sourceURL comment in inline script was used as a script name");
76                 }
77                 next();
78             }
79         },
80
81         function testSourceURLCommentInScript(next)
82         {
83             InspectorTest.showScriptSource("scriptWithSourceURL.js", didShowScriptSource);
84             InspectorTest.evaluateInPage("setTimeout(addScriptWithURL, 0)");
85
86             function didShowScriptSource(sourceFrame)
87             {
88                 InspectorTest.addResult(sourceFrame.textEditor.text().trim());
89                 forEachScriptMatchingURL("scriptWithSourceURL.js", checkScriptSourceURL);
90                 next();
91             }
92         },
93
94         function testPoorSourceURLCommentInScript(next)
95         {
96             InspectorTest.showScriptSource("source-url-comment.html", didShowScriptSource);
97             InspectorTest.evaluateInPage("setTimeout(addScriptWithPoorURL, 0)");
98
99             function didShowScriptSource(sourceFrame)
100             {
101                 var panel = WebInspector.inspectorView.panel("sources");
102                 var uiSourceCodes = panel._workspace.uiSourceCodes();
103                 for (var i = 0; i < uiSourceCodes.length; ++i) {
104                     if (uiSourceCodes[i].originURL().indexOf("scriptWithPoorSourceURL.js") !== -1)
105                         InspectorTest.addResult("FAILED: poor sourceURL comment in script was used as a script name");
106                 }
107                 next();
108             }
109         },
110
111         function testSourceURLComment(next)
112         {
113             InspectorTest.showScriptSource("evalURL.js", didShowScriptSource);
114             InspectorTest.evaluateInPage("setTimeout(doEval, 0)");
115
116             function didShowScriptSource(sourceFrame)
117             {
118                 InspectorTest.addResult(sourceFrame.textEditor.text());
119                 forEachScriptMatchingURL("evalURL.js", checkScriptSourceURL);
120                 next();
121             }
122         },
123
124         function testDeprecatedSourceURLComment(next)
125         {
126             InspectorTest.showScriptSource("deprecatedEvalURL.js", didShowScriptSource);
127             InspectorTest.evaluateInPage("setTimeout(doDeprecatedEval, 0)");
128
129             function didShowScriptSource(sourceFrame)
130             {
131                 InspectorTest.addResult(sourceFrame.textEditor.text());
132                 forEachScriptMatchingURL("deprecatedEvalURL.js", checkScriptSourceURL);
133                 next();
134             }
135         },
136
137         function testSourceURLAndMappingURLComment(next)
138         {
139             InspectorTest.showScriptSource("sourceURL.js", didShowScriptSource);
140             InspectorTest.evaluateInPage("setTimeout(doURLAndMappingURL, 0)");
141
142             function didShowScriptSource(sourceFrame)
143             {
144                 function checkScriptSourceURLAndMappingURL(script)
145                 {
146                     InspectorTest.addResult("hasSourceURL: " + script.hasSourceURL);
147                     InspectorTest.addResult("sourceMapURL: " + script.sourceMapURL);
148                 }
149
150                 InspectorTest.addResult(sourceFrame.textEditor.text());
151                 forEachScriptMatchingURL("sourceURL.js", checkScriptSourceURLAndMappingURL);
152                 next();
153             }
154         },
155
156         function testSourceURLCommentInDynamicScript(next)
157         {
158             InspectorTest.showScriptSource("dynamicScriptURL.js", didShowScriptSource);
159             InspectorTest.evaluateInPage("setTimeout(doDynamicScript, 0)");
160
161             function didShowScriptSource(sourceFrame)
162             {
163                 InspectorTest.addResult(sourceFrame.textEditor.text());
164                 forEachScriptMatchingURL("dynamicScriptURL.js", checkScriptSourceURL);
165                 next();
166             }
167         },
168
169         function testNonRelativeURL(next)
170         {
171             InspectorTest.showScriptSource("/js/nonRelativeURL.js", didShowScriptSource);
172             InspectorTest.evaluateInPage("setTimeout(doEvalWithNonRelativeURL, 0)");
173
174             function didShowScriptSource(sourceFrame)
175             {
176                 InspectorTest.addResult(sourceFrame.textEditor.text());
177                 forEachScriptMatchingURL("nonRelativeURL.js", checkScriptSourceURL);
178                 next();
179             }
180         }
181     ]);
182
183     function checkScriptSourceURL(script)
184     {
185         InspectorTest.addResult("hasSourceURL: " + script.hasSourceURL);
186     }    
187 };
188
189 </script>
190
191 </head>
192
193 <body onload="runTest()">
194 <p>Tests that evals with sourceURL comment are shown in scripts panel.</p>
195 </body>
196 </html>