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

PromiseTestUtils.allowMatchingRejectionsGlobally(/Current state is running/);
PromiseTestUtils.allowMatchingRejectionsGlobally(/Connection closed/);

// Test that unusual objects have their contents shown in worker thread scopes.
add_task(async function () {
  const dbg = await initDebugger("doc-worker-scopes.html", "scopes-worker.js");

  await selectSource(dbg, "scopes-worker.js");
  await addBreakpointViaGutter(dbg, 11);
  await dbg.toolbox.target.waitForRequestsToSettle();
  invokeInTab("startWorker");
  await waitForPaused(dbg, "scopes-worker.js");
  await removeBreakpointViaGutter(dbg, 11);
  // We should be paused at the first line of simple-worker.js
  const workerSource2 = dbg.selectors.getSelectedSource();
  assertPausedAtSourceAndLine(dbg, workerSource2.id, 11);

  await toggleNode(dbg, "var_array");
  Assert.equal(findNodeValue(dbg, "0"), '"mango"', "array elem0");
  Assert.equal(findNodeValue(dbg, "1"), '"pamplemousse"', "array elem1");
  Assert.equal(findNodeValue(dbg, "2"), '"pineapple"', "array elem2");
  await toggleNode(dbg, "var_array");

  await toggleNode(dbg, "var_tarray");
  Assert.equal(findNodeValue(dbg, "0"), "42", "tarray elem0");
  Assert.equal(findNodeValue(dbg, "1"), "43", "tarray elem1");
  Assert.equal(findNodeValue(dbg, "2"), "44", "tarray elem2");
  await toggleNode(dbg, "var_tarray");

  await toggleNode(dbg, "var_set");
  await toggleNode(dbg, "<entries>");

  Assert.equal(findNodeValue(dbg, "0"), '"papaya"', "set elem0");
  Assert.equal(findNodeValue(dbg, "1"), '"banana"', "set elem1");
  await toggleNode(dbg, "var_set");

  await toggleNode(dbg, "var_map");
  await toggleNode(dbg, "<entries>");
  await toggleNode(dbg, "0");
  ok(findNodeValue(dbg, "<key>"), "1");
  ok(findNodeValue(dbg, "<value>"), '"one"');
  await toggleNode(dbg, "0");
  await toggleNode(dbg, "1");
  ok(findNodeValue(dbg, "<key>"), "2");
  ok(findNodeValue(dbg, "<value>"), '"two"');
  await toggleNode(dbg, "var_map");

  await toggleNode(dbg, "var_weakmap");
  await toggleNode(dbg, "<entries>");
  await toggleNode(dbg, "0");
  await toggleNode(dbg, "<key>");
  ok(findNodeValue(dbg, "foo"), "foo");
  await toggleNode(dbg, "<value>");
  ok(findNodeValue(dbg, "bar"), "bar");
  await toggleNode(dbg, "var_weakmap");

  await toggleNode(dbg, "var_weakset");
  await toggleNode(dbg, "<entries>");
  await toggleNode(dbg, "0");
  ok(findNodeValue(dbg, "foo"), "foo");
  await toggleNode(dbg, "var_weakset");

  // Close the scopes in order to unmount the reps in order to force spawning
  // the various `release` RDP requests which, otherwise, would happen in
  // middle of the toolbox destruction. Then, wait for them to finish.
  await toggleScopes(dbg);
  await waitForRequestsToSettle(dbg);
});

function findNode(dbg, text) {
  for (let index = 0; ; index++) {
    const elem = findElement(dbg, "scopeNode", index);
    if (elem?.innerText == text) {
      return elem;
    }
  }
}

function toggleNode(dbg, text) {
  return toggleObjectInspectorNode(findNode(dbg, text));
}

function findNodeValue(dbg, text) {
  for (let index = 0; ; index++) {
    const elem = findElement(dbg, "scopeNode", index);
    if (elem?.innerText == text) {
      return getScopeNodeValue(dbg, index);
    }
  }
}

async function removeBreakpointViaGutter(dbg, line) {
  const onRemoved = waitForDispatch(dbg.store, "REMOVE_BREAKPOINT");
  await clickGutter(dbg, line);
  await onRemoved;
}