1 Test IndexedDB cursor.advance().
3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
6 dbname = "cursor-advance.html"
7 indexedDB.deleteDatabase(dbname)
11 objectStore = db.createObjectStore(objectStoreName);
12 Now create the indexes.
13 objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
14 objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
15 objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
16 trans = db.transaction(objectStoreName, 'readwrite')
17 objectStore = trans.objectStore(objectStoreName)
18 First, add all our data to the object store.
19 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
20 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
21 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
22 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
23 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
24 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
25 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
26 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
27 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
28 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
29 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
30 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
31 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
33 trans = db.transaction(objectStoreName)
34 store = trans.objectStore(objectStoreName)
35 request = store.openCursor()
37 PASS expected is "{\"key\":\"237-23-7733\",\"value\":{\"name\":\"Ann\",\"height\":52,\"weight\":110},\"primaryKey\":\"237-23-7733\"}"
38 testContinueThenAdvance()
39 trans = db.transaction(objectStoreName)
40 store = trans.objectStore(objectStoreName)
41 request = store.openCursor()
46 PASS expected is "{\"key\":\"237-23-7736\",\"value\":{\"name\":\"Joe\",\"height\":65,\"weight\":150},\"primaryKey\":\"237-23-7736\"}"
48 trans = db.transaction(objectStoreName)
49 store = trans.objectStore(objectStoreName)
50 request = store.openCursor()
52 PASS expected is "{\"key\":\"237-23-7735\",\"value\":{\"name\":\"Sue\",\"height\":58,\"weight\":130},\"primaryKey\":\"237-23-7735\"}"
54 trans = db.transaction(objectStoreName)
55 store = trans.objectStore(objectStoreName)
56 request = store.openCursor()
58 PASS expected is "{\"key\":\"Jef\",\"value\":{\"name\":\"Jef\",\"height\":65,\"weight\":120},\"primaryKey\":\"237-23-7739\"}"
59 testAdvanceIndexNoDupe()
60 trans = db.transaction(objectStoreName)
61 store = trans.objectStore(objectStoreName)
62 request = store.openCursor(null, 'nextunique')
64 PASS expected is "{\"key\":130,\"value\":{\"name\":\"Sue\",\"height\":58,\"weight\":130},\"primaryKey\":\"237-23-7735\"}"
65 testAdvanceIndexPrev()
66 trans = db.transaction(objectStoreName)
67 store = trans.objectStore(objectStoreName)
68 request = store.openCursor(null, 'prev')
70 PASS expected is "{\"key\":150,\"value\":{\"name\":\"Joe\",\"height\":65,\"weight\":150},\"primaryKey\":\"237-23-7736\"}"
71 testAdvanceIndexPrevNoDupe()
72 trans = db.transaction(objectStoreName)
73 store = trans.objectStore(objectStoreName)
74 request = store.openCursor(null, 'prevunique')
76 PASS expected is "{\"key\":120,\"value\":{\"name\":\"Bob\",\"height\":60,\"weight\":120},\"primaryKey\":\"237-23-7732\"}"
78 trans = db.transaction(objectStoreName)
79 store = trans.objectStore(objectStoreName)
80 request = store.openCursor()
82 PASS expected is "null"
84 trans = db.transaction(objectStoreName)
85 objectStore = trans.objectStore(objectStoreName)
86 request = objectStore.openCursor()
89 PASS expected is "{\"key\":\"237-23-7732\",\"value\":{\"name\":\"Bob\",\"height\":60,\"weight\":120},\"primaryKey\":\"237-23-7732\"}"
93 PASS expected is "{\"key\":\"237-23-7733\",\"value\":{\"name\":\"Ann\",\"height\":52,\"weight\":110},\"primaryKey\":\"237-23-7733\"}"
97 PASS expected is "{\"key\":\"237-23-7734\",\"value\":{\"name\":\"Ron\",\"height\":73,\"weight\":180},\"primaryKey\":\"237-23-7734\"}"
101 PASS expected is "{\"key\":\"237-23-7735\",\"value\":{\"name\":\"Sue\",\"height\":58,\"weight\":130},\"primaryKey\":\"237-23-7735\"}"
105 PASS expected is "{\"key\":\"237-23-7737\",\"value\":{\"name\":\"Pat\",\"height\":65,\"weight\":100},\"primaryKey\":\"237-23-7737\"}"
109 PASS expected is "{\"key\":\"237-23-7738\",\"value\":{\"name\":\"Leo\",\"height\":65,\"weight\":180},\"primaryKey\":\"237-23-7738\"}"
113 PASS expected is "{\"key\":\"237-23-7739\",\"value\":{\"name\":\"Jef\",\"height\":65,\"weight\":120},\"primaryKey\":\"237-23-7739\"}"
117 PASS expected is "{\"key\":\"237-23-7740\",\"value\":{\"name\":\"Sam\",\"height\":71,\"weight\":110},\"primaryKey\":\"237-23-7740\"}"
121 PASS expected is "{\"key\":\"237-23-7741\",\"value\":{\"name\":\"Bug\",\"height\":63,\"weight\":100},\"primaryKey\":\"237-23-7741\"}"
125 PASS expected is "{\"key\":\"237-23-7742\",\"value\":{\"name\":\"Tub\",\"height\":69,\"weight\":180},\"primaryKey\":\"237-23-7742\"}"
129 PASS expected is "{\"key\":\"237-23-7743\",\"value\":{\"name\":\"Rug\",\"height\":77,\"weight\":120},\"primaryKey\":\"237-23-7743\"}"
133 PASS expected is "{\"key\":\"237-23-7744\",\"value\":{\"name\":\"Pug\",\"height\":66,\"weight\":110},\"primaryKey\":\"237-23-7744\"}"
137 testPrefetchOutOfRange()
138 trans = db.transaction(objectStoreName)
139 objectStore = trans.objectStore(objectStoreName)
140 request = objectStore.openCursor()
143 PASS expected is "{\"key\":\"237-23-7732\",\"value\":{\"name\":\"Bob\",\"height\":60,\"weight\":120},\"primaryKey\":\"237-23-7732\"}"
147 PASS expected is "{\"key\":\"237-23-7733\",\"value\":{\"name\":\"Ann\",\"height\":52,\"weight\":110},\"primaryKey\":\"237-23-7733\"}"
151 PASS expected is "{\"key\":\"237-23-7734\",\"value\":{\"name\":\"Ron\",\"height\":73,\"weight\":180},\"primaryKey\":\"237-23-7734\"}"
155 PASS expected is "{\"key\":\"237-23-7735\",\"value\":{\"name\":\"Sue\",\"height\":58,\"weight\":130},\"primaryKey\":\"237-23-7735\"}"
159 PASS expected is "{\"key\":\"237-23-7742\",\"value\":{\"name\":\"Tub\",\"height\":69,\"weight\":180},\"primaryKey\":\"237-23-7742\"}"
163 PASS expected is "{\"key\":\"237-23-7743\",\"value\":{\"name\":\"Rug\",\"height\":77,\"weight\":120},\"primaryKey\":\"237-23-7743\"}"
167 PASS expected is "{\"key\":\"237-23-7744\",\"value\":{\"name\":\"Pug\",\"height\":66,\"weight\":110},\"primaryKey\":\"237-23-7744\"}"
172 trans = db.transaction(objectStoreName, 'readwrite')
173 objectStore = trans.objectStore(objectStoreName)
174 request = objectStore.openCursor()
177 Expecting TypeError exception from cursor.advance(0)
178 PASS Exception was thrown.
179 PASS cursor.advance(0) threw TypeError: Failed to execute 'advance' on 'IDBCursor': A count argument with value 0 (zero) was supplied, must be greater than 0.
180 Expecting TypeError exception from cursor.advance(-1)
181 PASS Exception was thrown.
182 PASS cursor.advance(-1) threw TypeError: Failed to execute 'advance' on 'IDBCursor': Value is outside the 'unsigned long' value range.
183 Expecting TypeError exception from cursor.advance(0x100000000)
184 PASS Exception was thrown.
185 PASS cursor.advance(0x100000000) threw TypeError: Failed to execute 'advance' on 'IDBCursor': Value is outside the 'unsigned long' value range.
186 Expecting TypeError exception from cursor.advance(0x20000000000000)
187 PASS Exception was thrown.
188 PASS cursor.advance(0x20000000000000) threw TypeError: Failed to execute 'advance' on 'IDBCursor': Value is outside the 'unsigned long' value range.
191 trans = db.transaction(objectStoreName, 'readonly')
192 objectStore = trans.objectStore(objectStoreName)
193 request = objectStore.openCursor()
196 cursor = event.target.result
197 PASS cursor is non-null.
198 cursor.advance(0xffffffff)
201 cursor = event.target.result
204 trans = db.transaction(objectStoreName, 'readwrite')
205 objectStore = trans.objectStore(objectStoreName)
206 request = objectStore.openCursor()
209 PASS expected is "{\"key\":\"237-23-7732\",\"value\":{\"name\":\"Bob\",\"height\":60,\"weight\":120},\"primaryKey\":\"237-23-7732\"}"
213 PASS expected is "{\"key\":\"237-23-7733\",\"value\":{\"name\":\"Ann\",\"height\":52,\"weight\":110},\"primaryKey\":\"237-23-7733\"}"
217 PASS expected is "{\"key\":\"237-23-7734\",\"value\":{\"name\":\"Ron\",\"height\":73,\"weight\":180},\"primaryKey\":\"237-23-7734\"}"
221 PASS expected is "{\"key\":\"237-23-7738\",\"value\":{\"name\":\"Leo\",\"height\":65,\"weight\":180},\"primaryKey\":\"237-23-7738\"}"
225 PASS expected is "{\"key\":\"237-23-7739\",\"value\":{\"name\":\"Jef\",\"height\":65,\"weight\":120},\"primaryKey\":\"237-23-7739\"}"
229 PASS expected is "{\"key\":\"237-23-7740\",\"value\":{\"name\":\"Sam\",\"height\":71,\"weight\":110},\"primaryKey\":\"237-23-7740\"}"
233 PASS expected is "{\"key\":\"237-23-7741\",\"value\":{\"name\":\"Bug\",\"height\":63,\"weight\":100},\"primaryKey\":\"237-23-7741\"}"
237 PASS expected is "{\"key\":\"237-23-7742\",\"value\":{\"name\":\"Tub\",\"height\":69,\"weight\":180},\"primaryKey\":\"237-23-7742\"}"
241 PASS expected is "{\"key\":\"237-23-7743\",\"value\":{\"name\":\"Rug\",\"height\":77,\"weight\":120},\"primaryKey\":\"237-23-7743\"}"
245 PASS expected is "{\"key\":\"237-23-7744\",\"value\":{\"name\":\"Pug\",\"height\":66,\"weight\":110},\"primaryKey\":\"237-23-7744\"}"
249 PASS successfullyParsed is true