2010-06-23 23:46:08 +04:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
|
|
|
var testGenerator = testSteps();
|
2010-09-10 02:15:44 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
function runTest()
|
|
|
|
{
|
2010-09-10 02:15:44 +04:00
|
|
|
allowIndexedDB();
|
2011-12-16 11:34:24 +04:00
|
|
|
allowUnlimitedQuota();
|
2010-09-10 02:15:40 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
testGenerator.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
function finishTest()
|
|
|
|
{
|
2011-12-16 11:34:24 +04:00
|
|
|
resetUnlimitedQuota();
|
|
|
|
resetIndexedDB();
|
2010-09-10 02:15:44 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
testGenerator.close();
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-09-10 02:15:44 +04:00
|
|
|
function browserRunTest()
|
|
|
|
{
|
|
|
|
testGenerator.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
function browserFinishTest()
|
|
|
|
{
|
|
|
|
setTimeout(function() { testGenerator.close(); }, 0);
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
function grabEventAndContinueHandler(event)
|
|
|
|
{
|
|
|
|
testGenerator.send(event);
|
|
|
|
}
|
|
|
|
|
2010-08-27 00:57:30 +04:00
|
|
|
function continueToNextStep()
|
|
|
|
{
|
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
testGenerator.next();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
function errorHandler(event)
|
|
|
|
{
|
2011-01-07 09:21:36 +03:00
|
|
|
ok(false, "indexedDB error, code " + event.target.errorCode);
|
2010-06-23 23:46:08 +04:00
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
|
2010-09-10 02:15:44 +04:00
|
|
|
function browserErrorHandler(event)
|
|
|
|
{
|
|
|
|
browserFinishTest();
|
|
|
|
throw new Error("indexedDB error (" + event.code + "): " + event.message);
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
function unexpectedSuccessHandler()
|
|
|
|
{
|
|
|
|
ok(false, "Got success, but did not expect it!");
|
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function ExpectError(code)
|
|
|
|
{
|
|
|
|
this._code = code;
|
|
|
|
}
|
|
|
|
ExpectError.prototype = {
|
|
|
|
handleEvent: function(event)
|
|
|
|
{
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.type, "error", "Got an error event");
|
|
|
|
is(this._code, event.target.errorCode, "Expected error was thrown.");
|
2010-11-11 02:26:03 +03:00
|
|
|
event.preventDefault();
|
2010-06-23 23:46:08 +04:00
|
|
|
grabEventAndContinueHandler(event);
|
|
|
|
}
|
|
|
|
};
|
2010-09-10 02:15:44 +04:00
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
function addPermission(type, allow, url)
|
2010-09-10 02:15:44 +04:00
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
|
|
|
|
let uri;
|
|
|
|
if (url) {
|
|
|
|
uri = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService)
|
|
|
|
.newURI(url, null, null);
|
2011-12-16 11:34:24 +04:00
|
|
|
} else {
|
2011-09-23 09:03:50 +04:00
|
|
|
uri = SpecialPowers.getDocumentURIObject(window.document);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
let permission;
|
|
|
|
if (allow) {
|
|
|
|
permission = Components.interfaces.nsIPermissionManager.ALLOW_ACTION;
|
|
|
|
} else {
|
|
|
|
permission = Components.interfaces.nsIPermissionManager.DENY_ACTION;
|
|
|
|
}
|
|
|
|
|
2010-09-10 02:15:44 +04:00
|
|
|
Components.classes["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Components.interfaces.nsIPermissionManager)
|
2011-12-16 11:34:24 +04:00
|
|
|
.add(uri, type, permission);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function removePermission(permission, url)
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
|
|
|
|
let uri;
|
|
|
|
if (url) {
|
|
|
|
uri = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService)
|
|
|
|
.newURI(url, null, null);
|
|
|
|
}
|
|
|
|
else {
|
2011-09-23 09:03:50 +04:00
|
|
|
uri = SpecialPowers.getDocumentURIObject(window.document);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Components.classes["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Components.interfaces.nsIPermissionManager)
|
2010-10-19 21:58:52 +04:00
|
|
|
.remove(uri.host, permission);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setQuota(quota)
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
|
|
|
|
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
|
|
|
|
prefs.setIntPref("dom.indexedDB.warningQuota", quota);
|
|
|
|
}
|
|
|
|
|
|
|
|
function allowIndexedDB(url)
|
|
|
|
{
|
2011-12-16 11:34:24 +04:00
|
|
|
addPermission("indexedDB", true, url);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
function resetIndexedDB(url)
|
2010-09-10 02:15:44 +04:00
|
|
|
{
|
|
|
|
removePermission("indexedDB", url);
|
|
|
|
}
|
|
|
|
|
|
|
|
function allowUnlimitedQuota(url)
|
|
|
|
{
|
2011-12-16 11:34:24 +04:00
|
|
|
addPermission("indexedDB-unlimited", true, url);
|
|
|
|
}
|
|
|
|
|
|
|
|
function denyUnlimitedQuota(url)
|
|
|
|
{
|
|
|
|
addPermission("indexedDB-unlimited", false, url);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
function resetUnlimitedQuota(url)
|
2010-09-10 02:15:44 +04:00
|
|
|
{
|
|
|
|
removePermission("indexedDB-unlimited", url);
|
|
|
|
}
|