test_persist_globalLimit.js (1903B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 /** 7 * This test is mainly to verify that persisted origins are always bounded by 8 * the global limit. 9 */ 10 11 loadScript("dom/quota/test/common/file.js"); 12 13 async function testSteps() { 14 const globalLimitKB = 1; 15 16 const principal = getPrincipal("https://persisted.example.com"); 17 18 info("Setting limits"); 19 20 setGlobalLimit(globalLimitKB); 21 22 let request = clear(); 23 await requestFinished(request); 24 25 for (let initializeStorageBeforePersist of [false, true]) { 26 if (initializeStorageBeforePersist) { 27 info("Initializing"); 28 29 request = init(); 30 await requestFinished(request); 31 32 info("Initializing the temporary storage"); 33 34 request = initTemporaryStorage(); 35 await requestFinished(request); 36 } 37 38 info("Persisting an origin"); 39 40 request = persist(principal); 41 await requestFinished(request); 42 43 info("Verifying the persisted origin is bounded by global limit"); 44 45 let database = getSimpleDatabase(principal); 46 47 info("Opening a database for the persisted origin"); 48 49 request = database.open("data"); 50 await requestFinished(request); 51 52 try { 53 info("Writing over the limit shouldn't succeed"); 54 55 request = database.write(getBuffer(globalLimitKB * 1024 + 1)); 56 await requestFinished(request); 57 58 ok(false, "Should have thrown"); 59 } catch (e) { 60 ok(true, "Should have thrown"); 61 Assert.strictEqual( 62 e.resultCode, 63 NS_ERROR_FILE_NO_DEVICE_SPACE, 64 "Threw right result code" 65 ); 66 } 67 68 info("Closing the database and clearing"); 69 70 request = database.close(); 71 await requestFinished(request); 72 73 request = clear(); 74 await requestFinished(request); 75 } 76 77 info("Resetting limits"); 78 79 resetGlobalLimit(); 80 81 request = reset(); 82 await requestFinished(request); 83 }