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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_parser-04.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Check that faulty JS inside HTML can be separated and identified correctly.
     1.9 + */
    1.10 +
    1.11 +function test() {
    1.12 +  let { Parser } = Cu.import("resource:///modules/devtools/Parser.jsm", {});
    1.13 +
    1.14 +  let source = [
    1.15 +    "<!doctype html>",
    1.16 +    "<head>",
    1.17 +      "<SCRIPT>",
    1.18 +        "let a + 42;",
    1.19 +      "</SCRIPT>",
    1.20 +      "<script type='text/javascript'>",
    1.21 +        "let b = 42;",
    1.22 +      "</SCRIPT>",
    1.23 +      "<script type='text/javascript;version=1.8'>",
    1.24 +        "let c + 42;",
    1.25 +      "</SCRIPT>",
    1.26 +    "</head>"
    1.27 +  ].join("\n");
    1.28 +  let parser = new Parser();
    1.29 +  let parsed = parser.get(source);
    1.30 +
    1.31 +  ok(parsed,
    1.32 +    "HTML code should be parsed correctly.");
    1.33 +  is(parser.errors.length, 2,
    1.34 +    "There should be two errors logged when parsing.");
    1.35 +
    1.36 +  is(parser.errors[0].name, "SyntaxError",
    1.37 +    "The correct first exception was caught.");
    1.38 +  is(parser.errors[0].message, "missing ; before statement",
    1.39 +    "The correct first exception was caught.");
    1.40 +
    1.41 +  is(parser.errors[1].name, "SyntaxError",
    1.42 +    "The correct second exception was caught.");
    1.43 +  is(parser.errors[1].message, "missing ; before statement",
    1.44 +    "The correct second exception was caught.");
    1.45 +
    1.46 +  is(parsed.scriptCount, 1,
    1.47 +    "There should be 1 script parsed in the parent HTML source.");
    1.48 +
    1.49 +  is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:-1, length:-1, index:-1})",
    1.50 +    "The first script shouldn't be considered valid.");
    1.51 +  is(parsed.getScriptInfo(source.indexOf("let b")).toSource(), "({start:85, length:13, index:0})",
    1.52 +    "The second script was located correctly.");
    1.53 +  is(parsed.getScriptInfo(source.indexOf("let c")).toSource(), "({start:-1, length:-1, index:-1})",
    1.54 +    "The third script shouldn't be considered valid.");
    1.55 +
    1.56 +  finish();
    1.57 +}

mercurial