upgrade-transaction-lifecycle-backend-aborted.any.js (3588B)
1 // META: title=IndexedDB: backend-aborted versionchange transaction lifecycle 2 // META: global=window,worker 3 // META: script=resources/support.js 4 // META: script=resources/support-promises.js 5 6 // Spec: "https://w3c.github.io/IndexedDB/#upgrade-transaction-steps" 7 // "https://w3c.github.io/IndexedDB/#dom-idbdatabase-createobjectstore" 8 // "https://w3c.github.io/IndexedDB/#dom-idbdatabase-deleteobjectstore" 9 'use strict'; 10 11 promise_test(t => { 12 return createDatabase(t, database => { 13 createBooksStore(t, database); 14 }).then(database => { 15 database.close(); 16 }).then(() => migrateDatabase(t, 2, (database, transaction, request) => { 17 return new Promise((resolve, reject) => { 18 transaction.addEventListener('abort', () => { 19 resolve(new Promise((resolve, reject) => { 20 assert_equals( 21 request.transaction, transaction, 22 "The open request's transaction should be reset after onabort"); 23 assert_throws_dom( 24 'InvalidStateError', 25 () => { database.createObjectStore('books2'); }, 26 'createObjectStore exception should reflect that the ' + 27 'transaction is no longer running'); 28 assert_throws_dom( 29 'InvalidStateError', 30 () => { database.deleteObjectStore('books'); }, 31 'deleteObjectStore exception should reflect that the ' + 32 'transaction is no longer running'); 33 resolve(); 34 })); 35 }, false); 36 transaction.objectStore('books').add(BOOKS_RECORD_DATA[0]); 37 transaction._willBeAborted(); 38 }); 39 })); 40 }, 'in the abort event handler for a transaction aborted due to an unhandled ' + 41 'request error'); 42 43 promise_test(t => { 44 return createDatabase(t, database => { 45 createBooksStore(t, database); 46 }).then(database => { 47 database.close(); 48 }).then(() => migrateDatabase(t, 2, (database, transaction, request) => { 49 return new Promise((resolve, reject) => { 50 transaction.addEventListener('abort', () => { 51 setTimeout(() => { 52 resolve(new Promise((resolve, reject) => { 53 assert_equals( 54 request.transaction, null, 55 "The open request's transaction should be reset after " + 56 'onabort microtasks'); 57 assert_throws_dom( 58 'InvalidStateError', 59 () => { database.createObjectStore('books2'); }, 60 'createObjectStore exception should reflect that the ' + 61 'transaction is no longer running'); 62 assert_throws_dom( 63 'InvalidStateError', 64 () => { database.deleteObjectStore('books'); }, 65 'deleteObjectStore exception should reflect that the ' + 66 'transaction is no longer running'); 67 resolve(); 68 })); 69 }, 0); 70 }, false); 71 transaction.objectStore('books').add(BOOKS_RECORD_DATA[0]); 72 transaction._willBeAborted(); 73 }); 74 })); 75 }, 'in a setTimeout(0) callback after the abort event is fired for a ' + 76 'transaction aborted due to an unhandled request failure');