browser/devtools/debugger/test/browser_dbg_parser-05.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-05.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,43 @@
     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 JS code containing strings that might look like <script> tags
     1.9 + * inside an HTML source is parsed correctly.
    1.10 + */
    1.11 +
    1.12 +function test() {
    1.13 +  let { Parser } = Cu.import("resource:///modules/devtools/Parser.jsm", {});
    1.14 +
    1.15 +  let source = [
    1.16 +    "let a = [];",
    1.17 +    "a.push('<script>');",
    1.18 +    "a.push('var a = 42;');",
    1.19 +    "a.push('</script>');",
    1.20 +    "a.push('<script type=\"text/javascript\">');",
    1.21 +    "a.push('var b = 42;');",
    1.22 +    "a.push('</script>');",
    1.23 +    "a.push('<script type=\"text/javascript;version=1.8\">');",
    1.24 +    "a.push('var c = 42;');",
    1.25 +    "a.push('</script>');"
    1.26 +  ].join("\n");
    1.27 +  let parser = new Parser();
    1.28 +  let parsed = parser.get(source);
    1.29 +
    1.30 +  ok(parsed,
    1.31 +    "The javascript code should be parsed correctly.");
    1.32 +  is(parser.errors.length, 0,
    1.33 +    "There should be no errors logged when parsing.");
    1.34 +
    1.35 +  is(parsed.scriptCount, 1,
    1.36 +    "There should be 1 script parsed in the parent source.");
    1.37 +
    1.38 +  is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:0, length:261, index:0})",
    1.39 +    "The script location is correct (1).");
    1.40 +  is(parsed.getScriptInfo(source.indexOf("<script>")).toSource(), "({start:0, length:261, index:0})",
    1.41 +    "The script location is correct (2).");
    1.42 +  is(parsed.getScriptInfo(source.indexOf("</script>")).toSource(), "({start:0, length:261, index:0})",
    1.43 +    "The script location is correct (3).");
    1.44 +
    1.45 +  finish();
    1.46 +}

mercurial