Index: third_party/WebKit/LayoutTests/external/wpt/IndexedDB/idbcursor-continuePrimaryKey.htm |
diff --git a/third_party/WebKit/LayoutTests/external/wpt/IndexedDB/idbcursor-continuePrimaryKey.htm b/third_party/WebKit/LayoutTests/external/wpt/IndexedDB/idbcursor-continuePrimaryKey.htm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e18b8c8c252b04cfe450140340db5713947d5b44 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/external/wpt/IndexedDB/idbcursor-continuePrimaryKey.htm |
@@ -0,0 +1,134 @@ |
+<!doctype html> |
+<meta charset="utf8"> |
+<title>IndexedDB: IDBCursor method continuePrimaryKey()</title> |
+<link rel="help" |
+ href="http://w3c.github.io/IndexedDB/#dom-idbcursor-continueprimarykey"> |
+<script src="/resources/testharness.js"></script> |
+<script src="/resources/testharnessreport.js"></script> |
+<script src="support.js"></script> |
+ |
+<script> |
+'use strict'; |
+ |
+indexeddb_test( |
+ (t, db, txn) => { |
+ const store = db.createObjectStore('store'); |
+ const index = store.createIndex('index', 'indexKey', {multiEntry: true}); |
+ |
+ store.put({indexKey: ['a', 'b']}, 1); |
+ store.put({indexKey: ['a', 'b']}, 2); |
+ store.put({indexKey: ['a', 'b']}, 3); |
+ store.put({indexKey: ['b']}, 4); |
+ |
+ const expectedIndexEntries = [ |
+ {key: "a", primaryKey: 1}, |
+ {key: "a", primaryKey: 2}, |
+ {key: "a", primaryKey: 3}, |
+ {key: "b", primaryKey: 1}, |
+ {key: "b", primaryKey: 2}, |
+ {key: "b", primaryKey: 3}, |
+ {key: "b", primaryKey: 4}, |
+ ]; |
+ |
+ const request = index.openCursor(); |
+ request.onerror = t.unreached_func('IDBIndex.openCursor should not fail'); |
+ request.onsuccess = t.step_func(() => { |
+ const cursor = request.result; |
+ const expectedEntry = expectedIndexEntries.shift(); |
+ if (expectedEntry) { |
+ assert_equals(cursor.key, expectedEntry.key, |
+ 'The index entry keys should reflect the object store contents'); |
+ assert_equals(cursor.primaryKey, expectedEntry.primaryKey, |
+ 'The index entry primary keys should reflect the object store ' + |
+ 'contents'); |
+ cursor.continue(); |
+ } else { |
+ assert_equals(cursor, null, |
+ 'The index should not have entries that do not reflect the ' + |
+ 'object store contents'); |
+ } |
+ }); |
+ }, |
+ (t, db) => { |
+ const testCases = [ |
+ // Continuing index key |
+ { 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.
|
+ result: { key: "a", primaryKey: 2 } }, |
+ { call: (cursor) => { cursor.continue('a'); }, |
+ exception: 'DataError' }, |
+ { call: (cursor) => { cursor.continue('b'); }, |
+ result: { key: "b", primaryKey: 1 } }, |
+ { call: (cursor) => { cursor.continue('c'); }, result: null }, |
+ |
+ // Called w/ index key and primary key: |
+ { call: (cursor) => { cursor.continuePrimaryKey('a', 3); }, |
+ result: { key: 'a', primaryKey: 3 } }, |
+ { call: (cursor) => { cursor.continuePrimaryKey('a', 4); }, |
+ result: { key: 'b', primaryKey: 1 } }, |
+ { call: (cursor) => { cursor.continuePrimaryKey('b', 1); }, |
+ result: {key: 'b', primaryKey: 1} }, |
+ { call: (cursor) => { cursor.continuePrimaryKey('b', 4); }, |
+ result: {key: 'b', primaryKey: 4} }, |
+ { call: (cursor) => { cursor.continuePrimaryKey('b', 5); }, |
+ result: null }, |
+ { call: (cursor) => { cursor.continuePrimaryKey('c', 1); }, |
+ result: null }, |
+ |
+ // Called w/ primary key but w/o index key |
+ { call: (cursor) => { cursor.continuePrimaryKey(null, 1); }, |
+ exception: 'DataError' }, |
+ { call: (cursor) => { cursor.continuePrimaryKey(null, 2); }, |
+ exception: 'DataError' }, |
+ { call: (cursor) => { cursor.continuePrimaryKey(null, 3); }, |
+ exception: 'DataError' }, |
+ { call: (cursor) => { cursor.continuePrimaryKey(null, 4); }, |
+ exception: 'DataError' }, |
+ { call: (cursor) => { cursor.continuePrimaryKey(null, 5); }, |
+ exception: 'DataError' }, |
+ |
+ // Called w/ index key but w/o primary key |
+ { call: (cursor) => { cursor.continuePrimaryKey('a', null); }, |
+ exception: 'DataError' }, |
+ ]; |
+ |
+ const verifyContinueCalls = () => { |
+ if (!testCases.length) { |
+ t.done(); |
+ return; |
+ } |
+ |
+ const testCase = testCases.shift(); |
+ |
+ const txn = db.transaction('store'); |
+ txn.oncomplete = verifyContinueCalls; |
jsbell
2017/01/24 21:59:49
Needs t.step_func() wrapper
pwnall
2017/01/26 00:22:06
Done.
|
+ |
+ const request = txn.objectStore('store').index('index').openCursor(); |
+ let calledContinue = false; |
+ request.onerror = |
+ t.unreached_func('IDBIndex.openCursor should not fail'); |
+ request.onsuccess = t.step_func(() => { |
+ const cursor = request.result; |
+ if (calledContinue) { |
+ if (testCase.result) { |
+ assert_equals(cursor.key, testCase.result.key, |
+ `${testCase.call.toString()} - result key`); |
+ assert_equals(cursor.primaryKey, testCase.result.primaryKey, |
+ `${testCase.call.toString()} - result primary key`); |
+ } else { |
+ assert_equals(cursor, null); |
+ } |
+ } else { |
+ calledContinue = true; |
+ if('exception' in testCase) { |
+ assert_throws( |
+ testCase.exception, () => { testCase.call(cursor); }, |
+ testCase.call.toString()); |
+ } else { |
+ testCase.call(cursor); |
+ } |
+ } |
+ }); |
+ }; |
+ verifyContinueCalls(); |
+ }); |
+</script> |