summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_console_eager_eval_resolve.js
blob: cc2daa33eaf24ac3a445f2a644d7e52782bf31d6 (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
/* 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";

// Check evaluating eager-evaluation values.
const TEST_URI = "data:text/html;charset=utf8,<!DOCTYPE html>";

add_task(async function () {
  await addTab(TEST_URI);

  await pushPref("devtools.chrome.enabled", true);

  info("Open the Browser Console");
  const hud = await BrowserConsoleManager.toggleBrowserConsole();

  await executeResolveHookWithSideEffect(hud);
});

async function executeResolveHookWithSideEffect(hud) {
  // Services.droppedLinkHandler is implemented with resolve hook, which imports
  // ContentAreaDropListener.sys.mjs.
  //
  // In order to test the resolve hook behavior, ensure the module is not yet
  // loaded, which ensures the property is not yet resolved.
  //
  // NOTE: This test is not compatible with verify mode, given it depends on the
  //       initial state of the Services object and the module.
  is(
    Cu.isESModuleLoaded(
      "resource://gre/modules/ContentAreaDropListener.sys.mjs"
    ),
    false
  );

  setInputValue(hud, `Services.droppedLinkHandler`);

  await wait(500);
  // Eager evaluation should fail, due to the side effect in the resolve hook.
  await waitForEagerEvaluationResult(hud, "");

  setInputValue(hud, "");
  await wait(500);

  // The property should be resolved when evaluating after the eager evaluation.
  await executeAndWaitForResultMessage(
    hud,
    `Services.droppedLinkHandler;`,
    "XPCWrappedNative_NoHelper"
  );

  is(
    Cu.isESModuleLoaded(
      "resource://gre/modules/ContentAreaDropListener.sys.mjs"
    ),
    true
  );

  // Eager evaluation should work after the property is resolved.
  setInputValue(hud, `Services.droppedLinkHandler`);
  await wait(500);
  await waitForEagerEvaluationResult(hud, /XPCWrappedNative_NoHelper/);
}