test_breakpoint-20.js (2678B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Verify that when two of the "same" source are loaded concurrently (like e10s 8 * frame scripts), breakpoints get hit in scripts defined by all sources. 9 */ 10 11 var gDebuggee; 12 13 add_task( 14 threadFrontTest(async ({ threadFront, debuggee }) => { 15 gDebuggee = debuggee; 16 await testBreakpoint(threadFront); 17 }) 18 ); 19 20 const testBreakpoint = async function (threadFront) { 21 evalSetupCode(); 22 23 // Load the test source once. 24 25 evalTestCode(); 26 equal( 27 gDebuggee.functions.length, 28 1, 29 "The test code should have added a function." 30 ); 31 32 // Set a breakpoint in the test source. 33 34 const source = await getSource(threadFront, "test.js"); 35 setBreakpoint(threadFront, { sourceUrl: source.url, line: 3 }); 36 37 // Load the test source again. 38 39 evalTestCode(); 40 equal( 41 gDebuggee.functions.length, 42 2, 43 "The test code should have added another function." 44 ); 45 46 // Should hit our breakpoint in a script defined by the first instance of the 47 // test source. 48 49 const bpPause1 = await executeOnNextTickAndWaitForPause( 50 () => gDebuggee.eval("functions[0]()"), 51 threadFront 52 ); 53 equal( 54 bpPause1.why.type, 55 "breakpoint", 56 "Should pause because of hitting our breakpoint (not debugger statement)." 57 ); 58 const dbgStmtPause1 = await executeOnNextTickAndWaitForPause( 59 () => resume(threadFront), 60 threadFront 61 ); 62 equal( 63 dbgStmtPause1.why.type, 64 "debuggerStatement", 65 "And we should hit the debugger statement after the pause." 66 ); 67 await resume(threadFront); 68 69 // Should also hit our breakpoint in a script defined by the second instance 70 // of the test source. 71 72 const bpPause2 = await executeOnNextTickAndWaitForPause( 73 () => gDebuggee.eval("functions[1]()"), 74 threadFront 75 ); 76 equal( 77 bpPause2.why.type, 78 "breakpoint", 79 "Should pause because of hitting our breakpoint (not debugger statement)." 80 ); 81 const dbgStmtPause2 = await executeOnNextTickAndWaitForPause( 82 () => resume(threadFront), 83 threadFront 84 ); 85 equal( 86 dbgStmtPause2.why.type, 87 "debuggerStatement", 88 "And we should hit the debugger statement after the pause." 89 ); 90 }; 91 92 function evalSetupCode() { 93 Cu.evalInSandbox("this.functions = [];", gDebuggee, "1.8", "setup.js", 1); 94 } 95 96 function evalTestCode() { 97 Cu.evalInSandbox( 98 ` // 1 99 this.functions.push(function () { // 2 100 var setBreakpointHere = 1; // 3 101 debugger; // 4 102 }); // 5 103 `, 104 gDebuggee, 105 "1.8", 106 "test.js", 107 1 108 ); 109 }