3 <script src="../../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../../http/tests/inspector/debugger-test.js"></script>
5 <link rel="stylesheet" href="resources/style-formatter-obfuscated.css">
11 var worker = Runtime.startWorker("script_formatter_worker");
12 WebInspector.inspectorView.showPanel("sources");
14 InspectorTest.runTestSuite([
15 function testScriptFormatterWorker(next)
17 worker.onmessage = InspectorTest.safeWrap(function(event)
19 InspectorTest.assertEquals("a {\\n /* pre-comment */\\n color /* after name */ : /* before value */ red /* post-comment */\\n}\\n".replace(/\n/g, "\\n"), event.data.content.replace(/\n/g, "\\n"));
23 worker.onerror = function(event)
25 InspectorTest.addResult("Error in worker: " + event.data);
29 worker.postMessage({ method: "format", params: { mimeType: "text/css", content: "a { /* pre-comment */ color /* after name */ : /* before value */ red /* post-comment */ }" } });
32 function testSourceMapping(next)
34 var formatter = new WebInspector.ScriptFormatter();
36 InspectorTest.showScriptSource("style-formatter-obfuscated.css", didShowScriptSource);
37 function didShowScriptSource(sourceFrame)
39 formatter.formatContent("text/css", sourceFrame._textEditor.text(), didFormatContent);
42 function didFormatContent(content, mapping)
44 var source = WebInspector.inspectorView.panel("sources").visibleView._textEditor.text();
45 var formattedSource = content;
47 function testMapping(string)
49 var originalPosition = source.indexOf(string);
50 InspectorTest.assertTrue(originalPosition !== -1, "Not found '" + string + "'");
51 var originalLocation = WebInspector.Formatter.positionToLocation(source.lineEndings(), originalPosition);
52 var formattedLocation = mapping.originalToFormatted(originalLocation[0], originalLocation[1]);
53 var formattedPosition = WebInspector.Formatter.locationToPosition(formattedSource.lineEndings(), formattedLocation[0], formattedLocation[1]);
54 var expectedFormattedPosition = formattedSource.indexOf(string);
55 InspectorTest.assertEquals(expectedFormattedPosition, formattedPosition, "wrong mapping for <" + string + ">");
58 testMapping("@media");
59 testMapping("screen");
64 testMapping("foo-property");
65 testMapping("bar-value");
68 testMapping("background");
75 function testFormatInlinedStyles(next)
77 worker.onmessage = InspectorTest.safeWrap(function(event)
79 InspectorTest.addResult(event.data.content);
83 worker.onerror = function(event)
85 InspectorTest.addResult("Error in worker: " + event.data);
89 var content = "<html><body><style>@-webkit-keyframes{from{left: 0} to{left:100px;}}</style><style>badbraces { }} @media screen{a{color:red;text-decoration: none}}</style></body></html>";
90 worker.postMessage({ method: "format", params: { mimeType: "text/html", content: content, indentString: "**" } });
99 <body onload="runTest()">
100 <p>Tests the script formatting functionality.