tor-browser

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

test_slowStorageInitialization.js (2048B)


      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 
     25    info(
     26      "Testing origin clearing requested after starting client directory opening"
     27    );
     28 
     29    // We need some existing data on disk, otherwise the preloading won't create
     30    // a datastore in memory that holds a directory lock.
     31 
     32    info("Clearing");
     33 
     34    {
     35      const request = Services.qms.clear();
     36      await QuotaUtils.requestFinished(request);
     37    }
     38 
     39    info("Installing package");
     40 
     41    installPackage("somedata_profile");
     42 
     43    info("Starting database opening");
     44 
     45    const openPromise = Services.domStorageManager.preload(principal);
     46 
     47    info("Waiting for client directory opening to start");
     48 
     49    await TestUtils.topicObserved(
     50      "QuotaManager::ClientDirectoryOpeningStarted"
     51    );
     52 
     53    info("Starting origin clearing");
     54 
     55    const clearPromise = (async function () {
     56      const request = Services.qms.clearStoragesForPrincipal(principal);
     57      const promise = QuotaUtils.requestFinished(request);
     58      return promise;
     59    })();
     60 
     61    info("Waiting for database to finish opening");
     62 
     63    try {
     64      await openPromise;
     65      ok(false, "Should have thrown");
     66    } catch (e) {
     67      ok(true, "Should have thrown");
     68      Assert.strictEqual(
     69        e.result,
     70        Cr.NS_ERROR_ABORT,
     71        "Threw right result code"
     72      );
     73    }
     74 
     75    info("Waiting for origin to finish clearing");
     76 
     77    await clearPromise;
     78  }
     79 );