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 basic source map integration with the "newSource" packet in the RDP. |
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 | { |
michael@0 | 16 | initTestDebuggerServer(); |
michael@0 | 17 | gDebuggee = addTestGlobal("test-source-map"); |
michael@0 | 18 | gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
michael@0 | 19 | gClient.connect(function() { |
michael@0 | 20 | attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) { |
michael@0 | 21 | gThreadClient = aThreadClient; |
michael@0 | 22 | test_simple_source_map(); |
michael@0 | 23 | }); |
michael@0 | 24 | }); |
michael@0 | 25 | do_test_pending(); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function test_simple_source_map() |
michael@0 | 29 | { |
michael@0 | 30 | // Because we are source mapping, we should be notified of a.js, b.js, and |
michael@0 | 31 | // c.js as sources, and shouldn't receive abc.js or test_sourcemaps-01.js. |
michael@0 | 32 | let expectedSources = new Set(["http://example.com/www/js/a.js", |
michael@0 | 33 | "http://example.com/www/js/b.js", |
michael@0 | 34 | "http://example.com/www/js/c.js"]); |
michael@0 | 35 | |
michael@0 | 36 | gClient.addListener("newSource", function _onNewSource(aEvent, aPacket) { |
michael@0 | 37 | do_check_eq(aEvent, "newSource"); |
michael@0 | 38 | do_check_eq(aPacket.type, "newSource"); |
michael@0 | 39 | do_check_true(!!aPacket.source); |
michael@0 | 40 | |
michael@0 | 41 | do_check_true(expectedSources.has(aPacket.source.url), |
michael@0 | 42 | "The source url should be one of our original sources."); |
michael@0 | 43 | expectedSources.delete(aPacket.source.url); |
michael@0 | 44 | |
michael@0 | 45 | if (expectedSources.size === 0) { |
michael@0 | 46 | gClient.removeListener("newSource", _onNewSource); |
michael@0 | 47 | finishClient(gClient); |
michael@0 | 48 | } |
michael@0 | 49 | }); |
michael@0 | 50 | |
michael@0 | 51 | let { code, map } = (new SourceNode(null, null, null, [ |
michael@0 | 52 | new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"), |
michael@0 | 53 | new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"), |
michael@0 | 54 | new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"), |
michael@0 | 55 | ])).toStringWithSourceMap({ |
michael@0 | 56 | file: "abc.js", |
michael@0 | 57 | sourceRoot: "http://example.com/www/js/" |
michael@0 | 58 | }); |
michael@0 | 59 | |
michael@0 | 60 | code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString()); |
michael@0 | 61 | |
michael@0 | 62 | Components.utils.evalInSandbox(code, gDebuggee, "1.8", |
michael@0 | 63 | "http://example.com/www/js/abc.js", 1); |
michael@0 | 64 | } |