dom/indexedDB/test/unit/head.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /**
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 */
michael@0 5
michael@0 6 const { 'classes': Cc, 'interfaces': Ci, 'utils': Cu } = Components;
michael@0 7
michael@0 8 const DOMException = Ci.nsIDOMDOMException;
michael@0 9
michael@0 10 function is(a, b, msg) {
michael@0 11 dump("is(" + a + ", " + b + ", \"" + msg + "\")");
michael@0 12 do_check_eq(a, b, Components.stack.caller);
michael@0 13 }
michael@0 14
michael@0 15 function ok(cond, msg) {
michael@0 16 dump("ok(" + cond + ", \"" + msg + "\")");
michael@0 17 do_check_true(!!cond, Components.stack.caller);
michael@0 18 }
michael@0 19
michael@0 20 function isnot(a, b, msg) {
michael@0 21 dump("isnot(" + a + ", " + b + ", \"" + msg + "\")");
michael@0 22 do_check_neq(a, b, Components.stack.caller);
michael@0 23 }
michael@0 24
michael@0 25 function executeSoon(fun) {
michael@0 26 do_execute_soon(fun);
michael@0 27 }
michael@0 28
michael@0 29 function todo(condition, name, diag) {
michael@0 30 dump("TODO: ", diag);
michael@0 31 }
michael@0 32
michael@0 33 function info(name, message) {
michael@0 34 do_print(name);
michael@0 35 }
michael@0 36
michael@0 37 function run_test() {
michael@0 38 runTest();
michael@0 39 };
michael@0 40
michael@0 41 if (!this.runTest) {
michael@0 42 this.runTest = function()
michael@0 43 {
michael@0 44 // XPCShell does not get a profile by default.
michael@0 45 do_get_profile();
michael@0 46
michael@0 47 enableExperimental();
michael@0 48
michael@0 49 Cu.importGlobalProperties(["indexedDB"]);
michael@0 50
michael@0 51 do_test_pending();
michael@0 52 testGenerator.next();
michael@0 53 }
michael@0 54 }
michael@0 55
michael@0 56 function finishTest()
michael@0 57 {
michael@0 58 resetExperimental();
michael@0 59 SpecialPowers.notifyObserversInParentProcess(null, "disk-space-watcher",
michael@0 60 "free");
michael@0 61
michael@0 62 do_execute_soon(function(){
michael@0 63 testGenerator.close();
michael@0 64 do_test_finished();
michael@0 65 })
michael@0 66 }
michael@0 67
michael@0 68 function grabEventAndContinueHandler(event)
michael@0 69 {
michael@0 70 testGenerator.send(event);
michael@0 71 }
michael@0 72
michael@0 73 function continueToNextStep()
michael@0 74 {
michael@0 75 do_execute_soon(function() {
michael@0 76 testGenerator.next();
michael@0 77 });
michael@0 78 }
michael@0 79
michael@0 80 function errorHandler(event)
michael@0 81 {
michael@0 82 dump("indexedDB error: " + event.target.error.name);
michael@0 83 do_check_true(false);
michael@0 84 finishTest();
michael@0 85 }
michael@0 86
michael@0 87 function unexpectedSuccessHandler()
michael@0 88 {
michael@0 89 do_check_true(false);
michael@0 90 finishTest();
michael@0 91 }
michael@0 92
michael@0 93 function expectedErrorHandler(name)
michael@0 94 {
michael@0 95 return function(event) {
michael@0 96 do_check_eq(event.type, "error");
michael@0 97 do_check_eq(event.target.error.name, name);
michael@0 98 event.preventDefault();
michael@0 99 grabEventAndContinueHandler(event);
michael@0 100 };
michael@0 101 }
michael@0 102
michael@0 103 function ExpectError(name)
michael@0 104 {
michael@0 105 this._name = name;
michael@0 106 }
michael@0 107 ExpectError.prototype = {
michael@0 108 handleEvent: function(event)
michael@0 109 {
michael@0 110 do_check_eq(event.type, "error");
michael@0 111 do_check_eq(this._name, event.target.error.name);
michael@0 112 event.preventDefault();
michael@0 113 grabEventAndContinueHandler(event);
michael@0 114 }
michael@0 115 };
michael@0 116
michael@0 117 function continueToNextStepSync()
michael@0 118 {
michael@0 119 testGenerator.next();
michael@0 120 }
michael@0 121
michael@0 122 function compareKeys(k1, k2) {
michael@0 123 let t = typeof k1;
michael@0 124 if (t != typeof k2)
michael@0 125 return false;
michael@0 126
michael@0 127 if (t !== "object")
michael@0 128 return k1 === k2;
michael@0 129
michael@0 130 if (k1 instanceof Date) {
michael@0 131 return (k2 instanceof Date) &&
michael@0 132 k1.getTime() === k2.getTime();
michael@0 133 }
michael@0 134
michael@0 135 if (k1 instanceof Array) {
michael@0 136 if (!(k2 instanceof Array) ||
michael@0 137 k1.length != k2.length)
michael@0 138 return false;
michael@0 139
michael@0 140 for (let i = 0; i < k1.length; ++i) {
michael@0 141 if (!compareKeys(k1[i], k2[i]))
michael@0 142 return false;
michael@0 143 }
michael@0 144
michael@0 145 return true;
michael@0 146 }
michael@0 147
michael@0 148 return false;
michael@0 149 }
michael@0 150
michael@0 151 function addPermission(permission, url)
michael@0 152 {
michael@0 153 throw "addPermission";
michael@0 154 }
michael@0 155
michael@0 156 function removePermission(permission, url)
michael@0 157 {
michael@0 158 throw "removePermission";
michael@0 159 }
michael@0 160
michael@0 161 function setQuota(quota)
michael@0 162 {
michael@0 163 throw "setQuota";
michael@0 164 }
michael@0 165
michael@0 166 function allowIndexedDB(url)
michael@0 167 {
michael@0 168 throw "allowIndexedDB";
michael@0 169 }
michael@0 170
michael@0 171 function disallowIndexedDB(url)
michael@0 172 {
michael@0 173 throw "disallowIndexedDB";
michael@0 174 }
michael@0 175
michael@0 176 function allowUnlimitedQuota(url)
michael@0 177 {
michael@0 178 throw "allowUnlimitedQuota";
michael@0 179 }
michael@0 180
michael@0 181 function disallowUnlimitedQuota(url)
michael@0 182 {
michael@0 183 throw "disallowUnlimitedQuota";
michael@0 184 }
michael@0 185
michael@0 186 function enableExperimental()
michael@0 187 {
michael@0 188 SpecialPowers.setBoolPref("dom.indexedDB.experimental", true);
michael@0 189 }
michael@0 190
michael@0 191 function resetExperimental()
michael@0 192 {
michael@0 193 SpecialPowers.clearUserPref("dom.indexedDB.experimental");
michael@0 194 }
michael@0 195
michael@0 196 function gc()
michael@0 197 {
michael@0 198 Components.utils.forceGC();
michael@0 199 Components.utils.forceCC();
michael@0 200 }
michael@0 201
michael@0 202 function scheduleGC()
michael@0 203 {
michael@0 204 SpecialPowers.exactGC(null, continueToNextStep);
michael@0 205 }
michael@0 206
michael@0 207 function setTimeout(fun, timeout) {
michael@0 208 let timer = Components.classes["@mozilla.org/timer;1"]
michael@0 209 .createInstance(Components.interfaces.nsITimer);
michael@0 210 var event = {
michael@0 211 notify: function (timer) {
michael@0 212 fun();
michael@0 213 }
michael@0 214 };
michael@0 215 timer.initWithCallback(event, timeout,
michael@0 216 Components.interfaces.nsITimer.TYPE_ONE_SHOT);
michael@0 217 return timer;
michael@0 218 }
michael@0 219
michael@0 220 var SpecialPowers = {
michael@0 221 isMainProcess: function() {
michael@0 222 return Components.classes["@mozilla.org/xre/app-info;1"]
michael@0 223 .getService(Components.interfaces.nsIXULRuntime)
michael@0 224 .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
michael@0 225 },
michael@0 226 notifyObservers: function(subject, topic, data) {
michael@0 227 var obsvc = Cc['@mozilla.org/observer-service;1']
michael@0 228 .getService(Ci.nsIObserverService);
michael@0 229 obsvc.notifyObservers(subject, topic, data);
michael@0 230 },
michael@0 231 notifyObserversInParentProcess: function(subject, topic, data) {
michael@0 232 if (subject) {
michael@0 233 throw new Error("Can't send subject to another process!");
michael@0 234 }
michael@0 235 return this.notifyObservers(subject, topic, data);
michael@0 236 },
michael@0 237 getBoolPref: function(prefName) {
michael@0 238 return this._getPrefs().getBoolPref(prefName);
michael@0 239 },
michael@0 240 setBoolPref: function(prefName, value) {
michael@0 241 this._getPrefs().setBoolPref(prefName, value);
michael@0 242 },
michael@0 243 setIntPref: function(prefName, value) {
michael@0 244 this._getPrefs().setIntPref(prefName, value);
michael@0 245 },
michael@0 246 clearUserPref: function(prefName) {
michael@0 247 this._getPrefs().clearUserPref(prefName);
michael@0 248 },
michael@0 249 // Copied (and slightly adjusted) from specialpowersAPI.js
michael@0 250 exactGC: function(win, callback) {
michael@0 251 let count = 0;
michael@0 252
michael@0 253 function doPreciseGCandCC() {
michael@0 254 function scheduledGCCallback() {
michael@0 255 Components.utils.forceCC();
michael@0 256
michael@0 257 if (++count < 2) {
michael@0 258 doPreciseGCandCC();
michael@0 259 } else {
michael@0 260 callback();
michael@0 261 }
michael@0 262 }
michael@0 263
michael@0 264 Components.utils.schedulePreciseGC(scheduledGCCallback);
michael@0 265 }
michael@0 266
michael@0 267 doPreciseGCandCC();
michael@0 268 },
michael@0 269
michael@0 270 _getPrefs: function() {
michael@0 271 var prefService =
michael@0 272 Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
michael@0 273 return prefService.getBranch(null);
michael@0 274 }
michael@0 275 };

mercurial