tor-browser

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

browser_webconsole_eval_in_debugger_stackframe.js (3635B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that makes sure web console eval happens in the user-selected stackframe
      5 // from the js debugger.
      6 
      7 "use strict";
      8 
      9 const TEST_URI =
     10  "http://example.com/browser/devtools/client/webconsole/" +
     11  "test/browser/test-eval-in-stackframe.html";
     12 
     13 add_task(async function () {
     14  // TODO: Remove this pref change when middleware for terminating requests
     15  // when closing a panel is implemented
     16  await pushPref("devtools.debugger.features.inline-preview", false);
     17 
     18  info("open the console");
     19  const hud = await openNewTabAndConsole(TEST_URI);
     20 
     21  info("Check `foo` value");
     22  await executeAndWaitForResultMessage(hud, "foo", "globalFooBug783499");
     23  ok(true, "|foo| value is correct");
     24 
     25  info("Assign and check `foo2` value");
     26  await executeAndWaitForResultMessage(
     27    hud,
     28    "foo2 = 'newFoo'; window.foo2",
     29    "newFoo"
     30  );
     31  ok(true, "'newFoo' is displayed after adding `foo2`");
     32 
     33  info("Open the debugger and then select the console again");
     34  await openDebugger();
     35  const toolbox = hud.toolbox;
     36  const dbg = createDebuggerContext(toolbox);
     37 
     38  await openConsole();
     39 
     40  info("Check `foo + foo2` value");
     41  await executeAndWaitForResultMessage(
     42    hud,
     43    "foo + foo2",
     44    "globalFooBug783499newFoo"
     45  );
     46 
     47  info("Select the debugger again");
     48  await openDebugger();
     49  await pauseDebugger(dbg, { shouldWaitForInlinePreviews: false });
     50 
     51  const stackFrames = dbg.selectors.getCurrentThreadFrames();
     52 
     53  info("frames added, select the console again");
     54  await openConsole();
     55 
     56  info("Check `foo + foo2` value when paused");
     57  await executeAndWaitForResultMessage(
     58    hud,
     59    "foo + foo2",
     60    "globalFooBug783499foo2SecondCall"
     61  );
     62  ok(true, "`foo + foo2` from `secondCall()`");
     63 
     64  info("select the debugger and select the frame (1)");
     65  await openDebugger();
     66 
     67  await selectFrame(dbg, stackFrames[1]);
     68 
     69  await openConsole();
     70 
     71  info("Check `foo + foo2 + foo3` value when paused on a given frame");
     72  await executeAndWaitForResultMessage(
     73    hud,
     74    "foo + foo2 + foo3",
     75    "fooFirstCallnewFoofoo3FirstCall"
     76  );
     77  ok(true, "`foo + foo2 + foo3` from `firstCall()`");
     78 
     79  await executeAndWaitForResultMessage(
     80    hud,
     81    "foo = 'abba'; foo3 = 'bug783499'; foo + foo3",
     82    "abbabug783499"
     83  );
     84  ok(true, "`foo + foo3` updated in `firstCall()`");
     85 
     86  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     87    is(
     88      content.wrappedJSObject.foo,
     89      "globalFooBug783499",
     90      "`foo` in content window"
     91    );
     92    is(content.wrappedJSObject.foo2, "newFoo", "`foo2` in content window");
     93    ok(
     94      !content.wrappedJSObject.foo3,
     95      "`foo3` was not added to the content window"
     96    );
     97  });
     98  await resume(dbg);
     99 
    100  info(
    101    "Check executing expression with private properties access while paused in class method"
    102  );
    103  const onPaused = waitForPaused(dbg, null, {
    104    shouldWaitForInlinePreviews: false,
    105  });
    106  // breakFn has a debugger statement that will pause the debugger
    107  execute(hud, `x = new Foo(); x.breakFn()`);
    108  await onPaused;
    109  // pausing opens the debugger, switch to the console again
    110  await openConsole();
    111 
    112  await executeAndWaitForResultMessage(
    113    hud,
    114    "this.#privateProp",
    115    "privatePropValue"
    116  );
    117  ok(
    118    true,
    119    "evaluating a private properties while paused in a class method does work"
    120  );
    121 
    122  await executeAndWaitForResultMessage(
    123    hud,
    124    "Foo.#privateStatic",
    125    `Object { first: "a", second: "b" }`
    126  );
    127  ok(
    128    true,
    129    "evaluating a static private properties while paused in a class method does work"
    130  );
    131 
    132  await resume(dbg);
    133 });