tor-browser

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

test_shutdownDuringRequestFinalization.js (1825B)


      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.storage.requestFinalization.pauseOnDOMFileThreadMs", 2000],
     20    ],
     21  },
     22  async function testSteps() {
     23    const principal = PrincipalUtils.createPrincipal("https://example.com");
     24 
     25    info("Testing shutdown requested after starting request finalization");
     26 
     27    // We need some existing data on disk, otherwise the preloading won't create
     28    // a datastore in memory that holds a directory lock.
     29 
     30    info("Clearing");
     31 
     32    {
     33      const request = Services.qms.clear();
     34      await QuotaUtils.requestFinished(request);
     35    }
     36 
     37    info("Installing package");
     38 
     39    installPackage("somedata_profile");
     40 
     41    info("Preloading");
     42 
     43    await Services.domStorageManager.preload(principal);
     44 
     45    info("Starting database opening");
     46 
     47    const openPromise = Services.domStorageManager.preload(principal);
     48 
     49    info("Waiting for request finalization to start");
     50 
     51    await TestUtils.topicObserved("LocalStorage::RequestFinalizationStarted");
     52 
     53    info("Starting shutdown");
     54 
     55    QuotaUtils.startShutdown();
     56 
     57    info("Waiting for database to finish opening");
     58 
     59    try {
     60      await openPromise;
     61      ok(false, "Should have thrown");
     62    } catch (e) {
     63      ok(true, "Should have thrown");
     64      Assert.strictEqual(
     65        e.result,
     66        Cr.NS_ERROR_ABORT,
     67        "Threw right result code"
     68      );
     69    }
     70  }
     71 );