idbindex-rename-abort.any.js (5067B)
1 // META: title=IndexedDB: index renaming support in aborted transactions 2 // META: global=window,worker 3 // META: script=resources/support-promises.js 4 5 // Spec: https://w3c.github.io/IndexedDB/#dom-idbindex-name 6 7 'use strict'; 8 9 promise_test(testCase => { 10 const dbName = databaseName(testCase); 11 let authorIndex = null; 12 let authorIndex2 = null; 13 return createDatabase( 14 testCase, 15 (database, transaction) => { 16 createBooksStore(testCase, database); 17 }) 18 .then(database => { 19 database.close(); 20 }) 21 .then( 22 () => migrateDatabase( 23 testCase, 2, 24 (database, transaction) => { 25 const store = transaction.objectStore('books'); 26 authorIndex = store.index('by_author'); 27 authorIndex.name = 'renamed_by_author'; 28 29 transaction.abort(); 30 31 assert_equals( 32 authorIndex.name, 'by_author', 33 'IDBIndex.name should not reflect the rename any more ' + 34 'immediately after transaction.abort() returns'); 35 assert_array_equals( 36 store.indexNames, ['by_author', 'by_title'], 37 'IDBObjectStore.indexNames should not reflect the rename any ' + 38 'more immediately after transaction.abort() returns'); 39 })) 40 .then(event => { 41 assert_equals( 42 authorIndex.name, 'by_author', 43 'IDBIndex.name should not reflect the rename any more after the ' + 44 'versionchange transaction is aborted'); 45 46 const request = indexedDB.open(dbName, 1); 47 return promiseForRequest(testCase, request); 48 }) 49 .then(database => { 50 const transaction = database.transaction('books', 'readonly'); 51 const store = transaction.objectStore('books'); 52 assert_array_equals( 53 store.indexNames, ['by_author', 'by_title'], 54 'IDBDatabase.objectStoreNames should not reflect the rename ' + 55 'after the versionchange transaction is aborted'); 56 57 authorIndex2 = store.index('by_author'); 58 return checkAuthorIndexContents( 59 testCase, authorIndex2, 60 'Aborting an index rename transaction should not change the ' + 61 'index\'s records') 62 .then(() => database.close()); 63 }) 64 .then(() => { 65 assert_equals( 66 authorIndex.name, 'by_author', 67 'IDBIndex used in aborted rename transaction should not reflect ' + 68 'the rename after the transaction is aborted'); 69 assert_equals( 70 authorIndex2.name, 'by_author', 71 'IDBIndex obtained after an aborted rename transaction should ' + 72 'not reflect the rename'); 73 }); 74 }, 'IndexedDB index rename in aborted transaction'); 75 76 promise_test(testCase => { 77 const dbName = databaseName(testCase); 78 let authorIndex = null; 79 return createDatabase( 80 testCase, 81 (database, transaction) => { 82 createNotBooksStore(testCase, database); 83 }) 84 .then(database => { 85 database.close(); 86 }) 87 .then( 88 () => migrateDatabase( 89 testCase, 2, 90 (database, transaction) => { 91 const store = transaction.objectStore('not_books'); 92 authorIndex = store.createIndex('by_author', 'author'); 93 authorIndex.name = 'by_author_renamed'; 94 authorIndex.name = 'by_author_renamed_again'; 95 96 transaction.abort(); 97 98 assert_equals( 99 authorIndex.name, 'by_author_renamed_again', 100 'IDBIndex.name should reflect the last rename immediately after ' + 101 'transaction.abort() returns'); 102 assert_array_equals( 103 store.indexNames, ['not_by_author', 'not_by_title'], 104 'IDBObjectStore.indexNames should not reflect the creation or ' + 105 'the rename immediately after transaction.abort() returns'); 106 })) 107 .then(event => { 108 assert_equals( 109 authorIndex.name, 'by_author_renamed_again', 110 'IDBIndex.name should reflect the last rename after the ' + 111 'versionchange transaction is aborted'); 112 113 const request = indexedDB.open(dbName, 1); 114 return promiseForRequest(testCase, request); 115 }) 116 .then(database => { 117 const transaction = database.transaction('not_books', 'readonly'); 118 const store = transaction.objectStore('not_books'); 119 assert_array_equals( 120 store.indexNames, ['not_by_author', 'not_by_title'], 121 'IDBDatabase.objectStoreNames should not reflect the creation or ' + 122 'the rename after the versionchange transaction is aborted'); 123 124 database.close(); 125 }); 126 }, 'IndexedDB index creation and rename in an aborted transaction');