1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB keys ordering and readback from cursors.");
8 indexedDBTest(prepareDatabase, populateStore);
9 function prepareDatabase()
11 db = event.target.result;
12 store = evalAndLog("store = db.createObjectStore('store')");
13 evalAndLog("store.createIndex('index', '')");
16 function populateStore()
19 debug("populating store...");
20 evalAndLog("trans = db.transaction('store', 'readwrite')");
21 evalAndLog("store = trans.objectStore('store');");
22 trans.onerror = unexpectedErrorCallback;
23 trans.onabort = unexpectedAbortCallback;
25 evalAndLog("store.put(1, 1)");
26 evalAndLog("store.put(2, 2)");
27 evalAndLog("store.put(3, 3)");
28 trans.oncomplete = testCursor;
32 {upperBound: 7, open: false, expected: 3},
33 {upperBound: 7, open: true, expected: 3},
34 {upperBound: 3, open: false, expected: 3},
35 {upperBound: 3, open: true, expected: 2}
40 debug("testCursor()");
42 if (tests.length === 0) {
43 debug("No more tests.");
50 evalAndLog("trans = db.transaction('store', 'readonly')");
51 trans.onerror = unexpectedErrorCallback;
52 trans.onabort = unexpectedAbortCallback;
53 trans.oncomplete = testCursor;
54 evalAndLog("store = trans.objectStore('store');");
55 evalAndLog("index = store.index('index');");
57 var testFunction = function() {
58 evalAndLog("cursor = event.target.result");
59 if (cursor === null) {
60 debug("cursor should not be null");
65 shouldBe("cursor.key", "test.expected");
66 if ("value" in cursor)
67 shouldBe("cursor.value", "test.expected");
68 shouldBe("cursor.primaryKey", "test.expected");
70 // Let the transaction finish.
73 debug("upperBound: " + test.upperBound + " open: " + test.open + " expected: " + test.expected);
74 storeReq = evalAndLog("storeReq = store.openCursor(IDBKeyRange.upperBound(test.upperBound, test.open), 'prev')");
75 storeReq.onsuccess = testFunction;
77 indexReq = evalAndLog("indexReq = index.openCursor(IDBKeyRange.upperBound(test.upperBound, test.open), 'prev')");
78 indexReq.onsuccess = testFunction;
80 indexKeyReq = evalAndLog("indexKeyReq = index.openKeyCursor(IDBKeyRange.upperBound(test.upperBound, test.open), 'prev')");
81 indexKeyReq.onsuccess = testFunction;