2012-05-21 20:18:30 +04:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
|
|
|
var oldVal = false;
|
|
|
|
|
2013-05-16 13:26:51 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2012-06-11 09:50:44 +04:00
|
|
|
|
2012-05-21 20:18:30 +04:00
|
|
|
function devicestorage_setup() {
|
2012-07-13 23:35:33 +04:00
|
|
|
|
|
|
|
// ensure that the directory we are writing into is empty
|
|
|
|
try {
|
2012-09-24 16:46:29 +04:00
|
|
|
const Cc = SpecialPowers.Cc;
|
|
|
|
const Ci = SpecialPowers.Ci;
|
2012-07-13 23:35:33 +04:00
|
|
|
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) {}
|
|
|
|
|
2012-07-14 08:01:52 +04:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2012-07-13 20:36:19 +04:00
|
|
|
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);
|
|
|
|
}
|
2012-05-21 20:18:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function devicestorage_cleanup() {
|
2012-07-13 20:36:19 +04:00
|
|
|
if (SpecialPowers.isMainProcess()) {
|
|
|
|
SpecialPowers.setBoolPref("device.storage.enabled", oldVal);
|
|
|
|
SpecialPowers.setBoolPref("device.storage.testing", false);
|
|
|
|
SpecialPowers.setBoolPref("device.storage.prompt.testing", false);
|
|
|
|
}
|
2012-05-21 20:18:30 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-06 01:30:36 +04:00
|
|
|
function createRandomBlob(mime) {
|
|
|
|
return blob = new Blob([getRandomBuffer()], {type: mime});
|
2012-05-21 20:18:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function randomFilename(l) {
|
2012-08-02 10:29:34 +04:00
|
|
|
var set = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
|
|
|
|
var result = "";
|
|
|
|
for (var i=0; i<l; i++) {
|
|
|
|
var r = Math.floor(set.length * Math.random());
|
|
|
|
result += set.substring(r, r + 1);
|
|
|
|
}
|
|
|
|
return result;
|
2012-05-21 20:18:30 +04:00
|
|
|
}
|
|
|
|
|
2012-06-11 09:50:44 +04:00
|
|
|
function reportErrorAndQuit(e) {
|
|
|
|
ok(false, "handleError was called : " + e.target.error.name);
|
|
|
|
devicestorage_cleanup();
|
|
|
|
}
|