1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_sourcemaps-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 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 basic source map integration with the "newSource" packet in the RDP. 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 +{ 1.19 + initTestDebuggerServer(); 1.20 + gDebuggee = addTestGlobal("test-source-map"); 1.21 + gClient = new DebuggerClient(DebuggerServer.connectPipe()); 1.22 + gClient.connect(function() { 1.23 + attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) { 1.24 + gThreadClient = aThreadClient; 1.25 + test_simple_source_map(); 1.26 + }); 1.27 + }); 1.28 + do_test_pending(); 1.29 +} 1.30 + 1.31 +function test_simple_source_map() 1.32 +{ 1.33 + // Because we are source mapping, we should be notified of a.js, b.js, and 1.34 + // c.js as sources, and shouldn't receive abc.js or test_sourcemaps-01.js. 1.35 + let expectedSources = new Set(["http://example.com/www/js/a.js", 1.36 + "http://example.com/www/js/b.js", 1.37 + "http://example.com/www/js/c.js"]); 1.38 + 1.39 + gClient.addListener("newSource", function _onNewSource(aEvent, aPacket) { 1.40 + do_check_eq(aEvent, "newSource"); 1.41 + do_check_eq(aPacket.type, "newSource"); 1.42 + do_check_true(!!aPacket.source); 1.43 + 1.44 + do_check_true(expectedSources.has(aPacket.source.url), 1.45 + "The source url should be one of our original sources."); 1.46 + expectedSources.delete(aPacket.source.url); 1.47 + 1.48 + if (expectedSources.size === 0) { 1.49 + gClient.removeListener("newSource", _onNewSource); 1.50 + finishClient(gClient); 1.51 + } 1.52 + }); 1.53 + 1.54 + let { code, map } = (new SourceNode(null, null, null, [ 1.55 + new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"), 1.56 + new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"), 1.57 + new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"), 1.58 + ])).toStringWithSourceMap({ 1.59 + file: "abc.js", 1.60 + sourceRoot: "http://example.com/www/js/" 1.61 + }); 1.62 + 1.63 + code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString()); 1.64 + 1.65 + Components.utils.evalInSandbox(code, gDebuggee, "1.8", 1.66 + "http://example.com/www/js/abc.js", 1); 1.67 +}