OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>IndexedDB: index renaming error handling</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 return createDatabase(testCase, (database, transaction) => { |
| 13 createBooksStore(testCase, database); |
| 14 }).then(database => { |
| 15 database.close(); |
| 16 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => { |
| 17 const store = transaction.objectStore('books'); |
| 18 const index = store.index('by_author'); |
| 19 store.deleteIndex('by_author'); |
| 20 assert_throws( |
| 21 'InvalidStateError', () => index.name = 'renamed_by_author'); |
| 22 })).then(database => database.close()); |
| 23 }, 'IndexedDB deleted index rename throws'); |
| 24 |
| 25 promise_test(testCase => { |
| 26 return createDatabase(testCase, (database, transaction) => { |
| 27 createBooksStore(testCase, database); |
| 28 }).then(database => { |
| 29 const transaction = database.transaction('books', 'readonly'); |
| 30 const store = transaction.objectStore('books'); |
| 31 const index = store.index('by_author'); |
| 32 |
| 33 assert_throws( |
| 34 'InvalidStateError', () => index.name = 'renamed_by_author'); |
| 35 database.close(); |
| 36 }); |
| 37 }, 'IndexedDB index rename throws in a readonly transaction'); |
| 38 |
| 39 promise_test(testCase => { |
| 40 return createDatabase(testCase, (database, transaction) => { |
| 41 createBooksStore(testCase, database); |
| 42 }).then(database => { |
| 43 const transaction = database.transaction('books', 'readwrite'); |
| 44 const store = transaction.objectStore('books'); |
| 45 const index = store.index('by_author'); |
| 46 |
| 47 assert_throws( |
| 48 'InvalidStateError', () => index.name = 'renamed_by_author'); |
| 49 database.close(); |
| 50 }); |
| 51 }, 'IndexedDB index rename throws in a readwrite transaction'); |
| 52 |
| 53 promise_test(testCase => { |
| 54 let authorIndex = null; |
| 55 return createDatabase(testCase, (database, transaction) => { |
| 56 const store = createBooksStore(testCase, database); |
| 57 authorIndex = store.index('by_author'); |
| 58 }).then(database => { |
| 59 assert_throws( |
| 60 'TransactionInactiveError', |
| 61 () => authorIndex.name = 'renamed_by_author'); |
| 62 database.close(); |
| 63 }); |
| 64 }, 'IndexedDB index rename throws in an inactive transaction'); |
| 65 |
| 66 promise_test(testCase => { |
| 67 return createDatabase(testCase, (database, transaction) => { |
| 68 createBooksStore(testCase, database); |
| 69 }).then(database => { |
| 70 database.close(); |
| 71 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => { |
| 72 const store = transaction.objectStore('books'); |
| 73 const index = store.index('by_author'); |
| 74 |
| 75 assert_throws('ConstraintError', () => index.name = 'by_title'); |
| 76 assert_array_equals( |
| 77 store.indexNames, ['by_author', 'by_title'], |
| 78 'An index rename that throws an exception should not change the ' + |
| 79 "index's IDBObjectStore.indexNames"); |
| 80 })).then(database => { |
| 81 const transaction = database.transaction('books', 'readonly'); |
| 82 const store = transaction.objectStore('books'); |
| 83 assert_array_equals( |
| 84 store.indexNames, ['by_author', 'by_title'], |
| 85 'Committing a transaction with a failed store rename attempt ' + |
| 86 "should not change the index's IDBObjectStore.indexNames"); |
| 87 const index = store.index('by_author'); |
| 88 return checkAuthorIndexContents( |
| 89 testCase, index, |
| 90 'Committing a transaction with a failed rename attempt should ' + |
| 91 "not change the index's contents").then(() => database.close()); |
| 92 }); |
| 93 }, 'IndexedDB index rename to the name of another index throws'); |
| 94 |
| 95 promise_test(testCase => { |
| 96 return createDatabase(testCase, (database, transaction) => { |
| 97 createBooksStore(testCase, database); |
| 98 }).then(database => { |
| 99 database.close(); |
| 100 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => { |
| 101 const store = transaction.objectStore('books'); |
| 102 const index = store.index('by_author'); |
| 103 |
| 104 assert_throws( |
| 105 { name: 'Custom stringifying error' }, |
| 106 () => { |
| 107 index.name = { |
| 108 toString: () => { throw { name: 'Custom stringifying error'}; } |
| 109 }; |
| 110 }, 'IDBObjectStore rename should re-raise toString() exception'); |
| 111 assert_array_equals( |
| 112 store.indexNames, ['by_author', 'by_title'], |
| 113 'An index rename that throws an exception should not change the ' + |
| 114 "index's IDBObjectStore.indexNames"); |
| 115 })).then(database => { |
| 116 const transaction = database.transaction('books', 'readonly'); |
| 117 const store = transaction.objectStore('books'); |
| 118 assert_array_equals( |
| 119 store.indexNames, ['by_author', 'by_title'], |
| 120 'Committing a transaction with a failed store rename attempt ' + |
| 121 "should not change the index's IDBObjectStore.indexNames"); |
| 122 const index = store.index('by_author'); |
| 123 return checkAuthorIndexContents( |
| 124 testCase, index, |
| 125 'Committing a transaction with a failed rename attempt should ' + |
| 126 "not change the index's contents").then(() => database.close()); |
| 127 }); |
| 128 }, 'IndexedDB index rename handles exceptions when stringifying names'); |
| 129 |
| 130 </script> |
OLD | NEW |