test_breakpoint-17.js (3330B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 /* eslint-disable no-shadow */ 4 5 "use strict"; 6 7 /** 8 * Test that when we add 2 breakpoints to the same line at different columns and 9 * then remove one of them, we don't remove them both. 10 */ 11 12 const code = 13 "(" + 14 function (global) { 15 global.foo = function () { 16 Math.abs(-1); 17 Math.log(0.5); 18 debugger; 19 }; 20 debugger; 21 } + 22 "(this))"; 23 24 const firstLocation = { 25 line: 3, 26 column: 4, 27 }; 28 29 const secondLocation = { 30 line: 3, 31 column: 18, 32 }; 33 34 add_task( 35 threadFrontTest(({ threadFront, debuggee }) => { 36 return new Promise(resolve => { 37 threadFront.on("paused", async packet => { 38 const [first, second] = await set_breakpoints(packet, threadFront); 39 test_different_actors(first, second); 40 await test_remove_one(first, second, threadFront, debuggee); 41 resolve(); 42 }); 43 44 Cu.evalInSandbox(code, debuggee, "1.8", "http://example.com/", 1); 45 }); 46 }) 47 ); 48 49 async function set_breakpoints(packet, threadFront) { 50 const source = await getSourceById(threadFront, packet.frame.where.actor); 51 return new Promise(resolve => { 52 let first, second; 53 54 source.setBreakpoint(firstLocation).then(function ([ 55 { actualLocation }, 56 breakpointClient, 57 ]) { 58 Assert.ok(!actualLocation, "Should not get an actualLocation"); 59 first = breakpointClient; 60 61 source.setBreakpoint(secondLocation).then(function ([ 62 { actualLocation }, 63 breakpointClient, 64 ]) { 65 Assert.ok(!actualLocation, "Should not get an actualLocation"); 66 second = breakpointClient; 67 68 resolve([first, second]); 69 }); 70 }); 71 }); 72 } 73 74 function test_different_actors(first, second) { 75 Assert.notEqual( 76 first.actor, 77 second.actor, 78 "Each breakpoint should have a different actor" 79 ); 80 } 81 82 function test_remove_one(first, second, threadFront, debuggee) { 83 return new Promise(resolve => { 84 first.remove(function ({ error }) { 85 Assert.ok(!error, "Should not get an error removing a breakpoint"); 86 87 let hitSecond; 88 threadFront.on("paused", function _onPaused({ why, frame }) { 89 if (why.type == "breakpoint") { 90 hitSecond = true; 91 Assert.equal( 92 why.actors.length, 93 1, 94 "Should only be paused because of one breakpoint actor" 95 ); 96 Assert.equal( 97 why.actors[0], 98 second.actor, 99 "Should be paused because of the correct breakpoint actor" 100 ); 101 Assert.equal( 102 frame.where.line, 103 secondLocation.line, 104 "Should be at the right line" 105 ); 106 Assert.equal( 107 frame.where.column, 108 secondLocation.column, 109 "Should be at the right column" 110 ); 111 threadFront.resume(); 112 return; 113 } 114 115 if (why.type == "debuggerStatement") { 116 threadFront.off("paused", _onPaused); 117 Assert.ok( 118 hitSecond, 119 "We should still hit `second`, but not `first`." 120 ); 121 122 resolve(); 123 return; 124 } 125 126 Assert.ok(false, "Should never get here"); 127 }); 128 129 threadFront.resume().then(() => debuggee.foo()); 130 }); 131 }); 132 }