Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / 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 src="resources/load-dynamic-script.js"></script>
7 <script>
8
9 var test = function()
10 {
11     InspectorTest.runDebuggerTestSuite([
12         function testOpenDevToolsAfterLoad(next)
13         {
14             var consoleMessagesCount = 2;
15
16             var messages = WebInspector.console.messages;
17             for (var i = 0; i < messages.length; ++i)
18                 processMessage(messages[i]);
19             checkWhenScriptsLoaded();
20
21             function processMessage(message)
22             {
23                 if (message._messageText.indexOf("DYNAMIC") !== -1)
24                     --consoleMessagesCount;
25             }
26
27             function consoleMessageAppended(message)
28             {
29                 processMessage(message);
30                 checkWhenScriptsLoaded();
31             }
32
33             function checkWhenScriptsLoaded()
34             {
35                 if (consoleMessagesCount) {
36                     InspectorTest.addConsoleSniffer(consoleMessageAppended);
37                     return;
38                 }
39
40                 InspectorTest.addResult("Both dynamic scripts were loaded.");
41                 var scripts = Object.values(WebInspector.debuggerModel.scripts);
42
43                 function filterOutInlineAndStandaloneScripts(script)
44                 {
45                     return !script.isInlineScript() && script.sourceURL.indexOf("dynamic-script-tag.html") !== -1;
46                 }
47                 scripts = scripts.filter(filterOutInlineAndStandaloneScripts);
48                 InspectorTest.addResult("Number of non-inline scripts with document url as a sourceURL: " + scripts.length + ".");
49                 next();
50             }
51         },
52
53         function testOpenDevToolsThenReload(next)
54         {
55             WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, scriptParsed);
56             InspectorTest.addResult("Reloading page.");
57             InspectorTest.reloadPage(onPageReloaded);
58
59             var eventsCountBeforeNext = 2;
60             function onPageReloaded()
61             {
62                 if (!--eventsCountBeforeNext)
63                     next();            
64             }
65
66             function scriptParsed(event)
67             {
68                 var script = event.data;
69                 if (script.sourceURL.indexOf("dynamic-script-tag.html") !== -1) {
70                     // Both dynamic scripts will be loaded before inline script on reload, so we are just checking
71                     // that the first one that has document url as a sourceURL is inline.
72                     InspectorTest.addResult("The first script with document url as a sourceURL to be seen is " + (script.isInlineScript() ? "" : "not ") + "inline script.");
73                     InspectorTest.assertTrue(script.isInlineScript(), "Only inline scripts should have document url as a sourceURL.");
74                     WebInspector.debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, scriptParsed);
75                     if (!--eventsCountBeforeNext)
76                         next();            
77                 }
78             }
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>