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