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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/IndexedDB/idbcursor-continuePrimaryKey.htm

Issue 2657533002: Upstream IDBCursor.continuePrimaryKey test to WPT. (Closed)
Patch Set: Removed old layout test. Created 3 years, 10 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/external/wpt/MANIFEST.json » ('j') | 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 <meta charset="utf8">
3 <title>IndexedDB: IDBCursor method continuePrimaryKey()</title>
4 <link rel="help"
5 href="http://w3c.github.io/IndexedDB/#dom-idbcursor-continueprimarykey">
6 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
8 <script src="support.js"></script>
9
10 <script>
11 'use strict';
12
13 indexeddb_test(
14 (t, db, txn) => {
15 const store = db.createObjectStore('store');
16 const index = store.createIndex('index', 'indexKey', {multiEntry: true});
17
18 store.put({indexKey: ['a', 'b']}, 1);
19 store.put({indexKey: ['a', 'b']}, 2);
20 store.put({indexKey: ['a', 'b']}, 3);
21 store.put({indexKey: ['b']}, 4);
22
23 const expectedIndexEntries = [
24 {key: "a", primaryKey: 1},
25 {key: "a", primaryKey: 2},
26 {key: "a", primaryKey: 3},
27 {key: "b", primaryKey: 1},
28 {key: "b", primaryKey: 2},
29 {key: "b", primaryKey: 3},
30 {key: "b", primaryKey: 4},
31 ];
32
33 const request = index.openCursor();
34 request.onerror = t.unreached_func('IDBIndex.openCursor should not fail');
35 request.onsuccess = t.step_func(() => {
36 const cursor = request.result;
37 const expectedEntry = expectedIndexEntries.shift();
38 if (expectedEntry) {
39 assert_equals(cursor.key, expectedEntry.key,
40 'The index entry keys should reflect the object store contents');
41 assert_equals(cursor.primaryKey, expectedEntry.primaryKey,
42 'The index entry primary keys should reflect the object store ' +
43 'contents');
44 cursor.continue();
45 } else {
46 assert_equals(cursor, null,
47 'The index should not have entries that do not reflect the ' +
48 'object store contents');
49 }
50 });
51 },
52 (t, db) => {
53 const testCases = [
54 // Continuing index key
55 { call: (cursor) => { cursor.continue(); },
jsbell 2017/01/24 21:59:49 nit: no need for () around single argument => func
pwnall 2017/01/26 00:22:06 Done.
56 result: { key: "a", primaryKey: 2 } },
57 { call: (cursor) => { cursor.continue('a'); },
58 exception: 'DataError' },
59 { call: (cursor) => { cursor.continue('b'); },
60 result: { key: "b", primaryKey: 1 } },
61 { call: (cursor) => { cursor.continue('c'); }, result: null },
62
63 // Called w/ index key and primary key:
64 { call: (cursor) => { cursor.continuePrimaryKey('a', 3); },
65 result: { key: 'a', primaryKey: 3 } },
66 { call: (cursor) => { cursor.continuePrimaryKey('a', 4); },
67 result: { key: 'b', primaryKey: 1 } },
68 { call: (cursor) => { cursor.continuePrimaryKey('b', 1); },
69 result: {key: 'b', primaryKey: 1} },
70 { call: (cursor) => { cursor.continuePrimaryKey('b', 4); },
71 result: {key: 'b', primaryKey: 4} },
72 { call: (cursor) => { cursor.continuePrimaryKey('b', 5); },
73 result: null },
74 { call: (cursor) => { cursor.continuePrimaryKey('c', 1); },
75 result: null },
76
77 // Called w/ primary key but w/o index key
78 { call: (cursor) => { cursor.continuePrimaryKey(null, 1); },
79 exception: 'DataError' },
80 { call: (cursor) => { cursor.continuePrimaryKey(null, 2); },
81 exception: 'DataError' },
82 { call: (cursor) => { cursor.continuePrimaryKey(null, 3); },
83 exception: 'DataError' },
84 { call: (cursor) => { cursor.continuePrimaryKey(null, 4); },
85 exception: 'DataError' },
86 { call: (cursor) => { cursor.continuePrimaryKey(null, 5); },
87 exception: 'DataError' },
88
89 // Called w/ index key but w/o primary key
90 { call: (cursor) => { cursor.continuePrimaryKey('a', null); },
91 exception: 'DataError' },
92 ];
93
94 const verifyContinueCalls = () => {
95 if (!testCases.length) {
96 t.done();
97 return;
98 }
99
100 const testCase = testCases.shift();
101
102 const txn = db.transaction('store');
103 txn.oncomplete = verifyContinueCalls;
jsbell 2017/01/24 21:59:49 Needs t.step_func() wrapper
pwnall 2017/01/26 00:22:06 Done.
104
105 const request = txn.objectStore('store').index('index').openCursor();
106 let calledContinue = false;
107 request.onerror =
108 t.unreached_func('IDBIndex.openCursor should not fail');
109 request.onsuccess = t.step_func(() => {
110 const cursor = request.result;
111 if (calledContinue) {
112 if (testCase.result) {
113 assert_equals(cursor.key, testCase.result.key,
114 `${testCase.call.toString()} - result key`);
115 assert_equals(cursor.primaryKey, testCase.result.primaryKey,
116 `${testCase.call.toString()} - result primary key`);
117 } else {
118 assert_equals(cursor, null);
119 }
120 } else {
121 calledContinue = true;
122 if('exception' in testCase) {
123 assert_throws(
124 testCase.exception, () => { testCase.call(cursor); },
125 testCase.call.toString());
126 } else {
127 testCase.call(cursor);
128 }
129 }
130 });
131 };
132 verifyContinueCalls();
133 });
134 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/external/wpt/MANIFEST.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698