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

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

Issue 1157173002: IndexedDB: IDL and tests for IDBIndex.getAllKeys. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@idb-index-getallkeys
Patch Set: Rewound stable/virtual expected and made getAllKeys experimental Created 5 years, 6 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
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>IndexedDB: Test IDBIndex.getAllKeys.</title>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script>
6
7 var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
8
9 function doSetup(dbName, dbVersion, onsuccess) {
10 var delete_request = indexedDB.deleteDatabase(dbName);
11 delete_request.onerror = function() {
12 assert_unreached('deleteDatabase should not fail');
13 };
14 delete_request.onsuccess = function(e) {
15 var req = indexedDB.open(dbName, dbVersion);
16 req.onsuccess = onsuccess;
17 req.onerror = function() {
18 assert_unreached('open should not fail');
19 };
20 req.onupgradeneeded = function(evt) {
21 var connection = evt.target.result;
22
23 var store = connection.createObjectStore('generated',
24 {autoIncrement: true, keyPath: 'id'});
25 var index = store.createIndex('test_idx', 'upper');
26 alphabet.forEach(function(letter) {
27 store.put({ch: letter, upper: letter.toUpperCase()});
28 });
29
30 store = connection.createObjectStore('out-of-line', null);
31 index = store.createIndex('test_idx', 'upper');
32 alphabet.forEach(function(letter) {
33 store.put({ch: letter, upper: letter.toUpperCase()}, letter);
34 });
35
36 store = connection.createObjectStore('out-of-line-multi', null);
37 index = store.createIndex('test_idx', 'attribs', {multiEntry: true});
38 alphabet.forEach(function(letter) {
39 attrs = [];
40 if (['a', 'e', 'i', 'o', 'u'].indexOf(letter) != -1)
41 attrs.push('vowel');
42 else
43 attrs.push('consonant');
44 if (letter == 'a')
45 attrs.push('first');
46 if (letter == 'z')
47 attrs.push('last');
48 store.put({ch: letter, attribs: attrs}, letter.toUpperCase());
49 });
50
51 store = connection.createObjectStore('empty', null);
52 index = store.createIndex('test_idx', 'upper');
53 };
54 };
55 }
56
57 function createGetAllKeysRequest(t, storeName, connection, range, maxCount) {
58 var transaction = connection.transaction(storeName, 'readonly');
59 var store = transaction.objectStore(storeName);
60 var index = store.index('test_idx');
61 // TODO(cmumford): Simplify once crbug.com/335871 is fixed.
62 var req = maxCount !== undefined ? index.getAllKeys(range, maxCount) :
63 range !== undefined ? index.getAllKeys(range) : index.getAllKeys() ;
64 req.onerror = t.unreached_func('getAllKeys request should succeed');
65 return req;
66 }
67
68 doSetup(location.pathname + '-IDBIndex.getAllKeys', 1, function(evt) {
69 var connection = evt.target.result;
70 async_test(function(t) {
71 var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'C');
72 req.onsuccess = t.step_func(function(evt) {
73 var data = evt.target.result;
74 assert_array_equals(evt.target.result, ['c']);
75 t.done();
76 });
77 }, 'Single item get');
78
79 async_test(function(t) {
80 var req = createGetAllKeysRequest(t, 'empty', connection);
81 req.onsuccess = t.step_func(function(evt) {
82 assert_array_equals(evt.target.result, [],
83 'getAllKeys() on empty object store should return empty array');
84 t.done();
85 });
86 }, 'Empty object store');
87
88 async_test(function(t) {
89 var req = createGetAllKeysRequest(t, 'out-of-line', connection);
90 req.onsuccess = t.step_func(function(evt) {
91 assert_array_equals(evt.target.result, alphabet,
92 'getAllKeys() should return a..z');
93 t.done();
94 });
95 }, 'Get all keys');
96
97 async_test(function(t) {
98 var req = createGetAllKeysRequest(t, 'generated', connection);
99 req.onsuccess = t.step_func(function(evt) {
100 assert_array_equals(evt.target.result,
101 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
102 19, 20, 21, 22, 23, 24, 25, 26],
103 'getAllKeys() should return 1..26');
104 t.done();
105 });
106 }, 'Get all generated keys');
107
108 async_test(function(t) {
109 var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined,
110 10);
111 req.onsuccess = t.step_func(function(evt) {
112 assert_array_equals(evt.target.result,
113 ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],
114 'getAllKeys() should return a..j');
115 t.done();
116 });
117 }, 'maxCount=10');
118
119 async_test(function(t) {
120 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
121 IDBKeyRange.bound('G', 'M'));
122 req.onsuccess = t.step_func(function(evt) {
123 assert_array_equals(evt.target.result,
124 ['g', 'h', 'i', 'j', 'k', 'l', 'm'],
125 'getAllKeys() should return g..m');
126 t.done();
127 });
128 }, 'Get bound range');
129
130 async_test(function(t) {
131 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
132 IDBKeyRange.bound('G', 'M'), 3);
133 req.onsuccess = t.step_func(function(evt) {
134 assert_array_equals(evt.target.result,
135 ['g', 'h', 'i'],
136 'getAllKeys() should return g..i');
137 t.done();
138 });
139 }, 'Get bound range with maxCount');
140
141 async_test(function(t) {
142 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
143 IDBKeyRange.bound('G', 'K', false, true));
144 req.onsuccess = t.step_func(function(evt) {
145 assert_array_equals(evt.target.result,
146 ['g', 'h', 'i', 'j'],
147 'getAllKeys() should return g..j');
148 t.done();
149 });
150 }, 'Get upper excluded');
151
152 async_test(function(t) {
153 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
154 IDBKeyRange.bound('G', 'K', true, false));
155 req.onsuccess = t.step_func(function(evt) {
156 assert_array_equals(evt.target.result,
157 ['h', 'i', 'j', 'k'],
158 'getAllKeys() should return h..k');
159 t.done();
160 });
161 }, 'Get lower excluded');
162
163 async_test(function(t) {
164 var req = createGetAllKeysRequest(t, 'generated',
165 connection, IDBKeyRange.bound(4, 15), 3);
166 req.onsuccess = t.step_func(function(evt) {
167 assert_array_equals(evt.target.result, [],
168 'getAllKeys() should return []');
169 t.done();
170 });
171 }, 'Get bound range (generated) with maxCount');
172
173 async_test(function(t) {
174 var req = createGetAllKeysRequest(t, 'out-of-line',
175 connection, "Doesn't exist");
176 req.onsuccess = t.step_func(function(evt) {
177 assert_array_equals(evt.target.result, [],
178 'getAllKeys() using a nonexistent key should return empty array');
179 t.done();
180 req.onerror = t.unreached_func('getAllKeys request should succeed');
181 });
182 }, 'Non existent key');
183
184 async_test(function(t) {
185 var transaction = connection.transaction('out-of-line', 'readonly');
186 var store = transaction.objectStore('out-of-line');
187 var index = store.index('test_idx');
188 assert_throws(new TypeError(), function () {
189 index.getAllKeys(undefined, 0);
190 }, 'getAllKeys() with maxCount=0 should throw TypeError');
191 t.done();
192 }, 'maxCount=0');
193
194 async_test(function(t) {
195 var req = createGetAllKeysRequest(t, 'out-of-line-multi', connection,
196 'vowel');
197 req.onsuccess = t.step_func(function(evt) {
198 assert_array_equals(evt.target.result, ['A','E','I','O','U'])
199 t.done();
200 });
201 req.onerror = t.unreached_func('getAllKeys request should succeed');
202 }, 'Retrieve multiEntry keys');
203 });
204
205 </script>
OLDNEW
« no previous file with comments | « LayoutTests/storage/indexeddb/exceptions-expected.txt ('k') | LayoutTests/storage/indexeddb/resources/deleted-objects.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698