utils.js (1395B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 loadScript("dom/quota/test/common/file.js"); 7 8 function getOriginDir(persistence, origin) { 9 return getRelativeFile(`storage/${persistence}/${origin}`); 10 } 11 12 function getMetadataFile(persistence, origin) { 13 const metadataFile = getOriginDir(persistence, origin); 14 metadataFile.append(".metadata-v2"); 15 return metadataFile; 16 } 17 18 function populateRepository(persistence) { 19 const originDir = getOriginDir(persistence, "https+++good-example.com"); 20 originDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755); 21 } 22 23 function makeRepositoryUnusable(persistence) { 24 // For the purpose of testing, we make a repository unusable by creating an 25 // origin directory with the metadata file created as a directory (not a 26 // file). 27 const metadataFile = getMetadataFile(persistence, "https+++bad-example.com"); 28 metadataFile.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755); 29 } 30 31 async function fillOrigin(principal, size) { 32 let database = getSimpleDatabase(principal); 33 34 let request = database.open("data"); 35 await requestFinished(request); 36 37 try { 38 request = database.write(getBuffer(size)); 39 await requestFinished(request); 40 ok(true, "Should not have thrown"); 41 } catch (ex) { 42 ok(false, "Should not have thrown"); 43 } 44 45 request = database.close(); 46 await requestFinished(request); 47 }