tor-browser

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

browser_webconsole_lenient_this_warning.js (2301B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Check that calling the LenientThis warning is only called when expected.
      7 const TEST_URI = `data:text/html;charset=utf8,<!DOCTYPE html>${encodeURI(`
      8    <h1>LenientThis warning</h1>
      9    <script>
     10      const el = document.createElement('div');
     11      globalThis.htmlDivElementProto = Object.getPrototypeOf(el);
     12      function triggerLenientThisWarning(){
     13        Object.getOwnPropertyDescriptor(
     14          Object.getPrototypeOf(globalThis.htmlDivElementProto),
     15          'onmouseenter'
     16        ).get.call()
     17      }
     18    </script>`)}`;
     19 
     20 add_task(async function () {
     21  const hud = await openNewTabAndConsole(TEST_URI);
     22 
     23  const expectedWarningMessageText =
     24    "Ignoring get or set of property that has [LenientThis] ";
     25 
     26  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     27    const global = content.wrappedJSObject;
     28    global.console.log(global.htmlDivElementProto);
     29  });
     30 
     31  info("Wait for a bit so any warning message could be displayed");
     32  await wait(1000);
     33  await waitFor(() => findConsoleAPIMessage(hud, "HTMLDivElementPrototype"));
     34 
     35  ok(
     36    !findWarningMessage(hud, expectedWarningMessageText, ".warn"),
     37    "Displaying the HTMLDivElementPrototype does not trigger the LenientThis warning"
     38  );
     39 
     40  info(
     41    "Call a LenientThis getter with the wrong `this` to trigger a warning message"
     42  );
     43  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     44    content.wrappedJSObject.triggerLenientThisWarning();
     45  });
     46 
     47  await waitFor(() =>
     48    findWarningMessage(hud, expectedWarningMessageText, ".warn")
     49  );
     50  ok(
     51    true,
     52    "Calling the LenientThis getter with an unexpected `this` did triggered the warning"
     53  );
     54 
     55  info(
     56    "Clear the console and call the LenientThis getter with an unexpected `this` again"
     57  );
     58  await clearOutput(hud);
     59  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     60    content.wrappedJSObject.triggerLenientThisWarning();
     61  });
     62  info("Wait for a bit so any warning message could be displayed");
     63  await wait(1000);
     64  ok(
     65    !findWarningMessage(hud, expectedWarningMessageText, ".warn"),
     66    "Calling the LenientThis getter a second time did not trigger the warning again"
     67  );
     68 });