dom/indexedDB/test/unit/test_optionalArguments.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 osName = "people";
michael@0 11 const indexName = "weight";
michael@0 12
michael@0 13 const data = [
michael@0 14 { ssn: "237-23-7732", name: "Bob", height: 60, weight: 120 },
michael@0 15 { ssn: "237-23-7733", name: "Ann", height: 52, weight: 110 },
michael@0 16 { ssn: "237-23-7734", name: "Ron", height: 73, weight: 180 },
michael@0 17 { ssn: "237-23-7735", name: "Sue", height: 58, weight: 130 },
michael@0 18 { ssn: "237-23-7736", name: "Joe", height: 65, weight: 150 },
michael@0 19 { ssn: "237-23-7737", name: "Pat", height: 65 },
michael@0 20 { ssn: "237-23-7738", name: "Mel", height: 66, weight: {} },
michael@0 21 { ssn: "237-23-7739", name: "Tom", height: 62, weight: 130 }
michael@0 22 ];
michael@0 23
michael@0 24 const weightSort = [1, 0, 3, 7, 4, 2];
michael@0 25
michael@0 26 let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
michael@0 27 request.onerror = errorHandler;
michael@0 28 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 29 request.onsuccess = grabEventAndContinueHandler;
michael@0 30 let event = yield undefined;
michael@0 31
michael@0 32 is(event.type, "upgradeneeded", "Got upgradeneeded event");
michael@0 33
michael@0 34 let db = event.target.result;
michael@0 35 db.onerror = errorHandler;
michael@0 36
michael@0 37 let objectStore = db.createObjectStore(osName, { keyPath: "ssn" });
michael@0 38 objectStore.createIndex(indexName, "weight", { unique: false });
michael@0 39
michael@0 40 for each (let i in data) {
michael@0 41 objectStore.add(i);
michael@0 42 }
michael@0 43
michael@0 44 event = yield undefined;
michael@0 45
michael@0 46 is(event.type, "success", "Got success event");
michael@0 47
michael@0 48 try {
michael@0 49 IDBKeyRange.bound(1, -1);
michael@0 50 ok(false, "Bound keyRange with backwards args should throw!");
michael@0 51 }
michael@0 52 catch (e) {
michael@0 53 is(e.name, "DataError", "Threw correct exception");
michael@0 54 is(e.code, 0, "Threw with correct code");
michael@0 55 }
michael@0 56
michael@0 57 try {
michael@0 58 IDBKeyRange.bound(1, 1);
michael@0 59 ok(true, "Bound keyRange with same arg should be ok");
michael@0 60 }
michael@0 61 catch (e) {
michael@0 62 ok(false, "Bound keyRange with same arg should have been ok");
michael@0 63 }
michael@0 64
michael@0 65 try {
michael@0 66 IDBKeyRange.bound(1, 1, true);
michael@0 67 ok(false, "Bound keyRange with same arg and open should throw!");
michael@0 68 }
michael@0 69 catch (e) {
michael@0 70 is(e.name, "DataError", "Threw correct exception");
michael@0 71 is(e.code, 0, "Threw with correct code");
michael@0 72 }
michael@0 73
michael@0 74 try {
michael@0 75 IDBKeyRange.bound(1, 1, true, true);
michael@0 76 ok(false, "Bound keyRange with same arg and open should throw!");
michael@0 77 }
michael@0 78 catch (e) {
michael@0 79 is(e.name, "DataError", "Threw correct exception");
michael@0 80 is(e.code, 0, "Threw with correct code");
michael@0 81 }
michael@0 82
michael@0 83 objectStore = db.transaction(osName).objectStore(osName);
michael@0 84
michael@0 85 try {
michael@0 86 objectStore.get();
michael@0 87 ok(false, "Get with unspecified arg should have thrown");
michael@0 88 }
michael@0 89 catch(e) {
michael@0 90 ok(true, "Get with unspecified arg should have thrown");
michael@0 91 }
michael@0 92
michael@0 93 try {
michael@0 94 objectStore.get(undefined);
michael@0 95 ok(false, "Get with undefined should have thrown");
michael@0 96 }
michael@0 97 catch(e) {
michael@0 98 ok(true, "Get with undefined arg should have thrown");
michael@0 99 }
michael@0 100
michael@0 101 try {
michael@0 102 objectStore.get(null);
michael@0 103 ok(false, "Get with null should have thrown");
michael@0 104 }
michael@0 105 catch(e) {
michael@0 106 is(e instanceof DOMException, true,
michael@0 107 "Got right kind of exception");
michael@0 108 is(e.name, "DataError", "Correct error.");
michael@0 109 is(e.code, 0, "Correct code.");
michael@0 110 }
michael@0 111
michael@0 112 objectStore.get(data[2].ssn).onsuccess = grabEventAndContinueHandler;
michael@0 113 event = yield undefined;
michael@0 114
michael@0 115 is(event.target.result.name, data[2].name, "Correct data");
michael@0 116
michael@0 117 let keyRange = IDBKeyRange.only(data[2].ssn);
michael@0 118
michael@0 119 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 120 event = yield undefined;
michael@0 121
michael@0 122 is(event.target.result.name, data[2].name, "Correct data");
michael@0 123
michael@0 124 keyRange = IDBKeyRange.lowerBound(data[2].ssn);
michael@0 125
michael@0 126 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 127 event = yield undefined;
michael@0 128
michael@0 129 is(event.target.result.name, data[2].name, "Correct data");
michael@0 130
michael@0 131 keyRange = IDBKeyRange.lowerBound(data[2].ssn, true);
michael@0 132
michael@0 133 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 134 event = yield undefined;
michael@0 135
michael@0 136 is(event.target.result.name, data[3].name, "Correct data");
michael@0 137
michael@0 138 keyRange = IDBKeyRange.upperBound(data[2].ssn);
michael@0 139
michael@0 140 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 141 event = yield undefined;
michael@0 142
michael@0 143 is(event.target.result.name, data[0].name, "Correct data");
michael@0 144
michael@0 145 keyRange = IDBKeyRange.bound(data[2].ssn, data[4].ssn);
michael@0 146
michael@0 147 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 148 event = yield undefined;
michael@0 149
michael@0 150 is(event.target.result.name, data[2].name, "Correct data");
michael@0 151
michael@0 152 keyRange = IDBKeyRange.bound(data[2].ssn, data[4].ssn, true);
michael@0 153
michael@0 154 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 155 event = yield undefined;
michael@0 156
michael@0 157 is(event.target.result.name, data[3].name, "Correct data");
michael@0 158
michael@0 159 objectStore = db.transaction(osName, "readwrite")
michael@0 160 .objectStore(osName);
michael@0 161
michael@0 162 try {
michael@0 163 objectStore.delete();
michael@0 164 ok(false, "Delete with unspecified arg should have thrown");
michael@0 165 }
michael@0 166 catch(e) {
michael@0 167 ok(true, "Delete with unspecified arg should have thrown");
michael@0 168 }
michael@0 169
michael@0 170 try {
michael@0 171 objectStore.delete(undefined);
michael@0 172 ok(false, "Delete with undefined should have thrown");
michael@0 173 }
michael@0 174 catch(e) {
michael@0 175 ok(true, "Delete with undefined arg should have thrown");
michael@0 176 }
michael@0 177
michael@0 178 try {
michael@0 179 objectStore.delete(null);
michael@0 180 ok(false, "Delete with null should have thrown");
michael@0 181 }
michael@0 182 catch(e) {
michael@0 183 is(e instanceof DOMException, true,
michael@0 184 "Got right kind of exception");
michael@0 185 is(e.name, "DataError", "Correct error.");
michael@0 186 is(e.code, 0, "Correct code.");
michael@0 187 }
michael@0 188
michael@0 189 objectStore.count().onsuccess = grabEventAndContinueHandler;
michael@0 190 event = yield undefined;
michael@0 191
michael@0 192 is(event.target.result, data.length, "Correct count");
michael@0 193
michael@0 194 objectStore.delete(data[2].ssn).onsuccess = grabEventAndContinueHandler;
michael@0 195 event = yield undefined;
michael@0 196
michael@0 197 ok(event.target.result === undefined, "Correct result");
michael@0 198
michael@0 199 objectStore.count().onsuccess = grabEventAndContinueHandler;
michael@0 200 event = yield undefined;
michael@0 201
michael@0 202 is(event.target.result, data.length - 1, "Correct count");
michael@0 203
michael@0 204 keyRange = IDBKeyRange.bound(data[3].ssn, data[5].ssn);
michael@0 205
michael@0 206 objectStore.delete(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 207 event = yield undefined;
michael@0 208
michael@0 209 ok(event.target.result === undefined, "Correct result");
michael@0 210
michael@0 211 objectStore.count().onsuccess = grabEventAndContinueHandler;
michael@0 212 event = yield undefined;
michael@0 213
michael@0 214 is(event.target.result, data.length - 4, "Correct count");
michael@0 215
michael@0 216 keyRange = IDBKeyRange.lowerBound(10);
michael@0 217
michael@0 218 objectStore.delete(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 219 event = yield undefined;
michael@0 220
michael@0 221 ok(event.target.result === undefined, "Correct result");
michael@0 222
michael@0 223 objectStore.count().onsuccess = grabEventAndContinueHandler;
michael@0 224 event = yield undefined;
michael@0 225
michael@0 226 is(event.target.result, 0, "Correct count");
michael@0 227
michael@0 228 event.target.transaction.oncomplete = grabEventAndContinueHandler;
michael@0 229
michael@0 230 for each (let i in data) {
michael@0 231 objectStore.add(i);
michael@0 232 }
michael@0 233
michael@0 234 yield undefined;
michael@0 235
michael@0 236 objectStore = db.transaction(osName).objectStore(osName);
michael@0 237
michael@0 238 objectStore.count().onsuccess = grabEventAndContinueHandler;
michael@0 239 event = yield undefined;
michael@0 240
michael@0 241 is(event.target.result, data.length, "Correct count");
michael@0 242
michael@0 243 let count = 0;
michael@0 244
michael@0 245 objectStore.openCursor().onsuccess = function(event) {
michael@0 246 let cursor = event.target.result;
michael@0 247 if (cursor) {
michael@0 248 count++;
michael@0 249 cursor.continue();
michael@0 250 }
michael@0 251 else {
michael@0 252 testGenerator.next();
michael@0 253 }
michael@0 254 }
michael@0 255 yield undefined;
michael@0 256
michael@0 257 is(count, data.length, "Correct count for no arg to openCursor");
michael@0 258
michael@0 259 count = 0;
michael@0 260
michael@0 261 objectStore.openCursor(null).onsuccess = function(event) {
michael@0 262 let cursor = event.target.result;
michael@0 263 if (cursor) {
michael@0 264 count++;
michael@0 265 cursor.continue();
michael@0 266 }
michael@0 267 else {
michael@0 268 testGenerator.next();
michael@0 269 }
michael@0 270 }
michael@0 271 yield undefined;
michael@0 272
michael@0 273 is(count, data.length, "Correct count for null arg to openCursor");
michael@0 274
michael@0 275 count = 0;
michael@0 276
michael@0 277 objectStore.openCursor(undefined).onsuccess = function(event) {
michael@0 278 let cursor = event.target.result;
michael@0 279 if (cursor) {
michael@0 280 count++;
michael@0 281 cursor.continue();
michael@0 282 }
michael@0 283 else {
michael@0 284 testGenerator.next();
michael@0 285 }
michael@0 286 }
michael@0 287 yield undefined;
michael@0 288
michael@0 289 is(count, data.length, "Correct count for undefined arg to openCursor");
michael@0 290
michael@0 291 count = 0;
michael@0 292
michael@0 293 objectStore.openCursor(data[2].ssn).onsuccess = function(event) {
michael@0 294 let cursor = event.target.result;
michael@0 295 if (cursor) {
michael@0 296 count++;
michael@0 297 cursor.continue();
michael@0 298 }
michael@0 299 else {
michael@0 300 testGenerator.next();
michael@0 301 }
michael@0 302 }
michael@0 303 yield undefined;
michael@0 304
michael@0 305 is(count, 1, "Correct count for single key arg to openCursor");
michael@0 306
michael@0 307 count = 0;
michael@0 308
michael@0 309 objectStore.openCursor("foo").onsuccess = function(event) {
michael@0 310 let cursor = event.target.result;
michael@0 311 if (cursor) {
michael@0 312 count++;
michael@0 313 cursor.continue();
michael@0 314 }
michael@0 315 else {
michael@0 316 testGenerator.next();
michael@0 317 }
michael@0 318 }
michael@0 319 yield undefined;
michael@0 320
michael@0 321 is(count, 0,
michael@0 322 "Correct count for non-existent single key arg to openCursor");
michael@0 323
michael@0 324 count = 0;
michael@0 325 keyRange = IDBKeyRange.only(data[2].ssn);
michael@0 326
michael@0 327 objectStore.openCursor(keyRange).onsuccess = function(event) {
michael@0 328 let cursor = event.target.result;
michael@0 329 if (cursor) {
michael@0 330 count++;
michael@0 331 cursor.continue();
michael@0 332 }
michael@0 333 else {
michael@0 334 testGenerator.next();
michael@0 335 }
michael@0 336 }
michael@0 337 yield undefined;
michael@0 338
michael@0 339 is(count, 1, "Correct count for only keyRange arg to openCursor");
michael@0 340
michael@0 341 count = 0;
michael@0 342 keyRange = IDBKeyRange.lowerBound(data[2].ssn);
michael@0 343
michael@0 344 objectStore.openCursor(keyRange).onsuccess = function(event) {
michael@0 345 let cursor = event.target.result;
michael@0 346 if (cursor) {
michael@0 347 count++;
michael@0 348 cursor.continue();
michael@0 349 }
michael@0 350 else {
michael@0 351 testGenerator.next();
michael@0 352 }
michael@0 353 }
michael@0 354 yield undefined;
michael@0 355
michael@0 356 is(count, data.length - 2,
michael@0 357 "Correct count for lowerBound arg to openCursor");
michael@0 358
michael@0 359 count = 0;
michael@0 360 keyRange = IDBKeyRange.lowerBound(data[2].ssn, true);
michael@0 361
michael@0 362 objectStore.openCursor(keyRange).onsuccess = function(event) {
michael@0 363 let cursor = event.target.result;
michael@0 364 if (cursor) {
michael@0 365 count++;
michael@0 366 cursor.continue();
michael@0 367 }
michael@0 368 else {
michael@0 369 testGenerator.next();
michael@0 370 }
michael@0 371 }
michael@0 372 yield undefined;
michael@0 373
michael@0 374 is(count, data.length - 3,
michael@0 375 "Correct count for lowerBound arg to openCursor");
michael@0 376
michael@0 377 count = 0;
michael@0 378 keyRange = IDBKeyRange.lowerBound("foo");
michael@0 379
michael@0 380 objectStore.openCursor(keyRange).onsuccess = function(event) {
michael@0 381 let cursor = event.target.result;
michael@0 382 if (cursor) {
michael@0 383 count++;
michael@0 384 cursor.continue();
michael@0 385 }
michael@0 386 else {
michael@0 387 testGenerator.next();
michael@0 388 }
michael@0 389 }
michael@0 390 yield undefined;
michael@0 391
michael@0 392 is(count, 0,
michael@0 393 "Correct count for non-existent lowerBound arg to openCursor");
michael@0 394
michael@0 395 count = 0;
michael@0 396 keyRange = IDBKeyRange.bound(data[2].ssn, data[3].ssn);
michael@0 397
michael@0 398 objectStore.openCursor(keyRange).onsuccess = function(event) {
michael@0 399 let cursor = event.target.result;
michael@0 400 if (cursor) {
michael@0 401 count++;
michael@0 402 cursor.continue();
michael@0 403 }
michael@0 404 else {
michael@0 405 testGenerator.next();
michael@0 406 }
michael@0 407 }
michael@0 408 yield undefined;
michael@0 409
michael@0 410 is(count, 2, "Correct count for bound arg to openCursor");
michael@0 411
michael@0 412 count = 0;
michael@0 413 keyRange = IDBKeyRange.bound(data[2].ssn, data[3].ssn, true);
michael@0 414
michael@0 415 objectStore.openCursor(keyRange).onsuccess = function(event) {
michael@0 416 let cursor = event.target.result;
michael@0 417 if (cursor) {
michael@0 418 count++;
michael@0 419 cursor.continue();
michael@0 420 }
michael@0 421 else {
michael@0 422 testGenerator.next();
michael@0 423 }
michael@0 424 }
michael@0 425 yield undefined;
michael@0 426
michael@0 427 is(count, 1, "Correct count for bound arg to openCursor");
michael@0 428
michael@0 429 count = 0;
michael@0 430 keyRange = IDBKeyRange.bound(data[2].ssn, data[3].ssn, true, true);
michael@0 431
michael@0 432 objectStore.openCursor(keyRange).onsuccess = function(event) {
michael@0 433 let cursor = event.target.result;
michael@0 434 if (cursor) {
michael@0 435 count++;
michael@0 436 cursor.continue();
michael@0 437 }
michael@0 438 else {
michael@0 439 testGenerator.next();
michael@0 440 }
michael@0 441 }
michael@0 442 yield undefined;
michael@0 443
michael@0 444 is(count, 0, "Correct count for bound arg to openCursor");
michael@0 445
michael@0 446 let index = objectStore.index(indexName);
michael@0 447
michael@0 448 count = 0;
michael@0 449
michael@0 450 index.openKeyCursor().onsuccess = function(event) {
michael@0 451 let cursor = event.target.result;
michael@0 452 if (cursor) {
michael@0 453 count++;
michael@0 454 cursor.continue();
michael@0 455 }
michael@0 456 else {
michael@0 457 testGenerator.next();
michael@0 458 }
michael@0 459 }
michael@0 460 yield undefined;
michael@0 461
michael@0 462 is(count, weightSort.length,
michael@0 463 "Correct count for unspecified arg to index.openKeyCursor");
michael@0 464
michael@0 465 count = 0;
michael@0 466
michael@0 467 index.openKeyCursor(null).onsuccess = function(event) {
michael@0 468 let cursor = event.target.result;
michael@0 469 if (cursor) {
michael@0 470 count++;
michael@0 471 cursor.continue();
michael@0 472 }
michael@0 473 else {
michael@0 474 testGenerator.next();
michael@0 475 }
michael@0 476 }
michael@0 477 yield undefined;
michael@0 478
michael@0 479 is(count, weightSort.length,
michael@0 480 "Correct count for null arg to index.openKeyCursor");
michael@0 481
michael@0 482 count = 0;
michael@0 483
michael@0 484 index.openKeyCursor(undefined).onsuccess = function(event) {
michael@0 485 let cursor = event.target.result;
michael@0 486 if (cursor) {
michael@0 487 count++;
michael@0 488 cursor.continue();
michael@0 489 }
michael@0 490 else {
michael@0 491 testGenerator.next();
michael@0 492 }
michael@0 493 }
michael@0 494 yield undefined;
michael@0 495
michael@0 496 is(count, weightSort.length,
michael@0 497 "Correct count for undefined arg to index.openKeyCursor");
michael@0 498
michael@0 499 count = 0;
michael@0 500
michael@0 501 index.openKeyCursor(data[0].weight).onsuccess = function(event) {
michael@0 502 let cursor = event.target.result;
michael@0 503 if (cursor) {
michael@0 504 count++;
michael@0 505 cursor.continue();
michael@0 506 }
michael@0 507 else {
michael@0 508 testGenerator.next();
michael@0 509 }
michael@0 510 }
michael@0 511 yield undefined;
michael@0 512
michael@0 513 is(count, 1, "Correct count for single key arg to index.openKeyCursor");
michael@0 514
michael@0 515 count = 0;
michael@0 516
michael@0 517 index.openKeyCursor("foo").onsuccess = function(event) {
michael@0 518 let cursor = event.target.result;
michael@0 519 if (cursor) {
michael@0 520 count++;
michael@0 521 cursor.continue();
michael@0 522 }
michael@0 523 else {
michael@0 524 testGenerator.next();
michael@0 525 }
michael@0 526 }
michael@0 527 yield undefined;
michael@0 528
michael@0 529 is(count, 0,
michael@0 530 "Correct count for non-existent key arg to index.openKeyCursor");
michael@0 531
michael@0 532 count = 0;
michael@0 533 keyRange = IDBKeyRange.only("foo");
michael@0 534
michael@0 535 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 536 let cursor = event.target.result;
michael@0 537 if (cursor) {
michael@0 538 count++;
michael@0 539 cursor.continue();
michael@0 540 }
michael@0 541 else {
michael@0 542 testGenerator.next();
michael@0 543 }
michael@0 544 }
michael@0 545 yield undefined;
michael@0 546
michael@0 547 is(count, 0,
michael@0 548 "Correct count for non-existent keyRange arg to index.openKeyCursor");
michael@0 549
michael@0 550 count = 0;
michael@0 551 keyRange = IDBKeyRange.only(data[0].weight);
michael@0 552
michael@0 553 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 554 let cursor = event.target.result;
michael@0 555 if (cursor) {
michael@0 556 count++;
michael@0 557 cursor.continue();
michael@0 558 }
michael@0 559 else {
michael@0 560 testGenerator.next();
michael@0 561 }
michael@0 562 }
michael@0 563 yield undefined;
michael@0 564
michael@0 565 is(count, 1,
michael@0 566 "Correct count for only keyRange arg to index.openKeyCursor");
michael@0 567
michael@0 568 count = 0;
michael@0 569 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight);
michael@0 570
michael@0 571 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 572 let cursor = event.target.result;
michael@0 573 if (cursor) {
michael@0 574 count++;
michael@0 575 cursor.continue();
michael@0 576 }
michael@0 577 else {
michael@0 578 testGenerator.next();
michael@0 579 }
michael@0 580 }
michael@0 581 yield undefined;
michael@0 582
michael@0 583 is(count, weightSort.length,
michael@0 584 "Correct count for lowerBound keyRange arg to index.openKeyCursor");
michael@0 585
michael@0 586 count = 0;
michael@0 587 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true);
michael@0 588
michael@0 589 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 590 let cursor = event.target.result;
michael@0 591 if (cursor) {
michael@0 592 count++;
michael@0 593 cursor.continue();
michael@0 594 }
michael@0 595 else {
michael@0 596 testGenerator.next();
michael@0 597 }
michael@0 598 }
michael@0 599 yield undefined;
michael@0 600
michael@0 601 is(count, weightSort.length - 1,
michael@0 602 "Correct count for lowerBound keyRange arg to index.openKeyCursor");
michael@0 603
michael@0 604 count = 0;
michael@0 605 keyRange = IDBKeyRange.lowerBound("foo");
michael@0 606
michael@0 607 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 608 let cursor = event.target.result;
michael@0 609 if (cursor) {
michael@0 610 count++;
michael@0 611 cursor.continue();
michael@0 612 }
michael@0 613 else {
michael@0 614 testGenerator.next();
michael@0 615 }
michael@0 616 }
michael@0 617 yield undefined;
michael@0 618
michael@0 619 is(count, 0,
michael@0 620 "Correct count for lowerBound keyRange arg to index.openKeyCursor");
michael@0 621
michael@0 622 count = 0;
michael@0 623 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight);
michael@0 624
michael@0 625 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 626 let cursor = event.target.result;
michael@0 627 if (cursor) {
michael@0 628 count++;
michael@0 629 cursor.continue();
michael@0 630 }
michael@0 631 else {
michael@0 632 testGenerator.next();
michael@0 633 }
michael@0 634 }
michael@0 635 yield undefined;
michael@0 636
michael@0 637 is(count, 1,
michael@0 638 "Correct count for upperBound keyRange arg to index.openKeyCursor");
michael@0 639
michael@0 640 count = 0;
michael@0 641 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true);
michael@0 642
michael@0 643 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 644 let cursor = event.target.result;
michael@0 645 if (cursor) {
michael@0 646 count++;
michael@0 647 cursor.continue();
michael@0 648 }
michael@0 649 else {
michael@0 650 testGenerator.next();
michael@0 651 }
michael@0 652 }
michael@0 653 yield undefined;
michael@0 654
michael@0 655 is(count, 0,
michael@0 656 "Correct count for upperBound keyRange arg to index.openKeyCursor");
michael@0 657
michael@0 658 count = 0;
michael@0 659 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight);
michael@0 660
michael@0 661 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 662 let cursor = event.target.result;
michael@0 663 if (cursor) {
michael@0 664 count++;
michael@0 665 cursor.continue();
michael@0 666 }
michael@0 667 else {
michael@0 668 testGenerator.next();
michael@0 669 }
michael@0 670 }
michael@0 671 yield undefined;
michael@0 672
michael@0 673 is(count, weightSort.length,
michael@0 674 "Correct count for upperBound keyRange arg to index.openKeyCursor");
michael@0 675
michael@0 676 count = 0;
michael@0 677 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight,
michael@0 678 true);
michael@0 679
michael@0 680 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 681 let cursor = event.target.result;
michael@0 682 if (cursor) {
michael@0 683 count++;
michael@0 684 cursor.continue();
michael@0 685 }
michael@0 686 else {
michael@0 687 testGenerator.next();
michael@0 688 }
michael@0 689 }
michael@0 690 yield undefined;
michael@0 691
michael@0 692 is(count, weightSort.length - 1,
michael@0 693 "Correct count for upperBound keyRange arg to index.openKeyCursor");
michael@0 694
michael@0 695 count = 0;
michael@0 696 keyRange = IDBKeyRange.upperBound("foo");
michael@0 697
michael@0 698 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 699 let cursor = event.target.result;
michael@0 700 if (cursor) {
michael@0 701 count++;
michael@0 702 cursor.continue();
michael@0 703 }
michael@0 704 else {
michael@0 705 testGenerator.next();
michael@0 706 }
michael@0 707 }
michael@0 708 yield undefined;
michael@0 709
michael@0 710 is(count, weightSort.length,
michael@0 711 "Correct count for upperBound keyRange arg to index.openKeyCursor");
michael@0 712
michael@0 713 count = 0;
michael@0 714 keyRange = IDBKeyRange.upperBound(0);
michael@0 715
michael@0 716 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 717 let cursor = event.target.result;
michael@0 718 if (cursor) {
michael@0 719 count++;
michael@0 720 cursor.continue();
michael@0 721 }
michael@0 722 else {
michael@0 723 testGenerator.next();
michael@0 724 }
michael@0 725 }
michael@0 726 yield undefined;
michael@0 727
michael@0 728 is(count, 0,
michael@0 729 "Correct count for upperBound keyRange arg to index.openKeyCursor");
michael@0 730
michael@0 731 count = 0;
michael@0 732 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 733 data[weightSort[weightSort.length - 1]].weight);
michael@0 734
michael@0 735 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 736 let cursor = event.target.result;
michael@0 737 if (cursor) {
michael@0 738 count++;
michael@0 739 cursor.continue();
michael@0 740 }
michael@0 741 else {
michael@0 742 testGenerator.next();
michael@0 743 }
michael@0 744 }
michael@0 745 yield undefined;
michael@0 746
michael@0 747 is(count, weightSort.length,
michael@0 748 "Correct count for bound keyRange arg to index.openKeyCursor");
michael@0 749
michael@0 750 count = 0;
michael@0 751 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 752 data[weightSort[weightSort.length - 1]].weight,
michael@0 753 true);
michael@0 754
michael@0 755 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 756 let cursor = event.target.result;
michael@0 757 if (cursor) {
michael@0 758 count++;
michael@0 759 cursor.continue();
michael@0 760 }
michael@0 761 else {
michael@0 762 testGenerator.next();
michael@0 763 }
michael@0 764 }
michael@0 765 yield undefined;
michael@0 766
michael@0 767 is(count, weightSort.length - 1,
michael@0 768 "Correct count for bound keyRange arg to index.openKeyCursor");
michael@0 769
michael@0 770 count = 0;
michael@0 771 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 772 data[weightSort[weightSort.length - 1]].weight,
michael@0 773 true, true);
michael@0 774
michael@0 775 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 776 let cursor = event.target.result;
michael@0 777 if (cursor) {
michael@0 778 count++;
michael@0 779 cursor.continue();
michael@0 780 }
michael@0 781 else {
michael@0 782 testGenerator.next();
michael@0 783 }
michael@0 784 }
michael@0 785 yield undefined;
michael@0 786
michael@0 787 is(count, weightSort.length - 2,
michael@0 788 "Correct count for bound keyRange arg to index.openKeyCursor");
michael@0 789
michael@0 790 count = 0;
michael@0 791 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 1,
michael@0 792 data[weightSort[weightSort.length - 1]].weight + 1);
michael@0 793
michael@0 794 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 795 let cursor = event.target.result;
michael@0 796 if (cursor) {
michael@0 797 count++;
michael@0 798 cursor.continue();
michael@0 799 }
michael@0 800 else {
michael@0 801 testGenerator.next();
michael@0 802 }
michael@0 803 }
michael@0 804 yield undefined;
michael@0 805
michael@0 806 is(count, weightSort.length,
michael@0 807 "Correct count for bound keyRange arg to index.openKeyCursor");
michael@0 808
michael@0 809 count = 0;
michael@0 810 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 2,
michael@0 811 data[weightSort[0]].weight - 1);
michael@0 812
michael@0 813 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 814 let cursor = event.target.result;
michael@0 815 if (cursor) {
michael@0 816 count++;
michael@0 817 cursor.continue();
michael@0 818 }
michael@0 819 else {
michael@0 820 testGenerator.next();
michael@0 821 }
michael@0 822 }
michael@0 823 yield undefined;
michael@0 824
michael@0 825 is(count, 0,
michael@0 826 "Correct count for bound keyRange arg to index.openKeyCursor");
michael@0 827
michael@0 828 count = 0;
michael@0 829 keyRange = IDBKeyRange.bound(data[weightSort[1]].weight,
michael@0 830 data[weightSort[2]].weight);
michael@0 831
michael@0 832 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 833 let cursor = event.target.result;
michael@0 834 if (cursor) {
michael@0 835 count++;
michael@0 836 cursor.continue();
michael@0 837 }
michael@0 838 else {
michael@0 839 testGenerator.next();
michael@0 840 }
michael@0 841 }
michael@0 842 yield undefined;
michael@0 843
michael@0 844 is(count, 3,
michael@0 845 "Correct count for bound keyRange arg to index.openKeyCursor");
michael@0 846
michael@0 847 count = 0;
michael@0 848
michael@0 849 index.openCursor().onsuccess = function(event) {
michael@0 850 let cursor = event.target.result;
michael@0 851 if (cursor) {
michael@0 852 count++;
michael@0 853 cursor.continue();
michael@0 854 }
michael@0 855 else {
michael@0 856 testGenerator.next();
michael@0 857 }
michael@0 858 }
michael@0 859 yield undefined;
michael@0 860
michael@0 861 is(count, weightSort.length,
michael@0 862 "Correct count for unspecified arg to index.openCursor");
michael@0 863
michael@0 864 count = 0;
michael@0 865
michael@0 866 index.openCursor(null).onsuccess = function(event) {
michael@0 867 let cursor = event.target.result;
michael@0 868 if (cursor) {
michael@0 869 count++;
michael@0 870 cursor.continue();
michael@0 871 }
michael@0 872 else {
michael@0 873 testGenerator.next();
michael@0 874 }
michael@0 875 }
michael@0 876 yield undefined;
michael@0 877
michael@0 878 is(count, weightSort.length,
michael@0 879 "Correct count for null arg to index.openCursor");
michael@0 880
michael@0 881 count = 0;
michael@0 882
michael@0 883 index.openCursor(undefined).onsuccess = function(event) {
michael@0 884 let cursor = event.target.result;
michael@0 885 if (cursor) {
michael@0 886 count++;
michael@0 887 cursor.continue();
michael@0 888 }
michael@0 889 else {
michael@0 890 testGenerator.next();
michael@0 891 }
michael@0 892 }
michael@0 893 yield undefined;
michael@0 894
michael@0 895 is(count, weightSort.length,
michael@0 896 "Correct count for undefined arg to index.openCursor");
michael@0 897
michael@0 898 count = 0;
michael@0 899
michael@0 900 index.openCursor(data[0].weight).onsuccess = function(event) {
michael@0 901 let cursor = event.target.result;
michael@0 902 if (cursor) {
michael@0 903 count++;
michael@0 904 cursor.continue();
michael@0 905 }
michael@0 906 else {
michael@0 907 testGenerator.next();
michael@0 908 }
michael@0 909 }
michael@0 910 yield undefined;
michael@0 911
michael@0 912 is(count, 1, "Correct count for single key arg to index.openCursor");
michael@0 913
michael@0 914 count = 0;
michael@0 915
michael@0 916 index.openCursor("foo").onsuccess = function(event) {
michael@0 917 let cursor = event.target.result;
michael@0 918 if (cursor) {
michael@0 919 count++;
michael@0 920 cursor.continue();
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(count, 0,
michael@0 929 "Correct count for non-existent key arg to index.openCursor");
michael@0 930
michael@0 931 count = 0;
michael@0 932 keyRange = IDBKeyRange.only("foo");
michael@0 933
michael@0 934 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 935 let cursor = event.target.result;
michael@0 936 if (cursor) {
michael@0 937 count++;
michael@0 938 cursor.continue();
michael@0 939 }
michael@0 940 else {
michael@0 941 testGenerator.next();
michael@0 942 }
michael@0 943 }
michael@0 944 yield undefined;
michael@0 945
michael@0 946 is(count, 0,
michael@0 947 "Correct count for non-existent keyRange arg to index.openCursor");
michael@0 948
michael@0 949 count = 0;
michael@0 950 keyRange = IDBKeyRange.only(data[0].weight);
michael@0 951
michael@0 952 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 953 let cursor = event.target.result;
michael@0 954 if (cursor) {
michael@0 955 count++;
michael@0 956 cursor.continue();
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(count, 1,
michael@0 965 "Correct count for only keyRange arg to index.openCursor");
michael@0 966
michael@0 967 count = 0;
michael@0 968 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight);
michael@0 969
michael@0 970 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 971 let cursor = event.target.result;
michael@0 972 if (cursor) {
michael@0 973 count++;
michael@0 974 cursor.continue();
michael@0 975 }
michael@0 976 else {
michael@0 977 testGenerator.next();
michael@0 978 }
michael@0 979 }
michael@0 980 yield undefined;
michael@0 981
michael@0 982 is(count, weightSort.length,
michael@0 983 "Correct count for lowerBound keyRange arg to index.openCursor");
michael@0 984
michael@0 985 count = 0;
michael@0 986 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true);
michael@0 987
michael@0 988 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 989 let cursor = event.target.result;
michael@0 990 if (cursor) {
michael@0 991 count++;
michael@0 992 cursor.continue();
michael@0 993 }
michael@0 994 else {
michael@0 995 testGenerator.next();
michael@0 996 }
michael@0 997 }
michael@0 998 yield undefined;
michael@0 999
michael@0 1000 is(count, weightSort.length - 1,
michael@0 1001 "Correct count for lowerBound keyRange arg to index.openCursor");
michael@0 1002
michael@0 1003 count = 0;
michael@0 1004 keyRange = IDBKeyRange.lowerBound("foo");
michael@0 1005
michael@0 1006 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1007 let cursor = event.target.result;
michael@0 1008 if (cursor) {
michael@0 1009 count++;
michael@0 1010 cursor.continue();
michael@0 1011 }
michael@0 1012 else {
michael@0 1013 testGenerator.next();
michael@0 1014 }
michael@0 1015 }
michael@0 1016 yield undefined;
michael@0 1017
michael@0 1018 is(count, 0,
michael@0 1019 "Correct count for lowerBound keyRange arg to index.openCursor");
michael@0 1020
michael@0 1021 count = 0;
michael@0 1022 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight);
michael@0 1023
michael@0 1024 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1025 let cursor = event.target.result;
michael@0 1026 if (cursor) {
michael@0 1027 count++;
michael@0 1028 cursor.continue();
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(count, 1,
michael@0 1037 "Correct count for upperBound keyRange arg to index.openCursor");
michael@0 1038
michael@0 1039 count = 0;
michael@0 1040 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true);
michael@0 1041
michael@0 1042 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1043 let cursor = event.target.result;
michael@0 1044 if (cursor) {
michael@0 1045 count++;
michael@0 1046 cursor.continue();
michael@0 1047 }
michael@0 1048 else {
michael@0 1049 testGenerator.next();
michael@0 1050 }
michael@0 1051 }
michael@0 1052 yield undefined;
michael@0 1053
michael@0 1054 is(count, 0,
michael@0 1055 "Correct count for upperBound keyRange arg to index.openCursor");
michael@0 1056
michael@0 1057 count = 0;
michael@0 1058 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight);
michael@0 1059
michael@0 1060 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1061 let cursor = event.target.result;
michael@0 1062 if (cursor) {
michael@0 1063 count++;
michael@0 1064 cursor.continue();
michael@0 1065 }
michael@0 1066 else {
michael@0 1067 testGenerator.next();
michael@0 1068 }
michael@0 1069 }
michael@0 1070 yield undefined;
michael@0 1071
michael@0 1072 is(count, weightSort.length,
michael@0 1073 "Correct count for upperBound keyRange arg to index.openCursor");
michael@0 1074
michael@0 1075 count = 0;
michael@0 1076 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight,
michael@0 1077 true);
michael@0 1078
michael@0 1079 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1080 let cursor = event.target.result;
michael@0 1081 if (cursor) {
michael@0 1082 count++;
michael@0 1083 cursor.continue();
michael@0 1084 }
michael@0 1085 else {
michael@0 1086 testGenerator.next();
michael@0 1087 }
michael@0 1088 }
michael@0 1089 yield undefined;
michael@0 1090
michael@0 1091 is(count, weightSort.length - 1,
michael@0 1092 "Correct count for upperBound keyRange arg to index.openCursor");
michael@0 1093
michael@0 1094 count = 0;
michael@0 1095 keyRange = IDBKeyRange.upperBound("foo");
michael@0 1096
michael@0 1097 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1098 let cursor = event.target.result;
michael@0 1099 if (cursor) {
michael@0 1100 count++;
michael@0 1101 cursor.continue();
michael@0 1102 }
michael@0 1103 else {
michael@0 1104 testGenerator.next();
michael@0 1105 }
michael@0 1106 }
michael@0 1107 yield undefined;
michael@0 1108
michael@0 1109 is(count, weightSort.length,
michael@0 1110 "Correct count for upperBound keyRange arg to index.openCursor");
michael@0 1111
michael@0 1112 count = 0;
michael@0 1113 keyRange = IDBKeyRange.upperBound(0);
michael@0 1114
michael@0 1115 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1116 let cursor = event.target.result;
michael@0 1117 if (cursor) {
michael@0 1118 count++;
michael@0 1119 cursor.continue();
michael@0 1120 }
michael@0 1121 else {
michael@0 1122 testGenerator.next();
michael@0 1123 }
michael@0 1124 }
michael@0 1125 yield undefined;
michael@0 1126
michael@0 1127 is(count, 0,
michael@0 1128 "Correct count for upperBound keyRange arg to index.openCursor");
michael@0 1129
michael@0 1130 count = 0;
michael@0 1131 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 1132 data[weightSort[weightSort.length - 1]].weight);
michael@0 1133
michael@0 1134 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1135 let cursor = event.target.result;
michael@0 1136 if (cursor) {
michael@0 1137 count++;
michael@0 1138 cursor.continue();
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(count, weightSort.length,
michael@0 1147 "Correct count for bound keyRange arg to index.openCursor");
michael@0 1148
michael@0 1149 count = 0;
michael@0 1150 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 1151 data[weightSort[weightSort.length - 1]].weight,
michael@0 1152 true);
michael@0 1153
michael@0 1154 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1155 let cursor = event.target.result;
michael@0 1156 if (cursor) {
michael@0 1157 count++;
michael@0 1158 cursor.continue();
michael@0 1159 }
michael@0 1160 else {
michael@0 1161 testGenerator.next();
michael@0 1162 }
michael@0 1163 }
michael@0 1164 yield undefined;
michael@0 1165
michael@0 1166 is(count, weightSort.length - 1,
michael@0 1167 "Correct count for bound keyRange arg to index.openCursor");
michael@0 1168
michael@0 1169 count = 0;
michael@0 1170 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 1171 data[weightSort[weightSort.length - 1]].weight,
michael@0 1172 true, true);
michael@0 1173
michael@0 1174 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1175 let cursor = event.target.result;
michael@0 1176 if (cursor) {
michael@0 1177 count++;
michael@0 1178 cursor.continue();
michael@0 1179 }
michael@0 1180 else {
michael@0 1181 testGenerator.next();
michael@0 1182 }
michael@0 1183 }
michael@0 1184 yield undefined;
michael@0 1185
michael@0 1186 is(count, weightSort.length - 2,
michael@0 1187 "Correct count for bound keyRange arg to index.openCursor");
michael@0 1188
michael@0 1189 count = 0;
michael@0 1190 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 1,
michael@0 1191 data[weightSort[weightSort.length - 1]].weight + 1);
michael@0 1192
michael@0 1193 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1194 let cursor = event.target.result;
michael@0 1195 if (cursor) {
michael@0 1196 count++;
michael@0 1197 cursor.continue();
michael@0 1198 }
michael@0 1199 else {
michael@0 1200 testGenerator.next();
michael@0 1201 }
michael@0 1202 }
michael@0 1203 yield undefined;
michael@0 1204
michael@0 1205 is(count, weightSort.length,
michael@0 1206 "Correct count for bound keyRange arg to index.openCursor");
michael@0 1207
michael@0 1208 count = 0;
michael@0 1209 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 2,
michael@0 1210 data[weightSort[0]].weight - 1);
michael@0 1211
michael@0 1212 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1213 let cursor = event.target.result;
michael@0 1214 if (cursor) {
michael@0 1215 count++;
michael@0 1216 cursor.continue();
michael@0 1217 }
michael@0 1218 else {
michael@0 1219 testGenerator.next();
michael@0 1220 }
michael@0 1221 }
michael@0 1222 yield undefined;
michael@0 1223
michael@0 1224 is(count, 0,
michael@0 1225 "Correct count for bound keyRange arg to index.openCursor");
michael@0 1226
michael@0 1227 count = 0;
michael@0 1228 keyRange = IDBKeyRange.bound(data[weightSort[1]].weight,
michael@0 1229 data[weightSort[2]].weight);
michael@0 1230
michael@0 1231 index.openCursor(keyRange).onsuccess = function(event) {
michael@0 1232 let cursor = event.target.result;
michael@0 1233 if (cursor) {
michael@0 1234 count++;
michael@0 1235 cursor.continue();
michael@0 1236 }
michael@0 1237 else {
michael@0 1238 testGenerator.next();
michael@0 1239 }
michael@0 1240 }
michael@0 1241 yield undefined;
michael@0 1242
michael@0 1243 is(count, 3,
michael@0 1244 "Correct count for bound keyRange arg to index.openCursor");
michael@0 1245
michael@0 1246 try {
michael@0 1247 index.get();
michael@0 1248 ok(false, "Get with unspecified arg should have thrown");
michael@0 1249 }
michael@0 1250 catch(e) {
michael@0 1251 ok(true, "Get with unspecified arg should have thrown");
michael@0 1252 }
michael@0 1253
michael@0 1254 try {
michael@0 1255 index.get(undefined);
michael@0 1256 ok(false, "Get with undefined should have thrown");
michael@0 1257 }
michael@0 1258 catch(e) {
michael@0 1259 ok(true, "Get with undefined arg should have thrown");
michael@0 1260 }
michael@0 1261
michael@0 1262 try {
michael@0 1263 index.get(null);
michael@0 1264 ok(false, "Get with null should have thrown");
michael@0 1265 }
michael@0 1266 catch(e) {
michael@0 1267 is(e instanceof DOMException, true,
michael@0 1268 "Got right kind of exception");
michael@0 1269 is(e.name, "DataError", "Correct error.");
michael@0 1270 is(e.code, 0, "Correct code.");
michael@0 1271 }
michael@0 1272
michael@0 1273 index.get(data[0].weight).onsuccess = grabEventAndContinueHandler;
michael@0 1274 event = yield undefined;
michael@0 1275
michael@0 1276 is(event.target.result.weight, data[0].weight, "Got correct result");
michael@0 1277
michael@0 1278 keyRange = IDBKeyRange.only(data[0].weight);
michael@0 1279
michael@0 1280 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1281 event = yield undefined;
michael@0 1282
michael@0 1283 is(event.target.result.weight, data[0].weight, "Got correct result");
michael@0 1284
michael@0 1285 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight);
michael@0 1286
michael@0 1287 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1288 event = yield undefined;
michael@0 1289
michael@0 1290 is(event.target.result.weight, data[weightSort[0]].weight,
michael@0 1291 "Got correct result");
michael@0 1292
michael@0 1293 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight - 1);
michael@0 1294
michael@0 1295 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1296 event = yield undefined;
michael@0 1297
michael@0 1298 is(event.target.result.weight, data[weightSort[0]].weight,
michael@0 1299 "Got correct result");
michael@0 1300
michael@0 1301 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight + 1);
michael@0 1302
michael@0 1303 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1304 event = yield undefined;
michael@0 1305
michael@0 1306 is(event.target.result.weight, data[weightSort[1]].weight,
michael@0 1307 "Got correct result");
michael@0 1308
michael@0 1309 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true);
michael@0 1310
michael@0 1311 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1312 event = yield undefined;
michael@0 1313
michael@0 1314 is(event.target.result.weight, data[weightSort[1]].weight,
michael@0 1315 "Got correct result");
michael@0 1316
michael@0 1317 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 1318 data[weightSort[1]].weight);
michael@0 1319
michael@0 1320 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1321 event = yield undefined;
michael@0 1322
michael@0 1323 is(event.target.result.weight, data[weightSort[0]].weight,
michael@0 1324 "Got correct result");
michael@0 1325
michael@0 1326 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 1327 data[weightSort[1]].weight, true);
michael@0 1328
michael@0 1329 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1330 event = yield undefined;
michael@0 1331
michael@0 1332 is(event.target.result.weight, data[weightSort[1]].weight,
michael@0 1333 "Got correct result");
michael@0 1334
michael@0 1335 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 1336 data[weightSort[1]].weight, true, true);
michael@0 1337
michael@0 1338 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1339 event = yield undefined;
michael@0 1340
michael@0 1341 is(event.target.result, undefined, "Got correct result");
michael@0 1342
michael@0 1343 keyRange = IDBKeyRange.upperBound(data[weightSort[5]].weight);
michael@0 1344
michael@0 1345 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1346 event = yield undefined;
michael@0 1347
michael@0 1348 is(event.target.result.weight, data[weightSort[0]].weight,
michael@0 1349 "Got correct result");
michael@0 1350
michael@0 1351 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true);
michael@0 1352
michael@0 1353 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1354 event = yield undefined;
michael@0 1355
michael@0 1356 is(event.target.result, undefined, "Got correct result");
michael@0 1357
michael@0 1358 try {
michael@0 1359 index.getKey();
michael@0 1360 ok(false, "Get with unspecified arg should have thrown");
michael@0 1361 }
michael@0 1362 catch(e) {
michael@0 1363 ok(true, "Get with unspecified arg should have thrown");
michael@0 1364 }
michael@0 1365
michael@0 1366 try {
michael@0 1367 index.getKey(undefined);
michael@0 1368 ok(false, "Get with undefined should have thrown");
michael@0 1369 }
michael@0 1370 catch(e) {
michael@0 1371 ok(true, "Get with undefined arg should have thrown");
michael@0 1372 }
michael@0 1373
michael@0 1374 try {
michael@0 1375 index.getKey(null);
michael@0 1376 ok(false, "Get with null should have thrown");
michael@0 1377 }
michael@0 1378 catch(e) {
michael@0 1379 is(e instanceof DOMException, true,
michael@0 1380 "Got right kind of exception");
michael@0 1381 is(e.name, "DataError", "Correct error.");
michael@0 1382 is(e.code, 0, "Correct code.");
michael@0 1383 }
michael@0 1384
michael@0 1385 index.getKey(data[0].weight).onsuccess = grabEventAndContinueHandler;
michael@0 1386 event = yield undefined;
michael@0 1387
michael@0 1388 is(event.target.result, data[0].ssn, "Got correct result");
michael@0 1389
michael@0 1390 keyRange = IDBKeyRange.only(data[0].weight);
michael@0 1391
michael@0 1392 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1393 event = yield undefined;
michael@0 1394
michael@0 1395 is(event.target.result, data[0].ssn, "Got correct result");
michael@0 1396
michael@0 1397 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight);
michael@0 1398
michael@0 1399 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1400 event = yield undefined;
michael@0 1401
michael@0 1402 is(event.target.result, data[weightSort[0]].ssn, "Got correct result");
michael@0 1403
michael@0 1404 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight - 1);
michael@0 1405
michael@0 1406 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1407 event = yield undefined;
michael@0 1408
michael@0 1409 is(event.target.result, data[weightSort[0]].ssn, "Got correct result");
michael@0 1410
michael@0 1411 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight + 1);
michael@0 1412
michael@0 1413 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1414 event = yield undefined;
michael@0 1415
michael@0 1416 is(event.target.result, data[weightSort[1]].ssn, "Got correct result");
michael@0 1417
michael@0 1418 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true);
michael@0 1419
michael@0 1420 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1421 event = yield undefined;
michael@0 1422
michael@0 1423 is(event.target.result, data[weightSort[1]].ssn, "Got correct result");
michael@0 1424
michael@0 1425 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 1426 data[weightSort[1]].weight);
michael@0 1427
michael@0 1428 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1429 event = yield undefined;
michael@0 1430
michael@0 1431 is(event.target.result, data[weightSort[0]].ssn, "Got correct result");
michael@0 1432
michael@0 1433 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 1434 data[weightSort[1]].weight, true);
michael@0 1435
michael@0 1436 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1437 event = yield undefined;
michael@0 1438
michael@0 1439 is(event.target.result, data[weightSort[1]].ssn, "Got correct result");
michael@0 1440
michael@0 1441 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
michael@0 1442 data[weightSort[1]].weight, true, true);
michael@0 1443
michael@0 1444 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1445 event = yield undefined;
michael@0 1446
michael@0 1447 is(event.target.result, undefined, "Got correct result");
michael@0 1448
michael@0 1449 keyRange = IDBKeyRange.upperBound(data[weightSort[5]].weight);
michael@0 1450
michael@0 1451 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1452 event = yield undefined;
michael@0 1453
michael@0 1454 is(event.target.result, data[weightSort[0]].ssn, "Got correct result");
michael@0 1455
michael@0 1456 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true);
michael@0 1457
michael@0 1458 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1459 event = yield undefined;
michael@0 1460
michael@0 1461 is(event.target.result, undefined, "Got correct result");
michael@0 1462
michael@0 1463 count = 0;
michael@0 1464
michael@0 1465 index.openKeyCursor().onsuccess = function(event) {
michael@0 1466 let cursor = event.target.result;
michael@0 1467 if (cursor) {
michael@0 1468 count++;
michael@0 1469 cursor.continue();
michael@0 1470 }
michael@0 1471 else {
michael@0 1472 testGenerator.next();
michael@0 1473 }
michael@0 1474 }
michael@0 1475 yield undefined;
michael@0 1476
michael@0 1477 is(count, weightSort.length,
michael@0 1478 "Correct count for no arg to index.openKeyCursor");
michael@0 1479
michael@0 1480 count = 0;
michael@0 1481
michael@0 1482 index.openKeyCursor(null).onsuccess = function(event) {
michael@0 1483 let cursor = event.target.result;
michael@0 1484 if (cursor) {
michael@0 1485 count++;
michael@0 1486 cursor.continue();
michael@0 1487 }
michael@0 1488 else {
michael@0 1489 testGenerator.next();
michael@0 1490 }
michael@0 1491 }
michael@0 1492 yield undefined;
michael@0 1493
michael@0 1494 is(count, weightSort.length,
michael@0 1495 "Correct count for null arg to index.openKeyCursor");
michael@0 1496
michael@0 1497 count = 0;
michael@0 1498
michael@0 1499 index.openKeyCursor(undefined).onsuccess = function(event) {
michael@0 1500 let cursor = event.target.result;
michael@0 1501 if (cursor) {
michael@0 1502 count++;
michael@0 1503 cursor.continue();
michael@0 1504 }
michael@0 1505 else {
michael@0 1506 testGenerator.next();
michael@0 1507 }
michael@0 1508 }
michael@0 1509 yield undefined;
michael@0 1510
michael@0 1511 is(count, weightSort.length,
michael@0 1512 "Correct count for undefined arg to index.openKeyCursor");
michael@0 1513
michael@0 1514 count = 0;
michael@0 1515
michael@0 1516 index.openKeyCursor(data[weightSort[0]].weight).onsuccess = function(event) {
michael@0 1517 let cursor = event.target.result;
michael@0 1518 if (cursor) {
michael@0 1519 count++;
michael@0 1520 cursor.continue();
michael@0 1521 }
michael@0 1522 else {
michael@0 1523 testGenerator.next();
michael@0 1524 }
michael@0 1525 }
michael@0 1526 yield undefined;
michael@0 1527
michael@0 1528 is(count, 1, "Correct count for single key arg to index.openKeyCursor");
michael@0 1529
michael@0 1530 count = 0;
michael@0 1531
michael@0 1532 index.openKeyCursor("foo").onsuccess = function(event) {
michael@0 1533 let cursor = event.target.result;
michael@0 1534 if (cursor) {
michael@0 1535 count++;
michael@0 1536 cursor.continue();
michael@0 1537 }
michael@0 1538 else {
michael@0 1539 testGenerator.next();
michael@0 1540 }
michael@0 1541 }
michael@0 1542 yield undefined;
michael@0 1543
michael@0 1544 is(count, 0,
michael@0 1545 "Correct count for non-existent single key arg to index.openKeyCursor");
michael@0 1546
michael@0 1547 count = 0;
michael@0 1548 keyRange = IDBKeyRange.only(data[weightSort[0]].weight);
michael@0 1549
michael@0 1550 index.openKeyCursor(keyRange).onsuccess = function(event) {
michael@0 1551 let cursor = event.target.result;
michael@0 1552 if (cursor) {
michael@0 1553 count++;
michael@0 1554 cursor.continue();
michael@0 1555 }
michael@0 1556 else {
michael@0 1557 testGenerator.next();
michael@0 1558 }
michael@0 1559 }
michael@0 1560 yield undefined;
michael@0 1561
michael@0 1562 is(count, 1,
michael@0 1563 "Correct count for only keyRange arg to index.openKeyCursor");
michael@0 1564
michael@0 1565 objectStore.mozGetAll(data[1].ssn).onsuccess = grabEventAndContinueHandler;
michael@0 1566 event = yield undefined;
michael@0 1567
michael@0 1568 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1569 is(event.target.result.length, 1, "Got correct length");
michael@0 1570 is(event.target.result[0].ssn, data[1].ssn, "Got correct result");
michael@0 1571
michael@0 1572 objectStore.mozGetAll(null).onsuccess = grabEventAndContinueHandler;
michael@0 1573 event = yield undefined;
michael@0 1574
michael@0 1575 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1576 is(event.target.result.length, data.length, "Got correct length");
michael@0 1577 for (let i in event.target.result) {
michael@0 1578 is(event.target.result[i].ssn, data[i].ssn, "Got correct value");
michael@0 1579 }
michael@0 1580
michael@0 1581 objectStore.mozGetAll(undefined).onsuccess = grabEventAndContinueHandler;
michael@0 1582 event = yield undefined;
michael@0 1583
michael@0 1584 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1585 is(event.target.result.length, data.length, "Got correct length");
michael@0 1586 for (let i in event.target.result) {
michael@0 1587 is(event.target.result[i].ssn, data[i].ssn, "Got correct value");
michael@0 1588 }
michael@0 1589
michael@0 1590 objectStore.mozGetAll().onsuccess = grabEventAndContinueHandler;
michael@0 1591 event = yield undefined;
michael@0 1592
michael@0 1593 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1594 is(event.target.result.length, data.length, "Got correct length");
michael@0 1595 for (let i in event.target.result) {
michael@0 1596 is(event.target.result[i].ssn, data[i].ssn, "Got correct value");
michael@0 1597 }
michael@0 1598
michael@0 1599 keyRange = IDBKeyRange.lowerBound(0);
michael@0 1600
michael@0 1601 objectStore.mozGetAll(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1602 event = yield undefined;
michael@0 1603
michael@0 1604 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1605 is(event.target.result.length, data.length, "Got correct length");
michael@0 1606 for (let i in event.target.result) {
michael@0 1607 is(event.target.result[i].ssn, data[i].ssn, "Got correct value");
michael@0 1608 }
michael@0 1609
michael@0 1610 index.mozGetAll().onsuccess = grabEventAndContinueHandler;
michael@0 1611 event = yield undefined;
michael@0 1612
michael@0 1613 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1614 is(event.target.result.length, weightSort.length, "Got correct length");
michael@0 1615 for (let i in event.target.result) {
michael@0 1616 is(event.target.result[i].ssn, data[weightSort[i]].ssn,
michael@0 1617 "Got correct value");
michael@0 1618 }
michael@0 1619
michael@0 1620 index.mozGetAll(undefined).onsuccess = grabEventAndContinueHandler;
michael@0 1621 event = yield undefined;
michael@0 1622
michael@0 1623 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1624 is(event.target.result.length, weightSort.length, "Got correct length");
michael@0 1625 for (let i in event.target.result) {
michael@0 1626 is(event.target.result[i].ssn, data[weightSort[i]].ssn,
michael@0 1627 "Got correct value");
michael@0 1628 }
michael@0 1629
michael@0 1630 index.mozGetAll(null).onsuccess = grabEventAndContinueHandler;
michael@0 1631 event = yield undefined;
michael@0 1632
michael@0 1633 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1634 is(event.target.result.length, weightSort.length, "Got correct length");
michael@0 1635 for (let i in event.target.result) {
michael@0 1636 is(event.target.result[i].ssn, data[weightSort[i]].ssn,
michael@0 1637 "Got correct value");
michael@0 1638 }
michael@0 1639
michael@0 1640 index.mozGetAll(data[weightSort[0]].weight).onsuccess = grabEventAndContinueHandler;
michael@0 1641 event = yield undefined;
michael@0 1642
michael@0 1643 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1644 is(event.target.result.length, 1, "Got correct length");
michael@0 1645 is(event.target.result[0].ssn, data[weightSort[0]].ssn, "Got correct result");
michael@0 1646
michael@0 1647 keyRange = IDBKeyRange.lowerBound(0);
michael@0 1648
michael@0 1649 index.mozGetAll(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1650 event = yield undefined;
michael@0 1651
michael@0 1652 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1653 is(event.target.result.length, weightSort.length, "Got correct length");
michael@0 1654 for (let i in event.target.result) {
michael@0 1655 is(event.target.result[i].ssn, data[weightSort[i]].ssn,
michael@0 1656 "Got correct value");
michael@0 1657 }
michael@0 1658
michael@0 1659 index.mozGetAllKeys().onsuccess = grabEventAndContinueHandler;
michael@0 1660 event = yield undefined;
michael@0 1661
michael@0 1662 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1663 is(event.target.result.length, weightSort.length, "Got correct length");
michael@0 1664 for (let i in event.target.result) {
michael@0 1665 is(event.target.result[i], data[weightSort[i]].ssn,
michael@0 1666 "Got correct value");
michael@0 1667 }
michael@0 1668
michael@0 1669 index.mozGetAllKeys(undefined).onsuccess = grabEventAndContinueHandler;
michael@0 1670 event = yield undefined;
michael@0 1671
michael@0 1672 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1673 is(event.target.result.length, weightSort.length, "Got correct length");
michael@0 1674 for (let i in event.target.result) {
michael@0 1675 is(event.target.result[i], data[weightSort[i]].ssn,
michael@0 1676 "Got correct value");
michael@0 1677 }
michael@0 1678
michael@0 1679 index.mozGetAllKeys(null).onsuccess = grabEventAndContinueHandler;
michael@0 1680 event = yield undefined;
michael@0 1681
michael@0 1682 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1683 is(event.target.result.length, weightSort.length, "Got correct length");
michael@0 1684 for (let i in event.target.result) {
michael@0 1685 is(event.target.result[i], data[weightSort[i]].ssn,
michael@0 1686 "Got correct value");
michael@0 1687 }
michael@0 1688
michael@0 1689 index.mozGetAllKeys(data[weightSort[0]].weight).onsuccess = grabEventAndContinueHandler;
michael@0 1690 event = yield undefined;
michael@0 1691
michael@0 1692 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1693 is(event.target.result.length, 1, "Got correct length");
michael@0 1694 is(event.target.result[0], data[weightSort[0]].ssn, "Got correct result");
michael@0 1695
michael@0 1696 keyRange = IDBKeyRange.lowerBound(0);
michael@0 1697
michael@0 1698 index.mozGetAllKeys(keyRange).onsuccess = grabEventAndContinueHandler;
michael@0 1699 event = yield undefined;
michael@0 1700
michael@0 1701 is(event.target.result instanceof Array, true, "Got an array");
michael@0 1702 is(event.target.result.length, weightSort.length, "Got correct length");
michael@0 1703 for (let i in event.target.result) {
michael@0 1704 is(event.target.result[i], data[weightSort[i]].ssn,
michael@0 1705 "Got correct value");
michael@0 1706 }
michael@0 1707
michael@0 1708 finishTest();
michael@0 1709 yield undefined;
michael@0 1710 }
michael@0 1711

mercurial