summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-scopes-mutations.js
blob: 7d3f1a777efaea349fe647b530e7940ff350fbc2 (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
/* 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/>. */

"use strict";

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

  const onPaused = waitForPaused(dbg);
  invokeInTab("mutate");
  await onPaused;
  await waitForSelectedSource(dbg, "script-mutate");
  await waitForDispatch(dbg.store, "ADD_INLINE_PREVIEW");

  is(
    getScopeNodeLabel(dbg, 2),
    "<this>",
    'The second element in the scope panel is "<this>"'
  );
  is(
    getScopeNodeLabel(dbg, 4),
    "phonebook",
    'The fourth element in the scope panel is "phonebook"'
  );

  info("Expand `phonebook`");
  await expandNode(dbg, 4);
  is(
    getScopeNodeLabel(dbg, 5),
    "S",
    'The fifth element in the scope panel is "S"'
  );

  info("Expand `S`");
  await expandNode(dbg, 5);
  is(
    getScopeNodeLabel(dbg, 6),
    "sarah",
    'The sixth element in the scope panel is "sarah"'
  );
  is(
    getScopeNodeLabel(dbg, 7),
    "serena",
    'The seventh element in the scope panel is "serena"'
  );

  info("Expand `sarah`");
  await expandNode(dbg, 6);
  is(
    getScopeNodeLabel(dbg, 7),
    "lastName",
    'The seventh element in the scope panel is now "lastName"'
  );
  is(
    getScopeNodeValue(dbg, 7),
    '"Doe"',
    'The "lastName" element has the expected "Doe" value'
  );

  await resume(dbg);
  await waitForPaused(dbg);
  await waitForDispatch(dbg.store, "ADD_INLINE_PREVIEW");

  is(
    getScopeNodeLabel(dbg, 2),
    "<this>",
    'The second element in the scope panel is "<this>"'
  );
  is(
    getScopeNodeLabel(dbg, 4),
    "phonebook",
    'The fourth element in the scope panel is "phonebook"'
  );
});

function expandNode(dbg, index) {
  const node = findElement(dbg, "scopeNode", index);
  const objectInspector = node.closest(".object-inspector");
  const properties = objectInspector.querySelectorAll(".node").length;
  findElement(dbg, "scopeNode", index).click();
  return waitUntil(
    () => objectInspector.querySelectorAll(".node").length !== properties
  );
}