test_slowDatabaseInitialization.js (2120B)
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 { PrincipalUtils } = ChromeUtils.importESModule( 11 "resource://testing-common/dom/quota/test/modules/PrincipalUtils.sys.mjs" 12 ); 13 const { QuotaUtils } = ChromeUtils.importESModule( 14 "resource://testing-common/dom/quota/test/modules/QuotaUtils.sys.mjs" 15 ); 16 const { TestUtils } = ChromeUtils.importESModule( 17 "resource://testing-common/TestUtils.sys.mjs" 18 ); 19 20 add_task( 21 { pref_set: [["dom.fs.databaseInitialization.pauseOnIOThreadMs", 2000]] }, 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 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( 37 `storage.getDirectory().then(resolve, reject);`, 38 sandbox 39 ); 40 }); 41 42 info("Waiting for database work to start"); 43 44 await TestUtils.topicObserved("BucketFS::DatabaseWorkStarted"); 45 46 info("Starting origin clearing"); 47 48 const clearPromise = (async function () { 49 const request = Services.qms.clearStoragesForPrincipal(principal); 50 const promise = QuotaUtils.requestFinished(request); 51 return promise; 52 })(); 53 54 info("Waiting for database to finish opening"); 55 56 try { 57 await openPromise; 58 ok(false, "Should have thrown"); 59 } catch (e) { 60 ok(true, "Should have thrown"); 61 Assert.strictEqual(e.name, "AbortError", "Threw right result code"); 62 } 63 64 info("Waiting for origin to finish clearing"); 65 66 await clearPromise; 67 } 68 );