idbobjectstore-rename-abort.any.js (5787B)
1 // META: global=window,worker 2 // META: title=IndexedDB: object store renaming support in aborted transactions 3 // META: script=resources/support-promises.js 4 5 // Spec: https://w3c.github.io/IndexedDB/#dom-idbobjectstore-name 6 7 'use strict'; 8 9 promise_test(testCase => { 10 const dbName = databaseName(testCase); 11 let bookStore = null; 12 let bookStore2 = 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 bookStore = transaction.objectStore('books'); 26 bookStore.name = 'renamed_books'; 27 28 transaction.abort(); 29 30 assert_equals( 31 bookStore.name, 'books', 32 'IDBObjectStore.name should not reflect the rename any more ' + 33 'immediately after transaction.abort() returns'); 34 assert_array_equals( 35 database.objectStoreNames, ['books'], 36 'IDBDatabase.objectStoreNames should not reflect the rename ' + 37 'any more immediately after transaction.abort() returns'); 38 assert_array_equals( 39 transaction.objectStoreNames, ['books'], 40 'IDBTransaction.objectStoreNames should not reflect the ' + 41 'rename any more immediately after transaction.abort() returns'); 42 })) 43 .then(event => { 44 assert_equals( 45 bookStore.name, 'books', 46 'IDBObjectStore.name should not reflect the rename any more ' + 47 'after the versionchange transaction is aborted'); 48 const request = indexedDB.open(dbName, 1); 49 return promiseForRequest(testCase, request); 50 }) 51 .then(database => { 52 assert_array_equals( 53 database.objectStoreNames, ['books'], 54 'IDBDatabase.objectStoreNames should not reflect the rename ' + 55 'after the versionchange transaction is aborted'); 56 57 const transaction = database.transaction('books', 'readonly'); 58 bookStore2 = transaction.objectStore('books'); 59 return checkStoreContents( 60 testCase, bookStore2, 61 'Aborting an object store rename transaction should not change ' + 62 'the store\'s records') 63 .then(() => database.close()); 64 }) 65 .then(() => { 66 assert_equals( 67 bookStore.name, 'books', 68 'IDBObjectStore used in aborted rename transaction should not ' + 69 'reflect the rename after the transaction is aborted'); 70 assert_equals( 71 bookStore2.name, 'books', 72 'IDBObjectStore obtained after an aborted rename transaction ' + 73 'should not reflect the rename'); 74 }); 75 }, 'IndexedDB object store rename in aborted transaction'); 76 77 promise_test(testCase => { 78 const dbName = databaseName(testCase); 79 let notBookStore = null; 80 return createDatabase(testCase, (database, transaction) => {}) 81 .then(database => { 82 database.close(); 83 }) 84 .then( 85 () => migrateDatabase( 86 testCase, 2, 87 (database, transaction) => { 88 notBookStore = createNotBooksStore(testCase, database); 89 notBookStore.name = 'not_books_renamed'; 90 notBookStore.name = 'not_books_renamed_again'; 91 92 transaction.abort(); 93 94 assert_equals( 95 notBookStore.name, 'not_books_renamed_again', 96 'IDBObjectStore.name should reflect the last rename ' + 97 'immediately after transaction.abort() returns'); 98 assert_array_equals( 99 database.objectStoreNames, [], 100 'IDBDatabase.objectStoreNames should not reflect the creation ' + 101 'or the rename any more immediately after transaction.abort() ' + 102 'returns'); 103 assert_array_equals( 104 transaction.objectStoreNames, [], 105 'IDBTransaction.objectStoreNames should not reflect the ' + 106 'creation or the rename any more immediately after ' + 107 'transaction.abort() returns'); 108 assert_array_equals( 109 notBookStore.indexNames, [], 110 'IDBObjectStore.indexNames for the newly created store ' + 111 'should be empty immediately after transaction.abort() ' + 112 'returns'); 113 })) 114 .then(event => { 115 assert_equals( 116 notBookStore.name, 'not_books_renamed_again', 117 'IDBObjectStore.name should reflect the last rename after the ' + 118 'versionchange transaction is aborted'); 119 assert_array_equals( 120 notBookStore.indexNames, [], 121 'IDBObjectStore.indexNames for the newly created store ' + 122 'should be empty after the versionchange transaction is aborted ' + 123 'returns'); 124 const request = indexedDB.open(dbName, 1); 125 return promiseForRequest(testCase, request); 126 }) 127 .then(database => { 128 assert_array_equals( 129 database.objectStoreNames, [], 130 'IDBDatabase.objectStoreNames should not reflect the creation or ' + 131 'the rename after the versionchange transaction is aborted'); 132 133 database.close(); 134 }); 135 }, 'IndexedDB object store creation and rename in an aborted transaction');