tor-browser

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

browser_console_jsterm_await.js (1424B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // This is a lightweight version of browser_jsterm_await.js to only ensure top-level await
      5 // support in the Browser Console.
      6 
      7 "use strict";
      8 
      9 const TEST_URI =
     10  "data:text/html;charset=utf-8,<!DOCTYPE html>Top-level await Browser Console test";
     11 
     12 add_task(async function () {
     13  // Needed for the execute() function below
     14  await pushPref("security.allow_parent_unrestricted_js_loads", true);
     15  // Enable await mapping.
     16  await pushPref("devtools.debugger.features.map-await-expression", true);
     17 
     18  await addTab(TEST_URI);
     19  const hud = await BrowserConsoleManager.toggleBrowserConsole();
     20 
     21  info("Evaluate a top-level await expression");
     22  const simpleAwait = `await new Promise(r => setTimeout(() => r(["await1"]), 500))`;
     23  await executeAndWaitForResultMessage(hud, simpleAwait, `Array [ "await1" ]`);
     24 
     25  // Check that the resulting promise of the async iife is not displayed.
     26  const messages = hud.ui.outputNode.querySelectorAll(".message .message-body");
     27  const messagesText = Array.from(messages)
     28    .map(n => n.textContent)
     29    .join(" - ");
     30  is(
     31    messagesText.includes("Promise {"),
     32    false,
     33    "The output does not contain a Promise"
     34  );
     35  ok(
     36    messagesText.includes(simpleAwait) &&
     37      messagesText.includes(`Array [ "await1" ]`),
     38    "The output contains the the expected messages"
     39  );
     40 });