Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1095)

Side by Side Diff: LayoutTests/storage/indexeddb/objectstore-getallkeys.html

Issue 1303983002: IndexedDB: Treat count of 0 as unbounded for getAll() methods (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>IndexedDB: Test IDBObjectStore.getAll.</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 6
7 var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
8
7 function doSetup(dbName, dbVersion, onsuccess) { 9 function doSetup(dbName, dbVersion, onsuccess) {
8 var delete_request = indexedDB.deleteDatabase(dbName); 10 var delete_request = indexedDB.deleteDatabase(dbName);
9 delete_request.onerror = function() { 11 delete_request.onerror = function() {
10 assert_unreached('deleteDatabase should not fail'); 12 assert_unreached('deleteDatabase should not fail');
11 }; 13 };
12 delete_request.onsuccess = function(e) { 14 delete_request.onsuccess = function(e) {
13 var req = indexedDB.open(dbName, dbVersion); 15 var req = indexedDB.open(dbName, dbVersion);
14 req.onsuccess = onsuccess; 16 req.onsuccess = onsuccess;
15 req.onerror = function() { 17 req.onerror = function() {
16 assert_unreached('open should not fail'); 18 assert_unreached('open should not fail');
17 }; 19 };
18 req.onupgradeneeded = function(evt) { 20 req.onupgradeneeded = function(evt) {
19 var connection = evt.target.result; 21 var connection = evt.target.result;
20 var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
21 22
22 var store = connection.createObjectStore('generated', 23 var store = connection.createObjectStore('generated',
23 {autoIncrement: true, keyPath: 'id'}); 24 {autoIncrement: true, keyPath: 'id'});
24 alphabet.forEach(function(letter) { 25 alphabet.forEach(function(letter) {
25 store.put({ch: letter}); 26 store.put({ch: letter});
26 }); 27 });
27 28
28 store = connection.createObjectStore('out-of-line', null); 29 store = connection.createObjectStore('out-of-line', null);
29 alphabet.forEach(function(letter) { 30 alphabet.forEach(function(letter) {
30 store.put(letter, letter); 31 store.put('value-' + letter, letter);
31 }); 32 });
32 33
33 store = connection.createObjectStore('empty', null); 34 store = connection.createObjectStore('empty', null);
34 }; 35 };
35 }; 36 };
36 } 37 }
37 38
38 function createGetAllRequest(t, storeName, connection, range, maxCount) { 39 function createGetAllKeysRequest(t, storeName, connection, range, maxCount) {
39 var transaction = connection.transaction(storeName, 'readonly'); 40 var transaction = connection.transaction(storeName, 'readonly');
40 var store = transaction.objectStore(storeName); 41 var store = transaction.objectStore(storeName);
41 // TODO(cmumford): Simplify once crbug.com/335871 is closed. 42 // TODO(cmumford): Simplify once crbug.com/335871 is closed.
42 var req = maxCount !== undefined ? store.getAll(range, maxCount) : 43 var req = maxCount !== undefined ? store.getAllKeys(range, maxCount) :
43 range !== undefined ? store.getAll(range) : store.getAll(); 44 range !== undefined ? store.getAllKeys(range) : store.getAllKeys() ;
44 req.onerror = t.unreached_func('getAll request should succeed'); 45 req.onerror = t.unreached_func('getAllKeys request should succeed');
45 return req; 46 return req;
46 } 47 }
47 48
48 doSetup(location.pathname + '-IDBObjectStore.getAll', 1, function(evt) { 49 doSetup(location.pathname + '-IDBObjectStore.getAllKeys', 1, function(evt) {
49 var connection = evt.target.result; 50 var connection = evt.target.result;
50 async_test(function(t) { 51 async_test(function(t) {
51 var req = createGetAllRequest(t, 'out-of-line', connection, 'c'); 52 var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'c');
52 req.onsuccess = t.step_func(function(evt) { 53 req.onsuccess = t.step_func(function(evt) {
53 assert_array_equals(evt.target.result, ['c']); 54 assert_array_equals(evt.target.result, ['c']);
54 t.done(); 55 t.done();
55 }); 56 });
56 }, 'Single item get'); 57 }, 'Single item get');
57 58
58 async_test(function(t) { 59 async_test(function(t) {
59 var req = createGetAllRequest(t, 'generated', connection, 3); 60 var req = createGetAllKeysRequest(t, 'generated', connection, 3);
60 req.onsuccess = t.step_func(function(evt) { 61 req.onsuccess = t.step_func(function(evt) {
61 var data = evt.target.result; 62 var data = evt.target.result;
62 assert_true(Array.isArray(data)); 63 assert_true(Array.isArray(data));
63 assert_equals(data.length, 1); 64 assert_array_equals(data, [3]);
64 assert_object_equals(data[0], {ch: 'c', id: 3});
65 t.done(); 65 t.done();
66 }); 66 });
67 }, 'Single item get (generated key)'); 67 }, 'Single item get (generated key)');
68 68
69 async_test(function(t) { 69 async_test(function(t) {
70 var req = createGetAllRequest(t, 'empty', connection); 70 var req = createGetAllKeysRequest(t, 'empty', connection);
71 req.onsuccess = t.step_func(function(evt) { 71 req.onsuccess = t.step_func(function(evt) {
72 assert_array_equals(evt.target.result, [], 72 assert_array_equals(evt.target.result, [],
73 'getAll() on empty object store should return an empty array'); 73 'getAllKeys() on empty object store should return an empty array') ;
74 t.done(); 74 t.done();
75 }); 75 });
76 }, 'getAll on empty object store'); 76 }, 'getAllKeys on empty object store');
77 77
78 async_test(function(t) { 78 async_test(function(t) {
79 var req = createGetAllRequest(t, 'out-of-line', connection); 79 var req = createGetAllKeysRequest(t, 'out-of-line', connection);
80 req.onsuccess = t.step_func(function(evt) { 80 req.onsuccess = t.step_func(function(evt) {
81 assert_array_equals(evt.target.result, 81 assert_array_equals(evt.target.result, alphabet);
82 'abcdefghijklmnopqrstuvwxyz'.split(''));
83 t.done(); 82 t.done();
84 }); 83 });
85 }, 'Get all values'); 84 }, 'Get all values');
86 85
87 async_test(function(t) { 86 async_test(function(t) {
88 var req = createGetAllRequest(t, 'out-of-line', connection, undefined, 87 var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined,
89 10); 88 10);
90 req.onsuccess = t.step_func(function(evt) { 89 req.onsuccess = t.step_func(function(evt) {
91 assert_array_equals(evt.target.result, 90 assert_array_equals(evt.target.result,
92 ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']); 91 ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']);
93 t.done(); 92 t.done();
94 }); 93 });
95 }, 'Test maxCount'); 94 }, 'Test maxCount');
96 95
97 async_test(function(t) { 96 async_test(function(t) {
98 var req = createGetAllRequest(t, 'out-of-line', connection, 97 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
99 IDBKeyRange.bound('g', 'm')); 98 IDBKeyRange.bound('g', 'm'));
100 req.onsuccess = t.step_func(function(evt) { 99 req.onsuccess = t.step_func(function(evt) {
101 assert_array_equals(evt.target.result, 100 assert_array_equals(evt.target.result,
102 ['g', 'h', 'i', 'j', 'k', 'l', 'm']); 101 ['g', 'h', 'i', 'j', 'k', 'l', 'm']);
103 t.done(); 102 t.done();
104 }); 103 });
105 }, 'Get bound range'); 104 }, 'Get bound range');
106 105
107 async_test(function(t) { 106 async_test(function(t) {
108 var req = createGetAllRequest(t, 'out-of-line', connection, 107 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
109 IDBKeyRange.bound('g', 'm'), 3); 108 IDBKeyRange.bound('g', 'm'), 3);
110 req.onsuccess = t.step_func(function(evt) { 109 req.onsuccess = t.step_func(function(evt) {
111 assert_array_equals(evt.target.result, ['g', 'h', 'i']); 110 assert_array_equals(evt.target.result, ['g', 'h', 'i']);
112 t.done(); 111 t.done();
113 }); 112 });
114 }, 'Get bound range with maxCount'); 113 }, 'Get bound range with maxCount');
115 114
116 async_test(function(t) { 115 async_test(function(t) {
117 var req = createGetAllRequest(t, 'out-of-line', connection, 116 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
118 IDBKeyRange.bound('g', 'k', false, true)); 117 IDBKeyRange.bound('g', 'k', false, true));
119 req.onsuccess = t.step_func(function(evt) { 118 req.onsuccess = t.step_func(function(evt) {
120 assert_array_equals(evt.target.result, ['g', 'h', 'i', 'j']); 119 assert_array_equals(evt.target.result, ['g', 'h', 'i', 'j']);
121 t.done(); 120 t.done();
122 }); 121 });
123 }, 'Get upper excluded'); 122 }, 'Get upper excluded');
124 123
125 async_test(function(t) { 124 async_test(function(t) {
126 var req = createGetAllRequest(t, 'out-of-line', connection, 125 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
127 IDBKeyRange.bound('g', 'k', true, false)); 126 IDBKeyRange.bound('g', 'k', true, false));
128 req.onsuccess = t.step_func(function(evt) { 127 req.onsuccess = t.step_func(function(evt) {
129 assert_array_equals(evt.target.result, ['h', 'i', 'j', 'k']); 128 assert_array_equals(evt.target.result, ['h', 'i', 'j', 'k']);
130 t.done(); 129 t.done();
131 }); 130 });
132 }, 'Get lower excluded'); 131 }, 'Get lower excluded');
133 132
134 async_test(function(t) { 133 async_test(function(t) {
135 var req = createGetAllRequest(t, 'generated', connection, 134 var req = createGetAllKeysRequest(t, 'generated', connection,
136 IDBKeyRange.bound(4, 15), 3); 135 IDBKeyRange.bound(4, 15), 3);
137 req.onsuccess = t.step_func(function(evt) { 136 req.onsuccess = t.step_func(function(evt) {
138 var data = evt.target.result; 137 var data = evt.target.result;
139 assert_true(Array.isArray(data)); 138 assert_true(Array.isArray(data));
140 assert_equals(data.length, 3); 139 assert_array_equals(data, [4, 5, 6]);
141 assert_object_equals(data[0], {ch: 'd', id: 4});
142 assert_object_equals(data[1], {ch: 'e', id: 5});
143 assert_object_equals(data[2], {ch: 'f', id: 6});
144 t.done(); 140 t.done();
145 }); 141 });
146 }, 'Get bound range (generated) with maxCount'); 142 }, 'Get bound range (generated) with maxCount');
147 143
148 async_test(function(t) { 144 async_test(function(t) {
149 var req = createGetAllRequest(t, 'out-of-line', connection, 145 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
150 "Doesn't exist"); 146 "Doesn't exist");
151 req.onsuccess = t.step_func(function(evt) { 147 req.onsuccess = t.step_func(function(evt) {
152 assert_array_equals(evt.target.result, [], 148 assert_array_equals(evt.target.result, [],
153 'getAll() using a nonexistent key should return an empty array'); 149 'getAllKeys() using a nonexistent key should return an empty array ');
154 t.done(); 150 t.done();
155 }); 151 });
156 req.onerror = t.unreached_func('getAll request should succeed'); 152 req.onerror = t.unreached_func('getAllKeys request should succeed');
157 }, 'Non existent key'); 153 }, 'Non existent key');
158 154
159 async_test(function(t) { 155 async_test(function(t) {
160 var transaction = connection.transaction('out-of-line', 'readonly'); 156 var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined, 0);
161 var store = transaction.objectStore('out-of-line'); 157 req.onsuccess = t.step_func(function(evt) {
162 assert_throws(new TypeError(), function () { 158 assert_array_equals(evt.target.result, alphabet);
163 store.getAll(undefined, 0); 159 t.done();
164 }, 'getAll() with maxCount=0 should throw TypeError'); 160 });
165 t.done();
166 }, 'zero maxCount'); 161 }, 'zero maxCount');
167 }); 162 });
168 163
169 </script> 164 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698