michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: var oldVal = false; michael@0: michael@0: Object.defineProperty(Array.prototype, "remove", { michael@0: enumerable: false, michael@0: configurable: false, michael@0: writable: false, michael@0: value: function(from, to) { michael@0: // Array Remove - By John Resig (MIT Licensed) michael@0: var rest = this.slice((to || from) + 1 || this.length); michael@0: this.length = from < 0 ? this.length + from : from; michael@0: return this.push.apply(this, rest); michael@0: } michael@0: }); michael@0: michael@0: function devicestorage_setup() { michael@0: michael@0: // ensure that the directory we are writing into is empty michael@0: try { michael@0: const Cc = SpecialPowers.Cc; michael@0: const Ci = SpecialPowers.Ci; michael@0: var directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); michael@0: var f = directoryService.get("TmpD", Ci.nsIFile); michael@0: f.appendRelativePath("device-storage-testing"); michael@0: f.remove(true); michael@0: } catch(e) {} michael@0: michael@0: SimpleTest.waitForExplicitFinish(); michael@0: if (SpecialPowers.isMainProcess()) { michael@0: try { michael@0: oldVal = SpecialPowers.getBoolPref("device.storage.enabled"); michael@0: } catch(e) {} michael@0: SpecialPowers.setBoolPref("device.storage.enabled", true); michael@0: SpecialPowers.setBoolPref("device.storage.testing", true); michael@0: SpecialPowers.setBoolPref("device.storage.prompt.testing", true); michael@0: } michael@0: } michael@0: michael@0: function devicestorage_cleanup() { michael@0: if (SpecialPowers.isMainProcess()) { michael@0: SpecialPowers.setBoolPref("device.storage.enabled", oldVal); michael@0: SpecialPowers.setBoolPref("device.storage.testing", false); michael@0: SpecialPowers.setBoolPref("device.storage.prompt.testing", false); michael@0: } michael@0: SimpleTest.finish(); michael@0: } michael@0: michael@0: function getRandomBuffer() { michael@0: var size = 1024; michael@0: var buffer = new ArrayBuffer(size); michael@0: var view = new Uint8Array(buffer); michael@0: for (var i = 0; i < size; i++) { michael@0: view[i] = parseInt(Math.random() * 255); michael@0: } michael@0: return buffer; michael@0: } michael@0: michael@0: function createRandomBlob(mime) { michael@0: return blob = new Blob([getRandomBuffer()], {type: mime}); michael@0: } michael@0: michael@0: function randomFilename(l) { michael@0: var set = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"; michael@0: var result = ""; michael@0: for (var i=0; i