Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <title>IndexedDB: Exception Ordering</title> | |
| 3 <script src="../../resources/testharness.js"></script> | |
|
pwnall
2016/09/01 19:03:52
Would it make sense to point to the spec that you'
jsbell
2016/09/01 20:20:46
Done.
| |
| 4 <script src="../../resources/testharnessreport.js"></script> | |
| 5 <script src="resources/testharness-helpers.js"></script> | |
| 6 <script> | |
| 7 | |
| 8 indexeddb_test( | |
|
pwnall
2016/09/01 19:03:52
Can we upstream tests that reference helpers? I'm
jsbell
2016/09/01 20:20:46
Yes. There's a variation of this in web-platform-t
| |
| 9 function(t, db) { | |
| 10 db.createObjectStore('s'); | |
| 11 }, | |
| 12 function(t, db) { | |
| 13 db.close(); | |
| 14 assert_throws('InvalidStateError', function() { | |
| 15 // Could throw: | |
| 16 // * InvalidStateError (connection is closed) | |
| 17 // * InvalidAccessError (stores is empty) | |
| 18 db.transaction([]); | |
| 19 }, 'Connection closed check should precede stores check'); | |
|
pwnall
2016/09/01 19:03:52
Should the comment above be merged into the assert
jsbell
2016/09/01 20:20:46
Done.
| |
| 20 t.done(); | |
| 21 }, | |
| 22 'IDBDatabase.transaction exception order: InvalidStateError vs. InvalidAcces sError' | |
| 23 ); | |
| 24 | |
|
pwnall
2016/09/01 19:03:52
Would it make sense to also have a test for Invali
jsbell
2016/09/01 20:20:46
Done.
| |
| 25 indexeddb_test( | |
| 26 function(t, db) { | |
| 27 db.createObjectStore('s'); | |
| 28 }, | |
| 29 function(t, db) { | |
| 30 assert_throws('NotFoundError', function() { | |
| 31 // Could throw: | |
| 32 // * NotFoundError (no such store) | |
| 33 // * InvalidAccessError (invalid mode) | |
| 34 db.transaction('no-such-store', 'versionchange'); | |
| 35 }, 'Stores check should precede mode check'); | |
| 36 t.done(); | |
| 37 }, | |
| 38 'IDBDatabase.transaction exception order: NotFoundError vs. InvalidAccessErr or' | |
| 39 ); | |
| 40 | |
| 41 indexeddb_test( | |
| 42 function(t, db) { | |
| 43 db.createObjectStore('s'); | |
| 44 assert_throws('SyntaxError', function() { | |
|
pwnall
2016/09/01 19:03:52
I think the spec [1] says exactly the opposite. Th
jsbell
2016/09/01 20:20:46
Yes. Firefox matches the code here, so I'll just u
| |
| 45 // Could throw: | |
| 46 // * SyntaxError (invalid keypath) | |
| 47 // * ConstraintError (duplicate store name) | |
| 48 db.createObjectStore('s', {keyPath: 'not a valid key path'}); | |
| 49 }, 'Keypad validation should precede store name check'); | |
|
pwnall
2016/09/01 19:03:52
Keypad -> keypath?
jsbell
2016/09/01 20:20:46
Done.
| |
| 50 t.done(); | |
| 51 }, | |
| 52 function(t, db) {}, | |
| 53 'IDBDatabase.createObjectStore exception order: ConstraintError vs. SyntaxEr ror' | |
| 54 ); | |
| 55 | |
| 56 indexeddb_test( | |
| 57 function(t, db) { | |
| 58 var s = db.createObjectStore('s'); | |
| 59 s.put('value', 'key'); | |
| 60 }, | |
| 61 function(t, db) { | |
| 62 var s = db.transaction('s', 'readonly').objectStore('s'); | |
| 63 var r = s.openKeyCursor(); | |
| 64 r.onsuccess = t.step_func(function() { | |
| 65 r.onsuccess = null; | |
| 66 var cursor = r.result; | |
| 67 setTimeout(t.step_func(function() { | |
| 68 assert_throws('TransactionInactiveError', function() { | |
| 69 // Could throw: | |
| 70 // * TransactionInactiveError (not in callback) | |
| 71 // * DataError (invalid key) | |
| 72 cursor.continue({not:"a valid key"}); | |
| 73 }, 'Inactive check should precede key check'); | |
| 74 t.done(); | |
| 75 }), 0); | |
| 76 }); | |
| 77 }, | |
| 78 'IDBCursor.continue exception order: TransactionInactiveError vs. DataError' | |
| 79 ); | |
| 80 | |
| 81 indexeddb_test( | |
| 82 function(t, db) { | |
| 83 var s = db.createObjectStore('s'); | |
| 84 s.put('value', 'key'); | |
| 85 }, | |
| 86 function(t, db) { | |
| 87 var s = db.transaction('s', 'readonly').objectStore('s'); | |
| 88 var r = s.openKeyCursor(); | |
| 89 r.onsuccess = t.step_func(function() { | |
| 90 r.onsuccess = null; | |
| 91 var cursor = r.result; | |
| 92 cursor.continue(); | |
| 93 assert_throws('InvalidStateError', function() { | |
| 94 // Could throw: | |
| 95 // * InvalidStateError (cursor already advancing) | |
| 96 // * DataError (invalid key) | |
| 97 cursor.continue({not:"a valid key"}); | |
| 98 }, 'Inactive check should precede key check'); | |
| 99 t.done(); | |
| 100 }); | |
| 101 }, | |
| 102 'IDBCursor.continue exception order: InvalidStateError vs. DataError' | |
| 103 ); | |
| 104 | |
|
pwnall
2016/09/01 19:03:52
Would it also make sense to test TransactionInacti
jsbell
2016/09/01 20:20:46
Done.
| |
| 105 indexeddb_test( | |
| 106 function(t, db) { | |
| 107 var s = db.createObjectStore('s'); | |
| 108 s.put('value', 'key'); | |
| 109 }, | |
| 110 function(t, db) { | |
| 111 var s = db.transaction('s', 'readonly').objectStore('s'); | |
| 112 var r = s.openCursor(); | |
| 113 r.onsuccess = t.step_func(function() { | |
| 114 r.onsuccess = null; | |
| 115 var cursor = r.result; | |
| 116 setTimeout(t.step_func(function() { | |
| 117 assert_throws('TransactionInactiveError', function() { | |
| 118 // Could throw: | |
| 119 // * TransactionInactiveError (not in callback) | |
| 120 // * ReadOnlyError (key cursor) | |
| 121 cursor.delete(); | |
| 122 }, 'Inactive check should precede readonly check'); | |
| 123 t.done(); | |
| 124 }), 0); | |
| 125 }); | |
| 126 }, | |
| 127 'IDBCursor.delete exception order: TransactionInactiveError vs. ReadOnlyErro r' | |
| 128 ); | |
| 129 | |
| 130 indexeddb_test( | |
| 131 function(t, db) { | |
| 132 var s = db.createObjectStore('s'); | |
| 133 s.put('value', 'key'); | |
| 134 }, | |
| 135 function(t, db) { | |
| 136 var s = db.transaction('s', 'readonly').objectStore('s'); | |
| 137 var r = s.openCursor(); | |
| 138 r.onsuccess = t.step_func(function() { | |
| 139 r.onsuccess = null; | |
| 140 var cursor = r.result; | |
| 141 cursor.continue(); | |
| 142 assert_throws('ReadOnlyError', function() { | |
| 143 // Could throw: | |
| 144 // * ReadOnlyError (read only transaction) | |
| 145 // * InvalidStateError (cursor already advancing) | |
|
pwnall
2016/09/01 19:03:52
The spec [1] lists 3 causes that could end up in I
jsbell
2016/09/01 20:20:46
I did 2 of 3 (and ditto for "update"). You can't h
| |
| 146 cursor.delete(); | |
| 147 }, 'State check should precede readonly check'); | |
| 148 t.done(); | |
| 149 }); | |
| 150 }, | |
| 151 'IDBCursor.delete exception order: ReadOnlyError vs. InvalidStateError' | |
| 152 ); | |
| 153 | |
| 154 indexeddb_test( | |
| 155 function(t, db) { | |
| 156 var s = db.createObjectStore('s'); | |
| 157 s.put('value', 'key'); | |
| 158 }, | |
| 159 function(t, db) { | |
| 160 var s = db.transaction('s', 'readonly').objectStore('s'); | |
| 161 var r = s.openCursor(); | |
| 162 r.onsuccess = t.step_func(function() { | |
| 163 r.onsuccess = null; | |
| 164 var cursor = r.result; | |
| 165 setTimeout(t.step_func(function() { | |
| 166 assert_throws('TransactionInactiveError', function() { | |
| 167 // Could throw: | |
| 168 // * TransactionInactiveError (not in callback) | |
| 169 // * ReadOnlyError (key cursor) | |
| 170 cursor.update('value2'); | |
| 171 }, 'Inactive check should precede readonly check'); | |
| 172 t.done(); | |
| 173 }), 0); | |
| 174 }); | |
| 175 }, | |
| 176 'IDBCursor.update exception order: TransactionInactiveError vs. ReadOnlyErro r' | |
| 177 ); | |
| 178 | |
| 179 indexeddb_test( | |
| 180 function(t, db) { | |
| 181 var s = db.createObjectStore('s'); | |
| 182 s.put('value', 'key'); | |
| 183 }, | |
| 184 function(t, db) { | |
| 185 var s = db.transaction('s', 'readonly').objectStore('s'); | |
| 186 var r = s.openCursor(); | |
| 187 r.onsuccess = t.step_func(function() { | |
| 188 r.onsuccess = null; | |
| 189 var cursor = r.result; | |
| 190 cursor.continue(); | |
| 191 assert_throws('ReadOnlyError', function() { | |
| 192 // Could throw: | |
| 193 // * ReadOnlyError (read only transaction) | |
| 194 // * InvalidStateError (cursor already advancing) | |
| 195 cursor.update('value2'); | |
| 196 }, 'Readonly check should precede got value check'); | |
| 197 t.done(); | |
| 198 }); | |
| 199 }, | |
| 200 'IDBCursor.update exception order: ReadOnlyError vs. InvalidStateError' | |
| 201 ); | |
| 202 | |
| 203 indexeddb_test( | |
| 204 function(t, db) { | |
| 205 var s = db.createObjectStore('s', {keyPath: 'id'}); | |
| 206 s.put({id: 123, data: 'value'}); | |
| 207 }, | |
| 208 function(t, db) { | |
| 209 var s = db.transaction('s', 'readwrite').objectStore('s'); | |
| 210 var r = s.openCursor(); | |
| 211 r.onsuccess = t.step_func(function() { | |
| 212 r.onsuccess = null; | |
| 213 var cursor = r.result; | |
| 214 cursor.continue(); | |
| 215 assert_throws('InvalidStateError', function() { | |
| 216 // Could throw: | |
| 217 // * InvalidStateError (cursor already advancing) | |
| 218 // * DataError (modified key) | |
| 219 cursor.update({id: 123, data: 'value2'}); | |
| 220 }, 'Got value check should precede key check'); | |
| 221 t.done(); | |
| 222 }); | |
| 223 }, | |
| 224 'IDBCursor.update exception order: InvalidStateError vs. DataError' | |
| 225 ); | |
| 226 | |
| 227 </script> | |
| OLD | NEW |