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

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");
  const workerSource = findSource(dbg, "scopes-worker.js");

  await addBreakpoint(dbg, workerSource, 11);
  await dbg.toolbox.target.waitForRequestsToSettle();
  invokeInTab("startWorker");
  await waitForPaused(dbg, "scopes-worker.js");
  const onRemoved = waitForDispatch(dbg, "REMOVE_BREAKPOINT");
  await removeBreakpoint(dbg, workerSource.id, 11);
  await onRemoved;

  // We should be paused at the first line of simple-worker.js
  assertPausedAtSourceAndLine(dbg, workerSource.id, 11);

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

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

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

  ok(findNodeValue(dbg, "0") == '"papaya"', "set elem0");
  ok(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 findElement(dbg, "scopeValue", index).innerText;
    }
  }
}