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 that we can load sources whose content is embedded in the |
michael@0 | 6 | * "sourcesContent" field of a source map. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | var gDebuggee; |
michael@0 | 10 | var gClient; |
michael@0 | 11 | var gThreadClient; |
michael@0 | 12 | |
michael@0 | 13 | Components.utils.import("resource:///modules/devtools/SourceMap.jsm"); |
michael@0 | 14 | |
michael@0 | 15 | function run_test() |
michael@0 | 16 | { |
michael@0 | 17 | initTestDebuggerServer(); |
michael@0 | 18 | gDebuggee = addTestGlobal("test-source-map"); |
michael@0 | 19 | gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
michael@0 | 20 | gClient.connect(function() { |
michael@0 | 21 | attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) { |
michael@0 | 22 | gThreadClient = aThreadClient; |
michael@0 | 23 | test_source_content(); |
michael@0 | 24 | }); |
michael@0 | 25 | }); |
michael@0 | 26 | do_test_pending(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function test_source_content() |
michael@0 | 30 | { |
michael@0 | 31 | let numNewSources = 0; |
michael@0 | 32 | |
michael@0 | 33 | gClient.addListener("newSource", function _onNewSource(aEvent, aPacket) { |
michael@0 | 34 | if (++numNewSources !== 3) { |
michael@0 | 35 | return; |
michael@0 | 36 | } |
michael@0 | 37 | gClient.removeListener("newSource", _onNewSource); |
michael@0 | 38 | |
michael@0 | 39 | gThreadClient.getSources(function (aResponse) { |
michael@0 | 40 | do_check_true(!aResponse.error, "Should not get an error"); |
michael@0 | 41 | |
michael@0 | 42 | testContents(aResponse.sources, () => { |
michael@0 | 43 | finishClient(gClient); |
michael@0 | 44 | }); |
michael@0 | 45 | }); |
michael@0 | 46 | }); |
michael@0 | 47 | |
michael@0 | 48 | let node = new SourceNode(null, null, null, [ |
michael@0 | 49 | new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"), |
michael@0 | 50 | new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"), |
michael@0 | 51 | new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"), |
michael@0 | 52 | ]); |
michael@0 | 53 | |
michael@0 | 54 | node.setSourceContent("a.js", "content for http://example.com/www/js/a.js"); |
michael@0 | 55 | node.setSourceContent("b.js", "content for http://example.com/www/js/b.js"); |
michael@0 | 56 | node.setSourceContent("c.js", "content for http://example.com/www/js/c.js"); |
michael@0 | 57 | |
michael@0 | 58 | let { code, map } = node.toStringWithSourceMap({ |
michael@0 | 59 | file: "abc.js" |
michael@0 | 60 | }); |
michael@0 | 61 | |
michael@0 | 62 | code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString()); |
michael@0 | 63 | |
michael@0 | 64 | Components.utils.evalInSandbox(code, gDebuggee, "1.8", |
michael@0 | 65 | "http://example.com/www/js/abc.js", 1); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function testContents(aSources, aCallback) { |
michael@0 | 69 | if (aSources.length === 0) { |
michael@0 | 70 | aCallback(); |
michael@0 | 71 | return; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | let source = aSources[0]; |
michael@0 | 75 | let sourceClient = gThreadClient.source(aSources[0]); |
michael@0 | 76 | |
michael@0 | 77 | sourceClient.source((aResponse) => { |
michael@0 | 78 | do_check_true(!aResponse.error, |
michael@0 | 79 | "Should not get an error loading the source from sourcesContent"); |
michael@0 | 80 | |
michael@0 | 81 | let expectedContent = "content for " + source.url; |
michael@0 | 82 | do_check_eq(aResponse.source, expectedContent, |
michael@0 | 83 | "Should have the expected source content"); |
michael@0 | 84 | |
michael@0 | 85 | testContents(aSources.slice(1), aCallback); |
michael@0 | 86 | }); |
michael@0 | 87 | } |