test_flushing.js (1672B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 /* eslint-disable mozilla/no-arbitrary-setTimeout */ 6 7 /** 8 * This test is mainly to verify that the flush operation detaches the shadow 9 * database in the event of early return due to error. See bug 1559029. 10 */ 11 12 add_task(async function testSteps() { 13 const principal1 = getPrincipal("http://example1.com"); 14 15 const usageFile1 = getRelativeFile( 16 "storage/default/http+++example1.com/ls/usage" 17 ); 18 19 const principal2 = getPrincipal("http://example2.com"); 20 21 const data = { 22 key: "foo", 23 value: "bar", 24 }; 25 26 const flushSleepTimeSec = 6; 27 28 info("Setting prefs"); 29 30 Services.prefs.setBoolPref("dom.storage.next_gen", true); 31 32 info("Getting storage 1"); 33 34 let storage1 = getLocalStorage(principal1); 35 36 info("Adding item"); 37 38 storage1.setItem(data.key, data.value); 39 40 info("Creating usage as a directory"); 41 42 // This will cause a failure during the flush for first principal. 43 usageFile1.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8)); 44 45 info("Getting storage 2"); 46 47 let storage2 = getLocalStorage(principal2); 48 49 info("Adding item"); 50 51 storage2.setItem(data.key, data.value); 52 53 // The flush for second principal shouldn't be affected by failed flush for 54 // first principal. 55 56 info( 57 "Sleeping for " + 58 flushSleepTimeSec + 59 " seconds to let all flushes " + 60 "finish" 61 ); 62 63 await new Promise(function (resolve) { 64 setTimeout(resolve, flushSleepTimeSec * 1000); 65 }); 66 67 info("Resetting"); 68 69 // Wait for all database connections to close. 70 let request = reset(); 71 await requestFinished(request); 72 });