test_permmanager_removeall.js (1386B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 add_task(async function test() { 5 Services.prefs.setCharPref("permissions.manager.defaultsUrl", ""); 6 // setup a profile directory 7 var dir = do_get_profile(); 8 9 // We need to execute a pm method to be sure that the DB is fully 10 // initialized. 11 var pm = Services.perms; 12 Assert.strictEqual(pm.all.length, 0); 13 14 Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk"); 15 16 // Let's force the completion of the DB reading. 17 Assert.strictEqual(pm.all.length, 0); 18 19 // get the db file 20 var file = dir.clone(); 21 file.append("permissions.sqlite"); 22 23 Assert.ok(file.exists()); 24 25 // corrupt the file 26 var ostream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance( 27 Ci.nsIFileOutputStream 28 ); 29 ostream.init(file, 0x02, 0o666, 0); 30 var conv = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance( 31 Ci.nsIConverterOutputStream 32 ); 33 conv.init(ostream, "UTF-8"); 34 for (var i = 0; i < file.fileSize; ++i) { 35 conv.writeString("a"); 36 } 37 conv.close(); 38 39 // prepare an empty hostperm.1 file so that it can be used for importing 40 var hostperm = dir.clone(); 41 hostperm.append("hostperm.1"); 42 ostream.init(hostperm, 0x02 | 0x08, 0o666, 0); 43 ostream.close(); 44 45 // remove all should not throw 46 pm.removeAll(); 47 });