OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>IndexedDB: index renaming support in aborted transactions</title> |
| 3 <script src='../../resources/testharness.js'></script> |
| 4 <link rel="help" |
| 5 href="https://w3c.github.io/IndexedDB/#dom-idbindex-name"> |
| 6 <link rel="author" href="pwnall@chromium.org" title="Victor Costan"> |
| 7 <script src='../../resources/testharnessreport.js'></script> |
| 8 <script src='resources/rename-common.js'></script> |
| 9 <script> |
| 10 |
| 11 promise_test(testCase => { |
| 12 const dbName = databaseName(testCase); |
| 13 let authorIndex = null, authorIndex2 = null; |
| 14 return createDatabase(testCase, (database, transaction) => { |
| 15 createBooksStore(testCase, database); |
| 16 }).then(database => { |
| 17 database.close(); |
| 18 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => { |
| 19 const store = transaction.objectStore('books'); |
| 20 authorIndex = store.index('by_author'); |
| 21 authorIndex.name = 'renamed_by_author'; |
| 22 |
| 23 transaction.abort(); |
| 24 |
| 25 assert_equals( |
| 26 authorIndex.name, 'by_author', |
| 27 'IDBIndex.name should not reflect the rename any more ' + |
| 28 'immediately after transaction.abort() returns'); |
| 29 assert_array_equals( |
| 30 store.indexNames, ['by_author', 'by_title'], |
| 31 'IDBObjectStore.indexNames should not reflect the rename any ' + |
| 32 'more immediately after transaction.abort() returns'); |
| 33 })).then(event => { |
| 34 assert_equals( |
| 35 authorIndex.name, 'by_author', |
| 36 'IDBIndex.name should not reflect the rename any more after the ' + |
| 37 'versionchange transaction is aborted'); |
| 38 |
| 39 const request = indexedDB.open(dbName, 1); |
| 40 return requestWatcher(testCase, request).wait_for('success'); |
| 41 }).then(event => { |
| 42 const database = event.target.result; |
| 43 const transaction = database.transaction('books', 'readonly'); |
| 44 const store = transaction.objectStore('books'); |
| 45 assert_array_equals( |
| 46 store.indexNames, ['by_author', 'by_title'], |
| 47 'IDBDatabase.objectStoreNames should not reflect the rename ' + |
| 48 'after the versionchange transaction is aborted'); |
| 49 |
| 50 authorIndex2 = store.index('by_author'); |
| 51 return checkAuthorIndexContents( |
| 52 testCase, authorIndex2, |
| 53 'Aborting an index rename transaction should not change the ' + |
| 54 "index's records").then(() => database.close()); |
| 55 }).then(() => { |
| 56 assert_equals( |
| 57 authorIndex.name, 'by_author', |
| 58 'IDBIndex used in aborted rename transaction should not reflect ' + |
| 59 'the rename after the transaction is aborted'); |
| 60 assert_equals(authorIndex2.name, 'by_author', |
| 61 'IDBIndex obtained after an aborted rename transaction should ' + |
| 62 'not reflect the rename'); |
| 63 }); |
| 64 }, 'IndexedDB index rename in aborted transaction'); |
| 65 |
| 66 promise_test(testCase => { |
| 67 const dbName = databaseName(testCase); |
| 68 let authorIndex = null; |
| 69 return createDatabase(testCase, (database, transaction) => { |
| 70 createNotBooksStore(testCase, database); |
| 71 }).then(database => { |
| 72 database.close(); |
| 73 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => { |
| 74 const store = transaction.objectStore('not_books'); |
| 75 authorIndex = store.createIndex('by_author', 'author'); |
| 76 authorIndex.name = 'by_author_renamed'; |
| 77 authorIndex.name = 'by_author_renamed_again'; |
| 78 |
| 79 transaction.abort(); |
| 80 |
| 81 assert_equals( |
| 82 authorIndex.name, 'by_author_renamed_again', |
| 83 'IDBIndex.name should reflect the last rename immediately after ' + |
| 84 'transaction.abort() returns'); |
| 85 assert_array_equals( |
| 86 store.indexNames, ['not_by_author', 'not_by_title'], |
| 87 'IDBObjectStore.indexNames should not reflect the creation or ' + |
| 88 'the rename immediately after transaction.abort() returns'); |
| 89 })).then(event => { |
| 90 assert_equals( |
| 91 authorIndex.name, 'by_author_renamed_again', |
| 92 'IDBIndex.name should reflect the last rename after the ' + |
| 93 'versionchange transaction is aborted'); |
| 94 |
| 95 const request = indexedDB.open(dbName, 1); |
| 96 return requestWatcher(testCase, request).wait_for('success'); |
| 97 }).then(event => { |
| 98 const database = event.target.result; |
| 99 const transaction = database.transaction('not_books', 'readonly'); |
| 100 const store = transaction.objectStore('not_books'); |
| 101 assert_array_equals( |
| 102 store.indexNames, ['not_by_author', 'not_by_title'], |
| 103 'IDBDatabase.objectStoreNames should not reflect the creation or ' + |
| 104 'the rename after the versionchange transaction is aborted'); |
| 105 |
| 106 database.close(); |
| 107 }); |
| 108 }, 'IndexedDB index creation and rename in an aborted transaction'); |
| 109 |
| 110 </script> |
OLD | NEW |