michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Test that we can black box source mapped sources. michael@0: */ michael@0: michael@0: var gDebuggee; michael@0: var gClient; michael@0: var gThreadClient; michael@0: michael@0: Components.utils.import('resource:///modules/devtools/SourceMap.jsm'); michael@0: michael@0: function run_test() michael@0: { michael@0: initTestDebuggerServer(); michael@0: gDebuggee = addTestGlobal("test-black-box"); michael@0: gClient = new DebuggerClient(DebuggerServer.connectPipe()); michael@0: gClient.connect(function() { michael@0: attachTestTabAndResume(gClient, "test-black-box", function(aResponse, aTabClient, aThreadClient) { michael@0: gThreadClient = aThreadClient; michael@0: michael@0: promise.resolve(setup_code()) michael@0: .then(black_box_code) michael@0: .then(run_code) michael@0: .then(test_correct_location) michael@0: .then(null, function (error) { michael@0: do_check_true(false, "Should not get an error, got " + error); michael@0: }) michael@0: .then(function () { michael@0: finishClient(gClient); michael@0: }); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function setup_code() { michael@0: let { code, map } = (new SourceNode(null, null, null, [ michael@0: new SourceNode(1, 0, "a.js", "" + function a() { michael@0: return b(); michael@0: }), michael@0: "\n", michael@0: new SourceNode(1, 0, "b.js", "" + function b() { michael@0: debugger; // Don't want to stop here. michael@0: return c(); michael@0: }), michael@0: "\n", michael@0: new SourceNode(1, 0, "c.js", "" + function c() { michael@0: debugger; // Want to stop here. michael@0: }), michael@0: "\n" michael@0: ])).toStringWithSourceMap({ michael@0: file: "abc.js", michael@0: sourceRoot: "http://example.com/" michael@0: }); michael@0: michael@0: code += "//# sourceMappingURL=data:text/json," + map.toString(); michael@0: michael@0: Components.utils.evalInSandbox(code, michael@0: gDebuggee, michael@0: "1.8", michael@0: "http://example.com/abc.js"); michael@0: } michael@0: michael@0: function black_box_code() { michael@0: const d = promise.defer(); michael@0: michael@0: gThreadClient.getSources(function ({ sources, error }) { michael@0: do_check_true(!error, "Shouldn't get an error getting sources"); michael@0: const source = sources.filter((s) => { michael@0: return s.url.indexOf("b.js") !== -1; michael@0: })[0]; michael@0: do_check_true(!!source, "We should have our source in the sources list"); michael@0: michael@0: gThreadClient.source(source).blackBox(function ({ error }) { michael@0: do_check_true(!error, "Should not get an error black boxing"); michael@0: d.resolve(true); michael@0: }); michael@0: }); michael@0: michael@0: return d.promise; michael@0: } michael@0: michael@0: function run_code() { michael@0: const d = promise.defer(); michael@0: michael@0: gClient.addOneTimeListener("paused", function (aEvent, aPacket) { michael@0: d.resolve(aPacket); michael@0: gThreadClient.resume(); michael@0: }); michael@0: gDebuggee.a(); michael@0: michael@0: return d.promise; michael@0: } michael@0: michael@0: function test_correct_location(aPacket) { michael@0: do_check_eq(aPacket.why.type, "debuggerStatement", michael@0: "Should hit a debugger statement."); michael@0: do_check_eq(aPacket.frame.where.url, "http://example.com/c.js", michael@0: "Should have skipped over the debugger statement in the black boxed source"); michael@0: }