1 <html> 2 <head> 3 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css"> 4 <script src="../../fast/js/resources/js-test-pre.js"></script> 5 <script src="../../fast/js/resources/js-test-post-function.js"></script> 6 <script src="resources/shared.js"></script> 7 </head> 8 <body> 9 <p id="description"></p> 10 <div id="console"></div> 11 <script> 12 13 description("Test IndexedDB's openCursor."); 14 if (window.layoutTestController) 15 layoutTestController.waitUntilDone(); 16 17 test(); 18 19 function test() 20 { 21 request = evalAndLog("webkitIndexedDB.open('cursor-delete')"); 22 request.onsuccess = openSuccess; 23 request.onerror = unexpectedErrorCallback; 24 } 25 26 function openSuccess() 27 { 28 var db = evalAndLog("db = event.target.result"); 29 30 request = evalAndLog("db.setVersion('new version')"); 31 request.onsuccess = setVersionSuccess; 32 request.onerror = unexpectedErrorCallback; 33 } 34 35 function setVersionSuccess() 36 { 37 debug("setVersionSuccess():"); 38 window.trans = evalAndLog("trans = event.target.result"); 39 shouldBeTrue("trans !== null"); 40 trans.onabort = unexpectedAbortCallback; 41 trans.oncomplete = openCursor; 42 43 deleteAllObjectStores(db); 44 45 var objectStore = evalAndLog("objectStore = db.createObjectStore('test')"); 46 evalAndLog("objectStore.add('myValue1', 'myKey1')"); 47 evalAndLog("objectStore.add('myValue2', 'myKey2')"); 48 evalAndLog("objectStore.add('myValue3', 'myKey3')"); 49 evalAndLog("objectStore.add('myValue4', 'myKey4')"); 50 } 51 52 function openCursor() 53 { 54 debug("openCursor1"); 55 evalAndLog("trans = db.transaction(['test'], webkitIDBTransaction.READ_WRITE)"); 56 keyRange = webkitIDBKeyRange.lowerBound("myKey1"); 57 request = evalAndLog("trans.objectStore('test').openCursor({range: keyRange})"); 58 request.onsuccess = cursorSuccess; 59 request.onerror = unexpectedErrorCallback; 60 counter = 1; 61 } 62 63 function cursorSuccess() 64 { 65 if (event.target.result == null) { 66 shouldBe("counter", "5"); 67 request = evalAndLog("trans.objectStore('test').openCursor(keyRange)"); 68 request.onsuccess = cursorEmpty; 69 request.onerror = unexpectedErrorCallback; 70 return; 71 } 72 evalAndLog("event.target.result.delete()"); 73 shouldBeEqualToString("event.target.result.value", "myValue" + counter++); 74 evalAndLog("event.target.result.continue()"); 75 } 76 77 function cursorEmpty() 78 { 79 shouldBeNull("event.target.result"); 80 trans.oncomplete = addObject; 81 } 82 83 function addObject() 84 { 85 evalAndLog("trans = db.transaction(['test'], webkitIDBTransaction.READ_WRITE)"); 86 objectStore = evalAndLog("objectStore = trans.objectStore('test')"); 87 request = evalAndLog("objectStore.add('myValue1', 'myKey1')"); 88 request.onsuccess = openCursor2; 89 request.onerror = unexpectedErrorCallback; 90 } 91 92 function openCursor2() 93 { 94 debug("openCursor2"); 95 request = evalAndLog("objectStore.openCursor(keyRange)"); 96 request.onsuccess = deleteObject; 97 request.onerror = unexpectedErrorCallback; 98 } 99 100 function deleteObject() 101 { 102 shouldBeNonNull(event.target.result); 103 evalAndLog("event.target.result.delete()"); 104 request = evalAndLog("objectStore.get('myKey1')"); 105 request.onsuccess = verifyObjectDeleted; 106 request.onerror = unexpectedErrorCallback; 107 } 108 109 function verifyObjectDeleted() 110 { 111 shouldBe("event.target.result", "undefined"); 112 done(); 113 } 114 115 var successfullyParsed = true; 116 117 </script> 118 </body> 119 </html> 120