Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / 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 test()
34
35 {
36     function forEachScriptMatchingURL(url, handler)
37     {
38         var scripts = WebInspector.debuggerModel.scripts;
39         for (var i = 0; i < scripts.length; ++i) {
40             if (scripts[i].sourceURL.indexOf(url) !== -1)
41                 handler(scripts[i]);
42         }
43     }
44
45     InspectorTest.runDebuggerTestSuite([
46         function testSourceURLCommentInInlineScript(next)
47         {
48             InspectorTest.showScriptSource("source-url-comment.html", didShowScriptSource);
49
50             function didShowScriptSource(sourceFrame)
51             {
52                 function checkScriptDoesNotHaveSourceURL(script)
53                 {
54                     InspectorTest.assertTrue(!script.hasSourceURL, "hasSourceURL flag is set for inline script");
55                 }
56
57                 var panel = WebInspector.panel("sources");
58                 var uiSourceCodes = panel._workspace.uiSourceCodes();
59                 for (var i = 0; i < uiSourceCodes.length; ++i)
60                     InspectorTest.assertTrue(uiSourceCodes[i].originURL().indexOf("inlineScriptURL.js") === -1, "sourceURL comment in inline script was used as a script name");
61                 forEachScriptMatchingURL("source-url-comment.html", checkScriptDoesNotHaveSourceURL)
62                 next();
63             }
64         },
65
66         function testSourceURLComment(next)
67         {
68             InspectorTest.showScriptSource("evalURL.js", didShowScriptSource);
69             InspectorTest.evaluateInPage("setTimeout(doEval, 0)");
70
71             function didShowScriptSource(sourceFrame)
72             {
73                 function checkScriptHasSourceURL(script)
74                 {
75                     InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for eval with sourceURL comment");
76                 }
77
78                 InspectorTest.addResult(sourceFrame.textEditor.text());
79                 forEachScriptMatchingURL("evalURL.js", checkScriptHasSourceURL);
80                 next();
81             }
82         },
83
84         function testDeprecatedSourceURLComment(next)
85         {
86             InspectorTest.showScriptSource("deprecatedEvalURL.js", didShowScriptSource);
87             InspectorTest.evaluateInPage("setTimeout(doDeprecatedEval, 0)");
88
89             function didShowScriptSource(sourceFrame)
90             {
91                 function checkScriptHasSourceURL(script)
92                 {
93                     InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for eval with sourceURL comment");
94                 }
95
96                 InspectorTest.addResult(sourceFrame.textEditor.text());
97                 forEachScriptMatchingURL("deprecatedEvalURL.js", checkScriptHasSourceURL);
98                 next();
99             }
100         },
101
102         function testSourceURLCommentInDynamicScript(next)
103         {
104             InspectorTest.showScriptSource("dynamicScriptURL.js", didShowScriptSource);
105             InspectorTest.evaluateInPage("setTimeout(doDynamicScript, 0)");
106
107             function didShowScriptSource(sourceFrame)
108             {
109                 function checkScriptHasSourceURL(script)
110                 {
111                     InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for dynamic script with sourceURL comment");
112                 }
113
114                 InspectorTest.addResult(sourceFrame.textEditor.text());
115                 forEachScriptMatchingURL("dynamicScriptURL.js", checkScriptHasSourceURL);
116                 next();
117             }
118         },
119
120         function testNonRelativeURL(next)
121         {
122             InspectorTest.showScriptSource("/js/nonRelativeURL.js", didShowScriptSource);
123             InspectorTest.evaluateInPage("setTimeout(doEvalWithNonRelativeURL, 0)");
124
125             function didShowScriptSource(sourceFrame)
126             {
127                 function checkScriptHasSourceURL(script)
128                 {
129                     InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for eval with a non-relative URL in a sourceURL comment");
130                 }
131
132                 InspectorTest.addResult(sourceFrame.textEditor.text());
133                 forEachScriptMatchingURL("nonRelativeURL.js", checkScriptHasSourceURL);
134                 next();
135             }
136         }
137     ]);
138 };
139
140 </script>
141
142 </head>
143
144 <body onload="runTest()">
145 <p>Tests that evals with sourceURL comment are shown in scripts panel.</p>
146 </body>
147 </html>