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.

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

mercurial