transaction-abort-object-store-metadata-revert.any.js (13761B)
1 // META: title=IndexedDB: aborting transactions reverts object store metadata 2 // META: global=window,worker 3 // META: script=resources/support-promises.js 4 // META: script=resources/support.js 5 6 // Spec: https://w3c.github.io/IndexedDB/#abort-transaction 7 8 'use strict'; 9 10 promise_test(testCase => { 11 let store = null; 12 let migrationTransaction = null; 13 let migrationDatabase = null; 14 return createDatabase( 15 testCase, 16 (database, transaction) => { 17 createBooksStore(testCase, database); 18 }) 19 .then(database => { 20 database.close(); 21 }) 22 .then( 23 () => migrateDatabase( 24 testCase, 2, 25 (database, transaction) => { 26 store = createNotBooksStore(testCase, database); 27 migrationDatabase = database; 28 migrationTransaction = transaction; 29 assert_array_equals( 30 database.objectStoreNames, ['books', 'not_books'], 31 'IDBDatabase.objectStoreNames should include a newly created ' + 32 'store before the transaction is aborted'); 33 assert_array_equals( 34 transaction.objectStoreNames, ['books', 'not_books'], 35 'IDBTransaction.objectStoreNames should include a newly created ' + 36 'store before the transaction is aborted'); 37 38 transaction.abort(); 39 assert_throws_dom( 40 'InvalidStateError', () => store.get('query'), 41 'IDBObjectStore.get should throw InvalidStateError, indicating ' + 42 'that the store is marked for deletion, immediately after ' + 43 'IDBTransaction.abort() returns'); 44 assert_array_equals( 45 transaction.objectStoreNames, ['books'], 46 'IDBTransaction.objectStoreNames should stop including the newly ' + 47 'created store immediately after IDBTransaction.abort() returns'); 48 assert_array_equals( 49 database.objectStoreNames, ['books'], 50 'IDBDatabase.objectStoreNames should stop including the newly ' + 51 'created store immediately after IDBTransaction.abort() returns'); 52 })) 53 .then(() => { 54 assert_throws_dom( 55 'InvalidStateError', () => store.get('query'), 56 'IDBObjectStore.get should throw InvalidStateError, indicating ' + 57 'that the store is marked for deletion, after the transaction is ' + 58 'aborted'); 59 assert_array_equals( 60 migrationDatabase.objectStoreNames, ['books'], 61 'IDBDatabase.objectStoreNames should stop including the newly ' + 62 'created store after the transaction is aborted'); 63 assert_array_equals( 64 migrationTransaction.objectStoreNames, ['books'], 65 'IDBTransaction.objectStoreNames should stop including the newly ' + 66 'created store after the transaction is aborted'); 67 }); 68 }, 'Created stores get marked as deleted after their transaction aborts'); 69 70 promise_test(testCase => { 71 let store = null; 72 let migrationTransaction = null; 73 let migrationDatabase = null; 74 return createDatabase( 75 testCase, 76 (database, transaction) => { 77 createBooksStore(testCase, database); 78 createNotBooksStore(testCase, database); 79 }) 80 .then(database => { 81 database.close(); 82 }) 83 .then( 84 () => migrateDatabase( 85 testCase, 2, 86 (database, transaction) => { 87 migrationDatabase = database; 88 migrationTransaction = transaction; 89 store = transaction.objectStore('not_books'); 90 91 database.deleteObjectStore('not_books'); 92 assert_throws_dom( 93 'InvalidStateError', () => store.get('query'), 94 'IDBObjectStore.get should throw InvalidStateError, indicating ' + 95 'that the store is marked for deletion, immediately after ' + 96 'IDBDatabase.deleteObjectStore() returns'); 97 assert_array_equals( 98 transaction.objectStoreNames, ['books'], 99 'IDBTransaction.objectStoreNames should stop including the ' + 100 'deleted store immediately after IDBDatabase.deleteObjectStore() ' + 101 'returns'); 102 assert_array_equals( 103 database.objectStoreNames, ['books'], 104 'IDBDatabase.objectStoreNames should stop including the newly ' + 105 'created store immediately after IDBDatabase.deleteObjectStore() ' + 106 'returns'); 107 108 transaction.abort(); 109 assert_throws_dom( 110 'TransactionInactiveError', () => store.get('query'), 111 'IDBObjectStore.get should throw TransactionInactiveError, ' + 112 'indicating that the store is no longer marked for deletion, ' + 113 'immediately after IDBTransaction.abort() returns'); 114 assert_array_equals( 115 database.objectStoreNames, ['books', 'not_books'], 116 'IDBDatabase.objectStoreNames should include the deleted store ' + 117 'store immediately after IDBTransaction.abort() returns'); 118 assert_array_equals( 119 transaction.objectStoreNames, ['books', 'not_books'], 120 'IDBTransaction.objectStoreNames should include the deleted ' + 121 'store immediately after IDBTransaction.abort() returns'); 122 })) 123 .then(() => { 124 assert_throws_dom( 125 'TransactionInactiveError', () => store.get('query'), 126 'IDBObjectStore.get should throw TransactionInactiveError, ' + 127 'indicating that the store is no longer marked for deletion, ' + 128 'after the transaction is aborted'); 129 assert_array_equals( 130 migrationDatabase.objectStoreNames, ['books', 'not_books'], 131 'IDBDatabase.objectStoreNames should include the previously ' + 132 'deleted store after the transaction is aborted'); 133 assert_array_equals( 134 migrationTransaction.objectStoreNames, ['books', 'not_books'], 135 'IDBTransaction.objectStoreNames should include the previously ' + 136 'deleted store after the transaction is aborted'); 137 }); 138 }, 'Deleted stores get marked as not-deleted after the transaction aborts'); 139 140 promise_test( 141 testCase => { 142 let store = null; 143 let migrationTransaction = null; 144 let migrationDatabase = null; 145 return createDatabase( 146 testCase, 147 (database, transaction) => { 148 createBooksStore(testCase, database); 149 }) 150 .then(database => { 151 database.close(); 152 }) 153 .then( 154 () => migrateDatabase( 155 testCase, 2, 156 (database, transaction) => { 157 store = createNotBooksStore(testCase, database); 158 migrationDatabase = database; 159 migrationTransaction = transaction; 160 assert_array_equals( 161 database.objectStoreNames, ['books', 'not_books'], 162 'IDBDatabase.objectStoreNames should include a newly created ' + 163 'store before the transaction is aborted'); 164 assert_array_equals( 165 transaction.objectStoreNames, ['books', 'not_books'], 166 'IDBTransaction.objectStoreNames should include a newly created ' + 167 'store before the transaction is aborted'); 168 169 database.deleteObjectStore('not_books'); 170 assert_throws_dom( 171 'InvalidStateError', () => store.get('query'), 172 'IDBObjectStore.get should throw InvalidStateError, indicating ' + 173 'that the store is marked for deletion, immediately after ' + 174 'IDBDatabase.deleteObjectStore() returns'); 175 assert_array_equals( 176 transaction.objectStoreNames, ['books'], 177 'IDBTransaction.objectStoreNames should stop including the ' + 178 'deleted store immediately after IDBDatabase.deleteObjectStore() ' + 179 'returns'); 180 assert_array_equals( 181 database.objectStoreNames, ['books'], 182 'IDBDatabase.objectStoreNames should stop including the newly ' + 183 'created store immediately after IDBDatabase.deleteObjectStore() ' + 184 'returns'); 185 186 transaction.abort(); 187 assert_throws_dom( 188 'InvalidStateError', () => store.get('query'), 189 'IDBObjectStore.get should throw InvalidStateError, indicating ' + 190 'that the store is still marked for deletion, immediately after ' + 191 'IDBTransaction.abort() returns'); 192 assert_array_equals( 193 transaction.objectStoreNames, ['books'], 194 'IDBTransaction.objectStoreNames should not include the newly ' + 195 'created store immediately after IDBTransaction.abort() returns'); 196 assert_array_equals( 197 database.objectStoreNames, ['books'], 198 'IDBDatabase.objectStoreNames should not include the newly ' + 199 'created store immediately after IDBTransaction.abort() returns'); 200 })) 201 .then(() => { 202 assert_throws_dom( 203 'InvalidStateError', () => store.get('query'), 204 'IDBObjectStore.get should throw InvalidStateError, indicating ' + 205 'that the store is still marked for deletion, after the ' + 206 'transaction is aborted'); 207 assert_array_equals( 208 migrationDatabase.objectStoreNames, ['books'], 209 'IDBDatabase.objectStoreNames should not include the newly ' + 210 'created store after the transaction is aborted'); 211 assert_array_equals( 212 migrationTransaction.objectStoreNames, ['books'], 213 'IDBTransaction.objectStoreNames should not include the newly ' + 214 'created store after the transaction is aborted'); 215 }); 216 }, 217 'Created+deleted stores are still marked as deleted after their ' + 218 'transaction aborts'); 219 220 promise_test( 221 testCase => { 222 let migrationTransaction = null; 223 let migrationDatabase = null; 224 return createDatabase( 225 testCase, 226 (database, transaction) => { 227 createBooksStore(testCase, database); 228 createNotBooksStore(testCase, database); 229 }) 230 .then(database => { 231 database.close(); 232 }) 233 .then( 234 () => migrateDatabase( 235 testCase, 2, 236 (database, transaction) => { 237 migrationDatabase = database; 238 migrationTransaction = transaction; 239 240 database.deleteObjectStore('not_books'); 241 assert_array_equals( 242 transaction.objectStoreNames, ['books'], 243 'IDBTransaction.objectStoreNames should stop including the ' + 244 'deleted store immediately after IDBDatabase.deleteObjectStore() ' + 245 'returns'); 246 assert_array_equals( 247 database.objectStoreNames, ['books'], 248 'IDBDatabase.objectStoreNames should stop including the newly ' + 249 'created store immediately after IDBDatabase.deleteObjectStore() ' + 250 'returns'); 251 252 transaction.abort(); 253 assert_array_equals( 254 database.objectStoreNames, ['books', 'not_books'], 255 'IDBDatabase.objectStoreNames should include the deleted store ' + 256 'store immediately after IDBTransaction.abort() returns'); 257 assert_array_equals( 258 transaction.objectStoreNames, ['books', 'not_books'], 259 'IDBTransaction.objectStoreNames should include the deleted ' + 260 'store immediately after IDBTransaction.abort() returns'); 261 })) 262 .then(() => { 263 assert_array_equals( 264 migrationDatabase.objectStoreNames, ['books', 'not_books'], 265 'IDBDatabase.objectStoreNames should include the previously ' + 266 'deleted store after the transaction is aborted'); 267 assert_array_equals( 268 migrationTransaction.objectStoreNames, ['books', 'not_books'], 269 'IDBTransaction.objectStoreNames should include the previously ' + 270 'deleted store after the transaction is aborted'); 271 }); 272 }, 273 'Un-instantiated deleted stores get marked as not-deleted after the ' + 274 'transaction aborts');