Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /** |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | var testGenerator = testSteps(); |
michael@0 | 7 | |
michael@0 | 8 | function testSteps() |
michael@0 | 9 | { |
michael@0 | 10 | const name = this.window ? window.location.pathname : "Splendid Test"; |
michael@0 | 11 | |
michael@0 | 12 | const objectStoreName = "People"; |
michael@0 | 13 | |
michael@0 | 14 | const objectStoreData = [ |
michael@0 | 15 | { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } }, |
michael@0 | 16 | { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } }, |
michael@0 | 17 | { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }, |
michael@0 | 18 | { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }, |
michael@0 | 19 | { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } }, |
michael@0 | 20 | { key: "237-23-7737", value: { name: "Pat", height: 65 } } |
michael@0 | 21 | ]; |
michael@0 | 22 | |
michael@0 | 23 | const indexData = [ |
michael@0 | 24 | { name: "name", keyPath: "name", options: { unique: true } }, |
michael@0 | 25 | { name: "height", keyPath: "height", options: { } }, |
michael@0 | 26 | { name: "weight", keyPath: "weight", options: { unique: false } } |
michael@0 | 27 | ]; |
michael@0 | 28 | |
michael@0 | 29 | const objectStoreDataNameSort = [ |
michael@0 | 30 | { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } }, |
michael@0 | 31 | { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } }, |
michael@0 | 32 | { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } }, |
michael@0 | 33 | { key: "237-23-7737", value: { name: "Pat", height: 65 } }, |
michael@0 | 34 | { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }, |
michael@0 | 35 | { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } } |
michael@0 | 36 | ]; |
michael@0 | 37 | |
michael@0 | 38 | const objectStoreDataWeightSort = [ |
michael@0 | 39 | { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } }, |
michael@0 | 40 | { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } }, |
michael@0 | 41 | { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }, |
michael@0 | 42 | { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } }, |
michael@0 | 43 | { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } } |
michael@0 | 44 | ]; |
michael@0 | 45 | |
michael@0 | 46 | const objectStoreDataHeightSort = [ |
michael@0 | 47 | { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } }, |
michael@0 | 48 | { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }, |
michael@0 | 49 | { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } }, |
michael@0 | 50 | { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } }, |
michael@0 | 51 | { key: "237-23-7737", value: { name: "Pat", height: 65 } }, |
michael@0 | 52 | { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } } |
michael@0 | 53 | ]; |
michael@0 | 54 | |
michael@0 | 55 | let request = indexedDB.open(name, 1); |
michael@0 | 56 | request.onerror = errorHandler; |
michael@0 | 57 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 58 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 59 | let event = yield undefined; |
michael@0 | 60 | let db = event.target.result; |
michael@0 | 61 | |
michael@0 | 62 | let objectStore = db.createObjectStore(objectStoreName, { keyPath: null }); |
michael@0 | 63 | |
michael@0 | 64 | // First, add all our data to the object store. |
michael@0 | 65 | let addedData = 0; |
michael@0 | 66 | for (let i in objectStoreData) { |
michael@0 | 67 | request = objectStore.add(objectStoreData[i].value, |
michael@0 | 68 | objectStoreData[i].key); |
michael@0 | 69 | request.onerror = errorHandler; |
michael@0 | 70 | request.onsuccess = function(event) { |
michael@0 | 71 | if (++addedData == objectStoreData.length) { |
michael@0 | 72 | testGenerator.send(event); |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | event = yield undefined; |
michael@0 | 77 | // Now create the indexes. |
michael@0 | 78 | for (let i in indexData) { |
michael@0 | 79 | objectStore.createIndex(indexData[i].name, indexData[i].keyPath, |
michael@0 | 80 | indexData[i].options); |
michael@0 | 81 | } |
michael@0 | 82 | is(objectStore.indexNames.length, indexData.length, "Good index count"); |
michael@0 | 83 | yield undefined; |
michael@0 | 84 | objectStore = db.transaction(objectStoreName) |
michael@0 | 85 | .objectStore(objectStoreName); |
michael@0 | 86 | |
michael@0 | 87 | // Check global properties to make sure they are correct. |
michael@0 | 88 | is(objectStore.indexNames.length, indexData.length, "Good index count"); |
michael@0 | 89 | for (let i in indexData) { |
michael@0 | 90 | let found = false; |
michael@0 | 91 | for (let j = 0; j < objectStore.indexNames.length; j++) { |
michael@0 | 92 | if (objectStore.indexNames.item(j) == indexData[i].name) { |
michael@0 | 93 | found = true; |
michael@0 | 94 | break; |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | is(found, true, "objectStore has our index"); |
michael@0 | 98 | let index = objectStore.index(indexData[i].name); |
michael@0 | 99 | is(index.name, indexData[i].name, "Correct name"); |
michael@0 | 100 | is(index.storeName, objectStore.name, "Correct store name"); |
michael@0 | 101 | is(index.keyPath, indexData[i].keyPath, "Correct keyPath"); |
michael@0 | 102 | is(index.unique, indexData[i].options.unique ? true : false, |
michael@0 | 103 | "Correct unique value"); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | request = objectStore.index("name").getKey("Bob"); |
michael@0 | 107 | request.onerror = errorHandler; |
michael@0 | 108 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 109 | event = yield undefined; |
michael@0 | 110 | |
michael@0 | 111 | is(event.target.result, "237-23-7732", "Correct key returned!"); |
michael@0 | 112 | |
michael@0 | 113 | request = objectStore.index("name").get("Bob"); |
michael@0 | 114 | request.onerror = errorHandler; |
michael@0 | 115 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 116 | event = yield undefined; |
michael@0 | 117 | |
michael@0 | 118 | is(event.target.result.name, "Bob", "Correct name returned!"); |
michael@0 | 119 | is(event.target.result.height, 60, "Correct height returned!"); |
michael@0 | 120 | is(event.target.result.weight, 120, "Correct weight returned!"); |
michael@0 | 121 | |
michael@0 | 122 | ok(true, "Test group 1"); |
michael@0 | 123 | |
michael@0 | 124 | let keyIndex = 0; |
michael@0 | 125 | |
michael@0 | 126 | request = objectStore.index("name").openKeyCursor(); |
michael@0 | 127 | request.onerror = errorHandler; |
michael@0 | 128 | request.onsuccess = function (event) { |
michael@0 | 129 | let cursor = event.target.result; |
michael@0 | 130 | if (cursor) { |
michael@0 | 131 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 132 | "Correct key"); |
michael@0 | 133 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 134 | "Correct primary key"); |
michael@0 | 135 | ok(!("value" in cursor), "No value"); |
michael@0 | 136 | |
michael@0 | 137 | cursor.continue(); |
michael@0 | 138 | |
michael@0 | 139 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 140 | "Correct key"); |
michael@0 | 141 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 142 | "Correct value"); |
michael@0 | 143 | ok(!("value" in cursor), "No value"); |
michael@0 | 144 | |
michael@0 | 145 | keyIndex++; |
michael@0 | 146 | } |
michael@0 | 147 | else { |
michael@0 | 148 | testGenerator.next(); |
michael@0 | 149 | } |
michael@0 | 150 | } |
michael@0 | 151 | yield undefined; |
michael@0 | 152 | |
michael@0 | 153 | is(keyIndex, objectStoreData.length, "Saw all the expected keys"); |
michael@0 | 154 | |
michael@0 | 155 | ok(true, "Test group 2"); |
michael@0 | 156 | |
michael@0 | 157 | keyIndex = 0; |
michael@0 | 158 | |
michael@0 | 159 | request = objectStore.index("weight").openKeyCursor(null, "next"); |
michael@0 | 160 | request.onerror = errorHandler; |
michael@0 | 161 | request.onsuccess = function (event) { |
michael@0 | 162 | let cursor = event.target.result; |
michael@0 | 163 | if (cursor) { |
michael@0 | 164 | is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight, |
michael@0 | 165 | "Correct key"); |
michael@0 | 166 | is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key, |
michael@0 | 167 | "Correct value"); |
michael@0 | 168 | |
michael@0 | 169 | cursor.continue(); |
michael@0 | 170 | |
michael@0 | 171 | is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight, |
michael@0 | 172 | "Correct key"); |
michael@0 | 173 | is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key, |
michael@0 | 174 | "Correct value"); |
michael@0 | 175 | |
michael@0 | 176 | keyIndex++; |
michael@0 | 177 | } |
michael@0 | 178 | else { |
michael@0 | 179 | testGenerator.next(); |
michael@0 | 180 | } |
michael@0 | 181 | } |
michael@0 | 182 | yield undefined; |
michael@0 | 183 | |
michael@0 | 184 | is(keyIndex, objectStoreData.length - 1, "Saw all the expected keys"); |
michael@0 | 185 | |
michael@0 | 186 | // Check that the name index enforces its unique constraint. |
michael@0 | 187 | objectStore = db.transaction(objectStoreName, "readwrite") |
michael@0 | 188 | .objectStore(objectStoreName); |
michael@0 | 189 | request = objectStore.add({ name: "Bob", height: 62, weight: 170 }, |
michael@0 | 190 | "237-23-7738"); |
michael@0 | 191 | request.addEventListener("error", new ExpectError("ConstraintError", true)); |
michael@0 | 192 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 193 | event = yield undefined; |
michael@0 | 194 | |
michael@0 | 195 | ok(true, "Test group 3"); |
michael@0 | 196 | |
michael@0 | 197 | keyIndex = objectStoreDataNameSort.length - 1; |
michael@0 | 198 | |
michael@0 | 199 | request = objectStore.index("name").openKeyCursor(null, "prev"); |
michael@0 | 200 | request.onerror = errorHandler; |
michael@0 | 201 | request.onsuccess = function (event) { |
michael@0 | 202 | let cursor = event.target.result; |
michael@0 | 203 | if (cursor) { |
michael@0 | 204 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 205 | "Correct key"); |
michael@0 | 206 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 207 | "Correct value"); |
michael@0 | 208 | |
michael@0 | 209 | cursor.continue(); |
michael@0 | 210 | |
michael@0 | 211 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 212 | "Correct key"); |
michael@0 | 213 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 214 | "Correct value"); |
michael@0 | 215 | |
michael@0 | 216 | keyIndex--; |
michael@0 | 217 | } |
michael@0 | 218 | else { |
michael@0 | 219 | testGenerator.next(); |
michael@0 | 220 | } |
michael@0 | 221 | } |
michael@0 | 222 | yield undefined; |
michael@0 | 223 | |
michael@0 | 224 | is(keyIndex, -1, "Saw all the expected keys"); |
michael@0 | 225 | |
michael@0 | 226 | ok(true, "Test group 4"); |
michael@0 | 227 | |
michael@0 | 228 | keyIndex = 1; |
michael@0 | 229 | let keyRange = IDBKeyRange.bound("Bob", "Ron"); |
michael@0 | 230 | |
michael@0 | 231 | request = objectStore.index("name").openKeyCursor(keyRange); |
michael@0 | 232 | request.onerror = errorHandler; |
michael@0 | 233 | request.onsuccess = function (event) { |
michael@0 | 234 | let cursor = event.target.result; |
michael@0 | 235 | if (cursor) { |
michael@0 | 236 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 237 | "Correct key"); |
michael@0 | 238 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 239 | "Correct value"); |
michael@0 | 240 | |
michael@0 | 241 | cursor.continue(); |
michael@0 | 242 | keyIndex++; |
michael@0 | 243 | } |
michael@0 | 244 | else { |
michael@0 | 245 | testGenerator.next(); |
michael@0 | 246 | } |
michael@0 | 247 | } |
michael@0 | 248 | yield undefined; |
michael@0 | 249 | |
michael@0 | 250 | is(keyIndex, 5, "Saw all the expected keys"); |
michael@0 | 251 | |
michael@0 | 252 | ok(true, "Test group 5"); |
michael@0 | 253 | |
michael@0 | 254 | keyIndex = 2; |
michael@0 | 255 | let keyRange = IDBKeyRange.bound("Bob", "Ron", true); |
michael@0 | 256 | |
michael@0 | 257 | request = objectStore.index("name").openKeyCursor(keyRange); |
michael@0 | 258 | request.onerror = errorHandler; |
michael@0 | 259 | request.onsuccess = function (event) { |
michael@0 | 260 | let cursor = event.target.result; |
michael@0 | 261 | if (cursor) { |
michael@0 | 262 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 263 | "Correct key"); |
michael@0 | 264 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 265 | "Correct value"); |
michael@0 | 266 | |
michael@0 | 267 | cursor.continue(); |
michael@0 | 268 | keyIndex++; |
michael@0 | 269 | } |
michael@0 | 270 | else { |
michael@0 | 271 | testGenerator.next(); |
michael@0 | 272 | } |
michael@0 | 273 | } |
michael@0 | 274 | yield undefined; |
michael@0 | 275 | |
michael@0 | 276 | is(keyIndex, 5, "Saw all the expected keys"); |
michael@0 | 277 | |
michael@0 | 278 | ok(true, "Test group 6"); |
michael@0 | 279 | |
michael@0 | 280 | keyIndex = 1; |
michael@0 | 281 | let keyRange = IDBKeyRange.bound("Bob", "Ron", false, true); |
michael@0 | 282 | |
michael@0 | 283 | request = objectStore.index("name").openKeyCursor(keyRange); |
michael@0 | 284 | request.onerror = errorHandler; |
michael@0 | 285 | request.onsuccess = function (event) { |
michael@0 | 286 | let cursor = event.target.result; |
michael@0 | 287 | if (cursor) { |
michael@0 | 288 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 289 | "Correct key"); |
michael@0 | 290 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 291 | "Correct value"); |
michael@0 | 292 | |
michael@0 | 293 | cursor.continue(); |
michael@0 | 294 | keyIndex++; |
michael@0 | 295 | } |
michael@0 | 296 | else { |
michael@0 | 297 | testGenerator.next(); |
michael@0 | 298 | } |
michael@0 | 299 | } |
michael@0 | 300 | yield undefined; |
michael@0 | 301 | |
michael@0 | 302 | is(keyIndex, 4, "Saw all the expected keys"); |
michael@0 | 303 | |
michael@0 | 304 | ok(true, "Test group 7"); |
michael@0 | 305 | |
michael@0 | 306 | keyIndex = 2; |
michael@0 | 307 | keyRange = IDBKeyRange.bound("Bob", "Ron", true, true); |
michael@0 | 308 | |
michael@0 | 309 | request = objectStore.index("name").openKeyCursor(keyRange); |
michael@0 | 310 | request.onerror = errorHandler; |
michael@0 | 311 | request.onsuccess = function (event) { |
michael@0 | 312 | let cursor = event.target.result; |
michael@0 | 313 | if (cursor) { |
michael@0 | 314 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 315 | "Correct key"); |
michael@0 | 316 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 317 | "Correct value"); |
michael@0 | 318 | |
michael@0 | 319 | cursor.continue(); |
michael@0 | 320 | keyIndex++; |
michael@0 | 321 | } |
michael@0 | 322 | else { |
michael@0 | 323 | testGenerator.next(); |
michael@0 | 324 | } |
michael@0 | 325 | } |
michael@0 | 326 | yield undefined; |
michael@0 | 327 | |
michael@0 | 328 | is(keyIndex, 4, "Saw all the expected keys"); |
michael@0 | 329 | |
michael@0 | 330 | ok(true, "Test group 8"); |
michael@0 | 331 | |
michael@0 | 332 | keyIndex = 1; |
michael@0 | 333 | keyRange = IDBKeyRange.lowerBound("Bob"); |
michael@0 | 334 | |
michael@0 | 335 | request = objectStore.index("name").openKeyCursor(keyRange); |
michael@0 | 336 | request.onerror = errorHandler; |
michael@0 | 337 | request.onsuccess = function (event) { |
michael@0 | 338 | let cursor = event.target.result; |
michael@0 | 339 | if (cursor) { |
michael@0 | 340 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 341 | "Correct key"); |
michael@0 | 342 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 343 | "Correct value"); |
michael@0 | 344 | |
michael@0 | 345 | cursor.continue(); |
michael@0 | 346 | keyIndex++; |
michael@0 | 347 | } |
michael@0 | 348 | else { |
michael@0 | 349 | testGenerator.next(); |
michael@0 | 350 | } |
michael@0 | 351 | } |
michael@0 | 352 | yield undefined; |
michael@0 | 353 | |
michael@0 | 354 | is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); |
michael@0 | 355 | |
michael@0 | 356 | ok(true, "Test group 9"); |
michael@0 | 357 | |
michael@0 | 358 | keyIndex = 2; |
michael@0 | 359 | keyRange = IDBKeyRange.lowerBound("Bob", true); |
michael@0 | 360 | |
michael@0 | 361 | request = objectStore.index("name").openKeyCursor(keyRange); |
michael@0 | 362 | request.onerror = errorHandler; |
michael@0 | 363 | request.onsuccess = function (event) { |
michael@0 | 364 | let cursor = event.target.result; |
michael@0 | 365 | if (cursor) { |
michael@0 | 366 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 367 | "Correct key"); |
michael@0 | 368 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 369 | "Correct value"); |
michael@0 | 370 | |
michael@0 | 371 | cursor.continue(); |
michael@0 | 372 | keyIndex++; |
michael@0 | 373 | } |
michael@0 | 374 | else { |
michael@0 | 375 | testGenerator.next(); |
michael@0 | 376 | } |
michael@0 | 377 | } |
michael@0 | 378 | yield undefined; |
michael@0 | 379 | |
michael@0 | 380 | is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); |
michael@0 | 381 | |
michael@0 | 382 | ok(true, "Test group 10"); |
michael@0 | 383 | |
michael@0 | 384 | keyIndex = 0; |
michael@0 | 385 | keyRange = IDBKeyRange.upperBound("Joe"); |
michael@0 | 386 | |
michael@0 | 387 | request = objectStore.index("name").openKeyCursor(keyRange); |
michael@0 | 388 | request.onerror = errorHandler; |
michael@0 | 389 | request.onsuccess = function (event) { |
michael@0 | 390 | let cursor = event.target.result; |
michael@0 | 391 | if (cursor) { |
michael@0 | 392 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 393 | "Correct key"); |
michael@0 | 394 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 395 | "Correct value"); |
michael@0 | 396 | |
michael@0 | 397 | cursor.continue(); |
michael@0 | 398 | keyIndex++; |
michael@0 | 399 | } |
michael@0 | 400 | else { |
michael@0 | 401 | testGenerator.next(); |
michael@0 | 402 | } |
michael@0 | 403 | } |
michael@0 | 404 | yield undefined; |
michael@0 | 405 | |
michael@0 | 406 | is(keyIndex, 3, "Saw all the expected keys"); |
michael@0 | 407 | |
michael@0 | 408 | ok(true, "Test group 11"); |
michael@0 | 409 | |
michael@0 | 410 | keyIndex = 0; |
michael@0 | 411 | keyRange = IDBKeyRange.upperBound("Joe", true); |
michael@0 | 412 | |
michael@0 | 413 | request = objectStore.index("name").openKeyCursor(keyRange); |
michael@0 | 414 | request.onerror = errorHandler; |
michael@0 | 415 | request.onsuccess = function (event) { |
michael@0 | 416 | let cursor = event.target.result; |
michael@0 | 417 | if (cursor) { |
michael@0 | 418 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 419 | "Correct key"); |
michael@0 | 420 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 421 | "Correct value"); |
michael@0 | 422 | |
michael@0 | 423 | cursor.continue(); |
michael@0 | 424 | keyIndex++; |
michael@0 | 425 | } |
michael@0 | 426 | else { |
michael@0 | 427 | testGenerator.next(); |
michael@0 | 428 | } |
michael@0 | 429 | } |
michael@0 | 430 | yield undefined; |
michael@0 | 431 | |
michael@0 | 432 | is(keyIndex, 2, "Saw all the expected keys"); |
michael@0 | 433 | |
michael@0 | 434 | ok(true, "Test group 12"); |
michael@0 | 435 | |
michael@0 | 436 | keyIndex = 3; |
michael@0 | 437 | keyRange = IDBKeyRange.only("Pat"); |
michael@0 | 438 | |
michael@0 | 439 | request = objectStore.index("name").openKeyCursor(keyRange); |
michael@0 | 440 | request.onerror = errorHandler; |
michael@0 | 441 | request.onsuccess = function (event) { |
michael@0 | 442 | let cursor = event.target.result; |
michael@0 | 443 | if (cursor) { |
michael@0 | 444 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 445 | "Correct key"); |
michael@0 | 446 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 447 | "Correct value"); |
michael@0 | 448 | |
michael@0 | 449 | cursor.continue(); |
michael@0 | 450 | keyIndex++; |
michael@0 | 451 | } |
michael@0 | 452 | else { |
michael@0 | 453 | testGenerator.next(); |
michael@0 | 454 | } |
michael@0 | 455 | } |
michael@0 | 456 | yield undefined; |
michael@0 | 457 | |
michael@0 | 458 | is(keyIndex, 4, "Saw all the expected keys"); |
michael@0 | 459 | |
michael@0 | 460 | ok(true, "Test group 13"); |
michael@0 | 461 | |
michael@0 | 462 | keyIndex = 0; |
michael@0 | 463 | |
michael@0 | 464 | request = objectStore.index("name").openCursor(); |
michael@0 | 465 | request.onerror = errorHandler; |
michael@0 | 466 | request.onsuccess = function (event) { |
michael@0 | 467 | let cursor = event.target.result; |
michael@0 | 468 | if (cursor) { |
michael@0 | 469 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 470 | "Correct key"); |
michael@0 | 471 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 472 | "Correct primary key"); |
michael@0 | 473 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 474 | "Correct name"); |
michael@0 | 475 | is(cursor.value.height, |
michael@0 | 476 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 477 | "Correct height"); |
michael@0 | 478 | if ("weight" in cursor.value) { |
michael@0 | 479 | is(cursor.value.weight, |
michael@0 | 480 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 481 | "Correct weight"); |
michael@0 | 482 | } |
michael@0 | 483 | |
michael@0 | 484 | cursor.continue(); |
michael@0 | 485 | |
michael@0 | 486 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 487 | "Correct key"); |
michael@0 | 488 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 489 | "Correct primary key"); |
michael@0 | 490 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 491 | "Correct name"); |
michael@0 | 492 | is(cursor.value.height, |
michael@0 | 493 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 494 | "Correct height"); |
michael@0 | 495 | if ("weight" in cursor.value) { |
michael@0 | 496 | is(cursor.value.weight, |
michael@0 | 497 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 498 | "Correct weight"); |
michael@0 | 499 | } |
michael@0 | 500 | |
michael@0 | 501 | keyIndex++; |
michael@0 | 502 | } |
michael@0 | 503 | else { |
michael@0 | 504 | testGenerator.next(); |
michael@0 | 505 | } |
michael@0 | 506 | } |
michael@0 | 507 | yield undefined; |
michael@0 | 508 | |
michael@0 | 509 | is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); |
michael@0 | 510 | |
michael@0 | 511 | ok(true, "Test group 14"); |
michael@0 | 512 | |
michael@0 | 513 | keyIndex = objectStoreDataNameSort.length - 1; |
michael@0 | 514 | |
michael@0 | 515 | request = objectStore.index("name").openCursor(null, "prev"); |
michael@0 | 516 | request.onerror = errorHandler; |
michael@0 | 517 | request.onsuccess = function (event) { |
michael@0 | 518 | let cursor = event.target.result; |
michael@0 | 519 | if (cursor) { |
michael@0 | 520 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 521 | "Correct key"); |
michael@0 | 522 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 523 | "Correct primary key"); |
michael@0 | 524 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 525 | "Correct name"); |
michael@0 | 526 | is(cursor.value.height, |
michael@0 | 527 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 528 | "Correct height"); |
michael@0 | 529 | if ("weight" in cursor.value) { |
michael@0 | 530 | is(cursor.value.weight, |
michael@0 | 531 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 532 | "Correct weight"); |
michael@0 | 533 | } |
michael@0 | 534 | |
michael@0 | 535 | cursor.continue(); |
michael@0 | 536 | |
michael@0 | 537 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 538 | "Correct key"); |
michael@0 | 539 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 540 | "Correct primary key"); |
michael@0 | 541 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 542 | "Correct name"); |
michael@0 | 543 | is(cursor.value.height, |
michael@0 | 544 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 545 | "Correct height"); |
michael@0 | 546 | if ("weight" in cursor.value) { |
michael@0 | 547 | is(cursor.value.weight, |
michael@0 | 548 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 549 | "Correct weight"); |
michael@0 | 550 | } |
michael@0 | 551 | |
michael@0 | 552 | keyIndex--; |
michael@0 | 553 | } |
michael@0 | 554 | else { |
michael@0 | 555 | testGenerator.next(); |
michael@0 | 556 | } |
michael@0 | 557 | } |
michael@0 | 558 | yield undefined; |
michael@0 | 559 | |
michael@0 | 560 | is(keyIndex, -1, "Saw all the expected keys"); |
michael@0 | 561 | |
michael@0 | 562 | ok(true, "Test group 15"); |
michael@0 | 563 | |
michael@0 | 564 | keyIndex = 1; |
michael@0 | 565 | keyRange = IDBKeyRange.bound("Bob", "Ron"); |
michael@0 | 566 | |
michael@0 | 567 | request = objectStore.index("name").openCursor(keyRange); |
michael@0 | 568 | request.onerror = errorHandler; |
michael@0 | 569 | request.onsuccess = function (event) { |
michael@0 | 570 | let cursor = event.target.result; |
michael@0 | 571 | if (cursor) { |
michael@0 | 572 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 573 | "Correct key"); |
michael@0 | 574 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 575 | "Correct primary key"); |
michael@0 | 576 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 577 | "Correct name"); |
michael@0 | 578 | is(cursor.value.height, |
michael@0 | 579 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 580 | "Correct height"); |
michael@0 | 581 | if ("weight" in cursor.value) { |
michael@0 | 582 | is(cursor.value.weight, |
michael@0 | 583 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 584 | "Correct weight"); |
michael@0 | 585 | } |
michael@0 | 586 | |
michael@0 | 587 | cursor.continue(); |
michael@0 | 588 | |
michael@0 | 589 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 590 | "Correct key"); |
michael@0 | 591 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 592 | "Correct primary key"); |
michael@0 | 593 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 594 | "Correct name"); |
michael@0 | 595 | is(cursor.value.height, |
michael@0 | 596 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 597 | "Correct height"); |
michael@0 | 598 | if ("weight" in cursor.value) { |
michael@0 | 599 | is(cursor.value.weight, |
michael@0 | 600 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 601 | "Correct weight"); |
michael@0 | 602 | } |
michael@0 | 603 | |
michael@0 | 604 | keyIndex++; |
michael@0 | 605 | } |
michael@0 | 606 | else { |
michael@0 | 607 | testGenerator.next(); |
michael@0 | 608 | } |
michael@0 | 609 | } |
michael@0 | 610 | yield undefined; |
michael@0 | 611 | |
michael@0 | 612 | is(keyIndex, 5, "Saw all the expected keys"); |
michael@0 | 613 | |
michael@0 | 614 | ok(true, "Test group 16"); |
michael@0 | 615 | |
michael@0 | 616 | keyIndex = 2; |
michael@0 | 617 | keyRange = IDBKeyRange.bound("Bob", "Ron", true); |
michael@0 | 618 | |
michael@0 | 619 | request = objectStore.index("name").openCursor(keyRange); |
michael@0 | 620 | request.onerror = errorHandler; |
michael@0 | 621 | request.onsuccess = function (event) { |
michael@0 | 622 | let cursor = event.target.result; |
michael@0 | 623 | if (cursor) { |
michael@0 | 624 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 625 | "Correct key"); |
michael@0 | 626 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 627 | "Correct primary key"); |
michael@0 | 628 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 629 | "Correct name"); |
michael@0 | 630 | is(cursor.value.height, |
michael@0 | 631 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 632 | "Correct height"); |
michael@0 | 633 | if ("weight" in cursor.value) { |
michael@0 | 634 | is(cursor.value.weight, |
michael@0 | 635 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 636 | "Correct weight"); |
michael@0 | 637 | } |
michael@0 | 638 | |
michael@0 | 639 | cursor.continue(); |
michael@0 | 640 | |
michael@0 | 641 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 642 | "Correct key"); |
michael@0 | 643 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 644 | "Correct primary key"); |
michael@0 | 645 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 646 | "Correct name"); |
michael@0 | 647 | is(cursor.value.height, |
michael@0 | 648 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 649 | "Correct height"); |
michael@0 | 650 | if ("weight" in cursor.value) { |
michael@0 | 651 | is(cursor.value.weight, |
michael@0 | 652 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 653 | "Correct weight"); |
michael@0 | 654 | } |
michael@0 | 655 | |
michael@0 | 656 | keyIndex++; |
michael@0 | 657 | } |
michael@0 | 658 | else { |
michael@0 | 659 | testGenerator.next(); |
michael@0 | 660 | } |
michael@0 | 661 | } |
michael@0 | 662 | yield undefined; |
michael@0 | 663 | |
michael@0 | 664 | is(keyIndex, 5, "Saw all the expected keys"); |
michael@0 | 665 | |
michael@0 | 666 | ok(true, "Test group 17"); |
michael@0 | 667 | |
michael@0 | 668 | keyIndex = 1; |
michael@0 | 669 | keyRange = IDBKeyRange.bound("Bob", "Ron", false, true); |
michael@0 | 670 | |
michael@0 | 671 | request = objectStore.index("name").openCursor(keyRange); |
michael@0 | 672 | request.onerror = errorHandler; |
michael@0 | 673 | request.onsuccess = function (event) { |
michael@0 | 674 | let cursor = event.target.result; |
michael@0 | 675 | if (cursor) { |
michael@0 | 676 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 677 | "Correct key"); |
michael@0 | 678 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 679 | "Correct primary key"); |
michael@0 | 680 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 681 | "Correct name"); |
michael@0 | 682 | is(cursor.value.height, |
michael@0 | 683 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 684 | "Correct height"); |
michael@0 | 685 | if ("weight" in cursor.value) { |
michael@0 | 686 | is(cursor.value.weight, |
michael@0 | 687 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 688 | "Correct weight"); |
michael@0 | 689 | } |
michael@0 | 690 | |
michael@0 | 691 | cursor.continue(); |
michael@0 | 692 | |
michael@0 | 693 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 694 | "Correct key"); |
michael@0 | 695 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 696 | "Correct primary key"); |
michael@0 | 697 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 698 | "Correct name"); |
michael@0 | 699 | is(cursor.value.height, |
michael@0 | 700 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 701 | "Correct height"); |
michael@0 | 702 | if ("weight" in cursor.value) { |
michael@0 | 703 | is(cursor.value.weight, |
michael@0 | 704 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 705 | "Correct weight"); |
michael@0 | 706 | } |
michael@0 | 707 | |
michael@0 | 708 | keyIndex++; |
michael@0 | 709 | } |
michael@0 | 710 | else { |
michael@0 | 711 | testGenerator.next(); |
michael@0 | 712 | } |
michael@0 | 713 | } |
michael@0 | 714 | yield undefined; |
michael@0 | 715 | |
michael@0 | 716 | is(keyIndex, 4, "Saw all the expected keys"); |
michael@0 | 717 | |
michael@0 | 718 | ok(true, "Test group 18"); |
michael@0 | 719 | |
michael@0 | 720 | keyIndex = 2; |
michael@0 | 721 | keyRange = IDBKeyRange.bound("Bob", "Ron", true, true); |
michael@0 | 722 | |
michael@0 | 723 | request = objectStore.index("name").openCursor(keyRange); |
michael@0 | 724 | request.onerror = errorHandler; |
michael@0 | 725 | request.onsuccess = function (event) { |
michael@0 | 726 | let cursor = event.target.result; |
michael@0 | 727 | if (cursor) { |
michael@0 | 728 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 729 | "Correct key"); |
michael@0 | 730 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 731 | "Correct primary key"); |
michael@0 | 732 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 733 | "Correct name"); |
michael@0 | 734 | is(cursor.value.height, |
michael@0 | 735 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 736 | "Correct height"); |
michael@0 | 737 | if ("weight" in cursor.value) { |
michael@0 | 738 | is(cursor.value.weight, |
michael@0 | 739 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 740 | "Correct weight"); |
michael@0 | 741 | } |
michael@0 | 742 | |
michael@0 | 743 | cursor.continue(); |
michael@0 | 744 | |
michael@0 | 745 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 746 | "Correct key"); |
michael@0 | 747 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 748 | "Correct primary key"); |
michael@0 | 749 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 750 | "Correct name"); |
michael@0 | 751 | is(cursor.value.height, |
michael@0 | 752 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 753 | "Correct height"); |
michael@0 | 754 | if ("weight" in cursor.value) { |
michael@0 | 755 | is(cursor.value.weight, |
michael@0 | 756 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 757 | "Correct weight"); |
michael@0 | 758 | } |
michael@0 | 759 | |
michael@0 | 760 | keyIndex++; |
michael@0 | 761 | } |
michael@0 | 762 | else { |
michael@0 | 763 | testGenerator.next(); |
michael@0 | 764 | } |
michael@0 | 765 | } |
michael@0 | 766 | yield undefined; |
michael@0 | 767 | |
michael@0 | 768 | is(keyIndex, 4, "Saw all the expected keys"); |
michael@0 | 769 | |
michael@0 | 770 | ok(true, "Test group 19"); |
michael@0 | 771 | |
michael@0 | 772 | keyIndex = 4; |
michael@0 | 773 | keyRange = IDBKeyRange.bound("Bob", "Ron"); |
michael@0 | 774 | |
michael@0 | 775 | request = objectStore.index("name").openCursor(keyRange, "prev"); |
michael@0 | 776 | request.onerror = errorHandler; |
michael@0 | 777 | request.onsuccess = function (event) { |
michael@0 | 778 | let cursor = event.target.result; |
michael@0 | 779 | if (cursor) { |
michael@0 | 780 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 781 | "Correct key"); |
michael@0 | 782 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 783 | "Correct primary key"); |
michael@0 | 784 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 785 | "Correct name"); |
michael@0 | 786 | is(cursor.value.height, |
michael@0 | 787 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 788 | "Correct height"); |
michael@0 | 789 | if ("weight" in cursor.value) { |
michael@0 | 790 | is(cursor.value.weight, |
michael@0 | 791 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 792 | "Correct weight"); |
michael@0 | 793 | } |
michael@0 | 794 | |
michael@0 | 795 | cursor.continue(); |
michael@0 | 796 | |
michael@0 | 797 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 798 | "Correct key"); |
michael@0 | 799 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 800 | "Correct primary key"); |
michael@0 | 801 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 802 | "Correct name"); |
michael@0 | 803 | is(cursor.value.height, |
michael@0 | 804 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 805 | "Correct height"); |
michael@0 | 806 | if ("weight" in cursor.value) { |
michael@0 | 807 | is(cursor.value.weight, |
michael@0 | 808 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 809 | "Correct weight"); |
michael@0 | 810 | } |
michael@0 | 811 | |
michael@0 | 812 | keyIndex--; |
michael@0 | 813 | } |
michael@0 | 814 | else { |
michael@0 | 815 | testGenerator.next(); |
michael@0 | 816 | } |
michael@0 | 817 | } |
michael@0 | 818 | yield undefined; |
michael@0 | 819 | |
michael@0 | 820 | is(keyIndex, 0, "Saw all the expected keys"); |
michael@0 | 821 | |
michael@0 | 822 | ok(true, "Test group 20"); |
michael@0 | 823 | |
michael@0 | 824 | // Test "nextunique" |
michael@0 | 825 | keyIndex = 3; |
michael@0 | 826 | keyRange = IDBKeyRange.only(65); |
michael@0 | 827 | |
michael@0 | 828 | request = objectStore.index("height").openKeyCursor(keyRange, "next"); |
michael@0 | 829 | request.onerror = errorHandler; |
michael@0 | 830 | request.onsuccess = function (event) { |
michael@0 | 831 | let cursor = event.target.result; |
michael@0 | 832 | if (cursor) { |
michael@0 | 833 | is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 834 | "Correct key"); |
michael@0 | 835 | is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, |
michael@0 | 836 | "Correct value"); |
michael@0 | 837 | |
michael@0 | 838 | cursor.continue(); |
michael@0 | 839 | keyIndex++; |
michael@0 | 840 | } |
michael@0 | 841 | else { |
michael@0 | 842 | testGenerator.next(); |
michael@0 | 843 | } |
michael@0 | 844 | } |
michael@0 | 845 | yield undefined; |
michael@0 | 846 | |
michael@0 | 847 | is(keyIndex, 5, "Saw all the expected keys"); |
michael@0 | 848 | |
michael@0 | 849 | ok(true, "Test group 21"); |
michael@0 | 850 | |
michael@0 | 851 | keyIndex = 3; |
michael@0 | 852 | keyRange = IDBKeyRange.only(65); |
michael@0 | 853 | |
michael@0 | 854 | request = objectStore.index("height").openKeyCursor(keyRange, |
michael@0 | 855 | "nextunique"); |
michael@0 | 856 | request.onerror = errorHandler; |
michael@0 | 857 | request.onsuccess = function (event) { |
michael@0 | 858 | let cursor = event.target.result; |
michael@0 | 859 | if (cursor) { |
michael@0 | 860 | is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 861 | "Correct key"); |
michael@0 | 862 | is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, |
michael@0 | 863 | "Correct value"); |
michael@0 | 864 | |
michael@0 | 865 | cursor.continue(); |
michael@0 | 866 | keyIndex++; |
michael@0 | 867 | } |
michael@0 | 868 | else { |
michael@0 | 869 | testGenerator.next(); |
michael@0 | 870 | } |
michael@0 | 871 | } |
michael@0 | 872 | yield undefined; |
michael@0 | 873 | |
michael@0 | 874 | is(keyIndex, 4, "Saw all the expected keys"); |
michael@0 | 875 | |
michael@0 | 876 | ok(true, "Test group 21.5"); |
michael@0 | 877 | |
michael@0 | 878 | keyIndex = 5; |
michael@0 | 879 | |
michael@0 | 880 | request = objectStore.index("height").openKeyCursor(null, "prev"); |
michael@0 | 881 | request.onerror = errorHandler; |
michael@0 | 882 | request.onsuccess = function (event) { |
michael@0 | 883 | let cursor = event.target.result; |
michael@0 | 884 | if (cursor) { |
michael@0 | 885 | is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 886 | "Correct key"); |
michael@0 | 887 | is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, |
michael@0 | 888 | "Correct value"); |
michael@0 | 889 | |
michael@0 | 890 | cursor.continue(); |
michael@0 | 891 | keyIndex--; |
michael@0 | 892 | } |
michael@0 | 893 | else { |
michael@0 | 894 | testGenerator.next(); |
michael@0 | 895 | } |
michael@0 | 896 | } |
michael@0 | 897 | yield undefined; |
michael@0 | 898 | |
michael@0 | 899 | is(keyIndex, -1, "Saw all the expected keys"); |
michael@0 | 900 | |
michael@0 | 901 | ok(true, "Test group 22"); |
michael@0 | 902 | |
michael@0 | 903 | keyIndex = 5; |
michael@0 | 904 | |
michael@0 | 905 | request = objectStore.index("height").openKeyCursor(null, |
michael@0 | 906 | "prevunique"); |
michael@0 | 907 | request.onerror = errorHandler; |
michael@0 | 908 | request.onsuccess = function (event) { |
michael@0 | 909 | let cursor = event.target.result; |
michael@0 | 910 | if (cursor) { |
michael@0 | 911 | is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 912 | "Correct key"); |
michael@0 | 913 | is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, |
michael@0 | 914 | "Correct value"); |
michael@0 | 915 | |
michael@0 | 916 | cursor.continue(); |
michael@0 | 917 | if (keyIndex == 5) { |
michael@0 | 918 | keyIndex--; |
michael@0 | 919 | } |
michael@0 | 920 | keyIndex--; |
michael@0 | 921 | } |
michael@0 | 922 | else { |
michael@0 | 923 | testGenerator.next(); |
michael@0 | 924 | } |
michael@0 | 925 | } |
michael@0 | 926 | yield undefined; |
michael@0 | 927 | |
michael@0 | 928 | is(keyIndex, -1, "Saw all the expected keys"); |
michael@0 | 929 | |
michael@0 | 930 | ok(true, "Test group 23"); |
michael@0 | 931 | |
michael@0 | 932 | keyIndex = 3; |
michael@0 | 933 | keyRange = IDBKeyRange.only(65); |
michael@0 | 934 | |
michael@0 | 935 | request = objectStore.index("height").openCursor(keyRange, "next"); |
michael@0 | 936 | request.onerror = errorHandler; |
michael@0 | 937 | request.onsuccess = function (event) { |
michael@0 | 938 | let cursor = event.target.result; |
michael@0 | 939 | if (cursor) { |
michael@0 | 940 | is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 941 | "Correct key"); |
michael@0 | 942 | is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, |
michael@0 | 943 | "Correct primary key"); |
michael@0 | 944 | is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name, |
michael@0 | 945 | "Correct name"); |
michael@0 | 946 | is(cursor.value.height, |
michael@0 | 947 | objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 948 | "Correct height"); |
michael@0 | 949 | if ("weight" in cursor.value) { |
michael@0 | 950 | is(cursor.value.weight, |
michael@0 | 951 | objectStoreDataHeightSort[keyIndex].value.weight, |
michael@0 | 952 | "Correct weight"); |
michael@0 | 953 | } |
michael@0 | 954 | |
michael@0 | 955 | cursor.continue(); |
michael@0 | 956 | keyIndex++; |
michael@0 | 957 | } |
michael@0 | 958 | else { |
michael@0 | 959 | testGenerator.next(); |
michael@0 | 960 | } |
michael@0 | 961 | } |
michael@0 | 962 | yield undefined; |
michael@0 | 963 | |
michael@0 | 964 | is(keyIndex, 5, "Saw all the expected keys"); |
michael@0 | 965 | |
michael@0 | 966 | ok(true, "Test group 24"); |
michael@0 | 967 | |
michael@0 | 968 | keyIndex = 3; |
michael@0 | 969 | keyRange = IDBKeyRange.only(65); |
michael@0 | 970 | |
michael@0 | 971 | request = objectStore.index("height").openCursor(keyRange, |
michael@0 | 972 | "nextunique"); |
michael@0 | 973 | request.onerror = errorHandler; |
michael@0 | 974 | request.onsuccess = function (event) { |
michael@0 | 975 | let cursor = event.target.result; |
michael@0 | 976 | if (cursor) { |
michael@0 | 977 | is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 978 | "Correct key"); |
michael@0 | 979 | is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, |
michael@0 | 980 | "Correct primary key"); |
michael@0 | 981 | is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name, |
michael@0 | 982 | "Correct name"); |
michael@0 | 983 | is(cursor.value.height, |
michael@0 | 984 | objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 985 | "Correct height"); |
michael@0 | 986 | if ("weight" in cursor.value) { |
michael@0 | 987 | is(cursor.value.weight, |
michael@0 | 988 | objectStoreDataHeightSort[keyIndex].value.weight, |
michael@0 | 989 | "Correct weight"); |
michael@0 | 990 | } |
michael@0 | 991 | |
michael@0 | 992 | cursor.continue(); |
michael@0 | 993 | keyIndex++; |
michael@0 | 994 | } |
michael@0 | 995 | else { |
michael@0 | 996 | testGenerator.next(); |
michael@0 | 997 | } |
michael@0 | 998 | } |
michael@0 | 999 | yield undefined; |
michael@0 | 1000 | |
michael@0 | 1001 | is(keyIndex, 4, "Saw all the expected keys"); |
michael@0 | 1002 | |
michael@0 | 1003 | ok(true, "Test group 24.5"); |
michael@0 | 1004 | |
michael@0 | 1005 | keyIndex = 5; |
michael@0 | 1006 | |
michael@0 | 1007 | request = objectStore.index("height").openCursor(null, "prev"); |
michael@0 | 1008 | request.onerror = errorHandler; |
michael@0 | 1009 | request.onsuccess = function (event) { |
michael@0 | 1010 | let cursor = event.target.result; |
michael@0 | 1011 | if (cursor) { |
michael@0 | 1012 | is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 1013 | "Correct key"); |
michael@0 | 1014 | is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, |
michael@0 | 1015 | "Correct primary key"); |
michael@0 | 1016 | is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name, |
michael@0 | 1017 | "Correct name"); |
michael@0 | 1018 | is(cursor.value.height, |
michael@0 | 1019 | objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 1020 | "Correct height"); |
michael@0 | 1021 | if ("weight" in cursor.value) { |
michael@0 | 1022 | is(cursor.value.weight, |
michael@0 | 1023 | objectStoreDataHeightSort[keyIndex].value.weight, |
michael@0 | 1024 | "Correct weight"); |
michael@0 | 1025 | } |
michael@0 | 1026 | |
michael@0 | 1027 | cursor.continue(); |
michael@0 | 1028 | keyIndex--; |
michael@0 | 1029 | } |
michael@0 | 1030 | else { |
michael@0 | 1031 | testGenerator.next(); |
michael@0 | 1032 | } |
michael@0 | 1033 | } |
michael@0 | 1034 | yield undefined; |
michael@0 | 1035 | |
michael@0 | 1036 | is(keyIndex, -1, "Saw all the expected keys"); |
michael@0 | 1037 | |
michael@0 | 1038 | ok(true, "Test group 25"); |
michael@0 | 1039 | |
michael@0 | 1040 | keyIndex = 5; |
michael@0 | 1041 | |
michael@0 | 1042 | request = objectStore.index("height").openCursor(null, |
michael@0 | 1043 | "prevunique"); |
michael@0 | 1044 | request.onerror = errorHandler; |
michael@0 | 1045 | request.onsuccess = function (event) { |
michael@0 | 1046 | let cursor = event.target.result; |
michael@0 | 1047 | if (cursor) { |
michael@0 | 1048 | is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 1049 | "Correct key"); |
michael@0 | 1050 | is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, |
michael@0 | 1051 | "Correct primary key"); |
michael@0 | 1052 | is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name, |
michael@0 | 1053 | "Correct name"); |
michael@0 | 1054 | is(cursor.value.height, |
michael@0 | 1055 | objectStoreDataHeightSort[keyIndex].value.height, |
michael@0 | 1056 | "Correct height"); |
michael@0 | 1057 | if ("weight" in cursor.value) { |
michael@0 | 1058 | is(cursor.value.weight, |
michael@0 | 1059 | objectStoreDataHeightSort[keyIndex].value.weight, |
michael@0 | 1060 | "Correct weight"); |
michael@0 | 1061 | } |
michael@0 | 1062 | |
michael@0 | 1063 | cursor.continue(); |
michael@0 | 1064 | if (keyIndex == 5) { |
michael@0 | 1065 | keyIndex--; |
michael@0 | 1066 | } |
michael@0 | 1067 | keyIndex--; |
michael@0 | 1068 | } |
michael@0 | 1069 | else { |
michael@0 | 1070 | testGenerator.next(); |
michael@0 | 1071 | } |
michael@0 | 1072 | } |
michael@0 | 1073 | yield undefined; |
michael@0 | 1074 | |
michael@0 | 1075 | is(keyIndex, -1, "Saw all the expected keys"); |
michael@0 | 1076 | |
michael@0 | 1077 | ok(true, "Test group 26"); |
michael@0 | 1078 | |
michael@0 | 1079 | keyIndex = 0; |
michael@0 | 1080 | |
michael@0 | 1081 | request = objectStore.index("name").openKeyCursor(); |
michael@0 | 1082 | request.onerror = errorHandler; |
michael@0 | 1083 | request.onsuccess = function (event) { |
michael@0 | 1084 | let cursor = event.target.result; |
michael@0 | 1085 | if (cursor) { |
michael@0 | 1086 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1087 | "Correct key"); |
michael@0 | 1088 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 1089 | "Correct value"); |
michael@0 | 1090 | |
michael@0 | 1091 | let nextKey = !keyIndex ? "Pat" : undefined; |
michael@0 | 1092 | |
michael@0 | 1093 | cursor.continue(nextKey); |
michael@0 | 1094 | |
michael@0 | 1095 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1096 | "Correct key"); |
michael@0 | 1097 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 1098 | "Correct value"); |
michael@0 | 1099 | |
michael@0 | 1100 | if (!keyIndex) { |
michael@0 | 1101 | keyIndex = 3; |
michael@0 | 1102 | } |
michael@0 | 1103 | else { |
michael@0 | 1104 | keyIndex++; |
michael@0 | 1105 | } |
michael@0 | 1106 | } |
michael@0 | 1107 | else { |
michael@0 | 1108 | testGenerator.next(); |
michael@0 | 1109 | } |
michael@0 | 1110 | } |
michael@0 | 1111 | yield undefined; |
michael@0 | 1112 | |
michael@0 | 1113 | is(keyIndex, objectStoreData.length, "Saw all the expected keys"); |
michael@0 | 1114 | |
michael@0 | 1115 | ok(true, "Test group 27"); |
michael@0 | 1116 | |
michael@0 | 1117 | keyIndex = 0; |
michael@0 | 1118 | |
michael@0 | 1119 | request = objectStore.index("name").openKeyCursor(); |
michael@0 | 1120 | request.onerror = errorHandler; |
michael@0 | 1121 | request.onsuccess = function (event) { |
michael@0 | 1122 | let cursor = event.target.result; |
michael@0 | 1123 | if (cursor) { |
michael@0 | 1124 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1125 | "Correct key"); |
michael@0 | 1126 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 1127 | "Correct value"); |
michael@0 | 1128 | |
michael@0 | 1129 | let nextKey = !keyIndex ? "Flo" : undefined; |
michael@0 | 1130 | |
michael@0 | 1131 | cursor.continue(nextKey); |
michael@0 | 1132 | |
michael@0 | 1133 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1134 | "Correct key"); |
michael@0 | 1135 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 1136 | "Correct value"); |
michael@0 | 1137 | |
michael@0 | 1138 | keyIndex += keyIndex ? 1 : 2; |
michael@0 | 1139 | } |
michael@0 | 1140 | else { |
michael@0 | 1141 | testGenerator.next(); |
michael@0 | 1142 | } |
michael@0 | 1143 | } |
michael@0 | 1144 | yield undefined; |
michael@0 | 1145 | |
michael@0 | 1146 | is(keyIndex, objectStoreData.length, "Saw all the expected keys"); |
michael@0 | 1147 | |
michael@0 | 1148 | ok(true, "Test group 28"); |
michael@0 | 1149 | |
michael@0 | 1150 | keyIndex = 0; |
michael@0 | 1151 | |
michael@0 | 1152 | request = objectStore.index("name").openCursor(); |
michael@0 | 1153 | request.onerror = errorHandler; |
michael@0 | 1154 | request.onsuccess = function (event) { |
michael@0 | 1155 | let cursor = event.target.result; |
michael@0 | 1156 | if (cursor) { |
michael@0 | 1157 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1158 | "Correct key"); |
michael@0 | 1159 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 1160 | "Correct primary key"); |
michael@0 | 1161 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1162 | "Correct name"); |
michael@0 | 1163 | is(cursor.value.height, |
michael@0 | 1164 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 1165 | "Correct height"); |
michael@0 | 1166 | if ("weight" in cursor.value) { |
michael@0 | 1167 | is(cursor.value.weight, |
michael@0 | 1168 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 1169 | "Correct weight"); |
michael@0 | 1170 | } |
michael@0 | 1171 | |
michael@0 | 1172 | let nextKey = !keyIndex ? "Pat" : undefined; |
michael@0 | 1173 | |
michael@0 | 1174 | cursor.continue(nextKey); |
michael@0 | 1175 | |
michael@0 | 1176 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1177 | "Correct key"); |
michael@0 | 1178 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 1179 | "Correct primary key"); |
michael@0 | 1180 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1181 | "Correct name"); |
michael@0 | 1182 | is(cursor.value.height, |
michael@0 | 1183 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 1184 | "Correct height"); |
michael@0 | 1185 | if ("weight" in cursor.value) { |
michael@0 | 1186 | is(cursor.value.weight, |
michael@0 | 1187 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 1188 | "Correct weight"); |
michael@0 | 1189 | } |
michael@0 | 1190 | |
michael@0 | 1191 | if (!keyIndex) { |
michael@0 | 1192 | keyIndex = 3; |
michael@0 | 1193 | } |
michael@0 | 1194 | else { |
michael@0 | 1195 | keyIndex++; |
michael@0 | 1196 | } |
michael@0 | 1197 | } |
michael@0 | 1198 | else { |
michael@0 | 1199 | testGenerator.next(); |
michael@0 | 1200 | } |
michael@0 | 1201 | } |
michael@0 | 1202 | yield undefined; |
michael@0 | 1203 | |
michael@0 | 1204 | is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); |
michael@0 | 1205 | |
michael@0 | 1206 | ok(true, "Test group 29"); |
michael@0 | 1207 | |
michael@0 | 1208 | keyIndex = 0; |
michael@0 | 1209 | |
michael@0 | 1210 | request = objectStore.index("name").openCursor(); |
michael@0 | 1211 | request.onerror = errorHandler; |
michael@0 | 1212 | request.onsuccess = function (event) { |
michael@0 | 1213 | let cursor = event.target.result; |
michael@0 | 1214 | if (cursor) { |
michael@0 | 1215 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1216 | "Correct key"); |
michael@0 | 1217 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 1218 | "Correct primary key"); |
michael@0 | 1219 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1220 | "Correct name"); |
michael@0 | 1221 | is(cursor.value.height, |
michael@0 | 1222 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 1223 | "Correct height"); |
michael@0 | 1224 | if ("weight" in cursor.value) { |
michael@0 | 1225 | is(cursor.value.weight, |
michael@0 | 1226 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 1227 | "Correct weight"); |
michael@0 | 1228 | } |
michael@0 | 1229 | |
michael@0 | 1230 | let nextKey = !keyIndex ? "Flo" : undefined; |
michael@0 | 1231 | |
michael@0 | 1232 | cursor.continue(nextKey); |
michael@0 | 1233 | |
michael@0 | 1234 | is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1235 | "Correct key"); |
michael@0 | 1236 | is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
michael@0 | 1237 | "Correct primary key"); |
michael@0 | 1238 | is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, |
michael@0 | 1239 | "Correct name"); |
michael@0 | 1240 | is(cursor.value.height, |
michael@0 | 1241 | objectStoreDataNameSort[keyIndex].value.height, |
michael@0 | 1242 | "Correct height"); |
michael@0 | 1243 | if ("weight" in cursor.value) { |
michael@0 | 1244 | is(cursor.value.weight, |
michael@0 | 1245 | objectStoreDataNameSort[keyIndex].value.weight, |
michael@0 | 1246 | "Correct weight"); |
michael@0 | 1247 | } |
michael@0 | 1248 | |
michael@0 | 1249 | keyIndex += keyIndex ? 1 : 2; |
michael@0 | 1250 | } |
michael@0 | 1251 | else { |
michael@0 | 1252 | testGenerator.next(); |
michael@0 | 1253 | } |
michael@0 | 1254 | } |
michael@0 | 1255 | yield undefined; |
michael@0 | 1256 | |
michael@0 | 1257 | is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); |
michael@0 | 1258 | |
michael@0 | 1259 | finishTest(); |
michael@0 | 1260 | yield undefined; |
michael@0 | 1261 | } |