michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: const { 'classes': Cc, 'interfaces': Ci, 'utils': Cu } = Components; michael@0: michael@0: const DOMException = Ci.nsIDOMDOMException; michael@0: michael@0: function is(a, b, msg) { michael@0: dump("is(" + a + ", " + b + ", \"" + msg + "\")"); michael@0: do_check_eq(a, b, Components.stack.caller); michael@0: } michael@0: michael@0: function ok(cond, msg) { michael@0: dump("ok(" + cond + ", \"" + msg + "\")"); michael@0: do_check_true(!!cond, Components.stack.caller); michael@0: } michael@0: michael@0: function isnot(a, b, msg) { michael@0: dump("isnot(" + a + ", " + b + ", \"" + msg + "\")"); michael@0: do_check_neq(a, b, Components.stack.caller); michael@0: } michael@0: michael@0: function executeSoon(fun) { michael@0: do_execute_soon(fun); michael@0: } michael@0: michael@0: function todo(condition, name, diag) { michael@0: dump("TODO: ", diag); michael@0: } michael@0: michael@0: function info(name, message) { michael@0: do_print(name); michael@0: } michael@0: michael@0: function run_test() { michael@0: runTest(); michael@0: }; michael@0: michael@0: if (!this.runTest) { michael@0: this.runTest = function() michael@0: { michael@0: // XPCShell does not get a profile by default. michael@0: do_get_profile(); michael@0: michael@0: enableExperimental(); michael@0: michael@0: Cu.importGlobalProperties(["indexedDB"]); michael@0: michael@0: do_test_pending(); michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: michael@0: function finishTest() michael@0: { michael@0: resetExperimental(); michael@0: SpecialPowers.notifyObserversInParentProcess(null, "disk-space-watcher", michael@0: "free"); michael@0: michael@0: do_execute_soon(function(){ michael@0: testGenerator.close(); michael@0: do_test_finished(); michael@0: }) michael@0: } michael@0: michael@0: function grabEventAndContinueHandler(event) michael@0: { michael@0: testGenerator.send(event); michael@0: } michael@0: michael@0: function continueToNextStep() michael@0: { michael@0: do_execute_soon(function() { michael@0: testGenerator.next(); michael@0: }); michael@0: } michael@0: michael@0: function errorHandler(event) michael@0: { michael@0: dump("indexedDB error: " + event.target.error.name); michael@0: do_check_true(false); michael@0: finishTest(); michael@0: } michael@0: michael@0: function unexpectedSuccessHandler() michael@0: { michael@0: do_check_true(false); michael@0: finishTest(); michael@0: } michael@0: michael@0: function expectedErrorHandler(name) michael@0: { michael@0: return function(event) { michael@0: do_check_eq(event.type, "error"); michael@0: do_check_eq(event.target.error.name, name); michael@0: event.preventDefault(); michael@0: grabEventAndContinueHandler(event); michael@0: }; michael@0: } michael@0: michael@0: function ExpectError(name) michael@0: { michael@0: this._name = name; michael@0: } michael@0: ExpectError.prototype = { michael@0: handleEvent: function(event) michael@0: { michael@0: do_check_eq(event.type, "error"); michael@0: do_check_eq(this._name, event.target.error.name); michael@0: event.preventDefault(); michael@0: grabEventAndContinueHandler(event); michael@0: } michael@0: }; michael@0: michael@0: function continueToNextStepSync() michael@0: { michael@0: testGenerator.next(); michael@0: } michael@0: michael@0: function compareKeys(k1, k2) { michael@0: let t = typeof k1; michael@0: if (t != typeof k2) michael@0: return false; michael@0: michael@0: if (t !== "object") michael@0: return k1 === k2; michael@0: michael@0: if (k1 instanceof Date) { michael@0: return (k2 instanceof Date) && michael@0: k1.getTime() === k2.getTime(); michael@0: } michael@0: michael@0: if (k1 instanceof Array) { michael@0: if (!(k2 instanceof Array) || michael@0: k1.length != k2.length) michael@0: return false; michael@0: michael@0: for (let i = 0; i < k1.length; ++i) { michael@0: if (!compareKeys(k1[i], k2[i])) michael@0: return false; michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: return false; michael@0: } michael@0: michael@0: function addPermission(permission, url) michael@0: { michael@0: throw "addPermission"; michael@0: } michael@0: michael@0: function removePermission(permission, url) michael@0: { michael@0: throw "removePermission"; michael@0: } michael@0: michael@0: function setQuota(quota) michael@0: { michael@0: throw "setQuota"; michael@0: } michael@0: michael@0: function allowIndexedDB(url) michael@0: { michael@0: throw "allowIndexedDB"; michael@0: } michael@0: michael@0: function disallowIndexedDB(url) michael@0: { michael@0: throw "disallowIndexedDB"; michael@0: } michael@0: michael@0: function allowUnlimitedQuota(url) michael@0: { michael@0: throw "allowUnlimitedQuota"; michael@0: } michael@0: michael@0: function disallowUnlimitedQuota(url) michael@0: { michael@0: throw "disallowUnlimitedQuota"; michael@0: } michael@0: michael@0: function enableExperimental() michael@0: { michael@0: SpecialPowers.setBoolPref("dom.indexedDB.experimental", true); michael@0: } michael@0: michael@0: function resetExperimental() michael@0: { michael@0: SpecialPowers.clearUserPref("dom.indexedDB.experimental"); michael@0: } michael@0: michael@0: function gc() michael@0: { michael@0: Components.utils.forceGC(); michael@0: Components.utils.forceCC(); michael@0: } michael@0: michael@0: function scheduleGC() michael@0: { michael@0: SpecialPowers.exactGC(null, continueToNextStep); michael@0: } michael@0: michael@0: function setTimeout(fun, timeout) { michael@0: let timer = Components.classes["@mozilla.org/timer;1"] michael@0: .createInstance(Components.interfaces.nsITimer); michael@0: var event = { michael@0: notify: function (timer) { michael@0: fun(); michael@0: } michael@0: }; michael@0: timer.initWithCallback(event, timeout, michael@0: Components.interfaces.nsITimer.TYPE_ONE_SHOT); michael@0: return timer; michael@0: } michael@0: michael@0: var SpecialPowers = { michael@0: isMainProcess: function() { michael@0: return Components.classes["@mozilla.org/xre/app-info;1"] michael@0: .getService(Components.interfaces.nsIXULRuntime) michael@0: .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT; michael@0: }, michael@0: notifyObservers: function(subject, topic, data) { michael@0: var obsvc = Cc['@mozilla.org/observer-service;1'] michael@0: .getService(Ci.nsIObserverService); michael@0: obsvc.notifyObservers(subject, topic, data); michael@0: }, michael@0: notifyObserversInParentProcess: function(subject, topic, data) { michael@0: if (subject) { michael@0: throw new Error("Can't send subject to another process!"); michael@0: } michael@0: return this.notifyObservers(subject, topic, data); michael@0: }, michael@0: getBoolPref: function(prefName) { michael@0: return this._getPrefs().getBoolPref(prefName); michael@0: }, michael@0: setBoolPref: function(prefName, value) { michael@0: this._getPrefs().setBoolPref(prefName, value); michael@0: }, michael@0: setIntPref: function(prefName, value) { michael@0: this._getPrefs().setIntPref(prefName, value); michael@0: }, michael@0: clearUserPref: function(prefName) { michael@0: this._getPrefs().clearUserPref(prefName); michael@0: }, michael@0: // Copied (and slightly adjusted) from specialpowersAPI.js michael@0: exactGC: function(win, callback) { michael@0: let count = 0; michael@0: michael@0: function doPreciseGCandCC() { michael@0: function scheduledGCCallback() { michael@0: Components.utils.forceCC(); michael@0: michael@0: if (++count < 2) { michael@0: doPreciseGCandCC(); michael@0: } else { michael@0: callback(); michael@0: } michael@0: } michael@0: michael@0: Components.utils.schedulePreciseGC(scheduledGCCallback); michael@0: } michael@0: michael@0: doPreciseGCandCC(); michael@0: }, michael@0: michael@0: _getPrefs: function() { michael@0: var prefService = michael@0: Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService); michael@0: return prefService.getBranch(null); michael@0: } michael@0: };