summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_breakpoints-condition-thrown-message.js
blob: cefd429d278fe20dba14d3e3ea2ee0eee1da1e68 (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
/* -*- 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/ */

/**
 * Make sure that the message which breakpoint condition throws
 * could be displayed on UI correctly
 */

const TAB_URL = EXAMPLE_URL + "doc_conditional-breakpoints.html";

function test() {
  let options = {
    source: TAB_URL,
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    const gTab = aTab;
    const gPanel = aPanel;
    const gDebugger = gPanel.panelWin;
    const gEditor = gDebugger.DebuggerView.editor;
    const gSources = gDebugger.DebuggerView.Sources;
    const actions = bindActionCreators(gPanel);
    const getState = gDebugger.DebuggerController.getState;

    function initialCheck(aCaretLine) {
      let bp = gDebugger.queries.getBreakpoint(getState(),
                                               { actor: gSources.values[0], line: aCaretLine });
      ok(bp, "There should be a breakpoint on line " + aCaretLine);

      let attachment = gSources._getBreakpoint(bp).attachment;
      ok(attachment,
         "There should be a breakpoint on line " + aCaretLine + " in the sources pane.");

      let thrownNode = attachment.view.container.querySelector(".dbg-breakpoint-condition-thrown-message");
      ok(thrownNode,
         "The breakpoint item should contain a thrown message node.");

      ok(!attachment.view.container.classList.contains("dbg-breakpoint-condition-thrown"),
         "The thrown message on line " + aCaretLine + " should be hidden when condition has not been evaluated.");
    }

    function resumeAndTestThrownMessage(line) {
      doResume(gPanel);

      return waitForCaretUpdated(gPanel, line).then(() => {
        // Test that the thrown message is correctly shown.
        let bp = gDebugger.queries.getBreakpoint(
          getState(),
          { actor: gSources.values[0], line: line }
        );
        let attachment = gSources._getBreakpoint(bp).attachment;
        ok(attachment.view.container.classList.contains("dbg-breakpoint-condition-thrown"),
           "Message on line " + line + " should be shown when condition throws.");
      });
    }

    function resumeAndTestNoThrownMessage(line) {
      doResume(gPanel);

      return waitForCaretUpdated(gPanel, line).then(() => {
        // test that the thrown message is correctly shown
        let bp = gDebugger.queries.getBreakpoint(
          getState(),
          { actor: gSources.values[0], line: line }
        );
        let attachment = gSources._getBreakpoint(bp).attachment;
        ok(!attachment.view.container.classList.contains("dbg-breakpoint-condition-thrown"),
           "Message on line " + line + " should be hidden if condition doesn't throw.");
      });
    }

    Task.spawn(function* () {
      let onCaretUpdated = waitForCaretAndScopes(gPanel, 17);
      callInTab(gTab, "ermahgerd");
      yield onCaretUpdated;

      yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 18 }, " 1afff");
      // Close the popup because a SET_BREAKPOINT_CONDITION action is
      // fired when it's closed, and it sets it on the currently
      // selected breakpoint and we want to make sure it uses the
      // current breakpoint. This isn't a problem outside of tests
      // because any UI interaction will close the popup before the
      // new breakpoint is added.
      gSources._hideConditionalPopup();
      initialCheck(18);

      yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 19 }, "true");
      gSources._hideConditionalPopup();
      initialCheck(19);

      yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 20 }, "false");
      gSources._hideConditionalPopup();
      initialCheck(20);

      yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 22 }, "randomVar");
      gSources._hideConditionalPopup();
      initialCheck(22);

      yield resumeAndTestThrownMessage(18);
      yield resumeAndTestNoThrownMessage(19);
      yield resumeAndTestThrownMessage(22);
      resumeDebuggerThenCloseAndFinish(gPanel);
    });
  });
}