test_persist_groupLimit.js (2971B)
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 not constrained by 8 * the group limit. It consits of these steps: 9 * - Set the limits as small as our limits allow. This does result in needing 10 * to perform 10 megs of writes which is a lot for a test but not horrible. 11 * - Create databases for 2 origins under the same group. 12 * - Have the foo2 origin use up the shared group quota. 13 * - Verify neither origin can write additional data (via a single byte write). 14 * - Do navigator.storage.persist() for that foo2 origin. 15 * - Verify that both origins can now write an additional byte. This 16 * demonstrates that: 17 * - foo2 no longer counts against the group limit at all since foo1 can 18 * write a byte. 19 * - foo2 is no longer constrained by the group limit itself. 20 */ 21 async function testSteps() { 22 // The group limit is calculated as 20% of the global limit and the minimum 23 // value of the group limit is 10 MB. 24 25 const groupLimitKB = 10 * 1024; 26 const globalLimitKB = groupLimitKB * 5; 27 28 const urls = ["http://foo1.example.com", "http://foo2.example.com"]; 29 30 const foo2Index = 1; 31 32 let index; 33 34 info("Setting limits"); 35 36 setGlobalLimit(globalLimitKB); 37 38 let request = clear(); 39 await requestFinished(request); 40 41 info("Opening databases"); 42 43 let databases = []; 44 for (index = 0; index < urls.length; index++) { 45 let database = getSimpleDatabase(getPrincipal(urls[index])); 46 47 request = database.open("data"); 48 await requestFinished(request); 49 50 databases.push(database); 51 } 52 53 info("Filling up the whole group"); 54 55 try { 56 request = databases[foo2Index].write(new ArrayBuffer(groupLimitKB * 1024)); 57 await requestFinished(request); 58 ok(true, "Should not have thrown"); 59 } catch (ex) { 60 ok(false, "Should not have thrown"); 61 } 62 63 info("Verifying no more data can be written"); 64 65 for (index = 0; index < urls.length; index++) { 66 try { 67 request = databases[index].write(new ArrayBuffer(1)); 68 await requestFinished(request); 69 ok(false, "Should have thrown"); 70 } catch (e) { 71 ok(true, "Should have thrown"); 72 Assert.equal( 73 e.resultCode, 74 NS_ERROR_FILE_NO_DEVICE_SPACE, 75 "Threw right result code" 76 ); 77 } 78 } 79 80 info("Persisting origin"); 81 82 request = persist(getPrincipal(urls[foo2Index])); 83 await requestFinished(request); 84 85 info("Verifying more data data can be written"); 86 87 for (index = 0; index < urls.length; index++) { 88 try { 89 request = databases[index].write(new ArrayBuffer(1)); 90 await requestFinished(request); 91 ok(true, "Should not have thrown"); 92 } catch (ex) { 93 ok(false, "Should not have thrown"); 94 } 95 } 96 97 info("Closing databases"); 98 99 for (index = 0; index < urls.length; index++) { 100 request = databases[index].close(); 101 await requestFinished(request); 102 } 103 104 finishTest(); 105 }