toolkit/devtools/server/tests/unit/test_sourcemaps-02.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 "sources" 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.addOneTimeListener("paused", function (aEvent, aPacket) {
michael@0 37 gThreadClient.getSources(function (aResponse) {
michael@0 38 do_check_true(!aResponse.error, "Should not get an error");
michael@0 39
michael@0 40 for (let s of aResponse.sources) {
michael@0 41 do_check_neq(s.url, "http://example.com/www/js/abc.js",
michael@0 42 "Shouldn't get the generated source's url.")
michael@0 43 expectedSources.delete(s.url);
michael@0 44 }
michael@0 45
michael@0 46 do_check_eq(expectedSources.size, 0,
michael@0 47 "Should have found all the expected sources sources by now.");
michael@0 48
michael@0 49 finishClient(gClient);
michael@0 50 });
michael@0 51 });
michael@0 52
michael@0 53 let { code, map } = (new SourceNode(null, null, null, [
michael@0 54 new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"),
michael@0 55 new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"),
michael@0 56 new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"),
michael@0 57 "debugger;\n"
michael@0 58 ])).toStringWithSourceMap({
michael@0 59 file: "abc.js",
michael@0 60 sourceRoot: "http://example.com/www/js/"
michael@0 61 });
michael@0 62
michael@0 63 code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString());
michael@0 64
michael@0 65 Components.utils.evalInSandbox(code, gDebuggee, "1.8",
michael@0 66 "http://example.com/www/js/abc.js", 1);
michael@0 67 }

mercurial