1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test mutating an IndexedDB's objectstore from a cursor.");
8 indexedDBTest(prepareDatabase, openForwardCursor);
9 function prepareDatabase()
11 db = event.target.result;
12 event.target.transaction.onabort = unexpectedAbortCallback;
14 var objectStore = evalAndLog("objectStore = db.createObjectStore('store')");
15 evalAndLog("objectStore.add(1, 1).onerror = unexpectedErrorCallback");
16 evalAndLog("objectStore.add(2, 2).onerror = unexpectedErrorCallback");
17 evalAndLog("objectStore.add(3, 3).onerror = unexpectedErrorCallback");
18 evalAndLog("objectStore.add(4, 4).onerror = unexpectedErrorCallback");
21 function openForwardCursor()
23 debug("openForwardCursor()");
24 evalAndLog("trans = db.transaction(['store'], 'readwrite')");
25 trans.onabort = unexpectedAbortCallback;
26 trans.oncomplete = forwardCursorComplete;
28 self.objectStore = evalAndLog("trans.objectStore('store')");
29 request = evalAndLog("objectStore.openCursor()");
30 request.onsuccess = forwardCursor;
31 request.onerror = unexpectedErrorCallback;
35 function forwardCursor()
37 debug("forwardCursor()");
38 self.cursor = event.target.result;
40 if (event.target.result == null) {
41 shouldBe("cursorSteps", "5");
43 // Let the transaction finish.
48 shouldBe("cursor.key", "cursorSteps");
49 shouldBe("cursor.value", "cursorSteps");
51 if (cursorSteps == 1) {
52 request = evalAndLog("event.target.source.add(5, 5)");
53 request.onsuccess = function() { evalAndLog("cursor.continue()"); }
54 request.onerror = unexpectedErrorCallback;
56 evalAndLog("cursor.continue()");
60 function forwardCursorComplete()
62 debug("forwardCursorComplete()");
66 function openReverseCursor()
68 debug("openReverseCursor()");
69 evalAndLog("trans = db.transaction(['store'], 'readwrite')");
70 trans.onabort = unexpectedAbortCallback;
71 trans.oncomplete = reverseCursorComplete;
73 self.objectStore = evalAndLog("trans.objectStore('store')");
74 request = evalAndLog("objectStore.openCursor(null, 'prev')");
75 request.onsuccess = reverseCursor;
76 request.onerror = unexpectedErrorCallback;
80 function reverseCursor()
82 debug("reverseCursor()");
83 self.cursor = event.target.result;
85 if (event.target.result == null) {
86 shouldBe("cursorSteps", "0");
88 // Let the transaction finish.
93 shouldBe("cursor.key", "cursorSteps");
94 shouldBe("cursor.value", "cursorSteps");
96 if (cursorSteps == 2) {
97 request = evalAndLog("event.target.source.add(0, 0)");
98 request.onsuccess = function() { evalAndLog("cursor.continue()"); }
99 request.onerror = unexpectedErrorCallback;
101 evalAndLog("cursor.continue()");
105 function reverseCursorComplete()
107 debug("reverseCursorComplete()");