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

Side by Side Diff: third_party/WebKit/LayoutTests/storage/indexeddb/index-getall.html

Issue 1419013007: update-w3c-deps import using blink 83a52878976eaffc8753993a7689c9c178664fba: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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.getAll.</title>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script>
6
7 var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
8 var ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
9
10 function doSetup(dbName, dbVersion, onsuccess) {
11 var delete_request = indexedDB.deleteDatabase(dbName);
12 delete_request.onerror = function() {
13 assert_unreached('deleteDatabase should not fail');
14 };
15 delete_request.onsuccess = function(e) {
16 var req = indexedDB.open(dbName, dbVersion);
17 req.onsuccess = onsuccess;
18 req.onerror = function() {
19 assert_unreached('open should not fail');
20 };
21 req.onupgradeneeded = function(evt) {
22 var connection = evt.target.result;
23
24 var store = connection.createObjectStore('generated',
25 {autoIncrement: true, keyPath: 'id'});
26 var index = store.createIndex('test_idx', 'upper');
27 alphabet.forEach(function(letter) {
28 store.put({ch: letter, upper: letter.toUpperCase()});
29 });
30
31 store = connection.createObjectStore('out-of-line', null);
32 index = store.createIndex('test_idx', 'upper');
33 alphabet.forEach(function(letter) {
34 store.put({ch: letter, upper: letter.toUpperCase()}, letter);
35 });
36
37 store = connection.createObjectStore('out-of-line-not-unique', null);
38 index = store.createIndex('test_idx', 'half');
39 alphabet.forEach(function(letter) {
40 if (letter <= 'm')
41 store.put({ch: letter, half: 'first'}, letter);
42 else
43 store.put({ch: letter, half: 'second'}, letter);
44 });
45
46 store = connection.createObjectStore('out-of-line-multi', null);
47 index = store.createIndex('test_idx', 'attribs', {multiEntry: true});
48 alphabet.forEach(function(letter) {
49 attrs = [];
50 if (['a', 'e', 'i', 'o', 'u'].indexOf(letter) != -1)
51 attrs.push('vowel');
52 else
53 attrs.push('consonant');
54 if (letter == 'a')
55 attrs.push('first');
56 if (letter == 'z')
57 attrs.push('last');
58 store.put({ch: letter, attribs: attrs}, letter);
59 });
60
61 store = connection.createObjectStore('empty', null);
62 index = store.createIndex('test_idx', 'upper');
63 };
64 };
65 }
66
67 function createGetAllRequest(t, storeName, connection, range, maxCount) {
68 var transaction = connection.transaction(storeName, 'readonly');
69 var store = transaction.objectStore(storeName);
70 var index = store.index('test_idx');
71 // TODO(cmumford): Simplify once crbug.com/335871 is fixed.
72 var req = maxCount !== undefined ? index.getAll(range, maxCount) :
73 range !== undefined ? index.getAll(range) : index.getAll();
74 req.onerror = t.unreached_func('getAll request should succeed');
75 return req;
76 }
77
78 doSetup(location.pathname + '-IDBIndex.getAll', 1, function(evt) {
79 var connection = evt.target.result;
80 async_test(function(t) {
81 var req = createGetAllRequest(t, 'out-of-line', connection, 'C');
82 req.onsuccess = t.step_func(function(evt) {
83 var data = evt.target.result;
84 assert_class_string(data, 'Array', 'result should be an array');
85 assert_array_equals(data.map(e => e.ch), ['c']);
86 assert_array_equals(data.map(e => e.upper), ['C']);
87 t.done();
88 });
89 }, 'Single item get');
90
91 async_test(function(t) {
92 var req = createGetAllRequest(t, 'empty', connection);
93 req.onsuccess = t.step_func(function(evt) {
94 assert_array_equals(evt.target.result, [],
95 'getAll() on empty object store should return an empty array');
96 t.done();
97 });
98 }, 'Empty object store');
99
100 async_test(function(t) {
101 var req = createGetAllRequest(t, 'out-of-line', connection);
102 req.onsuccess = t.step_func(function(evt) {
103 var data = evt.target.result;
104 assert_class_string(data, 'Array', 'result should be an array');
105 assert_array_equals(data.map(e => e.ch), alphabet);
106 assert_array_equals(data.map(e => e.upper), ALPHABET);
107 t.done();
108 });
109 }, 'Get all keys');
110
111 async_test(function(t) {
112 var req = createGetAllRequest(t, 'out-of-line', connection, undefined,
113 10);
114 req.onsuccess = t.step_func(function(evt) {
115 var data = evt.target.result;
116 assert_class_string(data, 'Array', 'result should be an array');
117 assert_array_equals(data.map(e => e.ch), 'abcdefghij'.split(''));
118 assert_array_equals(data.map(e => e.upper), 'ABCDEFGHIJ'.split(''));
119 t.done();
120 });
121 }, 'maxCount=10');
122
123 async_test(function(t) {
124 var req = createGetAllRequest(t, 'out-of-line', connection,
125 IDBKeyRange.bound('G', 'M'));
126 req.onsuccess = t.step_func(function(evt) {
127 var data = evt.target.result;
128 assert_array_equals(data.map(e => e.ch), 'ghijklm'.split(''));
129 assert_array_equals(data.map(e => e.upper), 'GHIJKLM'.split(''));
130 t.done();
131 });
132 }, 'Get bound range');
133
134 async_test(function(t) {
135 var req = createGetAllRequest(t, 'out-of-line', connection,
136 IDBKeyRange.bound('G', 'M'), 3);
137 req.onsuccess = t.step_func(function(evt) {
138 var data = evt.target.result;
139 assert_class_string(data, 'Array', 'result should be an array');
140 assert_array_equals(data.map(e => e.ch), 'ghi'.split(''));
141 assert_array_equals(data.map(e => e.upper), 'GHI'.split(''));
142 t.done();
143 });
144 }, 'Get bound range with maxCount');
145
146 async_test(function(t) {
147 var req = createGetAllRequest(t, 'out-of-line', connection,
148 IDBKeyRange.bound('G', 'K', false, true));
149 req.onsuccess = t.step_func(function(evt) {
150 var data = evt.target.result;
151 assert_class_string(data, 'Array', 'result should be an array');
152 assert_array_equals(data.map(e => e.ch), 'ghij'.split(''));
153 assert_array_equals(data.map(e => e.upper), 'GHIJ'.split(''));
154 t.done();
155 });
156 }, 'Get upper excluded');
157
158 async_test(function(t) {
159 var req = createGetAllRequest(t, 'out-of-line', connection,
160 IDBKeyRange.bound('G', 'K', true, false));
161 req.onsuccess = t.step_func(function(evt) {
162 var data = evt.target.result;
163 assert_class_string(data, 'Array', 'result should be an array');
164 assert_array_equals(data.map(e => e.ch), 'hijk'.split(''));
165 assert_array_equals(data.map(e => e.upper), 'HIJK'.split(''));
166 t.done();
167 });
168 }, 'Get lower excluded');
169
170 async_test(function(t) {
171 var req = createGetAllRequest(t, 'generated',
172 connection, IDBKeyRange.bound(4, 15), 3);
173 req.onsuccess = t.step_func(function(evt) {
174 var data = evt.target.result;
175 assert_true(Array.isArray(data));
176 assert_equals(data.length, 0);
177 t.done();
178 });
179 }, 'Get bound range (generated) with maxCount');
180
181 async_test(function(t) {
182 var req = createGetAllRequest(t, 'out-of-line',
183 connection, "Doesn't exist");
184 req.onsuccess = t.step_func(function(evt) {
185 assert_array_equals(evt.target.result, [],
186 'getAll() using a nonexistent key should return an empty array');
187 t.done();
188 req.onerror = t.unreached_func('getAll request should succeed');
189 });
190 }, 'Non existent key');
191
192 async_test(function(t) {
193 var req = createGetAllRequest(t, 'out-of-line', connection,
194 undefined, 0);
195 req.onsuccess = t.step_func(function(evt) {
196 var data = evt.target.result;
197 assert_class_string(data, 'Array', 'result should be an array');
198 assert_array_equals(data.map(e => e.ch), alphabet);
199 assert_array_equals(data.map(e => e.upper), ALPHABET);
200 t.done();
201 });
202 }, 'maxCount=0');
203
204 async_test(function(t) {
205 var req = createGetAllRequest(t, 'out-of-line-not-unique', connection,
206 'first');
207 req.onsuccess = t.step_func(function(evt) {
208 var data = evt.target.result;
209 assert_class_string(data, 'Array', 'result should be an array');
210 assert_array_equals(data.map(e => e.ch), 'abcdefghijklm'.split(''));
211 assert_true(data.every(e => e.half === 'first'));
212 t.done();
213 });
214 }, 'Retrieve multiEntry key');
215
216 async_test(function(t) {
217 var req = createGetAllRequest(t, 'out-of-line-multi', connection,
218 'vowel');
219 req.onsuccess = t.step_func(function(evt) {
220 var data = evt.target.result;
221 assert_class_string(data, 'Array', 'result should be an array');
222 assert_array_equals(data.map(e => e.ch), ['a', 'e', 'i', 'o', 'u']);
223 assert_array_equals(data[0].attribs, ['vowel', 'first']);
224 assert_true(data.every(e => e.attribs[0] === 'vowel'));
225 t.done();
226 });
227 }, 'Retrieve one key multiple values');
228 });
229
230 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698