527987b12d1792ce7aba59ee1f34c7e32836a9a5
[WebKit-https.git] / LayoutTests / inspector / debugger / dynamic-script-tag.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 src="../../http/tests/inspector/workspace-test.js"></script>
6 <script>
7 document.write("<scrip" + "t>function foo() { }</sc" + "ript>");
8 var scriptElement = document.createElement("script");
9 scriptElement.textContent = "function bar() { }";
10 document.head.appendChild(scriptElement);
11
12 var test = function()
13 {
14     InspectorTest.startDebuggerTest(step1);
15
16     function step1()
17     {
18         var model = WebInspector.debuggerModel;
19
20         var scripts = Object.values(WebInspector.debuggerModel.scripts);
21         function filterOutStandaloneScripts(script)
22         {
23             return script.sourceURL.indexOf("dynamic-script-tag.html") !== -1;
24         }
25         scripts = scripts.filter(filterOutStandaloneScripts);
26
27         function compareScriptFunction(script1, script2)
28         {
29             return script1.sourceURL.localeCompare(script2.sourceURL);
30         }
31         scripts.sort(compareScriptFunction);
32         InspectorTest.assertEquals(3, scripts.length, "Wrong scripts count.");
33
34         var uiSourceCodes = [];
35         InspectorTest.addResult("Dumping scripts:");
36         for (var i = 0; i < scripts.length; ++i) {
37             var script = scripts[i];
38             InspectorTest.addResult("script" + (i+1) + ": " + script.sourceURL);
39             InspectorTest.addResult("Is anonymous:" + script.isAnonymousScript());
40             InspectorTest.addResult("Is inline script:" + script.isInlineScript());
41             if (!script.isInlineScript())
42                 uiSourceCodes.push(script.rawLocationToUILocation(0, 0).uiSourceCode);
43         }
44
45         function compareUISourceCodeFunction(uiSourceCode1, uiSourceCode2)
46         {
47             return uiSourceCode1.url.localeCompare(uiSourceCode2.url);
48         }
49         uiSourceCodes.sort(compareUISourceCodeFunction);
50
51         var seenUISourceCodes = new Map();
52         InspectorTest.assertEquals(2, uiSourceCodes.length, "Wrong uiSourceCodes count.");
53         InspectorTest.addResult("Dumping uiSourceCodes:");
54         
55         var index = 0;
56         dumpNextUISourceCode();
57         function dumpNextUISourceCode()
58         {
59             if (index >= uiSourceCodes.length) {
60                 uiSourceCodesDumped();
61                 return;
62             }
63             var uiSourceCode = uiSourceCodes[index];
64             InspectorTest.dumpUISourceCode(uiSourceCode, uiSourceCodeDumped);
65
66             function uiSourceCodeDumped()
67             {
68                 InspectorTest.addResult("UI resource: " + uiSourceCode.resource());
69                 InspectorTest.assertTrue(!seenUISourceCodes.get(uiSourceCode), "UISourceCode matches two scripts: " + uiSourceCode.url);
70                 seenUISourceCodes.put(uiSourceCode, uiSourceCode);
71                 ++index;
72                 dumpNextUISourceCode();
73             }
74         }
75         
76         function uiSourceCodesDumped()
77         {
78             InspectorTest.completeDebuggerTest();
79         }
80     }
81 }
82 </script>
83 </head>
84 <body onload="runTest()">
85 <p>Tests that inline scripts and document.write scripts get different uiSourceCodes with different URLs.
86 <a href="https://bugs.webkit.org/show_bug.cgi?id=87119">Bug 87119</a>
87 </body>
88 </html>