tor-browser

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

test_slowStorageInitialization.js (2033B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 const { PrincipalUtils } = ChromeUtils.importESModule(
      7  "resource://testing-common/dom/quota/test/modules/PrincipalUtils.sys.mjs"
      8 );
      9 const { QuotaUtils } = ChromeUtils.importESModule(
     10  "resource://testing-common/dom/quota/test/modules/QuotaUtils.sys.mjs"
     11 );
     12 const { TestUtils } = ChromeUtils.importESModule(
     13  "resource://testing-common/TestUtils.sys.mjs"
     14 );
     15 
     16 add_task(
     17  {
     18    pref_set: [
     19      ["dom.quotaManager.storageInitialization.pauseOnIOThreadMs", 2000],
     20    ],
     21  },
     22  async function testSteps() {
     23    const principal = PrincipalUtils.createPrincipal("https://example.com");
     24    const name = "test_slowStorageInitialization.js";
     25 
     26    info(
     27      "Testing origin clearing requested after starting client directory opening"
     28    );
     29 
     30    info("Starting database opening");
     31 
     32    const openPromise = new Promise(function (resolve, reject) {
     33      const sandbox = new Cu.Sandbox(principal, {
     34        wantGlobalProperties: ["caches"],
     35      });
     36      sandbox.resolve = resolve;
     37      sandbox.reject = reject;
     38      Cu.evalInSandbox(
     39        `caches.open("${name}").then(resolve, reject);`,
     40        sandbox
     41      );
     42    });
     43 
     44    info("Waiting for client directory opening to start");
     45 
     46    await TestUtils.topicObserved(
     47      "QuotaManager::ClientDirectoryOpeningStarted"
     48    );
     49 
     50    info("Starting origin clearing");
     51 
     52    const clearPromise = (async function () {
     53      const request = Services.qms.clearStoragesForPrincipal(principal);
     54      const promise = QuotaUtils.requestFinished(request);
     55      return promise;
     56    })();
     57 
     58    info("Waiting for database to finish opening");
     59 
     60    try {
     61      await openPromise;
     62      ok(false, "Should have thrown");
     63    } catch (e) {
     64      ok(true, "Should have thrown");
     65      Assert.strictEqual(
     66        e.result,
     67        Cr.NS_ERROR_ABORT,
     68        "Threw right result code"
     69      );
     70    }
     71 
     72    info("Waiting for origin to finish clearing");
     73 
     74    await clearPromise;
     75  }
     76 );