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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/IndexedDB/idbcursor-continuePrimaryKey-exception-order.htm

Issue 2408493002: Import wpt@357b83b809e3cbc7a1805e7c3ca108a7980d782f (Closed)
Patch Set: Added one more win7-specific baseline Created 4 years, 2 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 <meta charset="utf-8">
3 <meta name="timeout" content="long">
4 <title>IDBCursor.continuePrimaryKey() - Exception Orders </title>
5 <link rel="author" title="Mozilla" href="https://www.mozilla.org">
6 <link rel="help" href="http://w3c.github.io/IndexedDB/#dom-idbcursor-continuepri marykey">
7 <script src="/resources/testharness.js"></script>
8 <script src="/resources/testharnessreport.js"></script>
9 <script src="support.js"></script>
10
11 <script>
12 function setup_test_store(db) {
13 var records = [ { iKey: "A", pKey: 1 },
14 { iKey: "A", pKey: 2 },
15 { iKey: "A", pKey: 3 },
16 { iKey: "A", pKey: 4 },
17 { iKey: "B", pKey: 5 },
18 { iKey: "B", pKey: 6 },
19 { iKey: "B", pKey: 7 },
20 { iKey: "C", pKey: 8 },
21 { iKey: "C", pKey: 9 },
22 { iKey: "D", pKey: 10 } ];
23
24 var store = db.createObjectStore("test", { keyPath: "pKey" });
25 var index = store.createIndex("idx", "iKey");
26
27 for(var i = 0; i < records.length; i++) {
28 store.add(records[i]);
29 }
30
31 return store;
32 }
33
34 indexeddb_test(
35 function(t, db, txn) {
36 var store = setup_test_store(db);
37 var index = store.index("idx");
38 var cursor_rq = index.openCursor();
39 var cursor;
40
41 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
42 cursor_rq.onsuccess = t.step_func(function(e) {
43 cursor = e.target.result;
44 assert_true(!!cursor, "acquire cursor");
45
46 store.deleteIndex("idx");
47 });
48 txn.oncomplete = function() {
49 assert_throws("TransactionInactiveError", function() {
50 cursor.continuePrimaryKey("A", 4);
51 }, "transaction-state check should precede deletion check");
52 t.done();
53 };
54 },
55 null,
56 "TransactionInactiveError v.s. InvalidStateError(deleted index)"
57 );
58
59 indexeddb_test(
60 function(t, db, txn) {
61 var store = setup_test_store(db);
62 var cursor_rq = store.openCursor();
63 var cursor;
64
65 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
66 cursor_rq.onsuccess = t.step_func(function(e) {
67 cursor = e.target.result;
68 assert_true(!!cursor, "acquire cursor");
69
70 db.deleteObjectStore("test");
71
72 assert_throws("InvalidStateError", function() {
73 cursor.continuePrimaryKey("A", 4);
74 }, "deletion check should precede index source check");
75 t.done();
76 });
77 },
78 null,
79 "InvalidStateError(deleted source) v.s. InvalidAccessError(incorrect source) "
80 );
81
82 indexeddb_test(
83 function(t, db, txn) {
84 var store = setup_test_store(db);
85 var index = store.index("idx");
86 var cursor_rq = index.openCursor(null, "nextunique");
87 var cursor;
88
89 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
90 cursor_rq.onsuccess = t.step_func(function(e) {
91 cursor = e.target.result;
92 assert_true(!!cursor, "acquire cursor");
93
94 store.deleteIndex("idx");
95
96 assert_throws("InvalidStateError", function() {
97 cursor.continuePrimaryKey("A", 4);
98 }, "deletion check should precede cursor direction check");
99 t.done();
100 });
101 },
102 null,
103 "InvalidStateError(deleted source) v.s. InvalidAccessError(incorrect directi on)"
104 );
105
106 indexeddb_test(
107 function(t, db, txn) {
108 var store = db.createObjectStore("test", {keyPath:"pKey"});
109 var index = store.createIndex("idx", "iKey");
110
111 store.add({ iKey: "A", pKey: 1 });
112
113 var cursor_rq = index.openCursor(null, "nextunique");
114 var cursor;
115
116 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
117 cursor_rq.onsuccess = t.step_func(function(e) {
118 if (e.target.result) {
119 cursor = e.target.result;
120 cursor.continue();
121 return;
122 }
123
124 assert_throws("InvalidAccessError", function() {
125 cursor.continuePrimaryKey("A", 4);
126 }, "direction check should precede got_value_flag check");
127 t.done();
128 });
129 },
130 null,
131 "InvalidAccessError(incorrect direction) v.s. InvalidStateError(iteration co mplete)"
132 );
133
134 indexeddb_test(
135 function(t, db, txn) {
136 var store = db.createObjectStore("test", {keyPath:"pKey"});
137 var index = store.createIndex("idx", "iKey");
138
139 store.add({ iKey: "A", pKey: 1 });
140
141 var cursor_rq = index.openCursor(null, "nextunique");
142 var cursor;
143
144 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
145 cursor_rq.onsuccess = t.step_func(function(e) {
146 if (!cursor) {
147 cursor = e.target.result;
148 assert_true(!!cursor, "acquire cursor");
149
150 cursor.continue();
151
152 assert_throws("InvalidAccessError", function() {
153 cursor.continuePrimaryKey("A", 4);
154 }, "direction check should precede iteration ongoing check");
155 t.done();
156 }
157 });
158 },
159 null,
160 "InvalidAccessError(incorrect direction) v.s. InvalidStateError(iteration on going)"
161 );
162
163 indexeddb_test(
164 function(t, db, txn) {
165 var store = setup_test_store(db);
166 var cursor_rq = store.openCursor();
167 var cursor;
168
169 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
170 cursor_rq.onsuccess = t.step_func(function(e) {
171 if (!cursor) {
172 cursor = e.target.result;
173 assert_true(!!cursor, "acquire cursor");
174
175 cursor.continue();
176
177 assert_throws("InvalidAccessError", function() {
178 cursor.continuePrimaryKey("A", 4);
179 }, "index source check should precede iteration ongoing check");
180 t.done();
181 }
182 });
183 },
184 null,
185 "InvalidAccessError(incorrect source) v.s. InvalidStateError(iteration ongoi ng)"
186 );
187
188 indexeddb_test(
189 function(t, db, txn) {
190 var store = db.createObjectStore("test", {keyPath:"pKey"});
191
192 store.add({ iKey: "A", pKey: 1 });
193
194 var cursor_rq = store.openCursor();
195 var cursor;
196
197 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
198 cursor_rq.onsuccess = t.step_func(function(e) {
199 if (e.target.result) {
200 cursor = e.target.result;
201 cursor.continue();
202 return;
203 }
204
205 assert_throws("InvalidAccessError", function() {
206 cursor.continuePrimaryKey("A", 4);
207 }, "index source check should precede got_value_flag check");
208 t.done();
209 });
210 },
211 null,
212 "InvalidAccessError(incorrect source) v.s. InvalidStateError(iteration compl ete)"
213 );
214
215 indexeddb_test(
216 function(t, db, txn) {
217 var store = setup_test_store(db);
218 var index = store.index("idx");
219 var cursor_rq = index.openCursor();
220 var cursor;
221
222 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
223 cursor_rq.onsuccess = t.step_func(function(e) {
224 if (!cursor) {
225 cursor = e.target.result;
226 assert_true(!!cursor, "acquire cursor");
227
228 cursor.continue();
229
230 assert_throws("InvalidStateError", function() {
231 cursor.continuePrimaryKey(null, 4);
232 }, "iteration ongoing check should precede unset key check");
233 t.done();
234 }
235 });
236 },
237 null,
238 "InvalidStateError(iteration ongoing) v.s. DataError(unset key)"
239 );
240
241 indexeddb_test(
242 function(t, db, txn) {
243 var store = db.createObjectStore("test", {keyPath:"pKey"});
244 var index = store.createIndex("idx", "iKey");
245
246 store.add({ iKey: "A", pKey: 1 });
247
248 var cursor_rq = index.openCursor();
249 var cursor;
250
251 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
252 cursor_rq.onsuccess = t.step_func(function(e) {
253 if (e.target.result) {
254 cursor = e.target.result;
255 cursor.continue();
256 return;
257 }
258
259 assert_throws("InvalidStateError", function() {
260 cursor.continuePrimaryKey(null, 4);
261 }, "got_value_flag check should precede unset key check");
262 t.done();
263 });
264 },
265 null,
266 "InvalidStateError(iteration complete) v.s. DataError(unset key)"
267 );
268
269 indexeddb_test(
270 function(t, db, txn) {
271 var store = setup_test_store(db);
272 var index = store.index("idx");
273 var cursor_rq = index.openCursor();
274 var cursor;
275
276 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
277 cursor_rq.onsuccess = t.step_func(function(e) {
278 cursor = e.target.result;
279 assert_true(!!cursor, "acquire cursor");
280
281 assert_throws("DataError", function() {
282 cursor.continuePrimaryKey(null, 4);
283 }, "DataError is expected if key is unset.");
284 t.done();
285 });
286 },
287 null,
288 "DataError(unset key)"
289 );
290
291 indexeddb_test(
292 function(t, db, txn) {
293 var store = setup_test_store(db);
294 var index = store.index("idx");
295 var cursor_rq = index.openCursor();
296 var cursor;
297
298 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
299 cursor_rq.onsuccess = t.step_func(function(e) {
300 cursor = e.target.result;
301 assert_true(!!cursor, "acquire cursor");
302
303 assert_throws("DataError", function() {
304 cursor.continuePrimaryKey("A", null);
305 }, "DataError is expected if primary key is unset.");
306 t.done();
307 });
308 },
309 null,
310 "DataError(unset primary key)"
311 );
312
313 indexeddb_test(
314 function(t, db, txn) {
315 var store = setup_test_store(db);
316 var index = store.index("idx");
317 var cursor_rq = index.openCursor(IDBKeyRange.lowerBound("B"));
318 var cursor;
319
320 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
321 cursor_rq.onsuccess = t.step_func(function(e) {
322 cursor = e.target.result;
323 assert_true(!!cursor, "acquire cursor");
324
325 assert_equals(cursor.key, "B", "expected key");
326 assert_equals(cursor.primaryKey, 5, "expected primary key");
327
328 assert_throws("DataError", function() {
329 cursor.continuePrimaryKey("A", 6);
330 }, "DataError is expected if key is lower then current one.");
331
332 assert_throws("DataError", function() {
333 cursor.continuePrimaryKey("B", 5);
334 }, "DataError is expected if primary key is equal to current one.");
335
336 assert_throws("DataError", function() {
337 cursor.continuePrimaryKey("B", 4);
338 }, "DataError is expected if primary key is lower than current one." );
339
340 t.done();
341 });
342 },
343 null,
344 "DataError(keys are lower then current one) in 'next' direction"
345 );
346
347 indexeddb_test(
348 function(t, db, txn) {
349 var store = setup_test_store(db);
350 var index = store.index("idx");
351 var cursor_rq = index.openCursor(IDBKeyRange.upperBound("B"), "prev");
352 var cursor;
353
354 cursor_rq.onerror = t.unreached_func('openCursor should succeed');
355 cursor_rq.onsuccess = t.step_func(function(e) {
356 cursor = e.target.result;
357 assert_true(!!cursor, "acquire cursor");
358
359 assert_equals(cursor.key, "B", "expected key");
360 assert_equals(cursor.primaryKey, 7, "expected primary key");
361
362 assert_throws("DataError", function() {
363 cursor.continuePrimaryKey("C", 6);
364 }, "DataError is expected if key is larger then current one.");
365
366 assert_throws("DataError", function() {
367 cursor.continuePrimaryKey("B", 7);
368 }, "DataError is expected if primary key is equal to current one.");
369
370 assert_throws("DataError", function() {
371 cursor.continuePrimaryKey("B", 8);
372 }, "DataError is expected if primary key is larger than current one. ");
373
374 t.done();
375 });
376 },
377 null,
378 "DataError(keys are larger then current one) in 'prev' direction"
379 );
380 </script>
381
382 <div id="log"></div>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698