| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>IndexedDB: Test IDBObjectStore.getAllKeys.</title> | 2 <title>IndexedDB: Test IDBObjectStore.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 setup({explicit_done: true}); |
| 6 | 7 |
| 7 var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); | 8 var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); |
| 8 | 9 |
| 9 function doSetup(dbName, dbVersion, onsuccess) { | 10 function doSetup(dbName, dbVersion, onsuccess) { |
| 10 var delete_request = indexedDB.deleteDatabase(dbName); | 11 var delete_request = indexedDB.deleteDatabase(dbName); |
| 11 delete_request.onerror = function() { | 12 delete_request.onerror = function() { |
| 12 assert_unreached('deleteDatabase should not fail'); | 13 assert_unreached('deleteDatabase should not fail'); |
| 13 }; | 14 }; |
| 14 delete_request.onsuccess = function(e) { | 15 delete_request.onsuccess = function(e) { |
| 15 var req = indexedDB.open(dbName, dbVersion); | 16 var req = indexedDB.open(dbName, dbVersion); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 32 }); | 33 }); |
| 33 | 34 |
| 34 store = connection.createObjectStore('empty', null); | 35 store = connection.createObjectStore('empty', null); |
| 35 }; | 36 }; |
| 36 }; | 37 }; |
| 37 } | 38 } |
| 38 | 39 |
| 39 function createGetAllKeysRequest(t, storeName, connection, range, maxCount) { | 40 function createGetAllKeysRequest(t, storeName, connection, range, maxCount) { |
| 40 var transaction = connection.transaction(storeName, 'readonly'); | 41 var transaction = connection.transaction(storeName, 'readonly'); |
| 41 var store = transaction.objectStore(storeName); | 42 var store = transaction.objectStore(storeName); |
| 42 // TODO(cmumford): Simplify once crbug.com/335871 is closed. | 43 var req = store.getAllKeys(range, maxCount); |
| 43 var req = maxCount !== undefined ? store.getAllKeys(range, maxCount) : | |
| 44 range !== undefined ? store.getAllKeys(range) : | |
| 45 store.getAllKeys(); | |
| 46 req.onerror = t.unreached_func('getAllKeys request should succeed'); | 44 req.onerror = t.unreached_func('getAllKeys request should succeed'); |
| 47 return req; | 45 return req; |
| 48 } | 46 } |
| 49 | 47 |
| 50 doSetup(location.pathname + '-IDBObjectStore.getAllKeys', 1, function(evt) { | 48 doSetup(location.pathname + '-IDBObjectStore.getAllKeys', 1, function(evt) { |
| 51 var connection = evt.target.result; | 49 var connection = evt.target.result; |
| 52 async_test(function(t) { | 50 async_test(function(t) { |
| 53 var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'c'); | 51 var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'c'); |
| 54 req.onsuccess = t.step_func(function(evt) { | 52 req.onsuccess = t.step_func(function(evt) { |
| 55 assert_array_equals(evt.target.result, ['c']); | 53 assert_array_equals(evt.target.result, ['c']); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 82 req.onsuccess = t.step_func(function(evt) { | 80 req.onsuccess = t.step_func(function(evt) { |
| 83 assert_array_equals(evt.target.result, alphabet); | 81 assert_array_equals(evt.target.result, alphabet); |
| 84 t.done(); | 82 t.done(); |
| 85 }); | 83 }); |
| 86 }, 'Get all values'); | 84 }, 'Get all values'); |
| 87 | 85 |
| 88 async_test(function(t) { | 86 async_test(function(t) { |
| 89 var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined, | 87 var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined, |
| 90 10); | 88 10); |
| 91 req.onsuccess = t.step_func(function(evt) { | 89 req.onsuccess = t.step_func(function(evt) { |
| 92 assert_array_equals(evt.target.result, | 90 assert_array_equals(evt.target.result, 'abcdefghij'.split('')); |
| 93 ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']); | |
| 94 t.done(); | 91 t.done(); |
| 95 }); | 92 }); |
| 96 }, 'Test maxCount'); | 93 }, 'Test maxCount'); |
| 97 | 94 |
| 98 async_test(function(t) { | 95 async_test(function(t) { |
| 99 var req = createGetAllKeysRequest(t, 'out-of-line', connection, | 96 var req = createGetAllKeysRequest(t, 'out-of-line', connection, |
| 100 IDBKeyRange.bound('g', 'm')); | 97 IDBKeyRange.bound('g', 'm')); |
| 101 req.onsuccess = t.step_func(function(evt) { | 98 req.onsuccess = t.step_func(function(evt) { |
| 102 assert_array_equals(evt.target.result, | 99 assert_array_equals(evt.target.result, 'ghijklm'.split('')); |
| 103 ['g', 'h', 'i', 'j', 'k', 'l', 'm']); | |
| 104 t.done(); | 100 t.done(); |
| 105 }); | 101 }); |
| 106 }, 'Get bound range'); | 102 }, 'Get bound range'); |
| 107 | 103 |
| 108 async_test(function(t) { | 104 async_test(function(t) { |
| 109 var req = createGetAllKeysRequest(t, 'out-of-line', connection, | 105 var req = createGetAllKeysRequest(t, 'out-of-line', connection, |
| 110 IDBKeyRange.bound('g', 'm'), 3); | 106 IDBKeyRange.bound('g', 'm'), 3); |
| 111 req.onsuccess = t.step_func(function(evt) { | 107 req.onsuccess = t.step_func(function(evt) { |
| 112 assert_array_equals(evt.target.result, ['g', 'h', 'i']); | 108 assert_array_equals(evt.target.result, ['g', 'h', 'i']); |
| 113 t.done(); | 109 t.done(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 }, 'Non existent key'); | 152 }, 'Non existent key'); |
| 157 | 153 |
| 158 async_test(function(t) { | 154 async_test(function(t) { |
| 159 var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined, | 155 var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined, |
| 160 0); | 156 0); |
| 161 req.onsuccess = t.step_func(function(evt) { | 157 req.onsuccess = t.step_func(function(evt) { |
| 162 assert_array_equals(evt.target.result, alphabet); | 158 assert_array_equals(evt.target.result, alphabet); |
| 163 t.done(); | 159 t.done(); |
| 164 }); | 160 }); |
| 165 }, 'zero maxCount'); | 161 }, 'zero maxCount'); |
| 162 |
| 163 // Explicit done needed in case async_test body fails synchronously. |
| 164 done(); |
| 166 }); | 165 }); |
| 167 | 166 |
| 168 </script> | 167 </script> |
| OLD | NEW |