michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Test that disabled breakpoints survive target navigation. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: let gDebugger = aPanel.panelWin; michael@0: let gEvents = gDebugger.EVENTS; michael@0: let gEditor = gDebugger.DebuggerView.editor; michael@0: let gSources = gDebugger.DebuggerView.Sources; michael@0: let gBreakpoints = gDebugger.DebuggerController.Breakpoints; michael@0: let gBreakpointLocation = { url: EXAMPLE_URL + "code_script-switching-01.js", line: 5 }; michael@0: michael@0: Task.spawn(function() { michael@0: yield waitForSourceShown(aPanel, "-01.js"); michael@0: yield aPanel.addBreakpoint(gBreakpointLocation); michael@0: michael@0: yield ensureThreadClientState(aPanel, "resumed"); michael@0: yield testWhenBreakpointEnabledAndFirstSourceShown(); michael@0: michael@0: yield reloadActiveTab(aPanel, gEvents.SOURCE_SHOWN); michael@0: yield testWhenBreakpointEnabledAndSecondSourceShown(); michael@0: michael@0: yield gSources.disableBreakpoint(gBreakpointLocation); michael@0: yield reloadActiveTab(aPanel, gEvents.SOURCE_SHOWN); michael@0: yield testWhenBreakpointDisabledAndSecondSourceShown(); michael@0: michael@0: yield gSources.enableBreakpoint(gBreakpointLocation); michael@0: yield reloadActiveTab(aPanel, gEvents.SOURCE_SHOWN); michael@0: yield testWhenBreakpointEnabledAndSecondSourceShown(); michael@0: michael@0: yield resumeDebuggerThenCloseAndFinish(aPanel); michael@0: }); michael@0: michael@0: function verifyView({ disabled, visible }) { michael@0: return Task.spawn(function() { michael@0: // It takes a tick for the checkbox in the SideMenuWidget and the michael@0: // gutter in the editor to get updated. michael@0: yield waitForTick(); michael@0: michael@0: let breakpointItem = gSources.getBreakpoint(gBreakpointLocation); michael@0: let visibleBreakpoints = gEditor.getBreakpoints(); michael@0: is(!!breakpointItem.attachment.disabled, disabled, michael@0: "The selected brekapoint state was correct."); michael@0: is(breakpointItem.attachment.view.checkbox.hasAttribute("checked"), !disabled, michael@0: "The selected brekapoint's checkbox state was correct."); michael@0: michael@0: // Source editor starts counting line and column numbers from 0. michael@0: let breakpointLine = breakpointItem.attachment.line - 1; michael@0: let matchedBreakpoints = visibleBreakpoints.filter(e => e.line == breakpointLine); michael@0: is(!!matchedBreakpoints.length, visible, michael@0: "The selected breakpoint's visibility in the editor was correct."); michael@0: }); michael@0: } michael@0: michael@0: // All the following executeSoon()'s are required to spin the event loop michael@0: // before causing the debuggee to pause, to allow functions to yield first. michael@0: michael@0: function testWhenBreakpointEnabledAndFirstSourceShown() { michael@0: return Task.spawn(function() { michael@0: yield ensureSourceIs(aPanel, "-01.js"); michael@0: yield verifyView({ disabled: false, visible: true }); michael@0: michael@0: executeSoon(() => aDebuggee.firstCall()); michael@0: yield waitForDebuggerEvents(aPanel, gEvents.FETCHED_SCOPES); michael@0: yield ensureSourceIs(aPanel, "-01.js"); michael@0: yield ensureCaretAt(aPanel, 5); michael@0: yield verifyView({ disabled: false, visible: true }); michael@0: michael@0: executeSoon(() => gDebugger.gThreadClient.resume()); michael@0: yield waitForSourceAndCaretAndScopes(aPanel, "-02.js", 1); michael@0: yield verifyView({ disabled: false, visible: false }); michael@0: }); michael@0: } michael@0: michael@0: function testWhenBreakpointEnabledAndSecondSourceShown() { michael@0: return Task.spawn(function() { michael@0: yield ensureSourceIs(aPanel, "-02.js", true); michael@0: yield verifyView({ disabled: false, visible: false }); michael@0: michael@0: executeSoon(() => aDebuggee.firstCall()); michael@0: yield waitForSourceAndCaretAndScopes(aPanel, "-01.js", 1); michael@0: yield verifyView({ disabled: false, visible: true }); michael@0: michael@0: executeSoon(() => gDebugger.gThreadClient.resume()); michael@0: yield waitForSourceAndCaretAndScopes(aPanel, "-02.js", 1); michael@0: yield verifyView({ disabled: false, visible: false }); michael@0: }); michael@0: } michael@0: michael@0: function testWhenBreakpointDisabledAndSecondSourceShown() { michael@0: return Task.spawn(function() { michael@0: yield ensureSourceIs(aPanel, "-02.js", true); michael@0: yield verifyView({ disabled: true, visible: false }); michael@0: michael@0: executeSoon(() => aDebuggee.firstCall()); michael@0: yield waitForDebuggerEvents(aPanel, gEvents.FETCHED_SCOPES); michael@0: yield ensureSourceIs(aPanel, "-02.js"); michael@0: yield ensureCaretAt(aPanel, 1); michael@0: yield verifyView({ disabled: true, visible: false }); michael@0: michael@0: executeSoon(() => gDebugger.gThreadClient.resume()); michael@0: yield waitForDebuggerEvents(aPanel, gEvents.AFTER_FRAMES_CLEARED); michael@0: yield ensureSourceIs(aPanel, "-02.js"); michael@0: yield ensureCaretAt(aPanel, 1); michael@0: yield verifyView({ disabled: true, visible: false }); michael@0: }); michael@0: } michael@0: }); michael@0: }