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

Side by Side Diff: third_party/WebKit/LayoutTests/storage/indexeddb/objectstore-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 IDBObjectStore.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
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 createGetAllRequest(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.getAll(range, maxCount) :
44 range !== undefined ? store.getAll(range) : store.getAll();
45 req.onerror = t.unreached_func('getAll request should succeed');
46 return req;
47 }
48
49 doSetup(location.pathname + '-IDBObjectStore.getAll', 1, function(evt) {
50 var connection = evt.target.result;
51 async_test(function(t) {
52 var req = createGetAllRequest(t, 'out-of-line', connection, 'c');
53 req.onsuccess = t.step_func(function(evt) {
54 assert_array_equals(evt.target.result, ['value-c']);
55 t.done();
56 });
57 }, 'Single item get');
58
59 async_test(function(t) {
60 var req = createGetAllRequest(t, 'generated', connection, 3);
61 req.onsuccess = t.step_func(function(evt) {
62 var data = evt.target.result;
63 assert_true(Array.isArray(data));
64 assert_equals(data.length, 1);
65 assert_equals(data[0].id, 3);
66 assert_equals(data[0].ch, 'c');
67 t.done();
68 });
69 }, 'Single item get (generated key)');
70
71 async_test(function(t) {
72 var req = createGetAllRequest(t, 'empty', connection);
73 req.onsuccess = t.step_func(function(evt) {
74 assert_array_equals(evt.target.result, [],
75 'getAll() on empty object store should return an empty array');
76 t.done();
77 });
78 }, 'getAll on empty object store');
79
80 async_test(function(t) {
81 var req = createGetAllRequest(t, 'out-of-line', connection);
82 req.onsuccess = t.step_func(function(evt) {
83 assert_array_equals(evt.target.result,
84 alphabet.map(c => 'value-' + c));
85 t.done();
86 });
87 }, 'Get all values');
88
89 async_test(function(t) {
90 var req = createGetAllRequest(t, 'out-of-line', connection, undefined,
91 10);
92 req.onsuccess = t.step_func(function(evt) {
93 assert_array_equals(evt.target.result,
94 ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
95 .map(c => 'value-' + c));
96 t.done();
97 });
98 }, 'Test maxCount');
99
100 async_test(function(t) {
101 var req = createGetAllRequest(t, 'out-of-line', connection,
102 IDBKeyRange.bound('g', 'm'));
103 req.onsuccess = t.step_func(function(evt) {
104 assert_array_equals(evt.target.result,
105 ['g', 'h', 'i', 'j', 'k', 'l', 'm']
106 .map(c => 'value-' + c));
107 t.done();
108 });
109 }, 'Get bound range');
110
111 async_test(function(t) {
112 var req = createGetAllRequest(t, 'out-of-line', connection,
113 IDBKeyRange.bound('g', 'm'), 3);
114 req.onsuccess = t.step_func(function(evt) {
115 assert_array_equals(evt.target.result, ['g', 'h', 'i']
116 .map(c => 'value-' + c));
117 t.done();
118 });
119 }, 'Get bound range with maxCount');
120
121 async_test(function(t) {
122 var req = createGetAllRequest(t, 'out-of-line', connection,
123 IDBKeyRange.bound('g', 'k', false, true));
124 req.onsuccess = t.step_func(function(evt) {
125 assert_array_equals(evt.target.result, ['g', 'h', 'i', 'j']
126 .map(c => 'value-' + c));
127 t.done();
128 });
129 }, 'Get upper excluded');
130
131 async_test(function(t) {
132 var req = createGetAllRequest(t, 'out-of-line', connection,
133 IDBKeyRange.bound('g', 'k', true, false));
134 req.onsuccess = t.step_func(function(evt) {
135 assert_array_equals(evt.target.result, ['h', 'i', 'j', 'k']
136 .map(c => 'value-' + c));
137 t.done();
138 });
139 }, 'Get lower excluded');
140
141 async_test(function(t) {
142 var req = createGetAllRequest(t, 'generated', connection,
143 IDBKeyRange.bound(4, 15), 3);
144 req.onsuccess = t.step_func(function(evt) {
145 var data = evt.target.result;
146 assert_true(Array.isArray(data));
147 assert_array_equals(data.map(e => e.ch), ['d', 'e', 'f']);
148 assert_array_equals(data.map(e => e.id), [4, 5, 6]);
149 t.done();
150 });
151 }, 'Get bound range (generated) with maxCount');
152
153 async_test(function(t) {
154 var req = createGetAllRequest(t, 'out-of-line', connection,
155 "Doesn't exist");
156 req.onsuccess = t.step_func(function(evt) {
157 assert_array_equals(evt.target.result, [],
158 'getAll() using a nonexistent key should return an empty array');
159 t.done();
160 });
161 req.onerror = t.unreached_func('getAll request should succeed');
162 }, 'Non existent key');
163
164 async_test(function(t) {
165 var req = createGetAllRequest(t, 'out-of-line', connection, undefined, 0);
166 req.onsuccess = t.step_func(function(evt) {
167 assert_array_equals(evt.target.result,
168 alphabet.map(c => 'value-' + c));
169 t.done();
170 });
171 }, 'zero maxCount');
172 });
173
174 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698