1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_sourcemaps-02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 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 "sources" 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.addOneTimeListener("paused", function (aEvent, aPacket) { 1.40 + gThreadClient.getSources(function (aResponse) { 1.41 + do_check_true(!aResponse.error, "Should not get an error"); 1.42 + 1.43 + for (let s of aResponse.sources) { 1.44 + do_check_neq(s.url, "http://example.com/www/js/abc.js", 1.45 + "Shouldn't get the generated source's url.") 1.46 + expectedSources.delete(s.url); 1.47 + } 1.48 + 1.49 + do_check_eq(expectedSources.size, 0, 1.50 + "Should have found all the expected sources sources by now."); 1.51 + 1.52 + finishClient(gClient); 1.53 + }); 1.54 + }); 1.55 + 1.56 + let { code, map } = (new SourceNode(null, null, null, [ 1.57 + new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"), 1.58 + new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"), 1.59 + new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"), 1.60 + "debugger;\n" 1.61 + ])).toStringWithSourceMap({ 1.62 + file: "abc.js", 1.63 + sourceRoot: "http://example.com/www/js/" 1.64 + }); 1.65 + 1.66 + code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString()); 1.67 + 1.68 + Components.utils.evalInSandbox(code, gDebuggee, "1.8", 1.69 + "http://example.com/www/js/abc.js", 1); 1.70 +}