tor-browser

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

browser_console_eager_eval_resolve.js (1957B)


      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 // Check evaluating eager-evaluation values.
      8 const TEST_URI = "data:text/html;charset=utf8,<!DOCTYPE html>";
      9 
     10 add_task(async function () {
     11  await addTab(TEST_URI);
     12 
     13  await pushPref("devtools.chrome.enabled", true);
     14 
     15  info("Open the Browser Console");
     16  const hud = await BrowserConsoleManager.toggleBrowserConsole();
     17 
     18  await executeResolveHookWithSideEffect(hud);
     19 });
     20 
     21 async function executeResolveHookWithSideEffect(hud) {
     22  // Services.droppedLinkHandler is implemented with resolve hook, which imports
     23  // ContentAreaDropListener.sys.mjs.
     24  //
     25  // In order to test the resolve hook behavior, ensure the module is not yet
     26  // loaded, which ensures the property is not yet resolved.
     27  //
     28  // NOTE: This test is not compatible with verify mode, given it depends on the
     29  //       initial state of the Services object and the module.
     30  is(
     31    Cu.isESModuleLoaded(
     32      "resource://gre/modules/ContentAreaDropListener.sys.mjs"
     33    ),
     34    false
     35  );
     36 
     37  setInputValue(hud, `Services.droppedLinkHandler`);
     38 
     39  await wait(500);
     40  // Eager evaluation should fail, due to the side effect in the resolve hook.
     41  await waitForEagerEvaluationResult(hud, "");
     42 
     43  setInputValue(hud, "");
     44  await wait(500);
     45 
     46  // The property should be resolved when evaluating after the eager evaluation.
     47  await executeAndWaitForResultMessage(
     48    hud,
     49    `Services.droppedLinkHandler;`,
     50    "XPCWrappedNative_NoHelper"
     51  );
     52 
     53  is(
     54    Cu.isESModuleLoaded(
     55      "resource://gre/modules/ContentAreaDropListener.sys.mjs"
     56    ),
     57    true
     58  );
     59 
     60  // Eager evaluation should work after the property is resolved.
     61  setInputValue(hud, `Services.droppedLinkHandler`);
     62  await wait(500);
     63  await waitForEagerEvaluationResult(hud, /XPCWrappedNative_NoHelper/);
     64 }