Bug 1553210 - Implement clearing pending breakpoints and add tests. r=davidwalsh
authorJason Laster <jlaster@mozilla.com>
Fri, 06 Sep 2019 19:10:27 +0000
changeset 492096 1d506ae7fd6b58977586fbe6efa3ef99f1fdbf05
parent 492095 c4bf191d39492aa86e01a403facb0c65ae30c9e9
child 492097 e2dc5bc7d6d157abcc79cc1a4dcbbcf29a5f2656
push id94737
push userjlaster@mozilla.com
push dateFri, 06 Sep 2019 20:27:37 +0000
treeherderautoland@1d506ae7fd6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidwalsh
bugs1553210
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1553210 - Implement clearing pending breakpoints and add tests. r=davidwalsh Differential Revision: https://phabricator.services.mozilla.com/D44295
devtools/client/debugger/src/actions/breakpoints/index.js
devtools/client/debugger/src/actions/breakpoints/tests/breakpoints.spec.js
devtools/client/debugger/src/actions/types/BreakpointAction.js
devtools/client/debugger/src/reducers/breakpoints.js
devtools/client/debugger/src/reducers/pending-breakpoints.js
--- a/devtools/client/debugger/src/actions/breakpoints/index.js
+++ b/devtools/client/debugger/src/actions/breakpoints/index.js
@@ -144,16 +144,18 @@ export function toggleBreakpointsAtLine(
  * Removes all breakpoints
  *
  * @memberof actions/breakpoints
  * @static
  */
 export function removeAllBreakpoints(cx: Context) {
   return async ({ dispatch, getState }: ThunkArgs) => {
     const breakpointList = getBreakpointsList(getState());
+    dispatch({ type: "REMOVE_BREAKPOINTS" });
+
     return Promise.all(
       breakpointList.map(bp => dispatch(removeBreakpoint(cx, bp)))
     );
   };
 }
 
 /**
  * Removes breakpoints
--- a/devtools/client/debugger/src/actions/breakpoints/tests/breakpoints.spec.js
+++ b/devtools/client/debugger/src/actions/breakpoints/tests/breakpoints.spec.js
@@ -8,16 +8,18 @@ import {
   createStore,
   selectors,
   actions,
   makeSource,
   getTelemetryEvents,
 } from "../../../utils/test-head";
 
 import { mockCommandClient } from "../../tests/helpers/mockCommandClient";
+import { mockPendingBreakpoint } from "../../tests/helpers/breakpoints.js";
+import { makePendingLocationId } from "../../../utils/breakpoint";
 
 function mockClient(positionsResponse = {}) {
   return {
     ...mockCommandClient,
     getSourceActorBreakpointPositions: async () => positionsResponse,
     getSourceActorBreakableLines: async () => [],
   };
 }
@@ -297,16 +299,58 @@ describe("breakpoints", () => {
     await dispatch(actions.toggleAllBreakpoints(cx, false));
 
     bp1 = selectors.getBreakpoint(getState(), loc1);
     bp2 = selectors.getBreakpoint(getState(), loc2);
     expect(bp1 && bp1.disabled).toBe(false);
     expect(bp2 && bp2.disabled).toBe(false);
   });
 
+  it("should remove all the breakpoints", async () => {
+    const mockedPendingBreakpoint = mockPendingBreakpoint({ column: 2 });
+    const id = makePendingLocationId(mockedPendingBreakpoint.location);
+    const pendingBreakpoints = { [id]: mockedPendingBreakpoint };
+
+    const { dispatch, getState, cx } = createStore(
+      mockClient({ "5": [1], "6": [2] }),
+      { pendingBreakpoints }
+    );
+
+    const loc1 = {
+      sourceId: "a",
+      line: 5,
+      column: 1,
+      sourceUrl: "http://localhost:8000/examples/a",
+    };
+
+    const loc2 = {
+      sourceId: "b",
+      line: 6,
+      column: 2,
+      sourceUrl: "http://localhost:8000/examples/b",
+    };
+
+    const aSource = await dispatch(actions.newGeneratedSource(makeSource("a")));
+    await dispatch(actions.loadSourceText({ cx, source: aSource }));
+
+    const bSource = await dispatch(actions.newGeneratedSource(makeSource("b")));
+    await dispatch(actions.loadSourceText({ cx, source: bSource }));
+
+    await dispatch(actions.addBreakpoint(cx, loc1));
+    await dispatch(actions.addBreakpoint(cx, loc2));
+
+    await dispatch(actions.removeAllBreakpoints(cx));
+
+    const bps = selectors.getBreakpointsList(getState());
+    const pendingBps = selectors.getPendingBreakpointList(getState());
+
+    expect(bps).toHaveLength(0);
+    expect(pendingBps).toHaveLength(0);
+  });
+
   it("should toggle a breakpoint at a location", async () => {
     const loc = { sourceId: "foo1", line: 5, column: 1 };
     const getBp = () => selectors.getBreakpoint(getState(), loc);
 
     const { dispatch, getState, cx } = createStore(mockClient({ "5": [1] }));
 
     const source = await dispatch(
       actions.newGeneratedSource(makeSource("foo1"))
--- a/devtools/client/debugger/src/actions/types/BreakpointAction.js
+++ b/devtools/client/debugger/src/actions/types/BreakpointAction.js
@@ -46,16 +46,17 @@ export type BreakpointAction =
       +cx: Context,
       +breakpoint: Breakpoint,
     |}>
   | PromiseAction<{|
       +type: "REMOVE_BREAKPOINT",
       +cx: Context,
       +location: SourceLocation,
     |}>
+  | PromiseAction<{| +type: "REMOVE_BREAKPOINTS" |}>
   | {|
       +type: "REMOVE_PENDING_BREAKPOINT",
       +cx: Context,
       +location: PendingLocation,
     |}
   | {|
       type: "ADD_BREAKPOINT_POSITIONS",
       +cx: Context,
--- a/devtools/client/debugger/src/reducers/breakpoints.js
+++ b/devtools/client/debugger/src/reducers/breakpoints.js
@@ -58,16 +58,20 @@ function update(
 
     case "REMOVE_BREAKPOINT": {
       if (action.status === "start") {
         return removeBreakpoint(state, action);
       }
       return state;
     }
 
+    case "REMOVE_BREAKPOINTS": {
+      return { ...state, breakpoints: {} };
+    }
+
     case "NAVIGATE": {
       return initialBreakpointsState(state.xhrBreakpoints);
     }
 
     case "SET_XHR_BREAKPOINT": {
       return addXHRBreakpoint(state, action);
     }
 
--- a/devtools/client/debugger/src/reducers/pending-breakpoints.js
+++ b/devtools/client/debugger/src/reducers/pending-breakpoints.js
@@ -31,16 +31,20 @@ function update(state: PendingBreakpoint
     case "REMOVE_BREAKPOINT":
       if (action.status === "start") {
         return removeBreakpoint(state, action);
       }
       return state;
 
     case "REMOVE_PENDING_BREAKPOINT":
       return removeBreakpoint(state, action);
+
+    case "REMOVE_BREAKPOINTS": {
+      return {};
+    }
   }
 
   return state;
 }
 
 function setBreakpoint(state, { breakpoint }) {
   if (breakpoint.options.hidden) {
     return state;