Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 | var testGenerator = testSteps(); |
michael@0 | 7 | |
michael@0 | 8 | function testSteps() |
michael@0 | 9 | { |
michael@0 | 10 | const name = this.window ? window.location.pathname : "Splendid Test"; |
michael@0 | 11 | |
michael@0 | 12 | let request = indexedDB.open(name, 1); |
michael@0 | 13 | request.onerror = errorHandler; |
michael@0 | 14 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 15 | let event = yield undefined; |
michael@0 | 16 | |
michael@0 | 17 | let db = event.target.result; |
michael@0 | 18 | db.addEventListener("error", function(event) { |
michael@0 | 19 | event.preventDefault(); |
michael@0 | 20 | }, false); |
michael@0 | 21 | |
michael@0 | 22 | let objectStore = db.createObjectStore("foo", { autoIncrement: true }); |
michael@0 | 23 | |
michael@0 | 24 | request = objectStore.add({}); |
michael@0 | 25 | request.onerror = errorHandler; |
michael@0 | 26 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 27 | event = yield undefined; |
michael@0 | 28 | |
michael@0 | 29 | let key1 = event.target.result; |
michael@0 | 30 | |
michael@0 | 31 | request = objectStore.put({}, key1); |
michael@0 | 32 | request.onerror = errorHandler; |
michael@0 | 33 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 34 | event = yield undefined; |
michael@0 | 35 | |
michael@0 | 36 | is(event.target.result, key1, "put gave the same key back"); |
michael@0 | 37 | |
michael@0 | 38 | let key2 = 10; |
michael@0 | 39 | |
michael@0 | 40 | request = objectStore.put({}, key2); |
michael@0 | 41 | request.onerror = errorHandler; |
michael@0 | 42 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 43 | event = yield undefined; |
michael@0 | 44 | |
michael@0 | 45 | is(event.target.result, key2, "put gave the same key back"); |
michael@0 | 46 | |
michael@0 | 47 | key2 = 100; |
michael@0 | 48 | |
michael@0 | 49 | request = objectStore.add({}, key2); |
michael@0 | 50 | request.onerror = errorHandler; |
michael@0 | 51 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 52 | event = yield undefined; |
michael@0 | 53 | |
michael@0 | 54 | is(event.target.result, key2, "put gave the same key back"); |
michael@0 | 55 | |
michael@0 | 56 | try { |
michael@0 | 57 | objectStore.put({}); |
michael@0 | 58 | ok(true, "put with no key should not throw with autoIncrement!"); |
michael@0 | 59 | } |
michael@0 | 60 | catch (e) { |
michael@0 | 61 | ok(false, "put with no key threw with autoIncrement"); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | try { |
michael@0 | 65 | objectStore.put({}); |
michael@0 | 66 | ok(true, "put with no key should not throw with autoIncrement!"); |
michael@0 | 67 | } |
michael@0 | 68 | catch (e) { |
michael@0 | 69 | ok(false, "put with no key threw with autoIncrement"); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | try { |
michael@0 | 73 | objectStore.delete(); |
michael@0 | 74 | ok(false, "remove with no key should throw!"); |
michael@0 | 75 | } |
michael@0 | 76 | catch (e) { |
michael@0 | 77 | ok(true, "remove with no key threw"); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | objectStore = db.createObjectStore("bar"); |
michael@0 | 81 | |
michael@0 | 82 | try { |
michael@0 | 83 | objectStore.add({}); |
michael@0 | 84 | ok(false, "add with no key should throw!"); |
michael@0 | 85 | } |
michael@0 | 86 | catch (e) { |
michael@0 | 87 | ok(true, "add with no key threw"); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | try { |
michael@0 | 91 | objectStore.put({}); |
michael@0 | 92 | ok(false, "put with no key should throw!"); |
michael@0 | 93 | } |
michael@0 | 94 | catch (e) { |
michael@0 | 95 | ok(true, "put with no key threw"); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | try { |
michael@0 | 99 | objectStore.put({}); |
michael@0 | 100 | ok(false, "put with no key should throw!"); |
michael@0 | 101 | } |
michael@0 | 102 | catch (e) { |
michael@0 | 103 | ok(true, "put with no key threw"); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | try { |
michael@0 | 107 | objectStore.delete(); |
michael@0 | 108 | ok(false, "remove with no key should throw!"); |
michael@0 | 109 | } |
michael@0 | 110 | catch (e) { |
michael@0 | 111 | ok(true, "remove with no key threw"); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | objectStore = db.createObjectStore("baz", { keyPath: "id" }); |
michael@0 | 115 | |
michael@0 | 116 | try { |
michael@0 | 117 | objectStore.add({}); |
michael@0 | 118 | ok(false, "add with no key should throw!"); |
michael@0 | 119 | } |
michael@0 | 120 | catch (e) { |
michael@0 | 121 | ok(true, "add with no key threw"); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | try { |
michael@0 | 125 | objectStore.add({id:5}, 5); |
michael@0 | 126 | ok(false, "add with inline key and passed key should throw!"); |
michael@0 | 127 | } |
michael@0 | 128 | catch (e) { |
michael@0 | 129 | ok(true, "add with inline key and passed key threw"); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | try { |
michael@0 | 133 | objectStore.put({}); |
michael@0 | 134 | ok(false, "put with no key should throw!"); |
michael@0 | 135 | } |
michael@0 | 136 | catch (e) { |
michael@0 | 137 | ok(true, "put with no key threw"); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | try { |
michael@0 | 141 | objectStore.put({}); |
michael@0 | 142 | ok(false, "put with no key should throw!"); |
michael@0 | 143 | } |
michael@0 | 144 | catch (e) { |
michael@0 | 145 | ok(true, "put with no key threw"); |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | try { |
michael@0 | 149 | objectStore.delete(); |
michael@0 | 150 | ok(false, "remove with no key should throw!"); |
michael@0 | 151 | } |
michael@0 | 152 | catch (e) { |
michael@0 | 153 | ok(true, "remove with no key threw"); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | key1 = 10; |
michael@0 | 157 | |
michael@0 | 158 | request = objectStore.add({id:key1}); |
michael@0 | 159 | request.onerror = errorHandler; |
michael@0 | 160 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 161 | event = yield undefined; |
michael@0 | 162 | |
michael@0 | 163 | is(event.target.result, key1, "add gave back the same key"); |
michael@0 | 164 | |
michael@0 | 165 | request = objectStore.put({id:10}); |
michael@0 | 166 | request.onerror = errorHandler; |
michael@0 | 167 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 168 | event = yield undefined; |
michael@0 | 169 | |
michael@0 | 170 | is(event.target.result, key1, "put gave back the same key"); |
michael@0 | 171 | |
michael@0 | 172 | request = objectStore.put({id:10}); |
michael@0 | 173 | request.onerror = errorHandler; |
michael@0 | 174 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 175 | event = yield undefined; |
michael@0 | 176 | |
michael@0 | 177 | is(event.target.result, key1, "put gave back the same key"); |
michael@0 | 178 | |
michael@0 | 179 | request = objectStore.add({id:10}); |
michael@0 | 180 | request.addEventListener("error", new ExpectError("ConstraintError", true)); |
michael@0 | 181 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 182 | event = yield undefined; |
michael@0 | 183 | |
michael@0 | 184 | try { |
michael@0 | 185 | objectStore.add({}, null); |
michael@0 | 186 | ok(false, "add with null key should throw!"); |
michael@0 | 187 | } |
michael@0 | 188 | catch (e) { |
michael@0 | 189 | ok(true, "add with null key threw"); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | try { |
michael@0 | 193 | objectStore.put({}, null); |
michael@0 | 194 | ok(false, "put with null key should throw!"); |
michael@0 | 195 | } |
michael@0 | 196 | catch (e) { |
michael@0 | 197 | ok(true, "put with null key threw"); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | try { |
michael@0 | 201 | objectStore.put({}, null); |
michael@0 | 202 | ok(false, "put with null key should throw!"); |
michael@0 | 203 | } |
michael@0 | 204 | catch (e) { |
michael@0 | 205 | ok(true, "put with null key threw"); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | try { |
michael@0 | 209 | objectStore.delete({}, null); |
michael@0 | 210 | ok(false, "remove with null key should throw!"); |
michael@0 | 211 | } |
michael@0 | 212 | catch (e) { |
michael@0 | 213 | ok(true, "remove with null key threw"); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | objectStore = db.createObjectStore("bazing", { keyPath: "id", |
michael@0 | 217 | autoIncrement: true }); |
michael@0 | 218 | |
michael@0 | 219 | request = objectStore.add({}); |
michael@0 | 220 | request.onerror = errorHandler; |
michael@0 | 221 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 222 | event = yield undefined; |
michael@0 | 223 | |
michael@0 | 224 | key1 = event.target.result; |
michael@0 | 225 | |
michael@0 | 226 | request = objectStore.put({id:key1}); |
michael@0 | 227 | request.onerror = errorHandler; |
michael@0 | 228 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 229 | event = yield undefined; |
michael@0 | 230 | |
michael@0 | 231 | is(event.target.result, key1, "put gave the same key back"); |
michael@0 | 232 | |
michael@0 | 233 | key2 = 10; |
michael@0 | 234 | |
michael@0 | 235 | request = objectStore.put({id:key2}); |
michael@0 | 236 | request.onerror = errorHandler; |
michael@0 | 237 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 238 | event = yield undefined; |
michael@0 | 239 | |
michael@0 | 240 | is(event.target.result, key2, "put gave the same key back"); |
michael@0 | 241 | |
michael@0 | 242 | try { |
michael@0 | 243 | objectStore.put({}); |
michael@0 | 244 | ok(true, "put with no key should not throw with autoIncrement!"); |
michael@0 | 245 | } |
michael@0 | 246 | catch (e) { |
michael@0 | 247 | ok(false, "put with no key threw with autoIncrement"); |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | try { |
michael@0 | 251 | objectStore.put({}); |
michael@0 | 252 | ok(true, "put with no key should not throw with autoIncrement!"); |
michael@0 | 253 | } |
michael@0 | 254 | catch (e) { |
michael@0 | 255 | ok(false, "put with no key threw with autoIncrement"); |
michael@0 | 256 | } |
michael@0 | 257 | |
michael@0 | 258 | try { |
michael@0 | 259 | objectStore.delete(); |
michael@0 | 260 | ok(false, "remove with no key should throw!"); |
michael@0 | 261 | } |
michael@0 | 262 | catch (e) { |
michael@0 | 263 | ok(true, "remove with no key threw"); |
michael@0 | 264 | } |
michael@0 | 265 | |
michael@0 | 266 | try { |
michael@0 | 267 | objectStore.add({id:5}, 5); |
michael@0 | 268 | ok(false, "add with inline key and passed key should throw!"); |
michael@0 | 269 | } |
michael@0 | 270 | catch (e) { |
michael@0 | 271 | ok(true, "add with inline key and passed key threw"); |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | request = objectStore.delete(key2); |
michael@0 | 275 | request.onerror = errorHandler; |
michael@0 | 276 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 277 | event = yield undefined; |
michael@0 | 278 | |
michael@0 | 279 | finishTest(); |
michael@0 | 280 | yield undefined; |
michael@0 | 281 | } |