tor-browser

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

test_getDirectoryFailure.js (1609B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 // This test doesn't use the shared module system (running the same test in
      7 // multiple test suites) on purpose because it needs to create an unprivileged
      8 // sandbox which is not possible if the test is already running in a sandbox.
      9 
     10 const { FileUtils } = ChromeUtils.importESModule(
     11  "resource://testing-common/dom/quota/test/modules/FileUtils.sys.mjs"
     12 );
     13 
     14 const { PrincipalUtils } = ChromeUtils.importESModule(
     15  "resource://testing-common/dom/quota/test/modules/PrincipalUtils.sys.mjs"
     16 );
     17 
     18 add_task(async function init() {
     19  const principal = PrincipalUtils.createPrincipal("https://example.com");
     20  const clientDirectoryPath = "storage/default/https+++example.com/fs";
     21 
     22  info("Creating invalid client directory");
     23 
     24  const clientDirectory = FileUtils.getFile(clientDirectoryPath);
     25  clientDirectory.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0644", 8));
     26 
     27  info("Starting database opening");
     28 
     29  const openPromise = new Promise(function (resolve, reject) {
     30    const sandbox = new Cu.Sandbox(principal, {
     31      wantGlobalProperties: ["storage"],
     32      forceSecureContext: true,
     33    });
     34    sandbox.resolve = resolve;
     35    sandbox.reject = reject;
     36    Cu.evalInSandbox(`storage.getDirectory().then(resolve, reject);`, sandbox);
     37  });
     38 
     39  info("Waiting for database to finish opening");
     40 
     41  try {
     42    await openPromise;
     43    ok(false, "Should have thrown");
     44  } catch (e) {
     45    ok(true, "Should have thrown");
     46    Assert.strictEqual(e.name, "UnknownError", "Threw right result code");
     47  }
     48 });