toolkit/devtools/server/tests/unit/test_sourcemaps-11.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 we source map frame locations returned by "frames" requests.
michael@0 6 */
michael@0 7
michael@0 8 var gDebuggee;
michael@0 9 var gClient;
michael@0 10 var gThreadClient;
michael@0 11
michael@0 12 Components.utils.import('resource:///modules/devtools/SourceMap.jsm');
michael@0 13
michael@0 14 function run_test() {
michael@0 15 initTestDebuggerServer();
michael@0 16 gDebuggee = addTestGlobal("test-source-map");
michael@0 17 gClient = new DebuggerClient(DebuggerServer.connectPipe());
michael@0 18 gClient.connect(function() {
michael@0 19 attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) {
michael@0 20 gThreadClient = aThreadClient;
michael@0 21 promise.resolve(define_code())
michael@0 22 .then(run_code)
michael@0 23 .then(test_frames)
michael@0 24 .then(null, error => {
michael@0 25 dump(error + "\n");
michael@0 26 dump(error.stack);
michael@0 27 do_check_true(false);
michael@0 28 })
michael@0 29 .then(() => {
michael@0 30 finishClient(gClient);
michael@0 31 });
michael@0 32 });
michael@0 33 });
michael@0 34 do_test_pending();
michael@0 35 }
michael@0 36
michael@0 37 function define_code() {
michael@0 38 let { code, map } = (new SourceNode(null, null, null, [
michael@0 39 new SourceNode(1, 0, "a.js", "function a() {\n"),
michael@0 40 new SourceNode(2, 0, "a.js", " b();\n"),
michael@0 41 new SourceNode(3, 0, "a.js", "}\n"),
michael@0 42 new SourceNode(1, 0, "b.js", "function b() {\n"),
michael@0 43 new SourceNode(2, 0, "b.js", " c();\n"),
michael@0 44 new SourceNode(3, 0, "b.js", "}\n"),
michael@0 45 new SourceNode(1, 0, "c.js", "function c() {\n"),
michael@0 46 new SourceNode(2, 0, "c.js", " debugger;\n"),
michael@0 47 new SourceNode(3, 0, "c.js", "}\n"),
michael@0 48 ])).toStringWithSourceMap({
michael@0 49 file: "abc.js",
michael@0 50 sourceRoot: "http://example.com/www/js/"
michael@0 51 });
michael@0 52
michael@0 53 code += "//# sourceMappingURL=data:text/json," + map.toString();
michael@0 54
michael@0 55 Components.utils.evalInSandbox(code, gDebuggee, "1.8",
michael@0 56 "http://example.com/www/js/abc.js", 1);
michael@0 57 }
michael@0 58
michael@0 59 function run_code() {
michael@0 60 const d = promise.defer();
michael@0 61 gClient.addOneTimeListener("paused", function () {
michael@0 62 gThreadClient.getFrames(0, 3, function (aResponse) {
michael@0 63 d.resolve(aResponse);
michael@0 64 gThreadClient.resume();
michael@0 65 })
michael@0 66 });
michael@0 67 gDebuggee.a();
michael@0 68 return d.promise;
michael@0 69 }
michael@0 70
michael@0 71 function test_frames({ error, frames }) {
michael@0 72 do_check_true(!error);
michael@0 73 do_check_eq(frames.length, 3);
michael@0 74 check_frame(frames[0], "http://example.com/www/js/c.js");
michael@0 75 check_frame(frames[1], "http://example.com/www/js/b.js");
michael@0 76 check_frame(frames[2], "http://example.com/www/js/a.js");
michael@0 77 }
michael@0 78
michael@0 79 function check_frame({ where: { url, line, column } }, aExpectedUrl) {
michael@0 80 do_check_eq(url, aExpectedUrl);
michael@0 81 do_check_eq(line, 2);
michael@0 82 do_check_eq(column, 0);
michael@0 83 }

mercurial