upgrade-transaction-lifecycle-user-aborted.any.js (5187B)
1 // META: title=IndexedDB: user-abort()ed 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 10 'use strict'; 11 12 promise_test(t => { 13 return createDatabase(t, database => { 14 createBooksStore(t, database); 15 }).then(database => { 16 database.close(); 17 }).then(() => migrateDatabase(t, 2, (database, transaction, request) => { 18 transaction.abort(); 19 assert_equals( 20 request.transaction, transaction, 21 "The open request's transaction should be reset after onabort"); 22 23 assert_throws_dom( 24 'TransactionInactiveError', 25 () => { database.createObjectStore('books2'); }, 26 'createObjectStore exception should reflect that the transaction is ' + 27 'still running'); 28 assert_throws_dom( 29 'TransactionInactiveError', 30 () => { database.deleteObjectStore('books'); }, 31 'deleteObjectStore exception should reflect that the transaction is' + 32 'still running'); 33 })); 34 }, 'synchronously after abort() is called'); 35 36 promise_test(t => { 37 return createDatabase(t, database => { 38 createBooksStore(t, database); 39 }).then(database => { 40 database.close(); 41 }).then(() => migrateDatabase(t, 2, (database, transaction, request) => { 42 let abortFired = false; 43 const abortPromise = new Promise((resolve, reject) => { 44 transaction.addEventListener('abort', () => { 45 abortFired = true; 46 resolve(); 47 }, false); 48 transaction.abort(); 49 }); 50 51 return Promise.resolve().then(() => { 52 assert_false( 53 abortFired, 54 'The abort event should fire after promises are resolved'); 55 assert_equals( 56 request.transaction, transaction, 57 "The open request's transaction should be reset after onabort"); 58 assert_throws_dom( 59 'TransactionInactiveError', 60 () => { database.createObjectStore('books2'); }, 61 'createObjectStore exception should reflect that the transaction ' + 62 'is still running'); 63 assert_throws_dom( 64 'TransactionInactiveError', 65 () => { database.deleteObjectStore('books'); }, 66 'deleteObjectStore exception should reflect that the transaction ' + 67 'is still running'); 68 }).then(() => abortPromise); 69 })); 70 }, 'in a promise microtask after abort() is called, before the transaction ' + 71 'abort event is fired'); 72 73 promise_test(t => { 74 return createDatabase(t, database => { 75 createBooksStore(t, database); 76 }).then(database => { 77 database.close(); 78 }).then(() => migrateDatabase(t, 2, (database, transaction, request) => { 79 return new Promise((resolve, reject) => { 80 transaction.addEventListener('abort', () => { 81 resolve(new Promise((resolve, reject) => { 82 assert_equals( 83 request.transaction, transaction, 84 "The open request's transaction should be reset after onabort"); 85 assert_throws_dom( 86 'InvalidStateError', 87 () => { database.createObjectStore('books2'); }, 88 'createObjectStore exception should reflect that the ' + 89 'transaction is no longer running'); 90 assert_throws_dom( 91 'InvalidStateError', 92 () => { database.deleteObjectStore('books'); }, 93 'deleteObjectStore exception should reflect that the ' + 94 'transaction is no longer running'); 95 resolve(); 96 })); 97 }, false); 98 transaction.abort(); 99 }); 100 })); 101 }, 'in the abort event handler for a transaction aborted due to an abort() ' + 102 'call'); 103 104 promise_test(t => { 105 return createDatabase(t, database => { 106 createBooksStore(t, database); 107 }).then(database => { 108 database.close(); 109 }).then(() => migrateDatabase(t, 2, (database, transaction, request) => { 110 return new Promise((resolve, reject) => { 111 transaction.addEventListener('abort', () => { 112 setTimeout(() => { 113 resolve(new Promise((resolve, reject) => { 114 assert_equals( 115 request.transaction, null, 116 "The open request's transaction should be reset after " + 117 'onabort microtasks'); 118 assert_throws_dom( 119 'InvalidStateError', 120 () => { database.createObjectStore('books2'); }, 121 'createObjectStore exception should reflect that the ' + 122 'transaction is no longer running'); 123 assert_throws_dom( 124 'InvalidStateError', 125 () => { database.deleteObjectStore('books'); }, 126 'deleteObjectStore exception should reflect that the ' + 127 'transaction is no longer running'); 128 resolve(); 129 })); 130 }, 0); 131 }, false); 132 transaction.abort(); 133 }); 134 })); 135 }, 'in a setTimeout(0) callback after the abort event is fired for a ' + 136 'transaction aborted due to an abort() call');