1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_sourcemaps-10.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Check that we source map frame locations for the frame we are paused at. 1.9 + */ 1.10 + 1.11 +var gDebuggee; 1.12 +var gClient; 1.13 +var gThreadClient; 1.14 + 1.15 +Components.utils.import('resource:///modules/devtools/SourceMap.jsm'); 1.16 + 1.17 +function run_test() { 1.18 + initTestDebuggerServer(); 1.19 + gDebuggee = addTestGlobal("test-source-map"); 1.20 + gClient = new DebuggerClient(DebuggerServer.connectPipe()); 1.21 + gClient.connect(function() { 1.22 + attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) { 1.23 + gThreadClient = aThreadClient; 1.24 + promise.resolve(define_code()) 1.25 + .then(run_code) 1.26 + .then(test_frame_location) 1.27 + .then(null, error => { 1.28 + dump(error + "\n"); 1.29 + dump(error.stack); 1.30 + do_check_true(false); 1.31 + }) 1.32 + .then(() => { 1.33 + finishClient(gClient); 1.34 + }); 1.35 + }); 1.36 + }); 1.37 + do_test_pending(); 1.38 +} 1.39 + 1.40 +function define_code() { 1.41 + let { code, map } = (new SourceNode(null, null, null, [ 1.42 + new SourceNode(1, 0, "a.js", "function a() {\n"), 1.43 + new SourceNode(2, 0, "a.js", " b();\n"), 1.44 + new SourceNode(3, 0, "a.js", "}\n"), 1.45 + new SourceNode(1, 0, "b.js", "function b() {\n"), 1.46 + new SourceNode(2, 0, "b.js", " c();\n"), 1.47 + new SourceNode(3, 0, "b.js", "}\n"), 1.48 + new SourceNode(1, 0, "c.js", "function c() {\n"), 1.49 + new SourceNode(2, 0, "c.js", " debugger;\n"), 1.50 + new SourceNode(3, 0, "c.js", "}\n"), 1.51 + ])).toStringWithSourceMap({ 1.52 + file: "abc.js", 1.53 + sourceRoot: "http://example.com/www/js/" 1.54 + }); 1.55 + 1.56 + code += "//# sourceMappingURL=data:text/json," + map.toString(); 1.57 + 1.58 + Components.utils.evalInSandbox(code, gDebuggee, "1.8", 1.59 + "http://example.com/www/js/abc.js", 1); 1.60 +} 1.61 + 1.62 +function run_code() { 1.63 + const d = promise.defer(); 1.64 + gClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.65 + d.resolve(aPacket); 1.66 + gThreadClient.resume(); 1.67 + }); 1.68 + gDebuggee.a(); 1.69 + return d.promise; 1.70 +} 1.71 + 1.72 +function test_frame_location({ frame: { where: { url, line, column } } }) { 1.73 + do_check_eq(url, "http://example.com/www/js/c.js"); 1.74 + do_check_eq(line, 2); 1.75 + do_check_eq(column, 0); 1.76 +}