1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_blackboxing-02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Test that we don't hit breakpoints in black boxed sources, and that when we 1.9 + * unblack box the source again, the breakpoint hasn't disappeared and we will 1.10 + * hit it again. 1.11 + */ 1.12 + 1.13 +var gDebuggee; 1.14 +var gClient; 1.15 +var gThreadClient; 1.16 + 1.17 +function run_test() 1.18 +{ 1.19 + initTestDebuggerServer(); 1.20 + gDebuggee = addTestGlobal("test-black-box"); 1.21 + gClient = new DebuggerClient(DebuggerServer.connectPipe()); 1.22 + gClient.connect(function() { 1.23 + attachTestTabAndResume(gClient, "test-black-box", function(aResponse, aTabClient, aThreadClient) { 1.24 + gThreadClient = aThreadClient; 1.25 + test_black_box(); 1.26 + }); 1.27 + }); 1.28 + do_test_pending(); 1.29 +} 1.30 + 1.31 +const BLACK_BOXED_URL = "http://example.com/blackboxme.js"; 1.32 +const SOURCE_URL = "http://example.com/source.js"; 1.33 + 1.34 +function test_black_box() 1.35 +{ 1.36 + gClient.addOneTimeListener("paused", function () { 1.37 + gThreadClient.setBreakpoint({ 1.38 + url: BLACK_BOXED_URL, 1.39 + line: 2 1.40 + }, function (aResponse) { 1.41 + do_check_true(!aResponse.error, "Should be able to set breakpoint."); 1.42 + gThreadClient.resume(test_black_box_breakpoint); 1.43 + }); 1.44 + }); 1.45 + 1.46 + Components.utils.evalInSandbox( 1.47 + "" + function doStuff(k) { // line 1 1.48 + let arg = 15; // line 2 - Break here 1.49 + k(arg); // line 3 1.50 + }, // line 4 1.51 + gDebuggee, 1.52 + "1.8", 1.53 + BLACK_BOXED_URL, 1.54 + 1 1.55 + ); 1.56 + 1.57 + Components.utils.evalInSandbox( 1.58 + "" + function runTest() { // line 1 1.59 + doStuff( // line 2 1.60 + function (n) { // line 3 1.61 + debugger; // line 5 1.62 + } // line 6 1.63 + ); // line 7 1.64 + } // line 8 1.65 + + "\n debugger;", // line 9 1.66 + gDebuggee, 1.67 + "1.8", 1.68 + SOURCE_URL, 1.69 + 1 1.70 + ); 1.71 +} 1.72 + 1.73 +function test_black_box_breakpoint() { 1.74 + gThreadClient.getSources(function ({error, sources}) { 1.75 + do_check_true(!error, "Should not get an error: " + error); 1.76 + let sourceClient = gThreadClient.source(sources.filter(s => s.url == BLACK_BOXED_URL)[0]); 1.77 + sourceClient.blackBox(function ({error}) { 1.78 + do_check_true(!error, "Should not get an error: " + error); 1.79 + 1.80 + gClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.81 + do_check_eq(aPacket.why.type, "debuggerStatement", 1.82 + "We should pass over the breakpoint since the source is black boxed."); 1.83 + gThreadClient.resume(test_unblack_box_breakpoint.bind(null, sourceClient)); 1.84 + }); 1.85 + gDebuggee.runTest(); 1.86 + }); 1.87 + }); 1.88 +} 1.89 + 1.90 +function test_unblack_box_breakpoint(aSourceClient) { 1.91 + aSourceClient.unblackBox(function ({error}) { 1.92 + do_check_true(!error, "Should not get an error: " + error); 1.93 + gClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.94 + do_check_eq(aPacket.why.type, "breakpoint", 1.95 + "We should hit the breakpoint again"); 1.96 + 1.97 + // We will hit the debugger statement on resume, so do this nastiness to skip over it. 1.98 + gClient.addOneTimeListener( 1.99 + "paused", 1.100 + gThreadClient.resume.bind( 1.101 + gThreadClient, 1.102 + finishClient.bind(null, gClient))); 1.103 + gThreadClient.resume(); 1.104 + }); 1.105 + gDebuggee.runTest(); 1.106 + }); 1.107 +}