dom/indexedDB/test/unit/test_index_getAll.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 const objectStoreName = "People";
michael@0 12
michael@0 13 const objectStoreData = [
michael@0 14 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
michael@0 15 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
michael@0 16 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
michael@0 17 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
michael@0 18 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
michael@0 19 { key: "237-23-7737", value: { name: "Pat", height: 65 } }
michael@0 20 ];
michael@0 21
michael@0 22 const indexData = [
michael@0 23 { name: "name", keyPath: "name", options: { unique: true } },
michael@0 24 { name: "height", keyPath: "height", options: { unique: false } },
michael@0 25 { name: "weight", keyPath: "weight", options: { unique: false } }
michael@0 26 ];
michael@0 27
michael@0 28 const objectStoreDataNameSort = [
michael@0 29 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
michael@0 30 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
michael@0 31 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
michael@0 32 { key: "237-23-7737", value: { name: "Pat", height: 65 } },
michael@0 33 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
michael@0 34 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }
michael@0 35 ];
michael@0 36
michael@0 37 const objectStoreDataWeightSort = [
michael@0 38 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
michael@0 39 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
michael@0 40 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
michael@0 41 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
michael@0 42 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
michael@0 43 ];
michael@0 44
michael@0 45 const objectStoreDataHeightSort = [
michael@0 46 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
michael@0 47 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
michael@0 48 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
michael@0 49 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
michael@0 50 { key: "237-23-7737", value: { name: "Pat", height: 65 } },
michael@0 51 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
michael@0 52 ];
michael@0 53
michael@0 54 let request = indexedDB.open(name, 1);
michael@0 55 request.onerror = errorHandler;
michael@0 56 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 57 request.onsuccess = grabEventAndContinueHandler;
michael@0 58 let event = yield undefined;
michael@0 59
michael@0 60 let db = event.target.result;
michael@0 61
michael@0 62 let objectStore = db.createObjectStore(objectStoreName);
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 yield undefined;
michael@0 77 ok(true, "1");
michael@0 78
michael@0 79 // Now create the indexes.
michael@0 80 for (let i in indexData) {
michael@0 81 objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
michael@0 82 indexData[i].options);
michael@0 83 }
michael@0 84
michael@0 85 is(objectStore.indexNames.length, indexData.length, "Good index count");
michael@0 86 yield undefined;
michael@0 87
michael@0 88 ok(true, "2");
michael@0 89 objectStore = db.transaction(objectStoreName)
michael@0 90 .objectStore(objectStoreName);
michael@0 91
michael@0 92 request = objectStore.index("height").mozGetAllKeys(65);
michael@0 93 request.onerror = errorHandler;
michael@0 94 request.onsuccess = grabEventAndContinueHandler;
michael@0 95 event = yield undefined;
michael@0 96 ok(true, "3");
michael@0 97
michael@0 98 is(event.target.result instanceof Array, true, "Got an array object");
michael@0 99 is(event.target.result.length, 2, "Correct length");
michael@0 100
michael@0 101 for (let i in event.target.result) {
michael@0 102 is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
michael@0 103 "Correct key");
michael@0 104 }
michael@0 105
michael@0 106 request = objectStore.index("height").mozGetAllKeys(65, 0);
michael@0 107 request.onerror = errorHandler;
michael@0 108 request.onsuccess = grabEventAndContinueHandler;
michael@0 109 event = yield undefined;
michael@0 110 ok(true, "3");
michael@0 111
michael@0 112 is(event.target.result instanceof Array, true, "Got an array object");
michael@0 113 is(event.target.result.length, 2, "Correct length");
michael@0 114
michael@0 115 for (let i in event.target.result) {
michael@0 116 is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
michael@0 117 "Correct key");
michael@0 118 }
michael@0 119
michael@0 120 request = objectStore.index("height").mozGetAllKeys(65, null);
michael@0 121 request.onerror = errorHandler;
michael@0 122 request.onsuccess = grabEventAndContinueHandler;
michael@0 123 event = yield undefined;
michael@0 124 ok(true, "3");
michael@0 125
michael@0 126 is(event.target.result instanceof Array, true, "Got an array object");
michael@0 127 is(event.target.result.length, 2, "Correct length");
michael@0 128
michael@0 129 for (let i in event.target.result) {
michael@0 130 is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
michael@0 131 "Correct key");
michael@0 132 }
michael@0 133
michael@0 134 request = objectStore.index("height").mozGetAllKeys(65, undefined);
michael@0 135 request.onerror = errorHandler;
michael@0 136 request.onsuccess = grabEventAndContinueHandler;
michael@0 137 event = yield undefined;
michael@0 138 ok(true, "3");
michael@0 139
michael@0 140 is(event.target.result instanceof Array, true, "Got an array object");
michael@0 141 is(event.target.result.length, 2, "Correct length");
michael@0 142
michael@0 143 for (let i in event.target.result) {
michael@0 144 is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
michael@0 145 "Correct key");
michael@0 146 }
michael@0 147
michael@0 148 request = objectStore.index("height").mozGetAllKeys();
michael@0 149 request.onerror = errorHandler;
michael@0 150 request.onsuccess = grabEventAndContinueHandler;
michael@0 151 event = yield undefined;
michael@0 152 ok(true, "4");
michael@0 153
michael@0 154 is(event.target.result instanceof Array, true, "Got an array object");
michael@0 155 is(event.target.result.length, objectStoreDataHeightSort.length,
michael@0 156 "Correct length");
michael@0 157
michael@0 158 for (let i in event.target.result) {
michael@0 159 is(event.target.result[i], objectStoreDataHeightSort[i].key, "Correct key");
michael@0 160 }
michael@0 161
michael@0 162 request = objectStore.index("height").mozGetAllKeys(null, 4);
michael@0 163 request.onerror = errorHandler;
michael@0 164 request.onsuccess = grabEventAndContinueHandler;
michael@0 165 event = yield undefined;
michael@0 166
michael@0 167 ok(true, "5");
michael@0 168 is(event.target.result instanceof Array, true, "Got an array object");
michael@0 169 is(event.target.result.length, 4, "Correct length");
michael@0 170
michael@0 171 for (let i in event.target.result) {
michael@0 172 is(event.target.result[i], objectStoreDataHeightSort[i].key, "Correct key");
michael@0 173 }
michael@0 174
michael@0 175 request = objectStore.index("height").mozGetAllKeys(65, 1);
michael@0 176 request.onerror = errorHandler;
michael@0 177 request.onsuccess = grabEventAndContinueHandler;
michael@0 178 event = yield undefined;
michael@0 179
michael@0 180 ok(true, "6");
michael@0 181 is(event.target.result instanceof Array, true, "Got an array object");
michael@0 182 is(event.target.result.length, 1, "Correct length");
michael@0 183
michael@0 184 for (let i in event.target.result) {
michael@0 185 is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
michael@0 186 "Correct key");
michael@0 187 }
michael@0 188
michael@0 189 finishTest();
michael@0 190 yield undefined;
michael@0 191 }

mercurial