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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Check that JS inside HTML can be separated and parsed correctly.
     6  */
     8 function test() {
     9   let { Parser } = Cu.import("resource:///modules/devtools/Parser.jsm", {});
    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);
    28   ok(parsed,
    29     "HTML code should be parsed correctly.");
    30   is(parser.errors.length, 0,
    31     "There should be no errors logged when parsing.");
    33   is(parsed.scriptCount, 3,
    34     "There should be 3 scripts parsed in the parent HTML source.");
    36   is(parsed.getScriptInfo(0).toSource(), "({start:-1, length:-1, index:-1})",
    37     "There is no script at the beginning of the parent source.");
    38   is(parsed.getScriptInfo(source.length - 1).toSource(), "({start:-1, length:-1, index:-1})",
    39     "There is no script at the end of the parent source.");
    41   is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:31, length:13, index:0})",
    42     "The first script was located correctly.");
    43   is(parsed.getScriptInfo(source.indexOf("let b")).toSource(), "({start:85, length:13, index:1})",
    44     "The second script was located correctly.");
    45   is(parsed.getScriptInfo(source.indexOf("let c")).toSource(), "({start:151, length:13, index:2})",
    46     "The third script was located correctly.");
    48   is(parsed.getScriptInfo(source.indexOf("let a") - 1).toSource(), "({start:31, length:13, index:0})",
    49     "The left edge of the first script was interpreted correctly.");
    50   is(parsed.getScriptInfo(source.indexOf("let b") - 1).toSource(), "({start:85, length:13, index:1})",
    51     "The left edge of the second script was interpreted correctly.");
    52   is(parsed.getScriptInfo(source.indexOf("let c") - 1).toSource(), "({start:151, length:13, index:2})",
    53     "The left edge of the third script was interpreted correctly.");
    55   is(parsed.getScriptInfo(source.indexOf("let a") - 2).toSource(), "({start:-1, length:-1, index:-1})",
    56     "The left outside of the first script was interpreted correctly.");
    57   is(parsed.getScriptInfo(source.indexOf("let b") - 2).toSource(), "({start:-1, length:-1, index:-1})",
    58     "The left outside of the second script was interpreted correctly.");
    59   is(parsed.getScriptInfo(source.indexOf("let c") - 2).toSource(), "({start:-1, length:-1, index:-1})",
    60     "The left outside of the third script was interpreted correctly.");
    62   is(parsed.getScriptInfo(source.indexOf("let a") + 12).toSource(), "({start:31, length:13, index:0})",
    63     "The right edge of the first script was interpreted correctly.");
    64   is(parsed.getScriptInfo(source.indexOf("let b") + 12).toSource(), "({start:85, length:13, index:1})",
    65     "The right edge of the second script was interpreted correctly.");
    66   is(parsed.getScriptInfo(source.indexOf("let c") + 12).toSource(), "({start:151, length:13, index:2})",
    67     "The right edge of the third script was interpreted correctly.");
    69   is(parsed.getScriptInfo(source.indexOf("let a") + 13).toSource(), "({start:-1, length:-1, index:-1})",
    70     "The right outside of the first script was interpreted correctly.");
    71   is(parsed.getScriptInfo(source.indexOf("let b") + 13).toSource(), "({start:-1, length:-1, index:-1})",
    72     "The right outside of the second script was interpreted correctly.");
    73   is(parsed.getScriptInfo(source.indexOf("let c") + 13).toSource(), "({start:-1, length:-1, index:-1})",
    74     "The right outside of the third script was interpreted correctly.");
    76   finish();
    77 }

mercurial