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 basic black boxing. michael@0: */ michael@0: michael@0: var gDebuggee; michael@0: var gClient; michael@0: var gThreadClient; 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: test_black_box(); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: const BLACK_BOXED_URL = "http://example.com/blackboxme.js"; michael@0: const SOURCE_URL = "http://example.com/source.js"; michael@0: michael@0: function test_black_box() michael@0: { michael@0: gClient.addOneTimeListener("paused", function () { michael@0: gThreadClient.setBreakpoint({ michael@0: url: SOURCE_URL, michael@0: line: 2 michael@0: }, function (aResponse) { michael@0: do_check_true(!aResponse.error, "Should be able to set breakpoint."); michael@0: gThreadClient.resume(test_black_box_default); michael@0: }); michael@0: }); michael@0: michael@0: Components.utils.evalInSandbox( michael@0: "" + function doStuff(k) { // line 1 michael@0: let arg = 15; // line 2 - Step in here michael@0: k(arg); // line 3 michael@0: }, // line 4 michael@0: gDebuggee, michael@0: "1.8", michael@0: BLACK_BOXED_URL, michael@0: 1 michael@0: ); michael@0: michael@0: Components.utils.evalInSandbox( michael@0: "" + function runTest() { // line 1 michael@0: doStuff( // line 2 - Break here michael@0: function (n) { // line 3 - Step through `doStuff` to here michael@0: debugger; // line 5 michael@0: } // line 6 michael@0: ); // line 7 michael@0: } // line 8 michael@0: + "\n debugger;", // line 9 michael@0: gDebuggee, michael@0: "1.8", michael@0: SOURCE_URL, michael@0: 1 michael@0: ); michael@0: } michael@0: michael@0: function test_black_box_default() { michael@0: gThreadClient.getSources(function (aResponse) { michael@0: do_check_true(!aResponse.error, "Should be able to get sources."); michael@0: michael@0: let sourceClient = gThreadClient.source( michael@0: aResponse.sources.filter(s => s.url == BLACK_BOXED_URL)[0]); michael@0: do_check_true(!sourceClient.isBlackBoxed, michael@0: "By default the source is not black boxed."); michael@0: michael@0: // Test that we can step into `doStuff` when we are not black boxed. michael@0: runTest( michael@0: function onSteppedLocation(aLocation) { michael@0: do_check_eq(aLocation.url, BLACK_BOXED_URL, michael@0: "Should step into `doStuff`."); michael@0: do_check_eq(aLocation.line, 2, michael@0: "Should step into `doStuff`."); michael@0: }, michael@0: function onDebuggerStatementFrames(aFrames) { michael@0: do_check_true(!aFrames.some(f => f.source.isBlackBoxed)); michael@0: }, michael@0: test_black_boxing.bind(null, sourceClient) michael@0: ); michael@0: }); michael@0: } michael@0: michael@0: function test_black_boxing(aSourceClient) { michael@0: aSourceClient.blackBox(function (aResponse) { michael@0: do_check_true(!aResponse.error, "Should not get an error black boxing."); michael@0: do_check_true(aSourceClient.isBlackBoxed, michael@0: "The source client should report itself as black boxed correctly."); michael@0: michael@0: // Test that we step through `doStuff` when we are black boxed and its frame michael@0: // doesn't show up. michael@0: runTest( michael@0: function onSteppedLocation(aLocation) { michael@0: do_check_eq(aLocation.url, SOURCE_URL, michael@0: "Should step through `doStuff`."); michael@0: do_check_eq(aLocation.line, 3, michael@0: "Should step through `doStuff`."); michael@0: }, michael@0: function onDebuggerStatementFrames(aFrames) { michael@0: for (let f of aFrames) { michael@0: if (f.where.url == BLACK_BOXED_URL) { michael@0: do_check_true(f.source.isBlackBoxed, "Should be black boxed"); michael@0: } else { michael@0: do_check_true(!f.source.isBlackBoxed, "Should not be black boxed") michael@0: } michael@0: } michael@0: }, michael@0: test_unblack_boxing.bind(null, aSourceClient) michael@0: ); michael@0: }); michael@0: } michael@0: michael@0: function test_unblack_boxing(aSourceClient) { michael@0: aSourceClient.unblackBox(function (aResponse) { michael@0: do_check_true(!aResponse.error, "Should not get an error un-black boxing"); michael@0: do_check_true(!aSourceClient.isBlackBoxed, "The source is not black boxed."); michael@0: michael@0: // Test that we can step into `doStuff` again. michael@0: runTest( michael@0: function onSteppedLocation(aLocation) { michael@0: do_check_eq(aLocation.url, BLACK_BOXED_URL, michael@0: "Should step into `doStuff`."); michael@0: do_check_eq(aLocation.line, 2, michael@0: "Should step into `doStuff`."); michael@0: }, michael@0: function onDebuggerStatementFrames(aFrames) { michael@0: do_check_true(!aFrames.some(f => f.source.isBlackBoxed)); michael@0: }, michael@0: finishClient.bind(null, gClient) michael@0: ); michael@0: }); michael@0: } michael@0: michael@0: function runTest(aOnSteppedLocation, aOnDebuggerStatementFrames, aFinishedCallback) { michael@0: gClient.addOneTimeListener("paused", function (aEvent, aPacket) { michael@0: do_check_eq(aPacket.why.type, "breakpoint"); michael@0: gClient.addOneTimeListener("paused", function () { michael@0: gClient.addOneTimeListener("paused", function () { michael@0: getCurrentLocation(function (aLocation) { michael@0: aOnSteppedLocation(aLocation); michael@0: gClient.addOneTimeListener("paused", function (aEvent, aPacket) { michael@0: do_check_eq(aPacket.why.type, "debuggerStatement"); michael@0: gThreadClient.getFrames(0, 100, function ({frames}) { michael@0: aOnDebuggerStatementFrames(frames); michael@0: gThreadClient.resume(aFinishedCallback); michael@0: }); michael@0: }); michael@0: gThreadClient.resume(); michael@0: }); michael@0: }); michael@0: gThreadClient.stepIn(); michael@0: }); michael@0: gThreadClient.stepIn(); michael@0: }); michael@0: michael@0: gDebuggee.runTest(); michael@0: } michael@0: michael@0: function getCurrentLocation(aCallback) { michael@0: gThreadClient.getFrames(0, 1, function ({frames, error}) { michael@0: do_check_true(!error, "Should not get an error: " + error); michael@0: let [{where}] = frames; michael@0: aCallback(where); michael@0: }); michael@0: }