summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_watch-expressions-01.js
blob: fe55a55613c252f4cc4f96e1a149b57b54fd6f48 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* -*- 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/ */

/**
 * Bug 727429: Test the debugger watch expressions.
 */

const TAB_URL = EXAMPLE_URL + "doc_watch-expressions.html";

function test() {
  // Debug test slaves are a bit slow at this test.
  requestLongerTimeout(2);

  let gTab, gPanel, gDebugger;
  let gEditor, gWatch, gVariables;

  let options = {
    source: TAB_URL,
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    gTab = aTab;
    gPanel = aPanel;
    gDebugger = gPanel.panelWin;
    gEditor = gDebugger.DebuggerView.editor;
    gWatch = gDebugger.DebuggerView.WatchExpressions;
    gVariables = gDebugger.DebuggerView.Variables;

    gDebugger.DebuggerView.toggleInstrumentsPane({ visible: true, animated: false });

    performTest();
    closeDebuggerAndFinish(gPanel);
  });

  function performTest() {
    is(gWatch.getAllStrings().length, 0,
      "There should initially be no watch expressions.");

    addAndCheckExpressions(1, 0, "a");
    addAndCheckExpressions(2, 0, "b");
    addAndCheckExpressions(3, 0, "c");

    removeAndCheckExpression(2, 1, "a");
    removeAndCheckExpression(1, 0, "a");

    addAndCheckExpressions(2, 0, "", true);
    gEditor.focus();
    is(gWatch.getAllStrings().length, 1,
      "Empty watch expressions are automatically removed.");

    addAndCheckExpressions(2, 0, "a", true);
    gEditor.focus();
    is(gWatch.getAllStrings().length, 1,
      "Duplicate watch expressions are automatically removed.");

    addAndCheckExpressions(2, 0, "a\t", true);
    addAndCheckExpressions(2, 0, "a\r", true);
    addAndCheckExpressions(2, 0, "a\n", true);
    gEditor.focus();
    is(gWatch.getAllStrings().length, 1,
      "Duplicate watch expressions are automatically removed.");

    addAndCheckExpressions(2, 0, "\ta", true);
    addAndCheckExpressions(2, 0, "\ra", true);
    addAndCheckExpressions(2, 0, "\na", true);
    gEditor.focus();
    is(gWatch.getAllStrings().length, 1,
      "Duplicate watch expressions are automatically removed.");

    addAndCheckCustomExpression(2, 0, "bazΩΩka");
    addAndCheckCustomExpression(3, 0, "bambøøcha");

    EventUtils.sendMouseEvent({ type: "click" },
      gWatch.getItemAtIndex(0).attachment.view.closeNode,
      gDebugger);

    is(gWatch.getAllStrings().length, 2,
      "Watch expressions are removed when the close button is pressed.");
    is(gWatch.getAllStrings()[0], "bazΩΩka",
      "The expression at index " + 0 + " should be correct (1).");
    is(gWatch.getAllStrings()[1], "a",
      "The expression at index " + 1 + " should be correct (2).");

    EventUtils.sendMouseEvent({ type: "click" },
      gWatch.getItemAtIndex(0).attachment.view.closeNode,
      gDebugger);

    is(gWatch.getAllStrings().length, 1,
      "Watch expressions are removed when the close button is pressed.");
    is(gWatch.getAllStrings()[0], "a",
      "The expression at index " + 0 + " should be correct (3).");

    EventUtils.sendMouseEvent({ type: "click" },
      gWatch.getItemAtIndex(0).attachment.view.closeNode,
      gDebugger);

    is(gWatch.getAllStrings().length, 0,
      "Watch expressions are removed when the close button is pressed.");

    EventUtils.sendMouseEvent({ type: "click" },
      gWatch.widget._parent,
      gDebugger);

    is(gWatch.getAllStrings().length, 1,
      "Watch expressions are added when the view container is pressed.");
  }

  function addAndCheckCustomExpression(aTotal, aIndex, aString, noBlur) {
    addAndCheckExpressions(aTotal, aIndex, "", true);

    EventUtils.sendString(aString, gDebugger);

    gEditor.focus();

    let element = gWatch.getItemAtIndex(aIndex).target;

    is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, "",
      "The initial expression at index " + aIndex + " should be correct (1).");
    is(gWatch.getItemForElement(element).attachment.initialExpression, "",
      "The initial expression at index " + aIndex + " should be correct (2).");

    is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString,
      "The expression at index " + aIndex + " should be correct (1).");
    is(gWatch.getItemForElement(element).attachment.currentExpression, aString,
      "The expression at index " + aIndex + " should be correct (2).");

    is(gWatch.getString(aIndex), aString,
      "The expression at index " + aIndex + " should be correct (3).");
    is(gWatch.getAllStrings()[aIndex], aString,
      "The expression at index " + aIndex + " should be correct (4).");
  }

  function addAndCheckExpressions(aTotal, aIndex, aString, noBlur) {
    gWatch.addExpression(aString);

    is(gWatch.getAllStrings().length, aTotal,
      "There should be " + aTotal + " watch expressions available (1).");
    is(gWatch.itemCount, aTotal,
      "There should be " + aTotal + " watch expressions available (2).");

    ok(gWatch.getItemAtIndex(aIndex),
      "The expression at index " + aIndex + " should be available.");
    is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
      "The expression at index " + aIndex + " should have an initial expression.");

    let element = gWatch.getItemAtIndex(aIndex).target;

    ok(element,
      "There should be a new expression item in the view.");
    ok(gWatch.getItemForElement(element),
      "The watch expression item should be accessible.");
    is(gWatch.getItemForElement(element), gWatch.getItemAtIndex(aIndex),
      "The correct watch expression item was accessed.");

    ok(gWatch.widget.getItemAtIndex(aIndex) instanceof XULElement,
      "The correct watch expression element was accessed (1).");
    is(element, gWatch.widget.getItemAtIndex(aIndex),
      "The correct watch expression element was accessed (2).");

    is(gWatch.getItemForElement(element).attachment.view.arrowNode.hidden, false,
      "The arrow node should be visible.");
    is(gWatch.getItemForElement(element).attachment.view.closeNode.hidden, false,
      "The close button should be visible.");
    is(gWatch.getItemForElement(element).attachment.view.inputNode.getAttribute("focused"), "true",
      "The textbox input should be focused.");

    is(gVariables.parentNode.scrollTop, 0,
      "The variables view should be scrolled to top");

    is(gWatch.items[0], gWatch.getItemAtIndex(aIndex),
      "The correct watch expression was added to the cache (1).");
    is(gWatch.items[0], gWatch.getItemForElement(element),
      "The correct watch expression was added to the cache (2).");

    if (!noBlur) {
      gEditor.focus();

      is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
        "The initial expression at index " + aIndex + " should be correct (1).");
      is(gWatch.getItemForElement(element).attachment.initialExpression, aString,
        "The initial expression at index " + aIndex + " should be correct (2).");

      is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString,
        "The expression at index " + aIndex + " should be correct (1).");
      is(gWatch.getItemForElement(element).attachment.currentExpression, aString,
        "The expression at index " + aIndex + " should be correct (2).");

      is(gWatch.getString(aIndex), aString,
        "The expression at index " + aIndex + " should be correct (3).");
      is(gWatch.getAllStrings()[aIndex], aString,
        "The expression at index " + aIndex + " should be correct (4).");
    }
  }

  function removeAndCheckExpression(aTotal, aIndex, aString) {
    gWatch.removeAt(aIndex);

    is(gWatch.getAllStrings().length, aTotal,
      "There should be " + aTotal + " watch expressions available (1).");
    is(gWatch.itemCount, aTotal,
      "There should be " + aTotal + " watch expressions available (2).");

    ok(gWatch.getItemAtIndex(aIndex),
      "The expression at index " + aIndex + " should still be available.");
    is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
      "The expression at index " + aIndex + " should still have an initial expression.");

    let element = gWatch.getItemAtIndex(aIndex).target;

    is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
      "The initial expression at index " + aIndex + " should be correct (1).");
    is(gWatch.getItemForElement(element).attachment.initialExpression, aString,
      "The initial expression at index " + aIndex + " should be correct (2).");

    is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString,
      "The expression at index " + aIndex + " should be correct (1).");
    is(gWatch.getItemForElement(element).attachment.currentExpression, aString,
      "The expression at index " + aIndex + " should be correct (2).");

    is(gWatch.getString(aIndex), aString,
      "The expression at index " + aIndex + " should be correct (3).");
    is(gWatch.getAllStrings()[aIndex], aString,
      "The expression at index " + aIndex + " should be correct (4).");
  }
}