| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <title>IndexedDB: object store renaming error handling</title> | |
| 3 <link rel="help" | |
| 4 href="https://w3c.github.io/IndexedDB/#dom-idbobjectstore-name"> | |
| 5 <link rel="author" href="pwnall@chromium.org" title="Victor Costan"> | |
| 6 <script src="/resources/testharness.js"></script> | |
| 7 <script src="/resources/testharnessreport.js"></script> | |
| 8 <script src="support-promises.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 database.deleteObjectStore('books'); | |
| 19 assert_throws('InvalidStateError', () => store.name = 'renamed_books'); | |
| 20 })).then(database => { | |
| 21 database.close(); | |
| 22 }); | |
| 23 }, 'IndexedDB deleted object store 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 assert_throws('InvalidStateError', () => store.name = 'renamed_books'); | |
| 32 database.close(); | |
| 33 }); | |
| 34 }, 'IndexedDB object store rename throws in a readonly transaction'); | |
| 35 | |
| 36 promise_test(testCase => { | |
| 37 return createDatabase(testCase, (database, transaction) => { | |
| 38 createBooksStore(testCase, database); | |
| 39 }).then(database => { | |
| 40 const transaction = database.transaction('books', 'readwrite'); | |
| 41 const store = transaction.objectStore('books'); | |
| 42 | |
| 43 assert_throws('InvalidStateError', () => store.name = 'renamed_books'); | |
| 44 database.close(); | |
| 45 }); | |
| 46 }, 'IndexedDB object store rename throws in a readwrite transaction'); | |
| 47 | |
| 48 promise_test(testCase => { | |
| 49 let bookStore = null; | |
| 50 return createDatabase(testCase, (database, transaction) => { | |
| 51 bookStore = createBooksStore(testCase, database); | |
| 52 }).then(database => { | |
| 53 assert_throws('TransactionInactiveError', | |
| 54 () => { bookStore.name = 'renamed_books'; }); | |
| 55 database.close(); | |
| 56 }); | |
| 57 }, 'IndexedDB object store rename throws in an inactive transaction'); | |
| 58 | |
| 59 promise_test(testCase => { | |
| 60 return createDatabase(testCase, (database, transaction) => { | |
| 61 createBooksStore(testCase, database); | |
| 62 createNotBooksStore(testCase, database); | |
| 63 }).then(database => { | |
| 64 database.close(); | |
| 65 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => { | |
| 66 const store = transaction.objectStore('books'); | |
| 67 assert_throws('ConstraintError', () => store.name = 'not_books'); | |
| 68 assert_array_equals( | |
| 69 database.objectStoreNames, ['books', 'not_books'], | |
| 70 'A store rename that throws an exception should not change the ' + | |
| 71 "store's IDBDatabase.objectStoreNames"); | |
| 72 })).then(database => { | |
| 73 assert_array_equals( | |
| 74 database.objectStoreNames, ['books', 'not_books'], | |
| 75 'Committing a transaction with a failed store rename attempt ' + | |
| 76 "should not change the store's IDBDatabase.objectStoreNames"); | |
| 77 const transaction = database.transaction('books', 'readonly'); | |
| 78 const store = transaction.objectStore('books'); | |
| 79 return checkStoreContents( | |
| 80 testCase, store, | |
| 81 'Committing a transaction with a failed rename attempt should ' + | |
| 82 "not change the store's contents").then(() => database.close()); | |
| 83 }); | |
| 84 }, 'IndexedDB object store rename to the name of another store throws'); | |
| 85 | |
| 86 promise_test(testCase => { | |
| 87 return createDatabase(testCase, (database, transaction) => { | |
| 88 createBooksStore(testCase, database); | |
| 89 }).then(database => { | |
| 90 database.close(); | |
| 91 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => { | |
| 92 const store = transaction.objectStore('books'); | |
| 93 assert_throws( | |
| 94 { name: 'Custom stringifying error' }, | |
| 95 () => { | |
| 96 store.name = { | |
| 97 toString: () => { throw { name: 'Custom stringifying error'}; } | |
| 98 }; | |
| 99 }, 'IDBObjectStore rename should re-raise toString() exception'); | |
| 100 assert_array_equals( | |
| 101 database.objectStoreNames, ['books'], | |
| 102 'A store rename that throws an exception should not change the ' + | |
| 103 "store's IDBDatabase.objectStoreNames"); | |
| 104 })).then(database => { | |
| 105 assert_array_equals( | |
| 106 database.objectStoreNames, ['books'], | |
| 107 'Committing a transaction with a failed store rename attempt ' + | |
| 108 "should not change the store's IDBDatabase.objectStoreNames"); | |
| 109 const transaction = database.transaction('books', 'readonly'); | |
| 110 const store = transaction.objectStore('books'); | |
| 111 return checkStoreContents( | |
| 112 testCase, store, | |
| 113 'Committing a transaction with a failed rename attempt should ' + | |
| 114 "not change the store's contents").then(() => database.close()); | |
| 115 }); | |
| 116 }, 'IndexedDB object store rename handles exceptions when stringifying names'); | |
| 117 | |
| 118 </script> | |
| OLD | NEW |