summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_breakpoints-disabled-reload.js
blob: 1caf4994f9a1e4fafb061fb801075bf9595622e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Test that disabled breakpoints survive target navigation.
 */

const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";

function test() {
  let options = {
    source: EXAMPLE_URL + "code_script-switching-01.js",
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    const gPanel = aPanel;
    const gTab = aTab;
    const gDebugger = gPanel.panelWin;
    const gEvents = gDebugger.EVENTS;
    const gEditor = gDebugger.DebuggerView.editor;
    const gSources = gDebugger.DebuggerView.Sources;
    const queries = gDebugger.require("./content/queries");
    const actions = bindActionCreators(gPanel);
    const getState = gDebugger.DebuggerController.getState;
    let gBreakpointLocation;

    Task.spawn(function* () {
      gBreakpointLocation = { actor: getSourceActor(gSources, EXAMPLE_URL + "code_script-switching-01.js"),
                              line: 5 };

      yield actions.addBreakpoint(gBreakpointLocation);

      yield ensureThreadClientState(gPanel, "resumed");
      yield testWhenBreakpointEnabledAndFirstSourceShown();

      gSources._preferredSourceURL = EXAMPLE_URL + "code_script-switching-02.js";
      yield reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN);
      yield testWhenBreakpointEnabledAndSecondSourceShown();

      yield actions.disableBreakpoint(gBreakpointLocation);
      yield reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN);

      yield testWhenBreakpointDisabledAndSecondSourceShown();

      yield actions.enableBreakpoint(gBreakpointLocation);
      yield reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN);
      yield testWhenBreakpointEnabledAndSecondSourceShown();

      yield resumeDebuggerThenCloseAndFinish(gPanel);
    });

    function verifyView({ disabled }) {
      return Task.spawn(function* () {
        // It takes a tick for the checkbox in the SideMenuWidget and the
        // gutter in the editor to get updated.
        yield waitForTick();

        let breakpoint = queries.getBreakpoint(getState(), gBreakpointLocation);
        let breakpointItem = gSources._getBreakpoint(breakpoint);
        is(!!breakpoint.disabled, disabled,
           "The selected breakpoint state was correct.");

        is(breakpointItem.attachment.view.checkbox.hasAttribute("checked"), !disabled,
          "The selected breakpoint's checkbox state was correct.");
      });
    }

    // All the following executeSoon()'s are required to spin the event loop
    // before causing the debuggee to pause, to allow functions to yield first.

    function testWhenBreakpointEnabledAndFirstSourceShown() {
      return Task.spawn(function* () {
        yield ensureSourceIs(gPanel, "-01.js");
        yield verifyView({ disabled: false });

        callInTab(gTab, "firstCall");
        yield waitForDebuggerEvents(gPanel, gEvents.FETCHED_SCOPES);
        yield ensureSourceIs(gPanel, "-01.js");
        yield ensureCaretAt(gPanel, 5);
        yield verifyView({ disabled: false });

        executeSoon(() => gDebugger.gThreadClient.resume());
        yield waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6);
        yield verifyView({ disabled: false });
      });
    }

    function testWhenBreakpointEnabledAndSecondSourceShown() {
      return Task.spawn(function* () {
        yield ensureSourceIs(gPanel, "-02.js", true);
        yield verifyView({ disabled: false });

        callInTab(gTab, "firstCall");
        yield waitForSourceAndCaretAndScopes(gPanel, "-01.js", 1);
        yield verifyView({ disabled: false });

        executeSoon(() => gDebugger.gThreadClient.resume());
        yield waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6);
        yield verifyView({ disabled: false });
      });
    }

    function testWhenBreakpointDisabledAndSecondSourceShown() {
      return Task.spawn(function* () {
        yield ensureSourceIs(gPanel, "-02.js", true);
        yield verifyView({ disabled: true });

        callInTab(gTab, "firstCall");
        yield waitForDebuggerEvents(gPanel, gEvents.FETCHED_SCOPES);
        yield ensureSourceIs(gPanel, "-02.js");
        yield ensureCaretAt(gPanel, 6);
        yield verifyView({ disabled: true });

        executeSoon(() => gDebugger.gThreadClient.resume());
        yield waitForDebuggerEvents(gPanel, gEvents.AFTER_FRAMES_CLEARED);
        yield ensureSourceIs(gPanel, "-02.js");
        yield ensureCaretAt(gPanel, 6);
        yield verifyView({ disabled: true });
      });
    }
  });
}