tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_dbg-worker-scopes.js (3467B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 "use strict";
      6 
      7 PromiseTestUtils.allowMatchingRejectionsGlobally(/Current state is running/);
      8 PromiseTestUtils.allowMatchingRejectionsGlobally(/Connection closed/);
      9 
     10 // Test that unusual objects have their contents shown in worker thread scopes.
     11 add_task(async function () {
     12  const dbg = await initDebugger("doc-worker-scopes.html", "scopes-worker.js");
     13 
     14  await selectSource(dbg, "scopes-worker.js");
     15  await addBreakpointViaGutter(dbg, 11);
     16  await dbg.toolbox.target.waitForRequestsToSettle();
     17  invokeInTab("startWorker");
     18  await waitForPaused(dbg, "scopes-worker.js");
     19  await removeBreakpointViaGutter(dbg, 11);
     20  // We should be paused at the first line of simple-worker.js
     21  const workerSource2 = dbg.selectors.getSelectedSource();
     22  await assertPausedAtSourceAndLine(dbg, workerSource2.id, 11);
     23 
     24  await toggleNode(dbg, "var_array");
     25  Assert.equal(findNodeValue(dbg, "0"), '"mango"', "array elem0");
     26  Assert.equal(findNodeValue(dbg, "1"), '"pamplemousse"', "array elem1");
     27  Assert.equal(findNodeValue(dbg, "2"), '"pineapple"', "array elem2");
     28  await toggleNode(dbg, "var_array");
     29 
     30  await toggleNode(dbg, "var_tarray");
     31  Assert.equal(findNodeValue(dbg, "0"), "42", "tarray elem0");
     32  Assert.equal(findNodeValue(dbg, "1"), "43", "tarray elem1");
     33  Assert.equal(findNodeValue(dbg, "2"), "44", "tarray elem2");
     34  await toggleNode(dbg, "var_tarray");
     35 
     36  await toggleNode(dbg, "var_set");
     37  await toggleNode(dbg, "<entries>");
     38 
     39  Assert.equal(findNodeValue(dbg, "0"), '"papaya"', "set elem0");
     40  Assert.equal(findNodeValue(dbg, "1"), '"banana"', "set elem1");
     41  await toggleNode(dbg, "var_set");
     42 
     43  await toggleNode(dbg, "var_map");
     44  await toggleNode(dbg, "<entries>");
     45  await toggleNode(dbg, "0");
     46  ok(findNodeValue(dbg, "<key>"), "1");
     47  ok(findNodeValue(dbg, "<value>"), '"one"');
     48  await toggleNode(dbg, "0");
     49  await toggleNode(dbg, "1");
     50  ok(findNodeValue(dbg, "<key>"), "2");
     51  ok(findNodeValue(dbg, "<value>"), '"two"');
     52  await toggleNode(dbg, "var_map");
     53 
     54  await toggleNode(dbg, "var_weakmap");
     55  await toggleNode(dbg, "<entries>");
     56  await toggleNode(dbg, "0");
     57  await toggleNode(dbg, "<key>");
     58  ok(findNodeValue(dbg, "foo"), "foo");
     59  await toggleNode(dbg, "<value>");
     60  ok(findNodeValue(dbg, "bar"), "bar");
     61  await toggleNode(dbg, "var_weakmap");
     62 
     63  await toggleNode(dbg, "var_weakset");
     64  await toggleNode(dbg, "<entries>");
     65  await toggleNode(dbg, "0");
     66  ok(findNodeValue(dbg, "foo"), "foo");
     67  await toggleNode(dbg, "var_weakset");
     68 
     69  // Close the scopes in order to unmount the reps in order to force spawning
     70  // the various `release` RDP requests which, otherwise, would happen in
     71  // middle of the toolbox destruction. Then, wait for them to finish.
     72  await toggleScopes(dbg);
     73  await waitForRequestsToSettle(dbg);
     74 });
     75 
     76 function findNode(dbg, text) {
     77  for (let index = 0; ; index++) {
     78    const elem = findElement(dbg, "scopeNode", index);
     79    if (elem?.innerText == text) {
     80      return elem;
     81    }
     82  }
     83 }
     84 
     85 function toggleNode(dbg, text) {
     86  return toggleObjectInspectorNode(findNode(dbg, text));
     87 }
     88 
     89 function findNodeValue(dbg, text) {
     90  for (let index = 0; ; index++) {
     91    const elem = findElement(dbg, "scopeNode", index);
     92    if (elem?.innerText == text) {
     93      return getScopeNodeValue(dbg, index);
     94    }
     95  }
     96 }