Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / sources / debugger / source-url-comment.html
index 8bff06f..7ed8b12 100644 (file)
@@ -30,15 +30,34 @@ function doDynamicScript()
     document.body.appendChild(scriptElement);
 }
 
+function doURLAndMappingURL()
+{
+    eval("function keepAlive() {}\n//# sourceMappingURL=sourceMappingURL.map\n//# sourceURL=sourceURL.js");
+}
+
+function addScriptWithURL()
+{
+    var script = document.createElement("script");
+    script.src = "resources/script-with-url.js";
+    document.head.appendChild(script);
+}
+
+function addScriptWithPoorURL()
+{
+    var script = document.createElement("script");
+    script.src = "resources/script-with-poor-url.js";
+    document.head.appendChild(script);
+}
+
 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]);
+        var scripts = WebInspector.debuggerModel._scripts;
+        for (var id in scripts) {
+            if (scripts[id].sourceURL.indexOf(url) !== -1)
+                handler(scripts[id]);
         }
     }
 
@@ -49,16 +68,42 @@ function test()
 
             function didShowScriptSource(sourceFrame)
             {
-                function checkScriptDoesNotHaveSourceURL(script)
-                {
-                    InspectorTest.assertTrue(!script.hasSourceURL, "hasSourceURL flag is set for inline script");
+                var panel = WebInspector.inspectorView.panel("sources");
+                var uiSourceCodes = panel._workspace.uiSourceCodes();
+                for (var i = 0; i < uiSourceCodes.length; ++i) {
+                    if (uiSourceCodes[i].originURL().indexOf("inlineScriptURL.js") !== -1)
+                        InspectorTest.addResult("FAILED: sourceURL comment in inline script was used as a script name");
                 }
+                next();
+            }
+        },
+
+        function testSourceURLCommentInScript(next)
+        {
+            InspectorTest.showScriptSource("scriptWithSourceURL.js", didShowScriptSource);
+            InspectorTest.evaluateInPage("setTimeout(addScriptWithURL, 0)");
+
+            function didShowScriptSource(sourceFrame)
+            {
+                InspectorTest.addResult(sourceFrame.textEditor.text().trim());
+                forEachScriptMatchingURL("scriptWithSourceURL.js", checkScriptSourceURL);
+                next();
+            }
+        },
 
+        function testPoorSourceURLCommentInScript(next)
+        {
+            InspectorTest.showScriptSource("source-url-comment.html", didShowScriptSource);
+            InspectorTest.evaluateInPage("setTimeout(addScriptWithPoorURL, 0)");
+
+            function didShowScriptSource(sourceFrame)
+            {
                 var panel = WebInspector.inspectorView.panel("sources");
                 var uiSourceCodes = panel._workspace.uiSourceCodes();
-                for (var i = 0; i < uiSourceCodes.length; ++i)
-                    InspectorTest.assertTrue(uiSourceCodes[i].originURL().indexOf("inlineScriptURL.js") === -1, "sourceURL comment in inline script was used as a script name");
-                forEachScriptMatchingURL("source-url-comment.html", checkScriptDoesNotHaveSourceURL)
+                for (var i = 0; i < uiSourceCodes.length; ++i) {
+                    if (uiSourceCodes[i].originURL().indexOf("scriptWithPoorSourceURL.js") !== -1)
+                        InspectorTest.addResult("FAILED: poor sourceURL comment in script was used as a script name");
+                }
                 next();
             }
         },
@@ -70,13 +115,8 @@ function test()
 
             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);
+                forEachScriptMatchingURL("evalURL.js", checkScriptSourceURL);
                 next();
             }
         },
@@ -88,13 +128,27 @@ function test()
 
             function didShowScriptSource(sourceFrame)
             {
-                function checkScriptHasSourceURL(script)
+                InspectorTest.addResult(sourceFrame.textEditor.text());
+                forEachScriptMatchingURL("deprecatedEvalURL.js", checkScriptSourceURL);
+                next();
+            }
+        },
+
+        function testSourceURLAndMappingURLComment(next)
+        {
+            InspectorTest.showScriptSource("sourceURL.js", didShowScriptSource);
+            InspectorTest.evaluateInPage("setTimeout(doURLAndMappingURL, 0)");
+
+            function didShowScriptSource(sourceFrame)
+            {
+                function checkScriptSourceURLAndMappingURL(script)
                 {
-                    InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for eval with sourceURL comment");
+                    InspectorTest.addResult("hasSourceURL: " + script.hasSourceURL);
+                    InspectorTest.addResult("sourceMapURL: " + script.sourceMapURL);
                 }
 
                 InspectorTest.addResult(sourceFrame.textEditor.text());
-                forEachScriptMatchingURL("deprecatedEvalURL.js", checkScriptHasSourceURL);
+                forEachScriptMatchingURL("sourceURL.js", checkScriptSourceURLAndMappingURL);
                 next();
             }
         },
@@ -106,13 +160,8 @@ function test()
 
             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);
+                forEachScriptMatchingURL("dynamicScriptURL.js", checkScriptSourceURL);
                 next();
             }
         },
@@ -124,17 +173,17 @@ function test()
 
             function didShowScriptSource(sourceFrame)
             {
-                function checkScriptHasSourceURL(script)
-                {
-                    InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for eval with a non-relative URL in a sourceURL comment");
-                }
-
                 InspectorTest.addResult(sourceFrame.textEditor.text());
-                forEachScriptMatchingURL("nonRelativeURL.js", checkScriptHasSourceURL);
+                forEachScriptMatchingURL("nonRelativeURL.js", checkScriptSourceURL);
                 next();
             }
         }
     ]);
+
+    function checkScriptSourceURL(script)
+    {
+        InspectorTest.addResult("hasSourceURL: " + script.hasSourceURL);
+    }    
 };
 
 </script>