| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>IndexedDB: Test IDBObjectStore.getAll.</title> | 2 <title>IndexedDB: Test IDBObjectStore.getAll.</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 createGetAllRequest(t, storeName, connection, range, maxCount) { | 40 function createGetAllRequest(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.getAll(range, maxCount); |
| 43 var req = maxCount !== undefined ? store.getAll(range, maxCount) : | |
| 44 range !== undefined ? store.getAll(range) : store.getAll(); | |
| 45 req.onerror = t.unreached_func('getAll request should succeed'); | 44 req.onerror = t.unreached_func('getAll request should succeed'); |
| 46 return req; | 45 return req; |
| 47 } | 46 } |
| 48 | 47 |
| 49 doSetup(location.pathname + '-IDBObjectStore.getAll', 1, function(evt) { | 48 doSetup(location.pathname + '-IDBObjectStore.getAll', 1, function(evt) { |
| 50 var connection = evt.target.result; | 49 var connection = evt.target.result; |
| 51 async_test(function(t) { | 50 async_test(function(t) { |
| 52 var req = createGetAllRequest(t, 'out-of-line', connection, 'c'); | 51 var req = createGetAllRequest(t, 'out-of-line', connection, 'c'); |
| 53 req.onsuccess = t.step_func(function(evt) { | 52 req.onsuccess = t.step_func(function(evt) { |
| 54 assert_array_equals(evt.target.result, ['value-c']); | 53 assert_array_equals(evt.target.result, ['value-c']); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 74 assert_array_equals(evt.target.result, [], | 73 assert_array_equals(evt.target.result, [], |
| 75 'getAll() on empty object store should return an empty array'); | 74 'getAll() on empty object store should return an empty array'); |
| 76 t.done(); | 75 t.done(); |
| 77 }); | 76 }); |
| 78 }, 'getAll on empty object store'); | 77 }, 'getAll on empty object store'); |
| 79 | 78 |
| 80 async_test(function(t) { | 79 async_test(function(t) { |
| 81 var req = createGetAllRequest(t, 'out-of-line', connection); | 80 var req = createGetAllRequest(t, 'out-of-line', connection); |
| 82 req.onsuccess = t.step_func(function(evt) { | 81 req.onsuccess = t.step_func(function(evt) { |
| 83 assert_array_equals(evt.target.result, | 82 assert_array_equals(evt.target.result, |
| 84 alphabet.map(c => 'value-' + c)); | 83 alphabet.map(function(c) { return 'value-' + c; })); |
| 85 t.done(); | 84 t.done(); |
| 86 }); | 85 }); |
| 87 }, 'Get all values'); | 86 }, 'Get all values'); |
| 88 | 87 |
| 89 async_test(function(t) { | 88 async_test(function(t) { |
| 90 var req = createGetAllRequest(t, 'out-of-line', connection, undefined, | 89 var req = createGetAllRequest(t, 'out-of-line', connection, undefined, |
| 91 10); | 90 10); |
| 92 req.onsuccess = t.step_func(function(evt) { | 91 req.onsuccess = t.step_func(function(evt) { |
| 93 assert_array_equals(evt.target.result, | 92 assert_array_equals(evt.target.result, |
| 94 ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] | 93 'abcdefghij'.split('').map(function(c) { return 'value-' + c; })); |
| 95 .map(c => 'value-' + c)); | |
| 96 t.done(); | 94 t.done(); |
| 97 }); | 95 }); |
| 98 }, 'Test maxCount'); | 96 }, 'Test maxCount'); |
| 99 | 97 |
| 100 async_test(function(t) { | 98 async_test(function(t) { |
| 101 var req = createGetAllRequest(t, 'out-of-line', connection, | 99 var req = createGetAllRequest(t, 'out-of-line', connection, |
| 102 IDBKeyRange.bound('g', 'm')); | 100 IDBKeyRange.bound('g', 'm')); |
| 103 req.onsuccess = t.step_func(function(evt) { | 101 req.onsuccess = t.step_func(function(evt) { |
| 104 assert_array_equals(evt.target.result, | 102 assert_array_equals(evt.target.result, |
| 105 ['g', 'h', 'i', 'j', 'k', 'l', 'm'] | 103 'ghijklm'.split('').map(function(c) { return 'value-' + c; })); |
| 106 .map(c => 'value-' + c)); | |
| 107 t.done(); | 104 t.done(); |
| 108 }); | 105 }); |
| 109 }, 'Get bound range'); | 106 }, 'Get bound range'); |
| 110 | 107 |
| 111 async_test(function(t) { | 108 async_test(function(t) { |
| 112 var req = createGetAllRequest(t, 'out-of-line', connection, | 109 var req = createGetAllRequest(t, 'out-of-line', connection, |
| 113 IDBKeyRange.bound('g', 'm'), 3); | 110 IDBKeyRange.bound('g', 'm'), 3); |
| 114 req.onsuccess = t.step_func(function(evt) { | 111 req.onsuccess = t.step_func(function(evt) { |
| 115 assert_array_equals(evt.target.result, ['g', 'h', 'i'] | 112 assert_array_equals(evt.target.result, ['g', 'h', 'i'] |
| 116 .map(c => 'value-' + c)); | 113 .map(function(c) { return 'value-' + c; })); |
| 117 t.done(); | 114 t.done(); |
| 118 }); | 115 }); |
| 119 }, 'Get bound range with maxCount'); | 116 }, 'Get bound range with maxCount'); |
| 120 | 117 |
| 121 async_test(function(t) { | 118 async_test(function(t) { |
| 122 var req = createGetAllRequest(t, 'out-of-line', connection, | 119 var req = createGetAllRequest(t, 'out-of-line', connection, |
| 123 IDBKeyRange.bound('g', 'k', false, true)); | 120 IDBKeyRange.bound('g', 'k', false, true)); |
| 124 req.onsuccess = t.step_func(function(evt) { | 121 req.onsuccess = t.step_func(function(evt) { |
| 125 assert_array_equals(evt.target.result, ['g', 'h', 'i', 'j'] | 122 assert_array_equals(evt.target.result, ['g', 'h', 'i', 'j'] |
| 126 .map(c => 'value-' + c)); | 123 .map(function(c) { return 'value-' + c; })); |
| 127 t.done(); | 124 t.done(); |
| 128 }); | 125 }); |
| 129 }, 'Get upper excluded'); | 126 }, 'Get upper excluded'); |
| 130 | 127 |
| 131 async_test(function(t) { | 128 async_test(function(t) { |
| 132 var req = createGetAllRequest(t, 'out-of-line', connection, | 129 var req = createGetAllRequest(t, 'out-of-line', connection, |
| 133 IDBKeyRange.bound('g', 'k', true, false)); | 130 IDBKeyRange.bound('g', 'k', true, false)); |
| 134 req.onsuccess = t.step_func(function(evt) { | 131 req.onsuccess = t.step_func(function(evt) { |
| 135 assert_array_equals(evt.target.result, ['h', 'i', 'j', 'k'] | 132 assert_array_equals(evt.target.result, ['h', 'i', 'j', 'k'] |
| 136 .map(c => 'value-' + c)); | 133 .map(function(c) { return 'value-' + c; })); |
| 137 t.done(); | 134 t.done(); |
| 138 }); | 135 }); |
| 139 }, 'Get lower excluded'); | 136 }, 'Get lower excluded'); |
| 140 | 137 |
| 141 async_test(function(t) { | 138 async_test(function(t) { |
| 142 var req = createGetAllRequest(t, 'generated', connection, | 139 var req = createGetAllRequest(t, 'generated', connection, |
| 143 IDBKeyRange.bound(4, 15), 3); | 140 IDBKeyRange.bound(4, 15), 3); |
| 144 req.onsuccess = t.step_func(function(evt) { | 141 req.onsuccess = t.step_func(function(evt) { |
| 145 var data = evt.target.result; | 142 var data = evt.target.result; |
| 146 assert_true(Array.isArray(data)); | 143 assert_true(Array.isArray(data)); |
| 147 assert_array_equals(data.map(e => e.ch), ['d', 'e', 'f']); | 144 assert_array_equals(data.map(function(e) { return e.ch; }), ['d', 'e',
'f']); |
| 148 assert_array_equals(data.map(e => e.id), [4, 5, 6]); | 145 assert_array_equals(data.map(function(e) { return e.id; }), [4, 5, 6])
; |
| 149 t.done(); | 146 t.done(); |
| 150 }); | 147 }); |
| 151 }, 'Get bound range (generated) with maxCount'); | 148 }, 'Get bound range (generated) with maxCount'); |
| 152 | 149 |
| 153 async_test(function(t) { | 150 async_test(function(t) { |
| 154 var req = createGetAllRequest(t, 'out-of-line', connection, | 151 var req = createGetAllRequest(t, 'out-of-line', connection, |
| 155 "Doesn't exist"); | 152 "Doesn't exist"); |
| 156 req.onsuccess = t.step_func(function(evt) { | 153 req.onsuccess = t.step_func(function(evt) { |
| 157 assert_array_equals(evt.target.result, [], | 154 assert_array_equals(evt.target.result, [], |
| 158 'getAll() using a nonexistent key should return an empty array'); | 155 'getAll() using a nonexistent key should return an empty array'); |
| 159 t.done(); | 156 t.done(); |
| 160 }); | 157 }); |
| 161 req.onerror = t.unreached_func('getAll request should succeed'); | 158 req.onerror = t.unreached_func('getAll request should succeed'); |
| 162 }, 'Non existent key'); | 159 }, 'Non existent key'); |
| 163 | 160 |
| 164 async_test(function(t) { | 161 async_test(function(t) { |
| 165 var req = createGetAllRequest(t, 'out-of-line', connection, undefined, 0); | 162 var req = createGetAllRequest(t, 'out-of-line', connection, undefined, 0); |
| 166 req.onsuccess = t.step_func(function(evt) { | 163 req.onsuccess = t.step_func(function(evt) { |
| 167 assert_array_equals(evt.target.result, | 164 assert_array_equals(evt.target.result, |
| 168 alphabet.map(c => 'value-' + c)); | 165 alphabet.map(function(c) { return 'value-' + c; })); |
| 169 t.done(); | 166 t.done(); |
| 170 }); | 167 }); |
| 171 }, 'zero maxCount'); | 168 }, 'zero maxCount'); |
| 169 |
| 170 // Explicit done needed in case async_test body fails synchronously. |
| 171 done(); |
| 172 }); | 172 }); |
| 173 | 173 |
| 174 </script> | 174 </script> |
| OLD | NEW |