1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB's openCursor.");
8 indexedDBTest(prepareDatabase, openCursor);
9 function prepareDatabase()
11 db = event.target.result;
12 debug("setVersionSuccess():");
13 self.trans = evalAndLog("trans = event.target.result");
14 shouldBeNonNull("trans");
15 trans.onabort = unexpectedAbortCallback;
17 var objectStore = evalAndLog("objectStore = db.createObjectStore('test')");
18 evalAndLog("objectStore.add('myValue1', 'myKey1')");
19 evalAndLog("objectStore.add('myValue2', 'myKey2')");
20 evalAndLog("objectStore.add('myValue3', 'myKey3')");
21 evalAndLog("objectStore.add('myValue4', 'myKey4')");
27 evalAndLog("trans = db.transaction(['test'], 'readwrite')");
28 keyRange = IDBKeyRange.lowerBound("myKey1");
29 request = evalAndLog("trans.objectStore('test').openCursor(keyRange)");
30 request.onsuccess = cursorSuccess;
31 request.onerror = unexpectedErrorCallback;
35 function cursorSuccess()
37 if (event.target.result == null) {
38 shouldBe("counter", "5");
39 request = evalAndLog("trans.objectStore('test').openCursor(keyRange)");
40 request.onsuccess = cursorEmpty;
41 request.onerror = unexpectedErrorCallback;
44 evalAndLog("event.target.result.delete()");
45 shouldBeEqualToString("event.target.result.value", "myValue" + counter++);
46 evalAndLog("event.target.result.continue()");
49 function cursorEmpty()
51 shouldBeNull("event.target.result");
52 trans.oncomplete = addObject;
57 evalAndLog("trans = db.transaction(['test'], 'readwrite')");
58 objectStore = evalAndLog("objectStore = trans.objectStore('test')");
59 request = evalAndLog("objectStore.add('myValue1', 'myKey1')");
60 request.onsuccess = openCursor2;
61 request.onerror = unexpectedErrorCallback;
64 function openCursor2()
67 request = evalAndLog("objectStore.openCursor(keyRange)");
68 request.onsuccess = deleteObject;
69 request.onerror = unexpectedErrorCallback;
72 function deleteObject()
74 shouldBeNonNull(event.target.result);
75 evalAndLog("event.target.result.delete()");
76 request = evalAndLog("objectStore.get('myKey1')");
77 request.onsuccess = verifyObjectDeleted;
78 request.onerror = unexpectedErrorCallback;
81 function verifyObjectDeleted()
83 shouldBe("event.target.result", "undefined");