Wed, 31 Dec 2014 06:09:35 +0100
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 code containing strings that might look like <script> tags |
michael@0 | 6 | * inside an HTML source is parsed correctly. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | function test() { |
michael@0 | 10 | let { Parser } = Cu.import("resource:///modules/devtools/Parser.jsm", {}); |
michael@0 | 11 | |
michael@0 | 12 | let source = [ |
michael@0 | 13 | "let a = [];", |
michael@0 | 14 | "a.push('<script>');", |
michael@0 | 15 | "a.push('var a = 42;');", |
michael@0 | 16 | "a.push('</script>');", |
michael@0 | 17 | "a.push('<script type=\"text/javascript\">');", |
michael@0 | 18 | "a.push('var b = 42;');", |
michael@0 | 19 | "a.push('</script>');", |
michael@0 | 20 | "a.push('<script type=\"text/javascript;version=1.8\">');", |
michael@0 | 21 | "a.push('var c = 42;');", |
michael@0 | 22 | "a.push('</script>');" |
michael@0 | 23 | ].join("\n"); |
michael@0 | 24 | let parser = new Parser(); |
michael@0 | 25 | let parsed = parser.get(source); |
michael@0 | 26 | |
michael@0 | 27 | ok(parsed, |
michael@0 | 28 | "The javascript code should be parsed correctly."); |
michael@0 | 29 | is(parser.errors.length, 0, |
michael@0 | 30 | "There should be no errors logged when parsing."); |
michael@0 | 31 | |
michael@0 | 32 | is(parsed.scriptCount, 1, |
michael@0 | 33 | "There should be 1 script parsed in the parent source."); |
michael@0 | 34 | |
michael@0 | 35 | is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:0, length:261, index:0})", |
michael@0 | 36 | "The script location is correct (1)."); |
michael@0 | 37 | is(parsed.getScriptInfo(source.indexOf("<script>")).toSource(), "({start:0, length:261, index:0})", |
michael@0 | 38 | "The script location is correct (2)."); |
michael@0 | 39 | is(parsed.getScriptInfo(source.indexOf("</script>")).toSource(), "({start:0, length:261, index:0})", |
michael@0 | 40 | "The script location is correct (3)."); |
michael@0 | 41 | |
michael@0 | 42 | finish(); |
michael@0 | 43 | } |