test_slowStorageInitialization.js (2209B)
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 { 22 pref_set: [ 23 ["dom.quotaManager.storageInitialization.pauseOnIOThreadMs", 2000], 24 ], 25 }, 26 async function testSteps() { 27 const principal = PrincipalUtils.createPrincipal("https://example.com"); 28 29 info( 30 "Testing origin clearing requested after starting client directory opening" 31 ); 32 33 info("Starting database opening"); 34 35 const openPromise = new Promise(function (resolve, reject) { 36 const sandbox = new Cu.Sandbox(principal, { 37 wantGlobalProperties: ["storage"], 38 forceSecureContext: true, 39 }); 40 sandbox.resolve = resolve; 41 sandbox.reject = reject; 42 Cu.evalInSandbox( 43 `storage.getDirectory().then(resolve, reject);`, 44 sandbox 45 ); 46 }); 47 48 info("Waiting for client directory opening to start"); 49 50 await TestUtils.topicObserved( 51 "QuotaManager::ClientDirectoryOpeningStarted" 52 ); 53 54 info("Starting origin clearing"); 55 56 const clearPromise = (async function () { 57 const request = Services.qms.clearStoragesForPrincipal(principal); 58 const promise = QuotaUtils.requestFinished(request); 59 return promise; 60 })(); 61 62 info("Waiting for database to finish opening"); 63 64 try { 65 await openPromise; 66 ok(false, "Should have thrown"); 67 } catch (e) { 68 ok(true, "Should have thrown"); 69 Assert.strictEqual(e.name, "AbortError", "Threw right result code"); 70 } 71 72 info("Waiting for origin to finish clearing"); 73 74 await clearPromise; 75 } 76 );