browser_dbg-breakpoints-cond-ui-state.js (6283B)
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 the UI interaction and doesn't assert that the breakpoints actually works 8 9 add_task(async function () { 10 const dbg = await initDebugger("doc-scripts.html", "simple2.js"); 11 12 await selectSource(dbg, "simple2.js"); 13 await waitForSelectedSource(dbg, "simple2.js"); 14 15 info("Set condition `1`"); 16 await setConditionalBreakpoint(dbg, 5, "1"); 17 await waitForCondition(dbg, 1); 18 19 let bp = findBreakpoint(dbg, "simple2.js", 5); 20 is(bp.options.condition, "1", "breakpoint is created with the condition"); 21 await assertConditionBreakpoint(dbg, 5); 22 23 info("Edit the conditional breakpoint set above"); 24 await setConditionalBreakpoint(dbg, 5, "2"); 25 await waitForCondition(dbg, 12); 26 27 bp = findBreakpoint(dbg, "simple2.js", 5); 28 is(bp.options.condition, "12", "breakpoint is created with the condition"); 29 await assertConditionBreakpoint(dbg, 5); 30 31 info("Hit 'Enter' when the cursor is in the conditional statement"); 32 rightClickElement(dbg, "gutterElement", 5); 33 await waitForContextMenu(dbg); 34 selectContextMenuItem(dbg, `${selectors.editConditionItem}`); 35 await waitForConditionalPanelFocus(dbg); 36 pressKey(dbg, "Left"); 37 pressKey(dbg, "Enter"); 38 await waitForCondition(dbg, 12); 39 40 bp = findBreakpoint(dbg, "simple2.js", 5); 41 is(bp.options.condition, "12", "Hit 'Enter' doesn't add a new line"); 42 43 info("Hit 'Shift+Enter' when the cursor is in the conditional statement"); 44 rightClickElement(dbg, "gutterElement", 5); 45 await waitForContextMenu(dbg); 46 selectContextMenuItem(dbg, `${selectors.editConditionItem}`); 47 await waitForConditionalPanelFocus(dbg); 48 // The whole text is selected, hit Right key to get to the end of the input 49 pressKey(dbg, "Right"); 50 // Move one char left to put the cursor between 1 and 2 51 pressKey(dbg, "Left"); 52 // Insert a new line 53 pressKey(dbg, "ShiftEnter"); 54 // And validate 55 pressKey(dbg, "Enter"); 56 await waitForCondition(dbg, "1\n 2"); 57 58 bp = findBreakpoint(dbg, "simple2.js", 5); 59 is(bp.options.condition, "1\n 2", "Hit 'Shift+Enter' adds a new line"); 60 61 info("The condition can be removed using the ConditionalPanel"); 62 dblClickElement(dbg, "conditionalBreakpointInSecPane"); 63 await waitForConditionalPanelFocus(dbg); 64 pressKey(dbg, "Backspace"); 65 pressKey(dbg, "Enter"); 66 bp = findBreakpoint(dbg, "simple2.js", 5); 67 is(bp.options.condition, null, "The condition was removed"); 68 69 clickElement(dbg, "gutterElement", 5); 70 await waitForDispatch(dbg.store, "REMOVE_BREAKPOINT"); 71 bp = findBreakpoint(dbg, "simple2.js", 5); 72 is(bp, undefined, "breakpoint was removed"); 73 await assertNoBreakpoint(dbg, 5); 74 75 info("Adding a condition to a breakpoint"); 76 clickElement(dbg, "gutterElement", 5); 77 await waitForDispatch(dbg.store, "SET_BREAKPOINT"); 78 await setConditionalBreakpoint(dbg, 5, "1"); 79 await waitForCondition(dbg, 1); 80 81 bp = findBreakpoint(dbg, "simple2.js", 5); 82 is(bp.options.condition, "1", "breakpoint is created with the condition"); 83 await assertConditionBreakpoint(dbg, 5); 84 85 info("Double click the conditional breakpoint in secondary pane"); 86 dblClickElement(dbg, "conditionalBreakpointInSecPane"); 87 assertConditonalBreakpointPanelFocus(dbg, {}); 88 89 info("Click the conditional breakpoint in secondary pane"); 90 await clickElement(dbg, "conditionalBreakpointInSecPane"); 91 const conditonalPanel = findElement(dbg, "conditionalPanel"); 92 is(conditonalPanel, null, "The conditional breakpoint panel is closed"); 93 94 rightClickElement(dbg, "breakpointItem", 2); 95 await waitForContextMenu(dbg); 96 info('select "remove condition"'); 97 selectContextMenuItem(dbg, selectors.breakpointContextMenu.removeCondition); 98 await waitForBreakpointWithoutCondition(dbg, "simple2.js", 5); 99 bp = findBreakpoint(dbg, "simple2.js", 5); 100 is(bp.options.condition, null, "breakpoint condition removed"); 101 102 info('Add "log point"'); 103 await setLogPoint(dbg, 5, "44"); 104 await waitForLog(dbg, 44); 105 await assertLogBreakpoint(dbg, 5); 106 107 bp = findBreakpoint(dbg, "simple2.js", 5); 108 is(bp.options.logValue, "44", "breakpoint condition removed"); 109 110 await altClickElement(dbg, "gutterElement", 6); 111 bp = await waitForBreakpoint(dbg, "simple2.js", 6); 112 is(bp.options.logValue, "displayName", "logPoint has default value"); 113 114 info("Double click the logpoint in secondary pane"); 115 dblClickElement(dbg, "logPointInSecPane"); 116 assertConditonalBreakpointPanelFocus(dbg, { isLogPoint: true }); 117 118 info("Click the logpoint in secondary pane"); 119 await clickElement(dbg, "logPointInSecPane"); 120 const logPointPanel = findElement(dbg, "logPointPanel"); 121 is(logPointPanel, null, "The logpoint panel is closed"); 122 await waitForSelectedLocation(dbg, 5, 3); 123 124 info("The log value can be removed using the ConditionalPanel"); 125 dblClickElement(dbg, "logPointInSecPane"); 126 await waitForConditionalPanelFocus(dbg); 127 pressKey(dbg, "Backspace"); 128 pressKey(dbg, "Space"); 129 pressKey(dbg, "Enter"); 130 bp = findBreakpoint(dbg, "simple2.js", 5); 131 is(bp.options.logValue, null, "The log value was removed"); 132 }); 133 134 function waitForBreakpointWithoutCondition(dbg, url, line) { 135 return waitForState(dbg, () => { 136 const bp = findBreakpoint(dbg, url, line); 137 return bp && !bp.options.condition; 138 }); 139 } 140 141 async function setConditionalBreakpoint(dbg, index, condition) { 142 // Make this work with either add or edit menu items 143 const { addConditionItem, editConditionItem } = selectors; 144 const selector = `${addConditionItem},${editConditionItem}`; 145 rightClickElement(dbg, "gutterElement", index); 146 await waitForContextMenu(dbg); 147 selectContextMenuItem(dbg, selector); 148 typeInPanel(dbg, condition); 149 } 150 151 function assertConditonalBreakpointPanelFocus(dbg, { isLogPoint = false }) { 152 const focusedElement = dbg.win.document.activeElement; 153 const isPanelFocused = 154 focusedElement.classList.contains("cm-content") && 155 focusedElement.closest( 156 `.conditional-breakpoint-panel${isLogPoint ? ".log-point" : ""}` 157 ); 158 ok( 159 isPanelFocused, 160 `The content element of ${ 161 isLogPoint ? "log point" : "conditional breakpoint" 162 } panel is focused` 163 ); 164 }