summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-expressions-watch.js
blob: 5dbf65cde9ae4aa3448497d1fdcc54acd9464cb2 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

/**
 * Test the watch expressions "refresh" button:
 * - hidden when no expression is available
 * - visible with one or more expressions
 * - updates expressions values after clicking on it
 * - disappears when all expressions are removed
 */

add_task(async function() {
  const dbg = await initDebugger("doc-script-switching.html");

  invokeInTab("firstCall");
  await waitForPaused(dbg);

  ok(
    !getRefreshExpressionsElement(dbg),
    "No refresh button is displayed when there are no watch expressions"
  );

  await addExpression(dbg, "someVariable");

  ok(
    getRefreshExpressionsElement(dbg),
    "Refresh button is displayed after adding a watch expression"
  );

  is(getLabel(dbg, 1), "someVariable", "Watch expression was added");
  is(getValue(dbg, 1), "(unavailable)", "Watch expression has no value");

  info("Switch to the console and update the value of the watched variable");
  const { hud } = await dbg.toolbox.selectTool("webconsole");
  await evaluateExpressionInConsole(hud, "var someVariable = 1");

  info("Switch back to the debugger");
  await dbg.toolbox.selectTool("jsdebugger");

  is(getLabel(dbg, 1), "someVariable", "Watch expression is still available");
  is(getValue(dbg, 1), "(unavailable)", "Watch expression still has no value");

  info(
    "Click on the watch expression refresh button and wait for the " +
      "expression to update."
  );
  const refreshed = waitForDispatch(dbg, "EVALUATE_EXPRESSIONS");
  await clickElement(dbg, "expressionRefresh");
  await refreshed;

  is(getLabel(dbg, 1), "someVariable", "Watch expression is still available");
  is(getValue(dbg, 1), "1", "Watch expression value has been updated");

  await deleteExpression(dbg, "someVariable");

  ok(
    !getRefreshExpressionsElement(dbg),
    "The refresh button is no longer displayed after removing watch expressions"
  );
});

function getLabel(dbg, index) {
  return findElement(dbg, "expressionNode", index).innerText;
}

function getValue(dbg, index) {
  return findElement(dbg, "expressionValue", index).innerText;
}

function getRefreshExpressionsElement(dbg) {
  return findElement(dbg, "expressionRefresh", 1);
}