3 <script src="../../fast/js/resources/js-test-pre.js"></script>
4 <script src="resources/shared.js"></script>
7 <p id="description"></p>
8 <div id="console"></div>
11 description("Test consistency of IndexedDB's cursor objects.");
12 if (window.layoutTestController)
13 layoutTestController.waitUntilDone();
19 request = evalAndLog("webkitIndexedDB.open('cursor-inconsistency')");
20 request.onsuccess = openSuccess;
21 request.onerror = unexpectedErrorCallback;
24 function openSuccess()
26 var db = evalAndLog("db = event.target.result");
28 request = evalAndLog("db.setVersion('new version')");
29 request.onsuccess = setVersionSuccess;
30 request.onerror = unexpectedErrorCallback;
33 function setVersionSuccess()
35 debug("setVersionSuccess():");
36 window.trans = evalAndLog("trans = event.target.result");
37 shouldBeTrue("trans !== null");
38 trans.onabort = unexpectedAbortCallback;
39 trans.oncomplete = openBasicCursor;
41 deleteAllObjectStores(db);
43 var objectStore = evalAndLog("objectStore = db.createObjectStore('basicStore')");
44 evalAndLog("objectStore.add('someValue1', 'someKey1').onerror = unexpectedErrorCallback");
45 evalAndLog("objectStore.add('someValue2', 'someKey2').onerror = unexpectedErrorCallback");
46 evalAndLog("objectStore.add('someValue3', 'someKey3').onerror = unexpectedErrorCallback");
47 evalAndLog("objectStore.add('someValue4', 'someKey4').onerror = unexpectedErrorCallback");
51 function openBasicCursor()
53 debug("openBasicCursor()");
54 evalAndLog("trans = db.transaction(['basicStore'], webkitIDBTransaction.READ_WRITE)");
55 trans.onabort = unexpectedAbortCallback;
56 trans.oncomplete = transactionComplete;
58 keyRange = webkitIDBKeyRange.lowerBound("someKey1");
59 window.objectStore = evalAndLog("trans.objectStore('basicStore')");
60 request = evalAndLog("objectStore.openCursor(keyRange)");
61 request.onsuccess = checkCursor;
62 request.onerror = unexpectedErrorCallback;
67 function checkCursor()
70 debug("checkCursor()");
71 if (event.target.result == null) {
72 shouldBe("counter", "5");
75 if (storedCursor == null)
76 storedCursor = evalAndLog("storedCursor = event.target.result");
78 shouldBeTrue("storedCursor === event.target.result");
79 shouldBeEqualToString("storedCursor.key", "someKey" + counter);
80 shouldBeEqualToString("event.target.result.key", "someKey" + counter);
81 shouldBeEqualToString("storedCursor.value", "someValue" + counter);
82 shouldBeEqualToString("event.target.result.value", "someValue" + counter);
84 evalAndLog("event.target.result.continue()");
87 function transactionComplete()
89 debug("transactionComplete()");