OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>Fire error event - Exception thrown</title> |
| 4 <link rel="help" href="https://w3c.github.io/IndexedDB/#fire-error-event"> |
| 5 <script src=/resources/testharness.js></script> |
| 6 <script src=/resources/testharnessreport.js></script> |
| 7 <script src=support.js></script> |
| 8 <script> |
| 9 setup({allow_uncaught_exception:true}); |
| 10 |
| 11 function fire_error_event_test(func, description) { |
| 12 indexeddb_test( |
| 13 (t, db) => { |
| 14 db.createObjectStore('s'); |
| 15 }, |
| 16 (t, db) => { |
| 17 const tx = db.transaction('s', 'readwrite'); |
| 18 tx.oncomplete = t.unreached_func('transaction should abort'); |
| 19 const store = tx.objectStore('s'); |
| 20 store.put(0, 0); |
| 21 const request = store.add(0, 0); |
| 22 request.onsuccess = t.unreached_func('request should fail'); |
| 23 func(t, db, tx, request); |
| 24 }, |
| 25 description); |
| 26 } |
| 27 |
| 28 // Listeners on the request. |
| 29 |
| 30 fire_error_event_test((t, db, tx, request) => { |
| 31 request.onerror = () => { |
| 32 throw Error(); |
| 33 }; |
| 34 tx.onabort = t.step_func_done(() => { |
| 35 assert_equals(tx.error.name, 'AbortError'); |
| 36 }); |
| 37 }, 'Exception in error event handler on request'); |
| 38 |
| 39 fire_error_event_test((t, db, tx, request) => { |
| 40 request.onerror = e => { |
| 41 e.preventDefault(); |
| 42 throw Error(); |
| 43 }; |
| 44 tx.onabort = t.step_func_done(() => { |
| 45 assert_equals(tx.error.name, 'AbortError'); |
| 46 }); |
| 47 }, 'Exception in error event handler on request, with preventDefault'); |
| 48 |
| 49 fire_error_event_test((t, db, tx, request) => { |
| 50 request.addEventListener('error', () => { |
| 51 throw Error(); |
| 52 }); |
| 53 tx.onabort = t.step_func_done(() => { |
| 54 assert_equals(tx.error.name, 'AbortError'); |
| 55 }); |
| 56 }, 'Exception in error event listener on request'); |
| 57 |
| 58 fire_error_event_test((t, db, tx, request) => { |
| 59 request.addEventListener('error', () => { |
| 60 // no-op |
| 61 }); |
| 62 request.addEventListener('error', () => { |
| 63 throw Error(); |
| 64 }); |
| 65 tx.onabort = t.step_func_done(() => { |
| 66 assert_equals(tx.error.name, 'AbortError'); |
| 67 }); |
| 68 }, 'Exception in second error event listener on request'); |
| 69 |
| 70 fire_error_event_test((t, db, tx, request) => { |
| 71 let second_listener_called = false; |
| 72 request.addEventListener('error', () => { |
| 73 throw Error(); |
| 74 }); |
| 75 request.addEventListener('error', t.step_func(() => { |
| 76 second_listener_called = true; |
| 77 assert_true(is_transaction_active(tx, 's'), |
| 78 'Transaction should be active until dispatch completes'); |
| 79 })); |
| 80 tx.onabort = t.step_func_done(() => { |
| 81 assert_true(second_listener_called); |
| 82 assert_equals(tx.error.name, 'AbortError'); |
| 83 }); |
| 84 }, 'Exception in first error event listener on request, ' + |
| 85 'transaction active in second'); |
| 86 |
| 87 // Listeners on the transaction. |
| 88 |
| 89 fire_error_event_test((t, db, tx, request) => { |
| 90 tx.onerror = () => { |
| 91 throw Error(); |
| 92 }; |
| 93 tx.onabort = t.step_func_done(() => { |
| 94 assert_equals(tx.error.name, 'AbortError'); |
| 95 }); |
| 96 }, 'Exception in error event handler on transaction'); |
| 97 |
| 98 fire_error_event_test((t, db, tx, request) => { |
| 99 tx.onerror = e => { |
| 100 e.preventDefault(); |
| 101 throw Error(); |
| 102 }; |
| 103 tx.onabort = t.step_func_done(() => { |
| 104 assert_equals(tx.error.name, 'AbortError'); |
| 105 }); |
| 106 }, 'Exception in error event handler on transaction, with preventDefault'); |
| 107 |
| 108 fire_error_event_test((t, db, tx, request) => { |
| 109 tx.addEventListener('error', () => { |
| 110 throw Error(); |
| 111 }); |
| 112 tx.onabort = t.step_func_done(() => { |
| 113 assert_equals(tx.error.name, 'AbortError'); |
| 114 }); |
| 115 }, 'Exception in error event listener on transaction'); |
| 116 |
| 117 fire_error_event_test((t, db, tx, request) => { |
| 118 tx.addEventListener('error', () => { |
| 119 // no-op |
| 120 }); |
| 121 tx.addEventListener('error', () => { |
| 122 throw Error(); |
| 123 }); |
| 124 tx.onabort = t.step_func_done(() => { |
| 125 assert_equals(tx.error.name, 'AbortError'); |
| 126 }); |
| 127 }, 'Exception in second error event listener on transaction'); |
| 128 |
| 129 fire_error_event_test((t, db, tx, request) => { |
| 130 let second_listener_called = false; |
| 131 tx.addEventListener('error', () => { |
| 132 throw Error(); |
| 133 }); |
| 134 tx.addEventListener('error', t.step_func(() => { |
| 135 second_listener_called = true; |
| 136 assert_true(is_transaction_active(tx, 's'), |
| 137 'Transaction should be active until dispatch completes'); |
| 138 })); |
| 139 tx.onabort = t.step_func_done(() => { |
| 140 assert_true(second_listener_called); |
| 141 assert_equals(tx.error.name, 'AbortError'); |
| 142 }); |
| 143 }, 'Exception in first error event listener on transaction, ' + |
| 144 'transaction active in second'); |
| 145 |
| 146 // Listeners on the connection. |
| 147 |
| 148 fire_error_event_test((t, db, tx, request) => { |
| 149 db.onerror = () => { |
| 150 throw Error(); |
| 151 }; |
| 152 tx.onabort = t.step_func_done(() => { |
| 153 assert_equals(tx.error.name, 'AbortError'); |
| 154 }); |
| 155 }, 'Exception in error event handler on connection'); |
| 156 |
| 157 fire_error_event_test((t, db, tx, request) => { |
| 158 db.onerror = e => { |
| 159 e.preventDefault() |
| 160 throw Error(); |
| 161 }; |
| 162 tx.onabort = t.step_func_done(() => { |
| 163 assert_equals(tx.error.name, 'AbortError'); |
| 164 }); |
| 165 }, 'Exception in error event handler on connection, with preventDefault'); |
| 166 |
| 167 fire_error_event_test((t, db, tx, request) => { |
| 168 db.addEventListener('error', () => { |
| 169 throw Error(); |
| 170 }); |
| 171 tx.onabort = t.step_func_done(() => { |
| 172 assert_equals(tx.error.name, 'AbortError'); |
| 173 }); |
| 174 }, 'Exception in error event listener on connection'); |
| 175 |
| 176 fire_error_event_test((t, db, tx, request) => { |
| 177 db.addEventListener('error', () => { |
| 178 // no-op |
| 179 }); |
| 180 db.addEventListener('error', () => { |
| 181 throw Error(); |
| 182 }); |
| 183 tx.onabort = t.step_func_done(() => { |
| 184 assert_equals(tx.error.name, 'AbortError'); |
| 185 }); |
| 186 }, 'Exception in second error event listener on connection'); |
| 187 |
| 188 fire_error_event_test((t, db, tx, request) => { |
| 189 let second_listener_called = false; |
| 190 db.addEventListener('error', () => { |
| 191 throw Error(); |
| 192 }); |
| 193 db.addEventListener('error', t.step_func(() => { |
| 194 second_listener_called = true; |
| 195 assert_true(is_transaction_active(tx, 's'), |
| 196 'Transaction should be active until dispatch completes'); |
| 197 })); |
| 198 tx.onabort = t.step_func_done(() => { |
| 199 assert_true(second_listener_called); |
| 200 assert_equals(tx.error.name, 'AbortError'); |
| 201 }); |
| 202 }, 'Exception in first error event listener on connection, ' + |
| 203 'transaction active in second'); |
| 204 |
| 205 </script> |
OLD | NEW |