| OLD | NEW |
| (Empty) |
| 1 if (this.importScripts) { | |
| 2 importScripts('../../../fast/js/resources/js-test-pre.js'); | |
| 3 importScripts('shared.js'); | |
| 4 } | |
| 5 | |
| 6 description("Test IndexedDB's IDBCursor.continue() with a primary key parameter.
"); | |
| 7 | |
| 8 indexedDBTest(prepareDatabase, verifyContinueCalls); | |
| 9 function prepareDatabase(evt) | |
| 10 { | |
| 11 preamble(evt); | |
| 12 | |
| 13 evalAndLog("db = event.target.result"); | |
| 14 evalAndLog("store = db.createObjectStore('store')"); | |
| 15 evalAndLog("index = store.createIndex('index', 'indexKey', {multiEntry: true
})"); | |
| 16 | |
| 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)"); | |
| 21 | |
| 22 var indexExpected = [ | |
| 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} | |
| 30 ]; | |
| 31 debug("checking index structure..."); | |
| 32 debug(""); | |
| 33 debug("index key primary key"); | |
| 34 debug("========= ==========="); | |
| 35 var quiet = true; | |
| 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(); | |
| 41 if (expectedEntry) { | |
| 42 shouldBe("cursor.key", JSON.stringify(expectedEntry.key), quiet); | |
| 43 shouldBe("cursor.primaryKey", JSON.stringify(expectedEntry.primaryKe
y), quiet); | |
| 44 debug(cursor.key + " " + cursor.primaryKey); | |
| 45 evalAndLog("cursor.continue()", quiet); | |
| 46 } else { | |
| 47 shouldBeNull("cursor", quiet); | |
| 48 } | |
| 49 }; | |
| 50 } | |
| 51 | |
| 52 var testCases = [ | |
| 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 }, | |
| 58 | |
| 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 }, | |
| 66 | |
| 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' }, | |
| 73 | |
| 74 // Called w/ index key but w/o primary key | |
| 75 { call: "cursor.continuePrimaryKey('a', null)", exception: 'DataError' }, | |
| 76 ]; | |
| 77 | |
| 78 function verifyContinueCalls() { | |
| 79 debug(""); | |
| 80 if (!testCases.length) { | |
| 81 finishJSTest(); | |
| 82 return; | |
| 83 } | |
| 84 | |
| 85 var quiet = true; | |
| 86 testCase = testCases.shift(); | |
| 87 debug("Test case: " + testCase.call); | |
| 88 debug(""); | |
| 89 evalAndLog("tx = db.transaction('store')"); | |
| 90 evalAndLog("request = tx.objectStore('store').index('index').openCursor()"); | |
| 91 var i = 0; | |
| 92 request.onsuccess = function() { | |
| 93 ++i; | |
| 94 evalAndLog("cursor = request.result", true); | |
| 95 if (i === 1) { | |
| 96 if ('exception' in testCase) { | |
| 97 evalAndExpectException(testCase.call, "0", "'DataError'"); | |
| 98 } else { | |
| 99 evalAndLog(testCase.call); | |
| 100 } | |
| 101 return; | |
| 102 } | |
| 103 | |
| 104 if (i === 2) { | |
| 105 if (testCase.result) { | |
| 106 shouldBe("cursor.key", JSON.stringify(testCase.result.key)); | |
| 107 shouldBe("cursor.primaryKey", JSON.stringify(testCase.result.pri
maryKey)); | |
| 108 } else { | |
| 109 shouldBeNull("cursor"); | |
| 110 } | |
| 111 } | |
| 112 }; | |
| 113 | |
| 114 tx.oncomplete = verifyContinueCalls; | |
| 115 } | |
| OLD | NEW |