2012-06-03 09:33:52 -07:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
|
|
|
const IndexedDatabaseKey = "IDB";
|
|
|
|
const DeviceStorageKey = "DS";
|
|
|
|
|
|
|
|
var fileStorages = [
|
|
|
|
{ key: IndexedDatabaseKey }
|
|
|
|
// { key: DeviceStorageKey }
|
|
|
|
];
|
|
|
|
|
|
|
|
var utils = SpecialPowers.getDOMWindowUtils(window);
|
|
|
|
|
2012-11-08 07:57:17 -08:00
|
|
|
var archiveReaderEnabled = false;
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
var testGenerator = testSteps();
|
|
|
|
|
|
|
|
function runTest()
|
|
|
|
{
|
|
|
|
allowUnlimitedQuota();
|
2012-11-08 07:57:17 -08:00
|
|
|
enableArchiveReader();
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
testGenerator.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
function finishTest()
|
|
|
|
{
|
|
|
|
resetUnlimitedQuota();
|
2012-11-08 07:57:17 -08:00
|
|
|
resetArchiveReader();
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
testGenerator.close();
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function grabEventAndContinueHandler(event)
|
|
|
|
{
|
|
|
|
testGenerator.send(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
function continueToNextStep()
|
|
|
|
{
|
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
testGenerator.next();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function errorHandler(event)
|
|
|
|
{
|
|
|
|
ok(false, "indexedDB error, code " + event.target.errorCode);
|
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function unexpectedSuccessHandler()
|
|
|
|
{
|
|
|
|
ok(false, "Got success, but did not expect it!");
|
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function ExpectError(name)
|
|
|
|
{
|
|
|
|
this._name = name;
|
|
|
|
}
|
|
|
|
ExpectError.prototype = {
|
|
|
|
handleEvent: function(event)
|
|
|
|
{
|
|
|
|
is(event.type, "error", "Got an error event");
|
|
|
|
is(event.target.error.name, this._name, "Expected error was thrown.");
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
grabEventAndContinueHandler(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function addPermission(type, allow, url)
|
|
|
|
{
|
2012-06-18 10:09:26 -07:00
|
|
|
if (!url) {
|
|
|
|
url = window.document;
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
2012-06-18 10:09:26 -07:00
|
|
|
SpecialPowers.addPermission(type, allow, url);
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
2012-06-18 10:09:26 -07:00
|
|
|
function removePermission(type, url)
|
2012-06-03 09:33:52 -07:00
|
|
|
{
|
2012-06-18 10:09:26 -07:00
|
|
|
if (!url) {
|
|
|
|
url = window.document;
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
2012-06-18 10:09:26 -07:00
|
|
|
SpecialPowers.removePermission(type, url);
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function allowUnlimitedQuota(url)
|
|
|
|
{
|
|
|
|
addPermission("indexedDB-unlimited", true, url);
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetUnlimitedQuota(url)
|
|
|
|
{
|
|
|
|
removePermission("indexedDB-unlimited", url);
|
|
|
|
}
|
|
|
|
|
2012-11-08 07:57:17 -08:00
|
|
|
function enableArchiveReader()
|
|
|
|
{
|
|
|
|
archiveReaderEnabled = SpecialPowers.getBoolPref("dom.archivereader.enabled");
|
|
|
|
SpecialPowers.setBoolPref("dom.archivereader.enabled", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetArchiveReader()
|
|
|
|
{
|
|
|
|
SpecialPowers.setBoolPref("dom.archivereader.enabled", archiveReaderEnabled);
|
|
|
|
}
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
function getFileHandle(fileStorageKey, name)
|
|
|
|
{
|
|
|
|
var requestService = SpecialPowers.getDOMRequestService();
|
|
|
|
var request = requestService.createRequest(window);
|
|
|
|
|
|
|
|
switch (fileStorageKey) {
|
|
|
|
case IndexedDatabaseKey:
|
|
|
|
var dbname = window.location.pathname;
|
2012-06-29 09:48:35 -07:00
|
|
|
indexedDB.open(dbname, 1).onsuccess = function(event) {
|
2012-06-03 09:33:52 -07:00
|
|
|
var db = event.target.result;
|
|
|
|
db.mozCreateFileHandle(name).onsuccess = function(event) {
|
|
|
|
var fileHandle = event.target.result;
|
|
|
|
requestService.fireSuccess(request, fileHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeviceStorageKey:
|
|
|
|
var dbname = window.location.pathname;
|
2012-06-29 09:48:35 -07:00
|
|
|
indexedDB.open(dbname, 1).onsuccess = function(event) {
|
2012-06-03 09:33:52 -07:00
|
|
|
var db = event.target.result;
|
|
|
|
db.mozCreateFileHandle(name).onsuccess = function(event) {
|
|
|
|
var fileHandle = event.target.result;
|
|
|
|
requestService.fireSuccess(request, fileHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBuffer(size)
|
|
|
|
{
|
|
|
|
let buffer = new ArrayBuffer(size);
|
|
|
|
is(buffer.byteLength, size, "Correct byte length");
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getRandomBuffer(size)
|
|
|
|
{
|
|
|
|
let buffer = getBuffer(size);
|
|
|
|
let view = new Uint8Array(buffer);
|
|
|
|
for (let i = 0; i < size; i++) {
|
|
|
|
view[i] = parseInt(Math.random() * 255)
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
function compareBuffers(buffer1, buffer2)
|
|
|
|
{
|
|
|
|
if (buffer1.byteLength != buffer2.byteLength) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
let view1 = new Uint8Array(buffer1);
|
|
|
|
let view2 = new Uint8Array(buffer2);
|
|
|
|
for (let i = 0; i < buffer1.byteLength; i++) {
|
|
|
|
if (view1[i] != view2[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBlob(type, buffer)
|
|
|
|
{
|
2013-02-22 14:18:38 -08:00
|
|
|
return SpecialPowers.unwrap(utils.getBlob([buffer], {type: type}));
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function getRandomBlob(size)
|
|
|
|
{
|
|
|
|
return getBlob("binary/random", getRandomBuffer(size));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFileId(blob)
|
|
|
|
{
|
2013-02-22 14:18:38 -08:00
|
|
|
return SpecialPowers.unwrap(utils.getFileId(blob));
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|