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();
|
2012-11-08 07:57:17 -08:00
|
|
|
var archiveReaderEnabled = false;
|
2010-09-09 15:15:44 -07:00
|
|
|
|
2012-09-24 05:46:27 -07:00
|
|
|
// The test js is shared between xpcshell (which has no SpecialPowers object)
|
|
|
|
// and content mochitests (where the |Components| object is accessible only as
|
|
|
|
// SpecialPowers.Components). Expose Components if necessary here to make things
|
|
|
|
// work everywhere.
|
2013-03-28 14:26:02 -07:00
|
|
|
//
|
|
|
|
// Even if the real |Components| doesn't exist, we might shim in a simple JS
|
|
|
|
// placebo for compat. An easy way to differentiate this from the real thing
|
|
|
|
// is whether the property is read-only or not.
|
|
|
|
var c = Object.getOwnPropertyDescriptor(this, 'Components');
|
|
|
|
if ((!c.value || c.writable) && typeof SpecialPowers === 'object')
|
2012-09-24 05:46:27 -07:00
|
|
|
Components = SpecialPowers.Components;
|
|
|
|
|
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);
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
let quotaManager =
|
|
|
|
comp.classes["@mozilla.org/dom/quota/manager;1"]
|
|
|
|
.getService(comp.interfaces.nsIQuotaManager);
|
2012-06-19 18:50:39 -07:00
|
|
|
|
2013-06-04 19:56:42 -07:00
|
|
|
let uri = SpecialPowers.wrap(document).documentURIObject;
|
|
|
|
|
|
|
|
// We need to pass a JS callback to getUsageForURI. However, that callback
|
|
|
|
// takes an XPCOM URI object, which will cause us to throw when we wrap it
|
|
|
|
// for the content compartment. So we need to define the function in a
|
|
|
|
// privileged scope, which we do using a sandbox.
|
|
|
|
var sysPrin = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal();
|
|
|
|
var sb = new SpecialPowers.Cu.Sandbox(sysPrin);
|
|
|
|
sb.ok = ok;
|
|
|
|
sb.runCallback = runCallback;
|
|
|
|
var cb = SpecialPowers.Cu.evalInSandbox((function(uri, usage, fileUsage) {
|
2012-06-19 18:50:39 -07:00
|
|
|
if (usage) {
|
2012-08-28 07:59:18 -07:00
|
|
|
ok(false,
|
|
|
|
"getUsageForURI returned non-zero usage after clearing all " +
|
2013-03-26 04:13:17 -07:00
|
|
|
"storages!");
|
2012-06-19 18:50:39 -07:00
|
|
|
}
|
|
|
|
runCallback();
|
2013-06-04 19:56:42 -07:00
|
|
|
}).toSource(), sb);
|
|
|
|
|
|
|
|
quotaManager.clearStoragesForURI(uri);
|
|
|
|
quotaManager.getUsageForURI(uri, cb);
|
2012-06-19 18:50:39 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
enableExperimental();
|
2012-11-08 07:57:17 -08:00
|
|
|
enableArchiveReader();
|
|
|
|
|
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();
|
2013-09-10 21:18:36 -07:00
|
|
|
resetExperimental();
|
2012-11-08 07:57:17 -08:00
|
|
|
resetArchiveReader();
|
2013-05-12 21:10:58 -07:00
|
|
|
SpecialPowers.notifyObserversInParentProcess(null, "disk-space-watcher",
|
|
|
|
"free");
|
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();
|
|
|
|
}
|
|
|
|
|
2013-05-10 14:22:01 -07:00
|
|
|
function expectedErrorHandler(name)
|
|
|
|
{
|
|
|
|
return function(event) {
|
|
|
|
is(event.type, "error", "Got an error event");
|
|
|
|
is(event.target.error.name, name, "Expected error was thrown.");
|
|
|
|
event.preventDefault();
|
|
|
|
grabEventAndContinueHandler(event);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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;
|
2012-11-08 07:57:17 -08:00
|
|
|
|
2011-12-20 02:59:07 -08:00
|
|
|
for (let i = 0; i < k1.length; ++i) {
|
|
|
|
if (!compareKeys(k1[i], k2[i]))
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-08 07:57:17 -08:00
|
|
|
|
2011-12-20 02:59:07 -08:00
|
|
|
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
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
function enableExperimental()
|
|
|
|
{
|
|
|
|
SpecialPowers.setBoolPref("dom.indexedDB.experimental", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetExperimental()
|
|
|
|
{
|
|
|
|
SpecialPowers.clearUserPref("dom.indexedDB.experimental");
|
|
|
|
}
|
|
|
|
|
2012-08-10 09:15:02 -07:00
|
|
|
function gc()
|
|
|
|
{
|
|
|
|
SpecialPowers.forceGC();
|
|
|
|
SpecialPowers.forceCC();
|
|
|
|
}
|
2013-09-10 21:18:36 -07:00
|
|
|
|
|
|
|
function scheduleGC()
|
|
|
|
{
|
|
|
|
SpecialPowers.exactGC(window, continueToNextStep);
|
|
|
|
}
|