tor-browser

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

test_privileged_eval_blocking.js (1202B)


      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 // Workaround for bug 1973683
      6 add_setup(() => {
      7  Services.prefs.setBoolPref("extensions.webextensions.remote", true);
      8  registerCleanupFunction(() => {
      9    Services.prefs.clearUserPref("extensions.webextensions.remote");
     10  });
     11 });
     12 
     13 add_task(async function () {
     14  let errorObserved = new Promise(resolve => {
     15    const listener = {
     16      observe({ message }) {
     17        if (message.includes("eval() and eval-like")) {
     18          Services.console.unregisterListener(listener);
     19          resolve();
     20        }
     21      },
     22    };
     23    Services.console.registerListener(listener);
     24  });
     25 
     26  if (mozinfo.os == "android" && !mozinfo.nightly_build) {
     27    Assert.equal(
     28      // eslint-disable-next-line no-eval
     29      eval("42"),
     30      42,
     31      "eval on Android is not disabled yet outside of Nightly"
     32    );
     33  } else {
     34    Assert.throws(
     35      // eslint-disable-next-line no-eval
     36      () => eval("42"),
     37      EvalError,
     38      "eval() in privileged context should throw"
     39    );
     40  }
     41 
     42  await errorObserved;
     43 });