head.js (2012B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 async function require_module(id) { 7 if (!require_module.moduleLoader) { 8 const { ModuleLoader } = await import( 9 "/tests/dom/quota/test/modules/ModuleLoader.mjs" 10 ); 11 12 const base = window.location.href; 13 14 const depth = "../../../../"; 15 16 const { Assert } = await import("/tests/dom/quota/test/modules/Assert.mjs"); 17 18 const { Utils } = await import("/tests/dom/quota/test/modules/Utils.mjs"); 19 20 const proto = { 21 Assert, 22 Cr: SpecialPowers.Cr, 23 navigator, 24 TextEncoder, 25 Utils, 26 }; 27 28 require_module.moduleLoader = new ModuleLoader(base, depth, proto); 29 } 30 31 return require_module.moduleLoader.require(id); 32 } 33 34 async function run_test_in_worker(script) { 35 const { runTestInWorker } = await import( 36 "/tests/dom/quota/test/modules/WorkerDriver.mjs" 37 ); 38 39 const base = window.location.href; 40 41 const listener = { 42 onOk(value, message) { 43 ok(value, message); 44 }, 45 onIs(a, b, message) { 46 is(a, b, message); 47 }, 48 onInfo(message) { 49 info(message); 50 }, 51 }; 52 53 await runTestInWorker(script, base, listener); 54 } 55 56 // XXX This can be removed once we use <profile>/storage. See bug 1798015. 57 async function removeAllEntries() { 58 const root = await navigator.storage.getDirectory(); 59 for await (const value of root.values()) { 60 root.removeEntry(value.name, { recursive: true }); 61 } 62 } 63 64 add_setup(async function () { 65 const { setStoragePrefs, clearStoragesForOrigin } = await import( 66 "/tests/dom/quota/test/modules/StorageUtils.mjs" 67 ); 68 69 const optionalPrefsToSet = [ 70 ["dom.fs.enabled", true], 71 ["dom.fs.writable_file_stream.enabled", true], 72 ["dom.fs.testing", true], 73 ]; 74 75 await setStoragePrefs(optionalPrefsToSet); 76 77 SimpleTest.registerCleanupFunction(async function () { 78 await removeAllEntries(); 79 80 await clearStoragesForOrigin(SpecialPowers.wrap(document).nodePrincipal); 81 }); 82 });