Web Inspector: Provide a way to distinguish scripts having sourceURL from standalone scripts.
https://bugs.webkit.org/show_bug.cgi?id=97231

Reviewed by Pavel Feldman.

Source/WebCore:

DebuggerAgent now scans scripts for sourceURL comment and provides
hasSourceURL flag for each non-inline script with such a comment.

* bindings/js/ScriptDebugServer.cpp:
(WebCore::ScriptDebugServer::dispatchDidParseSource):
* inspector/Inspector.json:
* inspector/InspectorDebuggerAgent.cpp:
(WebCore::InspectorDebuggerAgent::didParseSource):
* inspector/front-end/DebuggerModel.js:
(WebInspector.DebuggerModel.prototype._parsedScriptSource):
(WebInspector.DebuggerDispatcher.prototype.scriptParsed):
* inspector/front-end/Script.js:
(WebInspector.Script):

LayoutTests:

* inspector/debugger/source-url-comment-expected.txt:
* inspector/debugger/source-url-comment.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk/LayoutTests@130138 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/ChangeLog b/ChangeLog
index 9c48fac..29b249b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-09-20  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: Provide a way to distinguish scripts having sourceURL from standalone scripts.
+        https://bugs.webkit.org/show_bug.cgi?id=97231
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/debugger/source-url-comment-expected.txt:
+        * inspector/debugger/source-url-comment.html:
+
 2012-10-02  Philip Rogers  <pdr@google.com>
 
         Fix PerfTest standard deviation calculation.
diff --git a/inspector/debugger/source-url-comment-expected.txt b/inspector/debugger/source-url-comment-expected.txt
index 04bbc19..5ee9fb8 100644
--- a/inspector/debugger/source-url-comment-expected.txt
+++ b/inspector/debugger/source-url-comment-expected.txt
@@ -2,8 +2,14 @@
 
 Debugger was enabled.
 
+Running: testSourceURLCommentInInlineScript
+
 Running: testSourceURLComment
 function keepAlive() {}
 //@ sourceURL=evalURL.js
+
+Running: testSourceURLCommentInDynamicScript
+function keepAliveInDynamicScript() {}
+//@ sourceURL=dynamicScriptURL.js
 Debugger was disabled.
 
diff --git a/inspector/debugger/source-url-comment.html b/inspector/debugger/source-url-comment.html
index 1eb28a9..33257ac 100644
--- a/inspector/debugger/source-url-comment.html
+++ b/inspector/debugger/source-url-comment.html
@@ -2,17 +2,57 @@
 <head>
 <script src="../../http/tests/inspector/inspector-test.js"></script>
 <script src="../../http/tests/inspector/debugger-test.js"></script>
-
 <script>
+function keepAliveInInlineScript() { }
 
+//@ sourceURL=inlineScriptURL.js
+</script>
+<script>
 function doEval()
 {
     eval("function keepAlive() {}\n//@ sourceURL=evalURL.js");
 }
 
-function test()
+function doDynamicScript()
 {
+    var scriptElement = document.createElement("script");
+    scriptElement.textContent = "function keepAliveInDynamicScript() {}\n//@ sourceURL=dynamicScriptURL.js";
+    document.body.appendChild(scriptElement);
+}
+
+function test()
+
+{
+    function forEachScriptMatchingURL(url, handler)
+    {
+        var scripts = WebInspector.debuggerModel.scripts;
+        for (var i = 0; i < scripts.length; ++i) {
+            if (scripts[i].sourceURL.indexOf(url) !== -1)
+                handler(scripts[i]);
+        }
+    }
+
     InspectorTest.runDebuggerTestSuite([
+        function testSourceURLCommentInInlineScript(next)
+        {
+            InspectorTest.showScriptSource("source-url-comment.html", didShowScriptSource);
+
+            function didShowScriptSource(sourceFrame)
+            {
+                function checkScriptDoesNotHaveSourceURL(script)
+                {
+                    InspectorTest.assertTrue(!script.hasSourceURL, "hasSourceURL flag is set for inline script");
+                }
+
+                var panel = WebInspector.panel("scripts");
+                var uiSourceCodes = panel._workspace.uiSourceCodes();
+                for (var i = 0; i < uiSourceCodes.length; ++i)
+                    InspectorTest.assertTrue(uiSourceCodes[i].url.indexOf("inlineScriptURL.js") === -1, "sourceURL comment in inline script was used as a script name");
+                forEachScriptMatchingURL("source-url-comment.html", checkScriptDoesNotHaveSourceURL)
+                next();
+            }
+        },
+
         function testSourceURLComment(next)
         {
             InspectorTest.showScriptSource("evalURL.js", didShowScriptSource);
@@ -20,7 +60,31 @@
 
             function didShowScriptSource(sourceFrame)
             {
+                function checkScriptHasSourceURL(script)
+                {
+                    InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for eval with sourceURL comment");
+                }
+
                 InspectorTest.addResult(sourceFrame.textEditor.text());
+                forEachScriptMatchingURL("evalURL.js", checkScriptHasSourceURL);
+                next();
+            }
+        },
+
+        function testSourceURLCommentInDynamicScript(next)
+        {
+            InspectorTest.showScriptSource("dynamicScriptURL.js", didShowScriptSource);
+            InspectorTest.evaluateInPage("setTimeout(doDynamicScript, 0)");
+
+            function didShowScriptSource(sourceFrame)
+            {
+                function checkScriptHasSourceURL(script)
+                {
+                    InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for dynamic script with sourceURL comment");
+                }
+
+                InspectorTest.addResult(sourceFrame.textEditor.text());
+                forEachScriptMatchingURL("dynamicScriptURL.js", checkScriptHasSourceURL);
                 next();
             }
         }