test_archive.js (1991B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 add_task(async function testSteps() { 7 const lsArchiveFile = "storage/ls-archive.sqlite"; 8 9 const principalInfo = { 10 url: "http://example.com", 11 attrs: {}, 12 }; 13 14 function checkStorage() { 15 let principal = getPrincipal(principalInfo.url, principalInfo.attrs); 16 let storage = getLocalStorage(principal); 17 try { 18 storage.open(); 19 ok(true, "Did not throw"); 20 } catch (ex) { 21 ok(false, "Should not have thrown"); 22 } 23 } 24 25 info("Setting pref"); 26 27 Services.prefs.setBoolPref("dom.storage.next_gen", true); 28 29 info("Sub test case 1 - Archive file is a directory."); 30 31 info("Clearing"); 32 33 let request = clear(); 34 await requestFinished(request); 35 36 let archiveFile = getRelativeFile(lsArchiveFile); 37 38 archiveFile.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8)); 39 40 checkStorage(); 41 42 info("Sub test case 2 - Corrupted archive file."); 43 44 info("Clearing"); 45 46 request = clear(); 47 await requestFinished(request); 48 49 let ostream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance( 50 Ci.nsIFileOutputStream 51 ); 52 ostream.init(archiveFile, -1, parseInt("0644", 8), 0); 53 ostream.write("foobar", 6); 54 ostream.close(); 55 56 checkStorage(); 57 58 info("Sub test case 3 - Nonupdateable archive file."); 59 60 info("Clearing"); 61 62 request = clear(); 63 await requestFinished(request); 64 65 info("Installing package"); 66 67 // The profile contains storage.sqlite and storage/ls-archive.sqlite 68 // storage/ls-archive.sqlite was taken from FF 54 to force an upgrade. 69 // There's just one record in the webappsstore2 table. The record was 70 // modified by renaming the origin attribute userContextId to userContextKey. 71 // This triggers an error during the upgrade. 72 installPackage("archive_profile"); 73 74 let fileSize = archiveFile.fileSize; 75 Assert.greater(fileSize, 0, "archive file size is greater than zero"); 76 77 checkStorage(); 78 });