OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>IndexedDB: Test IDBIndex.getAllKeys.</title> | 2 <title>IndexedDB: Test IDBIndex.getAllKeys.</title> |
3 <script src="../../resources/testharness.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
4 <script src="../../resources/testharnessreport.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
5 <script> | 5 <script> |
6 | 6 |
7 var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); | 7 var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); |
8 | 8 |
9 function doSetup(dbName, dbVersion, onsuccess) { | 9 function doSetup(dbName, dbVersion, onsuccess) { |
10 var delete_request = indexedDB.deleteDatabase(dbName); | 10 var delete_request = indexedDB.deleteDatabase(dbName); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 }; | 53 }; |
54 }; | 54 }; |
55 } | 55 } |
56 | 56 |
57 function createGetAllKeysRequest(t, storeName, connection, range, maxCount) { | 57 function createGetAllKeysRequest(t, storeName, connection, range, maxCount) { |
58 var transaction = connection.transaction(storeName, 'readonly'); | 58 var transaction = connection.transaction(storeName, 'readonly'); |
59 var store = transaction.objectStore(storeName); | 59 var store = transaction.objectStore(storeName); |
60 var index = store.index('test_idx'); | 60 var index = store.index('test_idx'); |
61 // TODO(cmumford): Simplify once crbug.com/335871 is fixed. | 61 // TODO(cmumford): Simplify once crbug.com/335871 is fixed. |
62 var req = maxCount !== undefined ? index.getAllKeys(range, maxCount) : | 62 var req = maxCount !== undefined ? index.getAllKeys(range, maxCount) : |
63 range !== undefined ? index.getAllKeys(range) : index.getAllKeys()
; | 63 range !== undefined ? index.getAllKeys(range) : |
| 64 index.getAllKeys(); |
64 req.onerror = t.unreached_func('getAllKeys request should succeed'); | 65 req.onerror = t.unreached_func('getAllKeys request should succeed'); |
65 return req; | 66 return req; |
66 } | 67 } |
67 | 68 |
68 doSetup(location.pathname + '-IDBIndex.getAllKeys', 1, function(evt) { | 69 doSetup(location.pathname + '-IDBIndex.getAllKeys', 1, function(evt) { |
69 var connection = evt.target.result; | 70 var connection = evt.target.result; |
70 async_test(function(t) { | 71 async_test(function(t) { |
71 var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'C'); | 72 var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'C'); |
72 req.onsuccess = t.step_func(function(evt) { | 73 req.onsuccess = t.step_func(function(evt) { |
73 var data = evt.target.result; | 74 var data = evt.target.result; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 connection, "Doesn't exist"); | 176 connection, "Doesn't exist"); |
176 req.onsuccess = t.step_func(function(evt) { | 177 req.onsuccess = t.step_func(function(evt) { |
177 assert_array_equals(evt.target.result, [], | 178 assert_array_equals(evt.target.result, [], |
178 'getAllKeys() using a nonexistent key should return empty array'); | 179 'getAllKeys() using a nonexistent key should return empty array'); |
179 t.done(); | 180 t.done(); |
180 req.onerror = t.unreached_func('getAllKeys request should succeed'); | 181 req.onerror = t.unreached_func('getAllKeys request should succeed'); |
181 }); | 182 }); |
182 }, 'Non existent key'); | 183 }, 'Non existent key'); |
183 | 184 |
184 async_test(function(t) { | 185 async_test(function(t) { |
185 var transaction = connection.transaction('out-of-line', 'readonly'); | 186 var req = createGetAllKeysRequest(t, 'out-of-line', connection, |
186 var store = transaction.objectStore('out-of-line'); | 187 undefined, 0); |
187 var index = store.index('test_idx'); | 188 req.onsuccess = t.step_func(function(evt) { |
188 assert_throws(new TypeError(), function () { | 189 assert_array_equals(evt.target.result, alphabet, |
189 index.getAllKeys(undefined, 0); | 190 'getAllKeys() should return a..z'); |
190 }, 'getAllKeys() with maxCount=0 should throw TypeError'); | 191 t.done(); |
191 t.done(); | 192 }); |
192 }, 'maxCount=0'); | 193 }, 'maxCount=0'); |
193 | 194 |
194 async_test(function(t) { | 195 async_test(function(t) { |
195 var req = createGetAllKeysRequest(t, 'out-of-line-multi', connection, | 196 var req = createGetAllKeysRequest(t, 'out-of-line-multi', connection, |
196 'vowel'); | 197 'vowel'); |
197 req.onsuccess = t.step_func(function(evt) { | 198 req.onsuccess = t.step_func(function(evt) { |
198 assert_array_equals(evt.target.result, ['A','E','I','O','U']) | 199 assert_array_equals(evt.target.result, ['A','E','I','O','U']) |
199 t.done(); | 200 t.done(); |
200 }); | 201 }); |
201 req.onerror = t.unreached_func('getAllKeys request should succeed'); | 202 req.onerror = t.unreached_func('getAllKeys request should succeed'); |
202 }, 'Retrieve multiEntry keys'); | 203 }, 'Retrieve multiEntry keys'); |
203 }); | 204 }); |
204 | 205 |
205 </script> | 206 </script> |
OLD | NEW |