browser_dbg-breakpoints-cond-functional.js (2680B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 "use strict"; 6 7 // This test focuses on verifying that the conditional breakpoint are trigerred. 8 9 add_task(async function () { 10 const dbg = await initDebugger("doc-scripts.html", "simple2.js"); 11 12 await selectSource(dbg, "simple2.js"); 13 14 info("Set condition `x === 1` in the foo function, and pause"); 15 await setConditionalBreakpoint(dbg, 5, "x === 1"); 16 17 invokeInTab("foo", /* x */ 1); 18 await waitForPaused(dbg); 19 ok(true, "Conditional breakpoint was hit"); 20 await resume(dbg); 21 22 await removeBreakpoint(dbg, findSource(dbg, "simple2.js").id, 5); 23 24 info("Set condition `x === 2` in the foo function, and do not pause"); 25 await setConditionalBreakpoint(dbg, 5, "x == 2"); 26 27 invokeInTab("foo", /* x */ 1); 28 // Let some time for a leftover breakpoint to be hit 29 await wait(500); 30 assertNotPaused(dbg); 31 32 await removeBreakpoint(dbg, findSource(dbg, "simple2.js").id, 5); 33 34 info("Set condition `foo(` (syntax error), and pause on the exception"); 35 await setConditionalBreakpoint(dbg, 5, "foo("); 36 37 invokeInTab("main"); 38 await waitForPaused(dbg); 39 let whyPaused = dbg.win.document.querySelector(".why-paused").innerText; 40 is( 41 whyPaused, 42 "Error with conditional breakpoint\nfoo - simple2.js:5:2\nexpected expression, got end of script" 43 ); 44 await resume(dbg); 45 assertNotPaused(dbg); 46 47 info( 48 "Retrigger the same breakpoint with pause on exception enabled and ensure it still reports the exception and only once" 49 ); 50 await togglePauseOnExceptions(dbg, true, false); 51 52 invokeInTab("main"); 53 await waitForPaused(dbg); 54 whyPaused = dbg.win.document.querySelector(".why-paused").innerText; 55 is( 56 whyPaused, 57 "Error with conditional breakpoint\nfoo - simple2.js:5:2\nexpected expression, got end of script" 58 ); 59 await resume(dbg); 60 61 // Let some time for a duplicated breakpoint to be hit 62 await wait(500); 63 assertNotPaused(dbg); 64 65 await removeBreakpoint(dbg, findSource(dbg, "simple2.js").id, 5); 66 }); 67 68 async function setConditionalBreakpoint(dbg, index, condition) { 69 // Make this work with either add or edit menu items 70 const { addConditionItem, editConditionItem } = selectors; 71 const selector = `${addConditionItem},${editConditionItem}`; 72 rightClickElement(dbg, "gutterElement", index); 73 await waitForContextMenu(dbg); 74 selectContextMenuItem(dbg, selector); 75 const dispatched = waitForDispatch(dbg.store, "SET_BREAKPOINT"); 76 typeInPanel(dbg, condition); 77 await dispatched; 78 await waitForCondition(dbg, condition); 79 }