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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Check that faulty JS inside HTML can be separated and identified 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, 2,
    31     "There should be two errors logged when parsing.");
    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.");
    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.");
    43   is(parsed.scriptCount, 1,
    44     "There should be 1 script parsed in the parent HTML source.");
    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.");
    53   finish();
    54 }

mercurial