Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <meta charset=utf-8> | |
| 3 <title>Fire error event - Exception thrown</title> | |
| 4 <script src=/resources/testharness.js></script> | |
|
pwnall
2017/03/04 00:27:33
Do you think it's worth adding help links, like be
jsbell
2017/03/06 18:25:02
Done.
| |
| 5 <script src=/resources/testharnessreport.js></script> | |
| 6 <script src=support.js></script> | |
| 7 <script> | |
| 8 setup({allow_uncaught_exception:true}); | |
| 9 | |
| 10 // Listeners on the request. | |
| 11 | |
| 12 indexeddb_test( | |
| 13 (t, db) => { | |
| 14 db.createObjectStore('s'); | |
| 15 }, | |
| 16 (t, db) => { | |
| 17 const tx = db.transaction('s', 'readwrite'); | |
|
pwnall
2017/03/04 00:27:33
It seems to me that lines 17-21 and 25-28 repeat i
jsbell
2017/03/06 18:25:02
Factored out wrapper functions here and in the oth
| |
| 18 const store = tx.objectStore('s'); | |
| 19 store.put(0, 0); | |
| 20 const request = store.add(0, 0); | |
| 21 request.onsuccess = t.unreached_func('request should fail'); | |
| 22 request.onerror = () => { | |
| 23 throw Error(); | |
| 24 }; | |
| 25 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 26 tx.onabort = t.step_func_done(() => { | |
| 27 assert_equals(tx.error.name, 'AbortError'); | |
| 28 }); | |
| 29 }, | |
| 30 'Exception in error event handler on request'); | |
| 31 | |
| 32 indexeddb_test( | |
| 33 (t, db) => { | |
| 34 db.createObjectStore('s'); | |
| 35 }, | |
| 36 (t, db) => { | |
| 37 const tx = db.transaction('s', 'readwrite'); | |
| 38 const store = tx.objectStore('s'); | |
| 39 store.put(0, 0); | |
| 40 const request = store.add(0, 0); | |
| 41 request.onsuccess = t.unreached_func('request should fail'); | |
| 42 request.onerror = e => { | |
| 43 e.preventDefault(); | |
| 44 throw Error(); | |
| 45 }; | |
| 46 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 47 tx.onabort = t.step_func_done(() => { | |
| 48 assert_equals(tx.error.name, 'AbortError'); | |
| 49 }); | |
| 50 }, | |
| 51 'Exception in error event handler on request, with preventDefault'); | |
| 52 | |
| 53 indexeddb_test( | |
| 54 (t, db) => { | |
| 55 db.createObjectStore('s'); | |
| 56 }, | |
| 57 (t, db) => { | |
| 58 const tx = db.transaction('s', 'readwrite'); | |
| 59 const store = tx.objectStore('s'); | |
| 60 store.put(0, 0); | |
| 61 const request = store.add(0, 0); | |
| 62 request.onsuccess = t.unreached_func('request should fail'); | |
| 63 request.addEventListener('error', () => { | |
| 64 throw Error(); | |
| 65 }); | |
| 66 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 67 tx.onabort = t.step_func_done(() => { | |
| 68 assert_equals(tx.error.name, 'AbortError'); | |
| 69 }); | |
| 70 }, | |
| 71 'Exception in error event listener on request'); | |
| 72 | |
| 73 indexeddb_test( | |
| 74 (t, db) => { | |
| 75 db.createObjectStore('s'); | |
| 76 }, | |
| 77 (t, db) => { | |
| 78 const tx = db.transaction('s', 'readwrite'); | |
| 79 const store = tx.objectStore('s'); | |
| 80 store.put(0, 0); | |
| 81 const request = store.add(0, 0); | |
| 82 request.onsuccess = t.unreached_func('request should fail'); | |
| 83 request.addEventListener('error', () => { | |
| 84 // no-op | |
| 85 }); | |
| 86 request.addEventListener('error', () => { | |
| 87 throw Error(); | |
| 88 }); | |
| 89 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 90 tx.onabort = t.step_func_done(() => { | |
| 91 assert_equals(tx.error.name, 'AbortError'); | |
| 92 }); | |
| 93 }, | |
| 94 'Exception in second error event listener on request'); | |
| 95 | |
| 96 indexeddb_test( | |
| 97 (t, db) => { | |
| 98 db.createObjectStore('s'); | |
| 99 }, | |
| 100 (t, db) => { | |
| 101 const tx = db.transaction('s', 'readwrite'); | |
| 102 const store = tx.objectStore('s'); | |
| 103 store.put(0, 0); | |
| 104 const request = store.add(0, 0); | |
| 105 request.onsuccess = t.unreached_func('request should fail'); | |
| 106 let second_listener_called = false; | |
| 107 request.addEventListener('error', () => { | |
| 108 throw Error(); | |
| 109 }); | |
| 110 request.addEventListener('error', t.step_func(() => { | |
| 111 second_listener_called = true; | |
| 112 assert_true(is_transaction_active(tx, 's'), | |
| 113 'Transaction should be active until dispatch completes'); | |
| 114 })); | |
| 115 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 116 tx.onabort = t.step_func_done(() => { | |
| 117 assert_true(second_listener_called); | |
|
pwnall
2017/03/04 00:27:33
This shows up in a few places. I imagine you could
jsbell
2017/03/06 18:25:02
I kept the onabort handler explicit in each test.
| |
| 118 assert_equals(tx.error.name, 'AbortError'); | |
| 119 }); | |
| 120 }, | |
| 121 'Exception in first error event listener on request, ' + | |
| 122 'transaction active in second'); | |
| 123 | |
| 124 // Listeners on the transaction. | |
| 125 | |
| 126 indexeddb_test( | |
| 127 (t, db) => { | |
| 128 db.createObjectStore('s'); | |
| 129 }, | |
| 130 (t, db) => { | |
| 131 const tx = db.transaction('s', 'readwrite'); | |
| 132 const store = tx.objectStore('s'); | |
| 133 store.put(0, 0); | |
| 134 const request = store.add(0, 0); | |
| 135 request.onsuccess = t.unreached_func('request should fail'); | |
| 136 tx.onerror = () => { | |
| 137 throw Error(); | |
| 138 }; | |
| 139 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 140 tx.onabort = t.step_func_done(() => { | |
| 141 assert_equals(tx.error.name, 'AbortError'); | |
| 142 }); | |
| 143 }, | |
| 144 'Exception in error event handler on transaction'); | |
| 145 | |
| 146 indexeddb_test( | |
| 147 (t, db) => { | |
| 148 db.createObjectStore('s'); | |
| 149 }, | |
| 150 (t, db) => { | |
| 151 const tx = db.transaction('s', 'readwrite'); | |
| 152 const store = tx.objectStore('s'); | |
| 153 store.put(0, 0); | |
| 154 const request = store.add(0, 0); | |
| 155 request.onsuccess = t.unreached_func('request should fail'); | |
| 156 tx.onerror = e => { | |
| 157 e.preventDefault(); | |
| 158 throw Error(); | |
| 159 }; | |
| 160 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 161 tx.onabort = t.step_func_done(() => { | |
| 162 assert_equals(tx.error.name, 'AbortError'); | |
| 163 }); | |
| 164 }, | |
| 165 'Exception in error event handler on transaction, with preventDefault'); | |
| 166 | |
| 167 indexeddb_test( | |
| 168 (t, db) => { | |
| 169 db.createObjectStore('s'); | |
| 170 }, | |
| 171 (t, db) => { | |
| 172 const tx = db.transaction('s', 'readwrite'); | |
| 173 const store = tx.objectStore('s'); | |
| 174 store.put(0, 0); | |
| 175 const request = store.add(0, 0); | |
| 176 request.onsuccess = t.unreached_func('request should fail'); | |
| 177 tx.addEventListener('error', () => { | |
| 178 throw Error(); | |
| 179 }); | |
| 180 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 181 tx.onabort = t.step_func_done(() => { | |
| 182 assert_equals(tx.error.name, 'AbortError'); | |
| 183 }); | |
| 184 }, | |
| 185 'Exception in error event listener on transaction'); | |
| 186 | |
| 187 indexeddb_test( | |
| 188 (t, db) => { | |
| 189 db.createObjectStore('s'); | |
| 190 }, | |
| 191 (t, db) => { | |
| 192 const tx = db.transaction('s', 'readwrite'); | |
| 193 const store = tx.objectStore('s'); | |
| 194 store.put(0, 0); | |
| 195 const request = store.add(0, 0); | |
| 196 request.onsuccess = t.unreached_func('request should fail'); | |
| 197 tx.addEventListener('error', () => { | |
| 198 // no-op | |
| 199 }); | |
| 200 tx.addEventListener('error', () => { | |
| 201 throw Error(); | |
| 202 }); | |
| 203 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 204 tx.onabort = t.step_func_done(() => { | |
| 205 assert_equals(tx.error.name, 'AbortError'); | |
| 206 }); | |
| 207 }, | |
| 208 'Exception in second error event listener on transaction'); | |
| 209 | |
| 210 indexeddb_test( | |
| 211 (t, db) => { | |
| 212 db.createObjectStore('s'); | |
| 213 }, | |
| 214 (t, db) => { | |
| 215 const tx = db.transaction('s', 'readwrite'); | |
| 216 const store = tx.objectStore('s'); | |
| 217 store.put(0, 0); | |
| 218 const request = store.add(0, 0); | |
| 219 request.onsuccess = t.unreached_func('request should fail'); | |
| 220 let second_listener_called = false; | |
| 221 tx.addEventListener('error', () => { | |
| 222 throw Error(); | |
| 223 }); | |
| 224 tx.addEventListener('error', t.step_func(() => { | |
| 225 second_listener_called = true; | |
| 226 assert_true(is_transaction_active(tx, 's'), | |
| 227 'Transaction should be active until dispatch completes'); | |
| 228 })); | |
| 229 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 230 tx.onabort = t.step_func_done(() => { | |
| 231 assert_true(second_listener_called); | |
| 232 assert_equals(tx.error.name, 'AbortError'); | |
| 233 }); | |
| 234 }, | |
| 235 'Exception in first error event listener on transaction, ' + | |
| 236 'transaction active in second'); | |
| 237 | |
| 238 // Listeners on the connection. | |
| 239 | |
| 240 indexeddb_test( | |
| 241 (t, db) => { | |
| 242 db.createObjectStore('s'); | |
| 243 }, | |
| 244 (t, db) => { | |
| 245 const tx = db.transaction('s', 'readwrite'); | |
| 246 const store = tx.objectStore('s'); | |
| 247 store.put(0, 0); | |
| 248 const request = store.add(0, 0); | |
| 249 request.onsuccess = t.unreached_func('request should fail'); | |
| 250 db.onerror = () => { | |
| 251 throw Error(); | |
| 252 }; | |
| 253 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 254 tx.onabort = t.step_func_done(() => { | |
| 255 assert_equals(tx.error.name, 'AbortError'); | |
| 256 }); | |
| 257 }, | |
| 258 'Exception in error event handler on connection'); | |
| 259 | |
| 260 indexeddb_test( | |
| 261 (t, db) => { | |
| 262 db.createObjectStore('s'); | |
| 263 }, | |
| 264 (t, db) => { | |
| 265 const tx = db.transaction('s', 'readwrite'); | |
| 266 const store = tx.objectStore('s'); | |
| 267 store.put(0, 0); | |
| 268 const request = store.add(0, 0); | |
| 269 request.onsuccess = t.unreached_func('request should fail'); | |
| 270 db.onerror = e => { | |
| 271 e.preventDefault() | |
| 272 throw Error(); | |
| 273 }; | |
| 274 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 275 tx.onabort = t.step_func_done(() => { | |
| 276 assert_equals(tx.error.name, 'AbortError'); | |
| 277 }); | |
| 278 }, | |
| 279 'Exception in error event handler on connection, with preventDefault'); | |
| 280 | |
| 281 indexeddb_test( | |
| 282 (t, db) => { | |
| 283 db.createObjectStore('s'); | |
| 284 }, | |
| 285 (t, db) => { | |
| 286 const tx = db.transaction('s', 'readwrite'); | |
| 287 const store = tx.objectStore('s'); | |
| 288 store.put(0, 0); | |
| 289 const request = store.add(0, 0); | |
| 290 request.onsuccess = t.unreached_func('request should fail'); | |
| 291 db.addEventListener('error', () => { | |
| 292 throw Error(); | |
| 293 }); | |
| 294 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 295 tx.onabort = t.step_func_done(() => { | |
| 296 assert_equals(tx.error.name, 'AbortError'); | |
| 297 }); | |
| 298 }, | |
| 299 'Exception in error event listener on connection'); | |
| 300 | |
| 301 indexeddb_test( | |
| 302 (t, db) => { | |
| 303 db.createObjectStore('s'); | |
| 304 }, | |
| 305 (t, db) => { | |
| 306 const tx = db.transaction('s', 'readwrite'); | |
| 307 const store = tx.objectStore('s'); | |
| 308 store.put(0, 0); | |
| 309 const request = store.add(0, 0); | |
| 310 request.onsuccess = t.unreached_func('request should fail'); | |
| 311 db.addEventListener('error', () => { | |
| 312 // no-op | |
| 313 }); | |
| 314 db.addEventListener('error', () => { | |
| 315 throw Error(); | |
| 316 }); | |
| 317 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 318 tx.onabort = t.step_func_done(() => { | |
| 319 assert_equals(tx.error.name, 'AbortError'); | |
| 320 }); | |
| 321 }, | |
| 322 'Exception in second error event listener on connection'); | |
| 323 | |
| 324 indexeddb_test( | |
| 325 (t, db) => { | |
| 326 db.createObjectStore('s'); | |
| 327 }, | |
| 328 (t, db) => { | |
| 329 const tx = db.transaction('s', 'readwrite'); | |
| 330 const store = tx.objectStore('s'); | |
| 331 store.put(0, 0); | |
| 332 const request = store.add(0, 0); | |
| 333 request.onsuccess = t.unreached_func('request should fail'); | |
| 334 let second_listener_called = false; | |
| 335 db.addEventListener('error', () => { | |
| 336 throw Error('hi there'); | |
|
pwnall
2017/03/04 00:27:33
It's slightly odd that this error has a message, w
jsbell
2017/03/06 18:25:02
Oops, I left that in from some debugging. Will rem
| |
| 337 }); | |
| 338 db.addEventListener('error', t.step_func(() => { | |
| 339 second_listener_called = true; | |
| 340 assert_true(is_transaction_active(tx, 's'), | |
| 341 'Transaction should be active until dispatch completes'); | |
| 342 })); | |
| 343 tx.oncomplete = t.unreached_func('transaction should abort'); | |
| 344 tx.onabort = t.step_func_done(() => { | |
| 345 assert_true(second_listener_called); | |
| 346 assert_equals(tx.error.name, 'AbortError'); | |
| 347 }); | |
| 348 }, | |
| 349 'Exception in first error event listener on connection, ' + | |
| 350 'transaction active in second'); | |
| 351 | |
| 352 </script> | |
| OLD | NEW |