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 IDBCursor.continue() with a key parameter."); 14 if (window.layoutTestController) 15 layoutTestController.waitUntilDone(); 16 17 var date = new Date(); 18 19 // In order of how it should be sorted by IndexedDB. 20 window.testData = [ 21 0, 22 1, 23 1, 24 3.14159, 25 3.14159, 26 10, 27 11, 28 12, 29 13, 30 date, 31 date, 32 new Date(date.valueOf() + 1000), 33 "A big string", 34 "A big string", 35 "A bit1", 36 "A bit2", 37 "A bit3", 38 "the BIGGEST string" 39 ]; 40 41 function openDatabase() 42 { 43 result = evalAndLog("webkitIndexedDB.open('cursor-continue')"); 44 result.onsuccess = setVersion; 45 result.onerror = unexpectedErrorCallback; 46 } 47 48 function setVersion() 49 { 50 window.db = evalAndLog("db = event.target.result"); 51 52 result = evalAndLog("db.setVersion('new version')"); 53 result.onsuccess = deleteExisting; 54 result.onerror = unexpectedErrorCallback; 55 } 56 57 function deleteExisting() 58 { 59 window.trans = evalAndLog("trans = event.target.result"); 60 shouldBeTrue("trans !== null"); 61 trans.onabort = unexpectedAbortCallback; 62 63 deleteAllObjectStores(db); 64 65 window.objectStore = evalAndLog("db.createObjectStore('someObjectStore')"); 66 window.indexObject = evalAndLog("objectStore.createIndex('someIndex', 'x')"); 67 window.nextToAdd = 0; 68 addData(); 69 } 70 71 function addData() 72 { 73 result = evalAndLog("objectStore.add({'x': testData[nextToAdd]}, nextToAdd)"); 74 result.onsuccess = ++window.nextToAdd < testData.length ? addData : ascendingTest; 75 result.onerror = unexpectedErrorCallback; 76 } 77 78 function ascendingTest() 79 { 80 debug(""); 81 var request = evalAndLog("indexObject.openKeyCursor(null, webkitIDBCursor.NEXT)"); 82 request.onsuccess = ascendingCallback; 83 request.onerror = unexpectedErrorCallback; 84 window.stage = 0; 85 } 86 87 function ascendingCallback() 88 89 { 90 if (window.stage == 0) { 91 shouldBe("event.target.result.primaryKey", "0"); 92 evalAndLog("event.target.result.continue(3.14159)"); 93 } else if (window.stage == 1) { 94 shouldBe("event.target.result.primaryKey", "3"); 95 evalAndLog("event.target.result.continue(3.14159)"); 96 } else if (window.stage == 2) { 97 shouldBe("event.target.result.primaryKey", "4"); 98 evalAndLog("event.target.result.continue(3.14159)"); 99 } else if (window.stage == 3) { 100 shouldBe("event.target.result.primaryKey", "5"); 101 evalAndLog("event.target.result.continue(12)"); 102 } else if (window.stage == 4) { 103 shouldBe("event.target.result.primaryKey", "7"); 104 evalAndLog("event.target.result.continue(date)"); 105 } else if (window.stage == 5) { 106 shouldBe("event.target.result.primaryKey", "9"); 107 evalAndLog("event.target.result.continue(date)"); 108 } else if (window.stage == 6) { 109 shouldBe("event.target.result.primaryKey", "10"); 110 evalAndLog("event.target.result.continue(date)"); 111 } else if (window.stage == 7) { 112 shouldBe("event.target.result.primaryKey", "11"); 113 evalAndLog("event.target.result.continue('A bit1')"); 114 } else if (window.stage == 8) { 115 shouldBe("event.target.result.primaryKey", "14"); 116 evalAndLog("event.target.result.continue('A bit3')"); 117 } else if (window.stage == 9) { 118 shouldBe("event.target.result.primaryKey", "16"); 119 evalAndLog("event.target.result.continue('the BIGGEST string')"); 120 } else if (window.stage == 10) { 121 shouldBe("event.target.result.primaryKey", "17"); 122 evalAndLog("event.target.result.continue('the BIGGEST string')"); 123 } else if (window.stage == 11) { 124 shouldBeNull("event.target.result"); 125 descendingTest(); 126 return; 127 } else { 128 testFailed("Illegal stage."); 129 } 130 window.stage++; 131 } 132 133 function descendingTest() 134 { 135 debug(""); 136 var request = evalAndLog("indexObject.openKeyCursor(null, webkitIDBCursor.PREV)"); 137 request.onsuccess = descendingCallback; 138 request.onerror = unexpectedErrorCallback; 139 window.stage = 0; 140 } 141 142 function descendingCallback() 143 { 144 if (window.stage == 0) { 145 shouldBe("event.target.result.primaryKey", "17"); 146 evalAndLog("event.target.result.continue('A bit2')"); 147 } else if (window.stage == 1) { 148 shouldBe("event.target.result.primaryKey", "15"); 149 evalAndLog("event.target.result.continue('A bit2')"); 150 } else if (window.stage == 2) { 151 shouldBe("event.target.result.primaryKey", "14"); 152 evalAndLog("event.target.result.continue(date)"); 153 } else if (window.stage == 3) { 154 shouldBe("event.target.result.primaryKey", "10"); 155 evalAndLog("event.target.result.continue(date)"); 156 } else if (window.stage == 4) { 157 shouldBe("event.target.result.primaryKey", "9"); 158 evalAndLog("event.target.result.continue(1)"); 159 } else if (window.stage == 5) { 160 shouldBe("event.target.result.primaryKey", "2"); 161 evalAndLog("event.target.result.continue(1)"); 162 } else if (window.stage == 6) { 163 shouldBe("event.target.result.primaryKey", "1"); 164 evalAndLog("event.target.result.continue(1)"); 165 } else if (window.stage == 7) { 166 shouldBe("event.target.result.primaryKey", "0"); 167 evalAndLog("event.target.result.continue(1)"); 168 } else if (window.stage == 8) { 169 shouldBeNull("event.target.result"); 170 done(); 171 return; 172 } else { 173 testFailed("Illegal stage."); 174 } 175 window.stage++; 176 } 177 178 openDatabase(); // The first step. 179 var successfullyParsed = true; 180 181 </script> 182 </body> 183 </html> 184