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

Side by Side Diff: third_party/WebKit/LayoutTests/storage/indexeddb/index-getallkeys.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.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) :
64 index.getAllKeys();
65 req.onerror = t.unreached_func('getAllKeys request should succeed');
66 return req;
67 }
68
69 doSetup(location.pathname + '-IDBIndex.getAllKeys', 1, function(evt) {
70 var connection = evt.target.result;
71 async_test(function(t) {
72 var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'C');
73 req.onsuccess = t.step_func(function(evt) {
74 var data = evt.target.result;
75 assert_array_equals(evt.target.result, ['c']);
76 t.done();
77 });
78 }, 'Single item get');
79
80 async_test(function(t) {
81 var req = createGetAllKeysRequest(t, 'empty', connection);
82 req.onsuccess = t.step_func(function(evt) {
83 assert_array_equals(evt.target.result, [],
84 'getAllKeys() on empty object store should return empty array');
85 t.done();
86 });
87 }, 'Empty object store');
88
89 async_test(function(t) {
90 var req = createGetAllKeysRequest(t, 'out-of-line', connection);
91 req.onsuccess = t.step_func(function(evt) {
92 assert_array_equals(evt.target.result, alphabet,
93 'getAllKeys() should return a..z');
94 t.done();
95 });
96 }, 'Get all keys');
97
98 async_test(function(t) {
99 var req = createGetAllKeysRequest(t, 'generated', connection);
100 req.onsuccess = t.step_func(function(evt) {
101 assert_array_equals(evt.target.result,
102 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
103 19, 20, 21, 22, 23, 24, 25, 26],
104 'getAllKeys() should return 1..26');
105 t.done();
106 });
107 }, 'Get all generated keys');
108
109 async_test(function(t) {
110 var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined,
111 10);
112 req.onsuccess = t.step_func(function(evt) {
113 assert_array_equals(evt.target.result,
114 ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],
115 'getAllKeys() should return a..j');
116 t.done();
117 });
118 }, 'maxCount=10');
119
120 async_test(function(t) {
121 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
122 IDBKeyRange.bound('G', 'M'));
123 req.onsuccess = t.step_func(function(evt) {
124 assert_array_equals(evt.target.result,
125 ['g', 'h', 'i', 'j', 'k', 'l', 'm'],
126 'getAllKeys() should return g..m');
127 t.done();
128 });
129 }, 'Get bound range');
130
131 async_test(function(t) {
132 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
133 IDBKeyRange.bound('G', 'M'), 3);
134 req.onsuccess = t.step_func(function(evt) {
135 assert_array_equals(evt.target.result,
136 ['g', 'h', 'i'],
137 'getAllKeys() should return g..i');
138 t.done();
139 });
140 }, 'Get bound range with maxCount');
141
142 async_test(function(t) {
143 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
144 IDBKeyRange.bound('G', 'K', false, true));
145 req.onsuccess = t.step_func(function(evt) {
146 assert_array_equals(evt.target.result,
147 ['g', 'h', 'i', 'j'],
148 'getAllKeys() should return g..j');
149 t.done();
150 });
151 }, 'Get upper excluded');
152
153 async_test(function(t) {
154 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
155 IDBKeyRange.bound('G', 'K', true, false));
156 req.onsuccess = t.step_func(function(evt) {
157 assert_array_equals(evt.target.result,
158 ['h', 'i', 'j', 'k'],
159 'getAllKeys() should return h..k');
160 t.done();
161 });
162 }, 'Get lower excluded');
163
164 async_test(function(t) {
165 var req = createGetAllKeysRequest(t, 'generated',
166 connection, IDBKeyRange.bound(4, 15), 3);
167 req.onsuccess = t.step_func(function(evt) {
168 assert_array_equals(evt.target.result, [],
169 'getAllKeys() should return []');
170 t.done();
171 });
172 }, 'Get bound range (generated) with maxCount');
173
174 async_test(function(t) {
175 var req = createGetAllKeysRequest(t, 'out-of-line',
176 connection, "Doesn't exist");
177 req.onsuccess = t.step_func(function(evt) {
178 assert_array_equals(evt.target.result, [],
179 'getAllKeys() using a nonexistent key should return empty array');
180 t.done();
181 req.onerror = t.unreached_func('getAllKeys request should succeed');
182 });
183 }, 'Non existent key');
184
185 async_test(function(t) {
186 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
187 undefined, 0);
188 req.onsuccess = t.step_func(function(evt) {
189 assert_array_equals(evt.target.result, alphabet,
190 'getAllKeys() should return a..z');
191 t.done();
192 });
193 }, 'maxCount=0');
194
195 async_test(function(t) {
196 var req = createGetAllKeysRequest(t, 'out-of-line-multi', connection,
197 'vowel');
198 req.onsuccess = t.step_func(function(evt) {
199 assert_array_equals(evt.target.result, ['A','E','I','O','U'])
200 t.done();
201 });
202 req.onerror = t.unreached_func('getAllKeys request should succeed');
203 }, 'Retrieve multiEntry keys');
204 });
205
206 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698