tor-browser

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

test_slowRequestFinalization.js (3551B)


      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 origin clearing requested after starting database work");
     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 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    const isPreloaded = await Services.domStorageManager.isPreloaded(principal);
     80    Assert.equal(isPreloaded, false, "Datastore is not preloaded");
     81  }
     82 );
     83 
     84 add_task(
     85  {
     86    pref_set: [
     87      ["dom.storage.requestFinalization.pauseOnDOMFileThreadMs", 2000],
     88    ],
     89  },
     90  async function testStepsChild() {
     91    const principal = PrincipalUtils.createPrincipal("https://example.com");
     92 
     93    info("Clearing");
     94 
     95    {
     96      const request = Services.qms.clear();
     97      await QuotaUtils.requestFinished(request);
     98    }
     99 
    100    info("Installing package");
    101 
    102    installPackage("somedata_profile");
    103 
    104    info("Preloading");
    105 
    106    await Services.domStorageManager.preload(principal);
    107 
    108    info("Starting database opening");
    109 
    110    const openPromise = run_test_in_child("slowRequestFinalization_child.js");
    111 
    112    info("Waiting for request finalization to start");
    113 
    114    await TestUtils.topicObserved("LocalStorage::RequestFinalizationStarted");
    115 
    116    info("Starting origin clearing");
    117 
    118    const clearPromise = (async function () {
    119      const request = Services.qms.clearStoragesForPrincipal(principal);
    120      const promise = QuotaUtils.requestFinished(request);
    121      return promise;
    122    })();
    123 
    124    info("Waiting for database to finish opening");
    125 
    126    // The abort error is checked in the child test, so this shouldn't throw.
    127    // We just wait for the child test to finish here.
    128    await openPromise;
    129 
    130    info("Waiting for origin to finish clearing");
    131 
    132    await clearPromise;
    133  }
    134 );