browser/devtools/debugger/test/browser_dbg_parser-04.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:934b861cc857
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Check that faulty JS inside HTML can be separated and identified correctly.
6 */
7
8 function test() {
9 let { Parser } = Cu.import("resource:///modules/devtools/Parser.jsm", {});
10
11 let source = [
12 "<!doctype html>",
13 "<head>",
14 "<SCRIPT>",
15 "let a + 42;",
16 "</SCRIPT>",
17 "<script type='text/javascript'>",
18 "let b = 42;",
19 "</SCRIPT>",
20 "<script type='text/javascript;version=1.8'>",
21 "let c + 42;",
22 "</SCRIPT>",
23 "</head>"
24 ].join("\n");
25 let parser = new Parser();
26 let parsed = parser.get(source);
27
28 ok(parsed,
29 "HTML code should be parsed correctly.");
30 is(parser.errors.length, 2,
31 "There should be two errors logged when parsing.");
32
33 is(parser.errors[0].name, "SyntaxError",
34 "The correct first exception was caught.");
35 is(parser.errors[0].message, "missing ; before statement",
36 "The correct first exception was caught.");
37
38 is(parser.errors[1].name, "SyntaxError",
39 "The correct second exception was caught.");
40 is(parser.errors[1].message, "missing ; before statement",
41 "The correct second exception was caught.");
42
43 is(parsed.scriptCount, 1,
44 "There should be 1 script parsed in the parent HTML source.");
45
46 is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:-1, length:-1, index:-1})",
47 "The first script shouldn't be considered valid.");
48 is(parsed.getScriptInfo(source.indexOf("let b")).toSource(), "({start:85, length:13, index:0})",
49 "The second script was located correctly.");
50 is(parsed.getScriptInfo(source.indexOf("let c")).toSource(), "({start:-1, length:-1, index:-1})",
51 "The third script shouldn't be considered valid.");
52
53 finish();
54 }

mercurial