1 Test IndexedDB's cursor update.
3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
6 dbname = "cursor-update.html"
7 indexedDB.deleteDatabase(dbname)
10 trans = event.target.transaction
11 PASS trans is non-null.
12 Deleted all object stores.
13 objectStore = db.createObjectStore('basicStore')
14 objectStore.add('myValue1', 'myKey1').onerror = unexpectedErrorCallback
15 objectStore.add('myValue2', 'myKey2').onerror = unexpectedErrorCallback
16 objectStore.add('myValue3', 'myKey3').onerror = unexpectedErrorCallback
17 objectStore.add('myValue4', 'myKey4').onerror = unexpectedErrorCallback
18 objectStore = db.createObjectStore('autoIncrementStore', {autoIncrement: true})
19 objectStore.add('foo1').onerror = unexpectedErrorCallback
20 objectStore.add('foo2').onerror = unexpectedErrorCallback
21 objectStore.add('foo3').onerror = unexpectedErrorCallback
22 objectStore.add('foo4').onerror = unexpectedErrorCallback
23 objectStore = db.createObjectStore('keyPathStore', {keyPath: 'id'})
24 objectStore.createIndex('numberIndex', 'number')
25 objectStore.add({number: 1, id: 1}).onerror = unexpectedErrorCallback
26 objectStore.add({number: 2, id: 2}).onerror = unexpectedErrorCallback
27 objectStore.add({number: 3, id: 3}).onerror = unexpectedErrorCallback
28 objectStore.add({number: 4, id: 4}).onerror = unexpectedErrorCallback
30 trans = db.transaction(['basicStore', 'autoIncrementStore', 'keyPathStore'], 'readwrite')
31 trans.objectStore('basicStore')
32 objectStore.openCursor(keyRange)
34 PASS event.target.source is objectStore
35 event.target.result.update('myUpdatedValue' + counter++)
36 event.target.source.continue()
38 PASS event.target.source is objectStore
39 event.target.result.update('myUpdatedValue' + counter++)
40 event.target.source.continue()
42 PASS event.target.source is objectStore
43 event.target.result.update('myUpdatedValue' + counter++)
44 event.target.source.continue()
46 PASS event.target.source is objectStore
47 event.target.result.update('myUpdatedValue' + counter++)
48 event.target.source.continue()
50 PASS event.target.source is objectStore
52 trans.objectStore('basicStore').openCursor(keyRange)
54 PASS event.target.result.key is "myKey1"
55 PASS event.target.result.value is "myUpdatedValue1"
56 event.target.result.continue()
58 PASS event.target.result.key is "myKey2"
59 PASS event.target.result.value is "myUpdatedValue2"
60 event.target.result.continue()
62 PASS event.target.result.key is "myKey3"
63 PASS event.target.result.value is "myUpdatedValue3"
64 event.target.result.continue()
66 PASS event.target.result.key is "myKey4"
67 PASS event.target.result.value is "myUpdatedValue4"
68 event.target.result.continue()
71 trans.objectStore('autoIncrementStore').openCursor(keyRange)
72 autoIncrementUpdateCursor()
73 event.target.result.update('myUpdatedFoo' + counter++)
74 event.target.source.continue()
75 autoIncrementUpdateCursor()
76 event.target.result.update('myUpdatedFoo' + counter++)
77 event.target.source.continue()
78 autoIncrementUpdateCursor()
79 event.target.result.update('myUpdatedFoo' + counter++)
80 event.target.source.continue()
81 autoIncrementUpdateCursor()
82 event.target.result.update('myUpdatedFoo' + counter++)
83 event.target.source.continue()
84 autoIncrementUpdateCursor()
86 trans.objectStore('autoIncrementStore').openCursor(keyRange)
87 autoIncrementCheckCursor()
88 PASS event.target.result.key is counter
89 PASS event.target.result.value is "myUpdatedFoo1"
90 event.target.result.continue()
91 autoIncrementCheckCursor()
92 PASS event.target.result.key is counter
93 PASS event.target.result.value is "myUpdatedFoo2"
94 event.target.result.continue()
95 autoIncrementCheckCursor()
96 PASS event.target.result.key is counter
97 PASS event.target.result.value is "myUpdatedFoo3"
98 event.target.result.continue()
99 autoIncrementCheckCursor()
100 PASS event.target.result.key is counter
101 PASS event.target.result.value is "myUpdatedFoo4"
102 event.target.result.continue()
103 autoIncrementCheckCursor()
105 trans.objectStore('keyPathStore').openCursor(keyRange)
106 keyPathUpdateCursor()
107 Expecting exception from event.target.result.update({id: 100 + counter, number: 100 + counter})
108 PASS Exception was thrown.
110 PASS ename is 'DataError'
111 Exception message: Failed to execute 'update' on 'IDBCursor': The effective object store of this cursor uses in-line keys and evaluating the key path of the value parameter results in a different value than the cursor's effective key.
112 event.target.result.update({id: counter, number: 100 + counter++})
113 event.target.source.continue()
114 keyPathUpdateCursor()
115 Expecting exception from event.target.result.update({id: 100 + counter, number: 100 + counter})
116 PASS Exception was thrown.
118 PASS ename is 'DataError'
119 Exception message: Failed to execute 'update' on 'IDBCursor': The effective object store of this cursor uses in-line keys and evaluating the key path of the value parameter results in a different value than the cursor's effective key.
120 event.target.result.update({id: counter, number: 100 + counter++})
121 event.target.source.continue()
122 keyPathUpdateCursor()
123 Expecting exception from event.target.result.update({id: 100 + counter, number: 100 + counter})
124 PASS Exception was thrown.
126 PASS ename is 'DataError'
127 Exception message: Failed to execute 'update' on 'IDBCursor': The effective object store of this cursor uses in-line keys and evaluating the key path of the value parameter results in a different value than the cursor's effective key.
128 event.target.result.update({id: counter, number: 100 + counter++})
129 event.target.source.continue()
130 keyPathUpdateCursor()
131 Expecting exception from event.target.result.update({id: 100 + counter, number: 100 + counter})
132 PASS Exception was thrown.
134 PASS ename is 'DataError'
135 Exception message: Failed to execute 'update' on 'IDBCursor': The effective object store of this cursor uses in-line keys and evaluating the key path of the value parameter results in a different value than the cursor's effective key.
136 event.target.result.update({id: counter, number: 100 + counter++})
137 event.target.source.continue()
138 keyPathUpdateCursor()
140 trans.objectStore('keyPathStore').openCursor(keyRange)
142 PASS event.target.result.key is counter
143 PASS event.target.result.value.id is counter
144 PASS event.target.result.value.number is 101
145 event.target.result.continue()
147 PASS event.target.result.key is counter
148 PASS event.target.result.value.id is counter
149 PASS event.target.result.value.number is 102
150 event.target.result.continue()
152 PASS event.target.result.key is counter
153 PASS event.target.result.value.id is counter
154 PASS event.target.result.value.number is 103
155 event.target.result.continue()
157 PASS event.target.result.key is counter
158 PASS event.target.result.value.id is counter
159 PASS event.target.result.value.number is 104
160 event.target.result.continue()
163 trans.objectStore('keyPathStore').index('numberIndex').openKeyCursor(keyRange)
165 PASS event.target.result.key is counter + 100
166 PASS event.target.result.primaryKey is counter
167 Expecting exception from event.target.result.update({id: counter, number: counter + 200})
168 PASS Exception was thrown.
169 PASS code is DOMException.INVALID_STATE_ERR
170 PASS ename is 'InvalidStateError'
171 Exception message: Failed to execute 'update' on 'IDBCursor': The cursor is a key cursor.
172 event.target.result.continue();
174 PASS event.target.result.key is counter + 100
175 PASS event.target.result.primaryKey is counter
176 Expecting exception from event.target.result.update({id: counter, number: counter + 200})
177 PASS Exception was thrown.
178 PASS code is DOMException.INVALID_STATE_ERR
179 PASS ename is 'InvalidStateError'
180 Exception message: Failed to execute 'update' on 'IDBCursor': The cursor is a key cursor.
181 event.target.result.continue();
183 PASS event.target.result.key is counter + 100
184 PASS event.target.result.primaryKey is counter
185 Expecting exception from event.target.result.update({id: counter, number: counter + 200})
186 PASS Exception was thrown.
187 PASS code is DOMException.INVALID_STATE_ERR
188 PASS ename is 'InvalidStateError'
189 Exception message: Failed to execute 'update' on 'IDBCursor': The cursor is a key cursor.
190 event.target.result.continue();
192 PASS event.target.result.key is counter + 100
193 PASS event.target.result.primaryKey is counter
194 Expecting exception from event.target.result.update({id: counter, number: counter + 200})
195 PASS Exception was thrown.
196 PASS code is DOMException.INVALID_STATE_ERR
197 PASS ename is 'InvalidStateError'
198 Exception message: Failed to execute 'update' on 'IDBCursor': The cursor is a key cursor.
199 event.target.result.continue();
203 trans = db.transaction('basicStore')
204 trans.objectStore('basicStore')
205 objectStore.openCursor(keyRange)
207 Expecting exception from cursor.update('myUpdatedValue')
208 PASS Exception was thrown.
210 PASS ename is 'ReadOnlyError'
211 Exception message: Failed to execute 'update' on 'IDBCursor': The record may not be updated inside a read-only transaction.
214 Expecting exception from cursor.update('myUpdatedValue')
215 PASS Exception was thrown.
217 PASS ename is 'ReadOnlyError'
218 Exception message: Failed to execute 'update' on 'IDBCursor': The record may not be updated inside a read-only transaction.
221 Expecting exception from cursor.update('myUpdatedValue')
222 PASS Exception was thrown.
224 PASS ename is 'ReadOnlyError'
225 Exception message: Failed to execute 'update' on 'IDBCursor': The record may not be updated inside a read-only transaction.
228 Expecting exception from cursor.update('myUpdatedValue')
229 PASS Exception was thrown.
231 PASS ename is 'ReadOnlyError'
232 Exception message: Failed to execute 'update' on 'IDBCursor': The record may not be updated inside a read-only transaction.
235 transactionComplete()
236 PASS successfullyParsed is true