| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 <!DOCTYPE html> | 
|  | 2 <script src='../resources/testharness.js'></script> | 
|  | 3 <script src='../resources/testharnessreport.js'></script> | 
|  | 4 <script> | 
|  | 5 // Returns an IndexedDB database name likely to be unique to the test case. | 
|  | 6 const databaseName = function(testCase) { | 
|  | 7     return 'db' + self.location.pathname + '-' + testCase.name; | 
|  | 8 }; | 
|  | 9 | 
|  | 10 // Creates an EventWatcher covering all the events that can be issued by | 
|  | 11 // IndexedDB requests and transactions. | 
|  | 12 const requestWatcher = function(testCase, request) { | 
|  | 13     return new EventWatcher(testCase, request, | 
|  | 14         ['error', 'success', 'upgradeneeded']); | 
|  | 15 }; | 
|  | 16 | 
|  | 17 // Migrates an IndexedDB database whose name is unique for the test case. | 
|  | 18 // | 
|  | 19 // setupCallback will be called during a versionchange transaction, and will be | 
|  | 20 // given the created database and the versionchange transaction. | 
|  | 21 // | 
|  | 22 // Returns a promise that resolves to an IndexedDB database. The caller must | 
|  | 23 // close the database. | 
|  | 24 const migrateDatabase = function(testCase, newVersion, setupCallback) { | 
|  | 25     // We cannot use eventWatcher.wait_for('upgradeneeded') here, because | 
|  | 26     // the versionchange transaction auto-commits before the Promise's then | 
|  | 27     // callback gets called. | 
|  | 28     return new Promise((resolve, reject) => { | 
|  | 29         const request = indexedDB.open(databaseName(testCase), newVersion); | 
|  | 30         request.onupgradeneeded = event => { | 
|  | 31             const eventWatcher = requestWatcher(testCase, request); | 
|  | 32             const database = event.target.result; | 
|  | 33             const transaction = event.target.transaction; | 
|  | 34             setupCallback(database, transaction); | 
|  | 35             resolve(eventWatcher.wait_for('success')); | 
|  | 36         }; | 
|  | 37         request.onerror = event => reject(event.target.error); | 
|  | 38     }).then(event => event.target.result); | 
|  | 39 }; | 
|  | 40 | 
|  | 41 // Creates an IndexedDB database whose name is unique for the test case. | 
|  | 42 // | 
|  | 43 // setupCallback will be called during a versionchange transaction, and will be | 
|  | 44 // given the created database and the versionchange transaction. | 
|  | 45 // | 
|  | 46 // Returns a promise that resolves to an IndexedDB database. The caller must | 
|  | 47 // close the database. | 
|  | 48 const createDatabase = function(testCase, setupCallback) { | 
|  | 49     const request = indexedDB.deleteDatabase(databaseName(testCase)); | 
|  | 50     const eventWatcher = requestWatcher(testCase, request); | 
|  | 51 | 
|  | 52     return eventWatcher.wait_for('success').then(event => | 
|  | 53         migrateDatabase(testCase, 1, setupCallback)); | 
|  | 54 }; | 
|  | 55 | 
|  | 56 promise_test(testCase => { | 
|  | 57     return createDatabase(testCase, (database, transaction) => { | 
|  | 58         const store = database.createObjectStore('books'); | 
|  | 59         store.name = 'renamed_books'; | 
|  | 60         assert_equals( | 
|  | 61             store.name, 'books', | 
|  | 62             'IndexedDB object store renaming should not be web-exposed'); | 
|  | 63         const authorIndex = store.createIndex('by_author', 'author'); | 
|  | 64         authorIndex.name = 'renamed_by_author'; | 
|  | 65         assert_equals( | 
|  | 66             authorIndex.name, 'by_author', | 
|  | 67             'IndexedDB object store renaming should not be web-exposed'); | 
|  | 68     }).then(database => database.close()); | 
|  | 69 }, 'IndexedDB object store and index renaming should not be web-exposed\nThis te
    st is expected to fail in LayoutTests/webexposed'); | 
|  | 70 </script> | 
| OLD | NEW | 
|---|