OLD | NEW |
---|---|
1 // Returns an IndexedDB database name likely to be unique to the test case. | 1 // Returns an IndexedDB database name likely to be unique to the test case. |
2 const databaseName = (testCase) => { | 2 const databaseName = (testCase) => { |
3 return 'db' + self.location.pathname + '-' + testCase.name; | 3 return 'db' + self.location.pathname + '-' + testCase.name; |
4 }; | 4 }; |
5 | 5 |
6 // Creates an EventWatcher covering all the events that can be issued by | 6 // Creates an EventWatcher covering all the events that can be issued by |
7 // IndexedDB requests and transactions. | 7 // IndexedDB requests and transactions. |
8 const requestWatcher = (testCase, request) => { | 8 const requestWatcher = (testCase, request) => { |
9 return new EventWatcher(testCase, request, | 9 return new EventWatcher(testCase, request, |
10 ['error', 'success', 'upgradeneeded']); | 10 ['error', 'success', 'upgradeneeded']); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 // Returns a promise that resolves to an IndexedDB database. The caller must | 68 // Returns a promise that resolves to an IndexedDB database. The caller must |
69 // close the database. | 69 // close the database. |
70 const createDatabase = (testCase, setupCallback) => { | 70 const createDatabase = (testCase, setupCallback) => { |
71 const request = indexedDB.deleteDatabase(databaseName(testCase)); | 71 const request = indexedDB.deleteDatabase(databaseName(testCase)); |
72 const eventWatcher = requestWatcher(testCase, request); | 72 const eventWatcher = requestWatcher(testCase, request); |
73 | 73 |
74 return eventWatcher.wait_for('success').then(event => | 74 return eventWatcher.wait_for('success').then(event => |
75 migrateDatabase(testCase, 1, setupCallback)); | 75 migrateDatabase(testCase, 1, setupCallback)); |
76 }; | 76 }; |
77 | 77 |
78 // Opens an IndexedDB database without performing schema changes. | |
79 // | |
80 // The given version number must match the database's current version. | |
81 // | |
82 // Returns a promise that resolves to an IndexedDB database. The caller must | |
83 // close the database. | |
84 const openDatabase = (testCase, version) => { | |
85 const request = indexedDB.open(databaseName(testCase), version); | |
jsbell
2016/09/16 18:17:28
Maybe add onupgradeneeded = testCase.unreached_fun
pwnall
2016/09/17 01:34:21
I thought EventWatcher is supposed to reject its p
| |
86 const eventWatcher = requestWatcher(testCase, request); | |
87 return eventWatcher.wait_for('success').then( | |
88 event => event.target.result); | |
89 } | |
90 | |
78 // The data in the 'books' object store records in the first example of the | 91 // The data in the 'books' object store records in the first example of the |
79 // IndexedDB specification. | 92 // IndexedDB specification. |
80 const BOOKS_RECORD_DATA = [ | 93 const BOOKS_RECORD_DATA = [ |
81 { title: 'Quarry Memories', author: 'Fred', isbn: 123456 }, | 94 { title: 'Quarry Memories', author: 'Fred', isbn: 123456 }, |
82 { title: 'Water Buffaloes', author: 'Fred', isbn: 234567 }, | 95 { title: 'Water Buffaloes', author: 'Fred', isbn: 234567 }, |
83 { title: 'Bedrock Nights', author: 'Barney', isbn: 345678 }, | 96 { title: 'Bedrock Nights', author: 'Barney', isbn: 345678 }, |
84 ]; | 97 ]; |
85 | 98 |
86 // Creates a 'books' object store whose contents closely resembles the first | 99 // Creates a 'books' object store whose contents closely resembles the first |
87 // example in the IndexedDB specification. | 100 // example in the IndexedDB specification. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 // is using it incorrectly. | 191 // is using it incorrectly. |
179 const checkTitleIndexContents = (testCase, index, errorMessage) => { | 192 const checkTitleIndexContents = (testCase, index, errorMessage) => { |
180 const request = index.get(BOOKS_RECORD_DATA[2].title); | 193 const request = index.get(BOOKS_RECORD_DATA[2].title); |
181 const eventWatcher = requestWatcher(testCase, request); | 194 const eventWatcher = requestWatcher(testCase, request); |
182 return eventWatcher.wait_for('success').then(() => { | 195 return eventWatcher.wait_for('success').then(() => { |
183 const result = request.result; | 196 const result = request.result; |
184 assert_equals(result.isbn, BOOKS_RECORD_DATA[2].isbn, errorMessage); | 197 assert_equals(result.isbn, BOOKS_RECORD_DATA[2].isbn, errorMessage); |
185 assert_equals(result.author, BOOKS_RECORD_DATA[2].author, errorMessage); | 198 assert_equals(result.author, BOOKS_RECORD_DATA[2].author, errorMessage); |
186 }); | 199 }); |
187 }; | 200 }; |
OLD | NEW |