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