3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/debugger-test.js"></script>
5 <script src="resources/obfuscated.js"></script>
11 var panel = WebInspector.panels.scripts;
12 var worker = new Worker("ScriptFormatterWorker.js");
14 InspectorTest.runDebuggerTestSuite([
15 function testScriptFormatterWorker(next)
17 worker.onmessage = InspectorTest.safeWrap(function(event)
19 InspectorTest.assertEquals("var x = 0\n", event.data.content);
23 worker.onerror = function(event)
25 InspectorTest.addResult("Error in worker: " + event.data);
29 worker.postMessage({ mimeType: "text/javascript", content: "var x=0" });
32 function testSourceMapping(next)
34 var formatter = new WebInspector.ScriptFormatter();
36 InspectorTest.showScriptSource("obfuscated.js", didShowScriptSource);
37 function didShowScriptSource(sourceFrame)
39 formatter.formatContent("text/javascript", sourceFrame._textModel.text, didFormatContent);
42 function didFormatContent(content, mapping)
44 var source = WebInspector.panels.scripts.visibleView._textModel.text;
45 var formattedSource = content;
47 function testMapping(string)
49 var originalPosition = source.indexOf(string);
50 InspectorTest.assertTrue(originalPosition !== -1);
51 var originalLocation = WebInspector.ScriptFormatter.positionToLocation(source.lineEndings(), originalPosition);
52 var formattedLocation = mapping.originalToFormatted(originalLocation);
53 var formattedPosition = WebInspector.ScriptFormatter.locationToPosition(formattedSource.lineEndings(), formattedLocation);
54 var expectedFormattedPosition = formattedSource.indexOf(string);
55 InspectorTest.assertEquals(expectedFormattedPosition, formattedPosition, "wrong mapping for <" + string + ">");
58 testMapping("function");
59 testMapping("formatted1");
60 testMapping("variable1");
62 testMapping(" return \"functionWithComments\"");
64 testMapping("onmessage");
65 testMapping("indent_start");
66 testMapping("function require");
67 testMapping("var regexp");
68 testMapping("importScripts");
70 testMapping("formatted2");
71 testMapping("variable2");
77 function testFormatInlinedScripts(next)
79 worker.onmessage = InspectorTest.safeWrap(function(event)
81 InspectorTest.addResult(event.data.content);
85 worker.onerror = function(event)
87 InspectorTest.addResult("Error in worker: " + event.data);
91 var content = "<html><body><script>function f(){}<" + "/script><script>function g(){var a;if (a) return;}<" + "/script></body></html>";
92 worker.postMessage({ mimeType: "text/html", content: content, indentString: "**" });
101 <body onload="runTest()">
102 <p>Tests the script formatting functionality.