Web Inspector: Create JavaScriptSources based on network resources.
[WebKit-https.git] / LayoutTests / inspector / debugger / dynamic-script-tag.html
index b45368c..527987b 100644 (file)
@@ -2,51 +2,79 @@
 <head>
 <script src="../../http/tests/inspector/inspector-test.js"></script>
 <script src="../../http/tests/inspector/debugger-test.js"></script>
-
+<script src="../../http/tests/inspector/workspace-test.js"></script>
 <script>
+document.write("<scrip" + "t>function foo() { }</sc" + "ript>");
+var scriptElement = document.createElement("script");
+scriptElement.textContent = "function bar() { }";
+document.head.appendChild(scriptElement);
 
-function createScriptTag()
-{
-    var script = document.createElement("script");
-    script.innerHTML = "console.log(123)";
-    document.head.appendChild(script);
-}
-
-function test()
+var test = function()
 {
     InspectorTest.startDebuggerTest(step1);
 
     function step1()
     {
-        InspectorTest.evaluateInPage("createScriptTag()");
-        WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, step2);
-    }
+        var model = WebInspector.debuggerModel;
 
-    function step2(event)
-    {
-        var script = event.data;
-        script.requestContent(callback);
-        function callback(content)
+        var scripts = Object.values(WebInspector.debuggerModel.scripts);
+        function filterOutStandaloneScripts(script)
         {
-            if (content !== "console.log(123)")
-                return;
+            return script.sourceURL.indexOf("dynamic-script-tag.html") !== -1;
+        }
+        scripts = scripts.filter(filterOutStandaloneScripts);
+
+        function compareScriptFunction(script1, script2)
+        {
+            return script1.sourceURL.localeCompare(script2.sourceURL);
+        }
+        scripts.sort(compareScriptFunction);
+        InspectorTest.assertEquals(3, scripts.length, "Wrong scripts count.");
+
+        var uiSourceCodes = [];
+        InspectorTest.addResult("Dumping scripts:");
+        for (var i = 0; i < scripts.length; ++i) {
+            var script = scripts[i];
+            InspectorTest.addResult("script" + (i+1) + ": " + script.sourceURL);
             InspectorTest.addResult("Is anonymous:" + script.isAnonymousScript());
             InspectorTest.addResult("Is inline script:" + script.isInlineScript());
-            InspectorTest.addResult(new WebInspector.ParsedURL(script.sourceURL).displayName);
-            // Invoke post source map install.
-            setTimeout(step3.bind(this, script), 0);
+            if (!script.isInlineScript())
+                uiSourceCodes.push(script.rawLocationToUILocation(0, 0).uiSourceCode);
         }
-    }
 
-    function step3(script)
-    {
-        var uiLocation = script.rawLocationToUILocation(0, 0);
-        InspectorTest.addResult("UI name: " + uiLocation.uiSourceCode.parsedURL.displayName);
-        InspectorTest.addResult("UI resource: " + uiLocation.uiSourceCode.resource());
-        uiLocation.uiSourceCode.requestContent(callback);
-        function callback(content)
+        function compareUISourceCodeFunction(uiSourceCode1, uiSourceCode2)
+        {
+            return uiSourceCode1.url.localeCompare(uiSourceCode2.url);
+        }
+        uiSourceCodes.sort(compareUISourceCodeFunction);
+
+        var seenUISourceCodes = new Map();
+        InspectorTest.assertEquals(2, uiSourceCodes.length, "Wrong uiSourceCodes count.");
+        InspectorTest.addResult("Dumping uiSourceCodes:");
+        
+        var index = 0;
+        dumpNextUISourceCode();
+        function dumpNextUISourceCode()
+        {
+            if (index >= uiSourceCodes.length) {
+                uiSourceCodesDumped();
+                return;
+            }
+            var uiSourceCode = uiSourceCodes[index];
+            InspectorTest.dumpUISourceCode(uiSourceCode, uiSourceCodeDumped);
+
+            function uiSourceCodeDumped()
+            {
+                InspectorTest.addResult("UI resource: " + uiSourceCode.resource());
+                InspectorTest.assertTrue(!seenUISourceCodes.get(uiSourceCode), "UISourceCode matches two scripts: " + uiSourceCode.url);
+                seenUISourceCodes.put(uiSourceCode, uiSourceCode);
+                ++index;
+                dumpNextUISourceCode();
+            }
+        }
+        
+        function uiSourceCodesDumped()
         {
-            InspectorTest.addResult("UI content: " + content);
             InspectorTest.completeDebuggerTest();
         }
     }
@@ -54,10 +82,7 @@ function test()
 </script>
 </head>
 <body onload="runTest()">
-<p>
-Tests that dynamically added script tag gets its own JavaScriptSource and is not bound to the resource.
+<p>Tests that inline scripts and document.write scripts get different uiSourceCodes with different URLs.
 <a href="https://bugs.webkit.org/show_bug.cgi?id=87119">Bug 87119</a>
-</p>
 </body>
-
 </html>