test_slowDatabaseInitialization.js (3302B)
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: [["dom.storage.databaseInitialization.pauseOnIOThreadMs", 2000]], 19 }, 20 async function testSteps() { 21 const principal = PrincipalUtils.createPrincipal("https://example.com"); 22 23 info("Testing origin clearing requested after starting database work"); 24 25 // We need some existing data on disk, otherwise the preloading won't create 26 // a datastore in memory that holds a directory lock. 27 28 info("Clearing"); 29 30 { 31 const request = Services.qms.clear(); 32 await QuotaUtils.requestFinished(request); 33 } 34 35 info("Installing package"); 36 37 installPackage("somedata_profile"); 38 39 const openPromise = Services.domStorageManager.preload(principal); 40 41 info("Waiting for database work to start"); 42 43 await TestUtils.topicObserved("LocalStorage::DatabaseWorkStarted"); 44 45 info("Starting origin clearing"); 46 47 const clearPromise = (async function () { 48 const request = Services.qms.clearStoragesForPrincipal(principal); 49 const promise = QuotaUtils.requestFinished(request); 50 return promise; 51 })(); 52 53 info("Waiting for database to finish opening"); 54 55 try { 56 await openPromise; 57 ok(false, "Should have thrown"); 58 } catch (e) { 59 ok(true, "Should have thrown"); 60 Assert.strictEqual( 61 e.result, 62 Cr.NS_ERROR_ABORT, 63 "Threw right result code" 64 ); 65 } 66 67 info("Waiting for origin to finish clearing"); 68 69 await clearPromise; 70 71 const isPreloaded = await Services.domStorageManager.isPreloaded(principal); 72 Assert.equal(isPreloaded, false, "Datastore is not preloaded"); 73 } 74 ); 75 76 add_task( 77 { 78 pref_set: [["dom.storage.databaseInitialization.pauseOnIOThreadMs", 2000]], 79 }, 80 async function testStepsChild() { 81 const principal = PrincipalUtils.createPrincipal("https://example.com"); 82 83 info("Clearing"); 84 85 { 86 const request = Services.qms.clear(); 87 await QuotaUtils.requestFinished(request); 88 } 89 90 info("Installing package"); 91 92 installPackage("somedata_profile"); 93 94 info("Starting database opening"); 95 96 const openPromise = run_test_in_child( 97 "slowDatabaseInitialization_child.js" 98 ); 99 100 info("Waiting for database work to start"); 101 102 await TestUtils.topicObserved("LocalStorage::DatabaseWorkStarted"); 103 104 info("Starting origin clearing"); 105 106 const clearPromise = (async function () { 107 const request = Services.qms.clearStoragesForPrincipal(principal); 108 const promise = QuotaUtils.requestFinished(request); 109 return promise; 110 })(); 111 112 info("Waiting for database to finish opening"); 113 114 // The abort error is checked in the child test, so this shouldn't throw. 115 // We just wait for the child test to finish here. 116 await openPromise; 117 118 info("Waiting for origin to finish clearing"); 119 120 await clearPromise; 121 } 122 );