browser/devtools/debugger/test/browser_dbg_parser-03.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 JS inside HTML can be separated and parsed 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, 0,
michael@0 31 "There should be no errors logged when parsing.");
michael@0 32
michael@0 33 is(parsed.scriptCount, 3,
michael@0 34 "There should be 3 scripts parsed in the parent HTML source.");
michael@0 35
michael@0 36 is(parsed.getScriptInfo(0).toSource(), "({start:-1, length:-1, index:-1})",
michael@0 37 "There is no script at the beginning of the parent source.");
michael@0 38 is(parsed.getScriptInfo(source.length - 1).toSource(), "({start:-1, length:-1, index:-1})",
michael@0 39 "There is no script at the end of the parent source.");
michael@0 40
michael@0 41 is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:31, length:13, index:0})",
michael@0 42 "The first script was located correctly.");
michael@0 43 is(parsed.getScriptInfo(source.indexOf("let b")).toSource(), "({start:85, length:13, index:1})",
michael@0 44 "The second script was located correctly.");
michael@0 45 is(parsed.getScriptInfo(source.indexOf("let c")).toSource(), "({start:151, length:13, index:2})",
michael@0 46 "The third script was located correctly.");
michael@0 47
michael@0 48 is(parsed.getScriptInfo(source.indexOf("let a") - 1).toSource(), "({start:31, length:13, index:0})",
michael@0 49 "The left edge of the first script was interpreted correctly.");
michael@0 50 is(parsed.getScriptInfo(source.indexOf("let b") - 1).toSource(), "({start:85, length:13, index:1})",
michael@0 51 "The left edge of the second script was interpreted correctly.");
michael@0 52 is(parsed.getScriptInfo(source.indexOf("let c") - 1).toSource(), "({start:151, length:13, index:2})",
michael@0 53 "The left edge of the third script was interpreted correctly.");
michael@0 54
michael@0 55 is(parsed.getScriptInfo(source.indexOf("let a") - 2).toSource(), "({start:-1, length:-1, index:-1})",
michael@0 56 "The left outside of the first script was interpreted correctly.");
michael@0 57 is(parsed.getScriptInfo(source.indexOf("let b") - 2).toSource(), "({start:-1, length:-1, index:-1})",
michael@0 58 "The left outside of the second script was interpreted correctly.");
michael@0 59 is(parsed.getScriptInfo(source.indexOf("let c") - 2).toSource(), "({start:-1, length:-1, index:-1})",
michael@0 60 "The left outside of the third script was interpreted correctly.");
michael@0 61
michael@0 62 is(parsed.getScriptInfo(source.indexOf("let a") + 12).toSource(), "({start:31, length:13, index:0})",
michael@0 63 "The right edge of the first script was interpreted correctly.");
michael@0 64 is(parsed.getScriptInfo(source.indexOf("let b") + 12).toSource(), "({start:85, length:13, index:1})",
michael@0 65 "The right edge of the second script was interpreted correctly.");
michael@0 66 is(parsed.getScriptInfo(source.indexOf("let c") + 12).toSource(), "({start:151, length:13, index:2})",
michael@0 67 "The right edge of the third script was interpreted correctly.");
michael@0 68
michael@0 69 is(parsed.getScriptInfo(source.indexOf("let a") + 13).toSource(), "({start:-1, length:-1, index:-1})",
michael@0 70 "The right outside of the first script was interpreted correctly.");
michael@0 71 is(parsed.getScriptInfo(source.indexOf("let b") + 13).toSource(), "({start:-1, length:-1, index:-1})",
michael@0 72 "The right outside of the second script was interpreted correctly.");
michael@0 73 is(parsed.getScriptInfo(source.indexOf("let c") + 13).toSource(), "({start:-1, length:-1, index:-1})",
michael@0 74 "The right outside of the third script was interpreted correctly.");
michael@0 75
michael@0 76 finish();
michael@0 77 }

mercurial