OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>IndexedDB: aborting transactions reverts an object store's key generator
state</title> |
| 3 <script src='../../resources/testharness.js'></script> |
| 4 <link rel="help" href="https://w3c.github.io/IndexedDB/#abort-transaction"> |
| 5 <link rel="author" href="pwnall@chromium.org" title="Victor Costan"> |
| 6 <script src='../../resources/testharnessreport.js'></script> |
| 7 <script src='resources/rename-common.js'></script> |
| 8 <script> |
| 9 |
| 10 promise_test(testCase => { |
| 11 return createDatabase(testCase, (database, transaction) => { |
| 12 createBooksStore(testCase, database); |
| 13 }).then(database => { |
| 14 database.close(); |
| 15 }).then(() => { |
| 16 return new Promise((resolve, reject) => { |
| 17 const request = indexedDB.open(databaseName(testCase), 2); |
| 18 request.onupgradeneeded = testCase.step_func(event => { |
| 19 const database = event.target.result; |
| 20 const transaction = event.target.transaction; |
| 21 const store = transaction.objectStore('books'); |
| 22 const request2 = store.put( |
| 23 { title: 'Bedrock Nights II', author: 'Barney' }); |
| 24 request2.onerror = testCase.unreached_func( |
| 25 'IDBObjectStore.put() should not receive an error request'); |
| 26 request2.onsuccess = testCase.step_func(event => { |
| 27 assert_equals( |
| 28 event.target.result, 345679, |
| 29 "The key generator's current number should be set by " + |
| 30 'the last put operation in the database creation ' + |
| 31 'transaction'); |
| 32 |
| 33 request.onerror = event => { |
| 34 event.preventDefault(); |
| 35 resolve(event); |
| 36 }; |
| 37 request.onsuccess = () => reject(new Error( |
| 38 'indexedDB.open should not succeed after the ' + |
| 39 'versionchange transaction is aborted')); |
| 40 |
| 41 transaction.abort(); |
| 42 }); |
| 43 }); |
| 44 request.onerror = event => reject(event.target.error); |
| 45 request.onsuccess = () => reject(new Error( |
| 46 'indexedDB.open should not succeed without creating a ' + |
| 47 'versionchange transaction')); |
| 48 }); |
| 49 }).then(() => { |
| 50 return openDatabase(testCase, 1); |
| 51 }).then(database => { |
| 52 const transaction = database.transaction(['books'], 'readwrite'); |
| 53 const store = transaction.objectStore('books'); |
| 54 |
| 55 return checkStoreGenerator( |
| 56 testCase, store, 345679, |
| 57 "The key generator's current number should be reverted after the " + |
| 58 'transaction modifying it is aborted').then(() => database.close()); |
| 59 }); |
| 60 }, 'The current number of a key generator is reverted when a versionchange ' + |
| 61 'transaction aborts'); |
| 62 |
| 63 promise_test(testCase => { |
| 64 return createDatabase(testCase, (database, transaction) => { |
| 65 createBooksStore(testCase, database); |
| 66 }).then(database => { |
| 67 return new Promise((resolve, reject) => { |
| 68 const transaction = database.transaction(['books'], 'readwrite'); |
| 69 const store = transaction.objectStore('books'); |
| 70 const request = store.put( |
| 71 { title: 'Bedrock Nights II', author: 'Barney' }); |
| 72 request.onerror = testCase.unreached_func( |
| 73 'IDBObjectStore.put() should not receive an error request'); |
| 74 request.onsuccess = testCase.step_func(event => { |
| 75 assert_equals( |
| 76 event.target.result, 345679, |
| 77 "The key generator's current number should be set by the " + |
| 78 'last put operation in the database creation transaction'); |
| 79 |
| 80 transaction.onabort = event => { |
| 81 event.preventDefault(); |
| 82 resolve(event); |
| 83 } |
| 84 transaction.abort(); |
| 85 }); |
| 86 transaction.onabort = () => reject(new Error( |
| 87 'The aborted readwrite transaction should not receive an ' + |
| 88 'abort event before IDBTransaction.abort() is called')); |
| 89 transaction.oncomplete = () => reject(new Error( |
| 90 'The aborted readwrite transaction should not receive a ' + |
| 91 'completed event')); |
| 92 transaction.onerror = () => reject(new Error( |
| 93 'The aborted readwrite transaction should not receive an ' + |
| 94 'error event')); |
| 95 }).then(() => database); |
| 96 }).then(database => { |
| 97 const transaction = database.transaction(['books'], 'readwrite'); |
| 98 const store = transaction.objectStore('books'); |
| 99 |
| 100 return checkStoreGenerator( |
| 101 testCase, store, 345679, |
| 102 "The key generator's current number should be reverted after the " + |
| 103 'transaction modifying it is aborted').then(() => database.close()); |
| 104 }); |
| 105 }, 'The current number of a key generator is reverted when a readwrite ' + |
| 106 'transaction aborts'); |
| 107 |
| 108 </script> |
OLD | NEW |