transaction-abort-generator-revert.any.js (5589B)
1 // META: title=IndexedDB: aborting transactions reverts an object store's key generator state 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( 11 testCase => { 12 return createDatabase( 13 testCase, 14 (database, transaction) => { 15 createBooksStore(testCase, database); 16 }) 17 .then(database => { 18 database.close(); 19 }) 20 .then(() => { 21 return new Promise((resolve, reject) => { 22 const request = indexedDB.open(databaseName(testCase), 2); 23 request.onupgradeneeded = testCase.step_func(event => { 24 const database = event.target.result; 25 const transaction = event.target.transaction; 26 const store = transaction.objectStore('books'); 27 const request2 = 28 store.put({title: 'Bedrock Nights II', author: 'Barney'}); 29 request2.onerror = testCase.unreached_func( 30 'IDBObjectStore.put() should not receive an error request'); 31 request2.onsuccess = testCase.step_func(event => { 32 assert_equals( 33 event.target.result, 345679, 34 'The key generator\'s current number should be set by ' + 35 'the last put operation in the database creation ' + 36 'transaction'); 37 38 request.onerror = event => { 39 event.preventDefault(); 40 resolve(event); 41 }; 42 request.onsuccess = () => reject(new Error( 43 'indexedDB.open should not succeed after the ' + 44 'versionchange transaction is aborted')); 45 46 transaction.abort(); 47 }); 48 }); 49 request.onerror = event => reject(event.target.error); 50 request.onsuccess = () => reject(new Error( 51 'indexedDB.open should not succeed without creating a ' + 52 'versionchange transaction')); 53 }); 54 }) 55 .then(() => { 56 return openDatabase(testCase, 1); 57 }) 58 .then(database => { 59 const transaction = database.transaction(['books'], 'readwrite'); 60 const store = transaction.objectStore('books'); 61 62 return checkStoreGenerator( 63 testCase, store, 345679, 64 'The key generator\'s current number should be reverted after the ' + 65 'transaction modifying it is aborted') 66 .then(() => database.close()); 67 }); 68 }, 69 'The current number of a key generator is reverted when a versionchange ' + 70 'transaction aborts'); 71 72 promise_test( 73 testCase => { 74 return createDatabase( 75 testCase, 76 (database, transaction) => { 77 createBooksStore(testCase, database); 78 }) 79 .then(database => { 80 return new Promise((resolve, reject) => { 81 const transaction = 82 database.transaction(['books'], 'readwrite'); 83 const store = transaction.objectStore('books'); 84 const request = store.put( 85 {title: 'Bedrock Nights II', author: 'Barney'}); 86 request.onerror = testCase.unreached_func( 87 'IDBObjectStore.put() should not receive an error request'); 88 request.onsuccess = testCase.step_func(event => { 89 assert_equals( 90 event.target.result, 345679, 91 'The key generator\'s current number should be set by the ' + 92 'last put operation in the database creation transaction'); 93 94 transaction.onabort = event => { 95 event.preventDefault(); 96 resolve(event); 97 }; 98 transaction.abort(); 99 }); 100 transaction.onabort = () => reject(new Error( 101 'The aborted readwrite transaction should not receive an ' + 102 'abort event before IDBTransaction.abort() is called')); 103 transaction.oncomplete = () => reject(new Error( 104 'The aborted readwrite transaction should not receive a ' + 105 'completed event')); 106 transaction.onerror = () => reject(new Error( 107 'The aborted readwrite transaction should not receive an ' + 108 'error event')); 109 }) 110 .then(() => database); 111 }) 112 .then(database => { 113 const transaction = database.transaction(['books'], 'readwrite'); 114 const store = transaction.objectStore('books'); 115 116 return checkStoreGenerator( 117 testCase, store, 345679, 118 'The key generator\'s current number should be reverted after the ' + 119 'transaction modifying it is aborted') 120 .then(() => database.close()); 121 }); 122 }, 123 'The current number of a key generator is reverted when a readwrite ' + 124 'transaction aborts');