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 | let testGenerator = testSteps(); |
michael@0 | 7 | |
michael@0 | 8 | function testSteps() { |
michael@0 | 9 | const dbName = this.window ? |
michael@0 | 10 | window.location.pathname : |
michael@0 | 11 | "test_objectStore_getAllKeys"; |
michael@0 | 12 | const dbVersion = 1; |
michael@0 | 13 | const objectStoreName = "foo"; |
michael@0 | 14 | const keyCount = 200; |
michael@0 | 15 | |
michael@0 | 16 | let request = indexedDB.open(dbName, dbVersion); |
michael@0 | 17 | request.onerror = errorHandler; |
michael@0 | 18 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 19 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 20 | |
michael@0 | 21 | let event = yield undefined; |
michael@0 | 22 | |
michael@0 | 23 | info("Creating database"); |
michael@0 | 24 | |
michael@0 | 25 | let db = event.target.result; |
michael@0 | 26 | let objectStore = db.createObjectStore(objectStoreName); |
michael@0 | 27 | for (let i = 0; i < keyCount; i++) { |
michael@0 | 28 | objectStore.add(true, i); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | request.onupgradeneeded = unexpectedSuccessHandler; |
michael@0 | 32 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 33 | |
michael@0 | 34 | event = yield undefined; |
michael@0 | 35 | |
michael@0 | 36 | db = event.target.result; |
michael@0 | 37 | objectStore = db.transaction(objectStoreName).objectStore(objectStoreName); |
michael@0 | 38 | |
michael@0 | 39 | info("Getting all keys"); |
michael@0 | 40 | objectStore.getAllKeys().onsuccess = grabEventAndContinueHandler; |
michael@0 | 41 | event = yield undefined; |
michael@0 | 42 | |
michael@0 | 43 | ok(Array.isArray(event.target.result), "Got an array result"); |
michael@0 | 44 | is(event.target.result.length, keyCount, "Got correct array length"); |
michael@0 | 45 | |
michael@0 | 46 | let match = true; |
michael@0 | 47 | for (let i = 0; i < keyCount; i++) { |
michael@0 | 48 | if (event.target.result[i] != i) { |
michael@0 | 49 | match = false; |
michael@0 | 50 | break; |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | ok(match, "Got correct keys"); |
michael@0 | 54 | |
michael@0 | 55 | info("Getting all keys with key range"); |
michael@0 | 56 | let keyRange = IDBKeyRange.bound(10, 20, false, true); |
michael@0 | 57 | objectStore.getAllKeys(keyRange).onsuccess = grabEventAndContinueHandler; |
michael@0 | 58 | event = yield undefined; |
michael@0 | 59 | |
michael@0 | 60 | ok(Array.isArray(event.target.result), "Got an array result"); |
michael@0 | 61 | is(event.target.result.length, 10, "Got correct array length"); |
michael@0 | 62 | |
michael@0 | 63 | match = true; |
michael@0 | 64 | for (let i = 10; i < 20; i++) { |
michael@0 | 65 | if (event.target.result[i - 10] != i) { |
michael@0 | 66 | match = false; |
michael@0 | 67 | break; |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | ok(match, "Got correct keys"); |
michael@0 | 71 | |
michael@0 | 72 | info("Getting all keys with unmatched key range"); |
michael@0 | 73 | keyRange = IDBKeyRange.bound(10000, 200000); |
michael@0 | 74 | objectStore.getAllKeys(keyRange).onsuccess = grabEventAndContinueHandler; |
michael@0 | 75 | event = yield undefined; |
michael@0 | 76 | |
michael@0 | 77 | ok(Array.isArray(event.target.result), "Got an array result"); |
michael@0 | 78 | is(event.target.result.length, 0, "Got correct array length"); |
michael@0 | 79 | |
michael@0 | 80 | info("Getting all keys with limit"); |
michael@0 | 81 | objectStore.getAllKeys(null, 5).onsuccess = grabEventAndContinueHandler; |
michael@0 | 82 | event = yield undefined; |
michael@0 | 83 | |
michael@0 | 84 | ok(Array.isArray(event.target.result), "Got an array result"); |
michael@0 | 85 | is(event.target.result.length, 5, "Got correct array length"); |
michael@0 | 86 | |
michael@0 | 87 | match = true; |
michael@0 | 88 | for (let i = 0; i < 5; i++) { |
michael@0 | 89 | if (event.target.result[i] != i) { |
michael@0 | 90 | match = false; |
michael@0 | 91 | break; |
michael@0 | 92 | } |
michael@0 | 93 | } |
michael@0 | 94 | ok(match, "Got correct keys"); |
michael@0 | 95 | |
michael@0 | 96 | info("Getting all keys with key range and limit"); |
michael@0 | 97 | keyRange = IDBKeyRange.bound(10, 20, false, true); |
michael@0 | 98 | objectStore.getAllKeys(keyRange, 5).onsuccess = grabEventAndContinueHandler; |
michael@0 | 99 | event = yield undefined; |
michael@0 | 100 | |
michael@0 | 101 | ok(Array.isArray(event.target.result), "Got an array result"); |
michael@0 | 102 | is(event.target.result.length, 5, "Got correct array length"); |
michael@0 | 103 | |
michael@0 | 104 | match = true; |
michael@0 | 105 | for (let i = 10; i < 15; i++) { |
michael@0 | 106 | if (event.target.result[i - 10] != i) { |
michael@0 | 107 | match = false; |
michael@0 | 108 | break; |
michael@0 | 109 | } |
michael@0 | 110 | } |
michael@0 | 111 | ok(match, "Got correct keys"); |
michael@0 | 112 | |
michael@0 | 113 | info("Getting all keys with unmatched key range and limit"); |
michael@0 | 114 | keyRange = IDBKeyRange.bound(10000, 200000); |
michael@0 | 115 | objectStore.getAllKeys(keyRange, 5).onsuccess = grabEventAndContinueHandler; |
michael@0 | 116 | event = yield undefined; |
michael@0 | 117 | |
michael@0 | 118 | ok(Array.isArray(event.target.result), "Got an array result"); |
michael@0 | 119 | is(event.target.result.length, 0, "Got correct array length"); |
michael@0 | 120 | |
michael@0 | 121 | finishTest(); |
michael@0 | 122 | yield undefined; |
michael@0 | 123 | } |