1 if (this.importScripts) {
2 importScripts('../../../fast/js/resources/js-test-pre.js');
3 importScripts('shared.js');
6 description("Test IndexedDB's IDBCursor.continue() with a primary key parameter.");
8 indexedDBTest(prepareDatabase, verifyContinueCalls);
9 function prepareDatabase(evt)
13 evalAndLog("db = event.target.result");
14 evalAndLog("store = db.createObjectStore('store')");
15 evalAndLog("index = store.createIndex('index', 'indexKey', {multiEntry: true})");
17 evalAndLog("store.put({indexKey: ['a', 'b']}, 1)");
18 evalAndLog("store.put({indexKey: ['a', 'b']}, 2)");
19 evalAndLog("store.put({indexKey: ['a', 'b']}, 3)");
20 evalAndLog("store.put({indexKey: ['b']}, 4)");
23 {key: "a", primaryKey: 1},
24 {key: "a", primaryKey: 2},
25 {key: "a", primaryKey: 3},
26 {key: "b", primaryKey: 1},
27 {key: "b", primaryKey: 2},
28 {key: "b", primaryKey: 3},
29 {key: "b", primaryKey: 4}
31 debug("checking index structure...");
33 debug("index key primary key");
34 debug("========= ===========");
36 evalAndLog("request = index.openCursor()", quiet);
37 request.onerror = unexpectedErrorCallback;
38 request.onsuccess = function onCursorSuccess() {
39 evalAndLog("cursor = request.result", quiet);
40 var expectedEntry = indexExpected.shift();
42 shouldBe("cursor.key", JSON.stringify(expectedEntry.key), quiet);
43 shouldBe("cursor.primaryKey", JSON.stringify(expectedEntry.primaryKey), quiet);
44 debug(cursor.key + " " + cursor.primaryKey);
45 evalAndLog("cursor.continue()", quiet);
47 shouldBeNull("cursor", quiet);
53 // Continuing index key
54 { call: "cursor.continue()", result: { key: "a", primaryKey: 2 } },
55 { call: "cursor.continue('a')", exception: 'DataError' },
56 { call: "cursor.continue('b')", result: { key: "b", primaryKey: 1 } },
57 { call: "cursor.continue('c')", result: null },
59 // Called w/ index key and primary key:
60 { call: "cursor.continuePrimaryKey('a', 3)", result: {key: 'a', primaryKey: 3} },
61 { call: "cursor.continuePrimaryKey('a', 4)", result: {key: 'b', primaryKey: 1} },
62 { call: "cursor.continuePrimaryKey('b', 1)", result: {key: 'b', primaryKey: 1} },
63 { call: "cursor.continuePrimaryKey('b', 4)", result: {key: 'b', primaryKey: 4} },
64 { call: "cursor.continuePrimaryKey('b', 5)", result: null },
65 { call: "cursor.continuePrimaryKey('c', 1)", result: null },
67 // Called w/ primary key but w/o index key
68 { call: "cursor.continuePrimaryKey(null, 1)", exception: 'DataError' },
69 { call: "cursor.continuePrimaryKey(null, 2)", exception: 'DataError' },
70 { call: "cursor.continuePrimaryKey(null, 3)", exception: 'DataError' },
71 { call: "cursor.continuePrimaryKey(null, 4)", exception: 'DataError' },
72 { call: "cursor.continuePrimaryKey(null, 5)", exception: 'DataError' },
74 // Called w/ index key but w/o primary key
75 { call: "cursor.continuePrimaryKey('a', null)", exception: 'DataError' },
78 function verifyContinueCalls() {
80 if (!testCases.length) {
86 testCase = testCases.shift();
87 debug("Test case: " + testCase.call);
89 evalAndLog("tx = db.transaction('store')");
90 evalAndLog("request = tx.objectStore('store').index('index').openCursor()");
92 request.onsuccess = function() {
94 evalAndLog("cursor = request.result", true);
96 if ('exception' in testCase) {
97 evalAndExpectException(testCase.call, "0", "'DataError'");
99 evalAndLog(testCase.call);
105 if (testCase.result) {
106 shouldBe("cursor.key", JSON.stringify(testCase.result.key));
107 shouldBe("cursor.primaryKey", JSON.stringify(testCase.result.primaryKey));
109 shouldBeNull("cursor");
114 tx.oncomplete = verifyContinueCalls;