2010-06-23 12:46:08 -07:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
|
|
|
var testGenerator = testSteps();
|
2010-09-09 15:15:44 -07:00
|
|
|
|
2012-01-04 07:43:33 -08:00
|
|
|
function executeSoon(aFun)
|
|
|
|
{
|
2012-06-26 08:09:25 -07:00
|
|
|
let comp = SpecialPowers.wrap(Components);
|
|
|
|
|
|
|
|
let thread = comp.classes["@mozilla.org/thread-manager;1"]
|
|
|
|
.getService(comp.interfaces.nsIThreadManager)
|
|
|
|
.mainThread;
|
|
|
|
|
|
|
|
thread.dispatch({
|
|
|
|
run: function() {
|
|
|
|
aFun();
|
|
|
|
}
|
|
|
|
}, Components.interfaces.nsIThread.DISPATCH_NORMAL);
|
2012-01-04 07:43:33 -08:00
|
|
|
}
|
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
function clearAllDatabases(callback) {
|
|
|
|
function runCallback() {
|
|
|
|
SimpleTest.executeSoon(function () { callback(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SpecialPowers.isMainProcess()) {
|
|
|
|
runCallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let comp = SpecialPowers.wrap(Components);
|
|
|
|
|
|
|
|
let idbManager =
|
|
|
|
comp.classes["@mozilla.org/dom/indexeddb/manager;1"]
|
|
|
|
.getService(comp.interfaces.nsIIndexedDatabaseManager);
|
|
|
|
|
|
|
|
let uri = SpecialPowers.getDocumentURIObject(document);
|
|
|
|
|
|
|
|
idbManager.clearDatabasesForURI(uri);
|
|
|
|
idbManager.getUsageForURI(uri, function(uri, usage, fileUsage) {
|
|
|
|
if (usage) {
|
2012-08-28 07:59:18 -07:00
|
|
|
ok(false,
|
|
|
|
"getUsageForURI returned non-zero usage after clearing all " +
|
|
|
|
"databases!");
|
2012-06-19 18:50:39 -07:00
|
|
|
}
|
|
|
|
runCallback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
if (!window.runTest) {
|
2012-06-03 09:33:52 -07:00
|
|
|
window.runTest = function(limitedQuota)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
2012-06-19 18:50:39 -07:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
if (limitedQuota) {
|
|
|
|
denyUnlimitedQuota();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
allowUnlimitedQuota();
|
|
|
|
}
|
2010-09-09 15:15:40 -07:00
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
clearAllDatabases(function () { testGenerator.next(); });
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function finishTest()
|
|
|
|
{
|
2011-12-15 23:34:24 -08:00
|
|
|
resetUnlimitedQuota();
|
2010-09-09 15:15:44 -07:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
testGenerator.close();
|
2012-07-01 21:49:38 -07:00
|
|
|
//clearAllDatabases(function() { SimpleTest.finish(); });
|
|
|
|
SimpleTest.finish();
|
2010-06-23 12:46:08 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-09-09 15:15:44 -07:00
|
|
|
function browserRunTest()
|
|
|
|
{
|
|
|
|
testGenerator.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
function browserFinishTest()
|
|
|
|
{
|
|
|
|
setTimeout(function() { testGenerator.close(); }, 0);
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
function grabEventAndContinueHandler(event)
|
|
|
|
{
|
|
|
|
testGenerator.send(event);
|
|
|
|
}
|
|
|
|
|
2010-08-26 13:57:30 -07:00
|
|
|
function continueToNextStep()
|
|
|
|
{
|
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
testGenerator.next();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
function continueToNextStepSync()
|
|
|
|
{
|
|
|
|
testGenerator.next();
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
function errorHandler(event)
|
|
|
|
{
|
2012-06-01 10:21:12 -07:00
|
|
|
ok(false, "indexedDB error, '" + event.target.error.name + "'");
|
2010-06-23 12:46:08 -07:00
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
|
2010-09-09 15:15:44 -07:00
|
|
|
function browserErrorHandler(event)
|
|
|
|
{
|
|
|
|
browserFinishTest();
|
|
|
|
throw new Error("indexedDB error (" + event.code + "): " + event.message);
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
function unexpectedSuccessHandler()
|
|
|
|
{
|
|
|
|
ok(false, "Got success, but did not expect it!");
|
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
|
2012-06-25 12:15:17 -07:00
|
|
|
function ExpectError(name, preventDefault)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2012-04-11 14:55:22 -07:00
|
|
|
this._name = name;
|
2012-06-25 12:15:17 -07:00
|
|
|
this._preventDefault = preventDefault;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
ExpectError.prototype = {
|
|
|
|
handleEvent: function(event)
|
|
|
|
{
|
2011-01-06 22:21:36 -08:00
|
|
|
is(event.type, "error", "Got an error event");
|
2012-04-11 14:55:22 -07:00
|
|
|
is(event.target.error.name, this._name, "Expected error was thrown.");
|
2012-06-25 12:15:17 -07:00
|
|
|
if (this._preventDefault) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
grabEventAndContinueHandler(event);
|
|
|
|
}
|
|
|
|
};
|
2010-09-09 15:15:44 -07:00
|
|
|
|
2011-12-20 02:59:07 -08:00
|
|
|
function compareKeys(k1, k2) {
|
|
|
|
let t = typeof k1;
|
|
|
|
if (t != typeof k2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (t !== "object")
|
|
|
|
return k1 === k2;
|
|
|
|
|
|
|
|
if (k1 instanceof Date) {
|
|
|
|
return (k2 instanceof Date) &&
|
|
|
|
k1.getTime() === k2.getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k1 instanceof Array) {
|
|
|
|
if (!(k2 instanceof Array) ||
|
|
|
|
k1.length != k2.length)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (let i = 0; i < k1.length; ++i) {
|
|
|
|
if (!compareKeys(k1[i], k2[i]))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
function addPermission(type, allow, url)
|
2010-09-09 15:15:44 -07:00
|
|
|
{
|
2012-06-01 10:21:12 -07:00
|
|
|
if (!url) {
|
|
|
|
url = window.document;
|
2011-12-20 03:23:27 -08:00
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
SpecialPowers.addPermission(type, allow, url);
|
2010-09-09 15:15:44 -07:00
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
function removePermission(type, url)
|
2010-09-09 15:15:44 -07:00
|
|
|
{
|
2012-06-01 10:21:12 -07:00
|
|
|
if (!url) {
|
|
|
|
url = window.document;
|
2010-09-09 15:15:44 -07:00
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
SpecialPowers.removePermission(type, url);
|
2010-09-09 15:15:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function setQuota(quota)
|
|
|
|
{
|
2012-06-01 10:21:12 -07:00
|
|
|
SpecialPowers.setIntPref("dom.indexedDB.warningQuota", quota);
|
2010-09-09 15:15:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function allowUnlimitedQuota(url)
|
|
|
|
{
|
2011-12-15 23:34:24 -08:00
|
|
|
addPermission("indexedDB-unlimited", true, url);
|
|
|
|
}
|
|
|
|
|
|
|
|
function denyUnlimitedQuota(url)
|
|
|
|
{
|
|
|
|
addPermission("indexedDB-unlimited", false, url);
|
2010-09-09 15:15:44 -07:00
|
|
|
}
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
function resetUnlimitedQuota(url)
|
2010-09-09 15:15:44 -07:00
|
|
|
{
|
|
|
|
removePermission("indexedDB-unlimited", url);
|
|
|
|
}
|
2012-08-10 09:15:02 -07:00
|
|
|
|
|
|
|
function gc()
|
|
|
|
{
|
|
|
|
SpecialPowers.forceGC();
|
|
|
|
SpecialPowers.forceCC();
|
|
|
|
}
|