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

Side by Side Diff: third_party/WebKit/LayoutTests/storage/indexeddb/objectstore-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
« no previous file with comments | « third_party/WebKit/LayoutTests/storage/indexeddb/objectstore-getall.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>IndexedDB: Test IDBObjectStore.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 alphabet.forEach(function(letter) {
26 store.put({ch: letter});
27 });
28
29 store = connection.createObjectStore('out-of-line', null);
30 alphabet.forEach(function(letter) {
31 store.put('value-' + letter, letter);
32 });
33
34 store = connection.createObjectStore('empty', null);
35 };
36 };
37 }
38
39 function createGetAllKeysRequest(t, storeName, connection, range, maxCount) {
40 var transaction = connection.transaction(storeName, 'readonly');
41 var store = transaction.objectStore(storeName);
42 // TODO(cmumford): Simplify once crbug.com/335871 is closed.
43 var req = maxCount !== undefined ? store.getAllKeys(range, maxCount) :
44 range !== undefined ? store.getAllKeys(range) :
45 store.getAllKeys();
46 req.onerror = t.unreached_func('getAllKeys request should succeed');
47 return req;
48 }
49
50 doSetup(location.pathname + '-IDBObjectStore.getAllKeys', 1, function(evt) {
51 var connection = evt.target.result;
52 async_test(function(t) {
53 var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'c');
54 req.onsuccess = t.step_func(function(evt) {
55 assert_array_equals(evt.target.result, ['c']);
56 t.done();
57 });
58 }, 'Single item get');
59
60 async_test(function(t) {
61 var req = createGetAllKeysRequest(t, 'generated', connection, 3);
62 req.onsuccess = t.step_func(function(evt) {
63 var data = evt.target.result;
64 assert_true(Array.isArray(data));
65 assert_array_equals(data, [3]);
66 t.done();
67 });
68 }, 'Single item get (generated key)');
69
70 async_test(function(t) {
71 var req = createGetAllKeysRequest(t, 'empty', connection);
72 req.onsuccess = t.step_func(function(evt) {
73 assert_array_equals(evt.target.result, [],
74 'getAllKeys() on empty object store should return an empty ' +
75 'array');
76 t.done();
77 });
78 }, 'getAllKeys on empty object store');
79
80 async_test(function(t) {
81 var req = createGetAllKeysRequest(t, 'out-of-line', connection);
82 req.onsuccess = t.step_func(function(evt) {
83 assert_array_equals(evt.target.result, alphabet);
84 t.done();
85 });
86 }, 'Get all values');
87
88 async_test(function(t) {
89 var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined,
90 10);
91 req.onsuccess = t.step_func(function(evt) {
92 assert_array_equals(evt.target.result,
93 ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']);
94 t.done();
95 });
96 }, 'Test maxCount');
97
98 async_test(function(t) {
99 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
100 IDBKeyRange.bound('g', 'm'));
101 req.onsuccess = t.step_func(function(evt) {
102 assert_array_equals(evt.target.result,
103 ['g', 'h', 'i', 'j', 'k', 'l', 'm']);
104 t.done();
105 });
106 }, 'Get bound range');
107
108 async_test(function(t) {
109 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
110 IDBKeyRange.bound('g', 'm'), 3);
111 req.onsuccess = t.step_func(function(evt) {
112 assert_array_equals(evt.target.result, ['g', 'h', 'i']);
113 t.done();
114 });
115 }, 'Get bound range with maxCount');
116
117 async_test(function(t) {
118 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
119 IDBKeyRange.bound('g', 'k', false, true));
120 req.onsuccess = t.step_func(function(evt) {
121 assert_array_equals(evt.target.result, ['g', 'h', 'i', 'j']);
122 t.done();
123 });
124 }, 'Get upper excluded');
125
126 async_test(function(t) {
127 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
128 IDBKeyRange.bound('g', 'k', true, false));
129 req.onsuccess = t.step_func(function(evt) {
130 assert_array_equals(evt.target.result, ['h', 'i', 'j', 'k']);
131 t.done();
132 });
133 }, 'Get lower excluded');
134
135 async_test(function(t) {
136 var req = createGetAllKeysRequest(t, 'generated', connection,
137 IDBKeyRange.bound(4, 15), 3);
138 req.onsuccess = t.step_func(function(evt) {
139 var data = evt.target.result;
140 assert_true(Array.isArray(data));
141 assert_array_equals(data, [4, 5, 6]);
142 t.done();
143 });
144 }, 'Get bound range (generated) with maxCount');
145
146 async_test(function(t) {
147 var req = createGetAllKeysRequest(t, 'out-of-line', connection,
148 "Doesn't exist");
149 req.onsuccess = t.step_func(function(evt) {
150 assert_array_equals(evt.target.result, [],
151 'getAllKeys() using a nonexistent key should return an ' +
152 'empty array');
153 t.done();
154 });
155 req.onerror = t.unreached_func('getAllKeys request should succeed');
156 }, 'Non existent key');
157
158 async_test(function(t) {
159 var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined,
160 0);
161 req.onsuccess = t.step_func(function(evt) {
162 assert_array_equals(evt.target.result, alphabet);
163 t.done();
164 });
165 }, 'zero maxCount');
166 });
167
168 </script>
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/storage/indexeddb/objectstore-getall.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698