dom/indexedDB/test/unit/test_index_empty_keyPath.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 name = this.window ? window.location.pathname : "Splendid Test";
michael@0 11
michael@0 12 const objectStoreData = [
michael@0 13 { key: "1", value: "foo" },
michael@0 14 { key: "2", value: "bar" },
michael@0 15 { key: "3", value: "baz" }
michael@0 16 ];
michael@0 17
michael@0 18 let request = indexedDB.open(name, 1);
michael@0 19 request.onerror = errorHandler;
michael@0 20 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 21 request.onsuccess = grabEventAndContinueHandler;
michael@0 22 let event = yield undefined; // upgradeneeded
michael@0 23
michael@0 24 let db = event.target.result;
michael@0 25
michael@0 26 let objectStore = db.createObjectStore("data", { keyPath: null });
michael@0 27
michael@0 28 // First, add all our data to the object store.
michael@0 29 let addedData = 0;
michael@0 30 for (let i in objectStoreData) {
michael@0 31 request = objectStore.add(objectStoreData[i].value,
michael@0 32 objectStoreData[i].key);
michael@0 33 request.onerror = errorHandler;
michael@0 34 request.onsuccess = function(event) {
michael@0 35 if (++addedData == objectStoreData.length) {
michael@0 36 testGenerator.send(event);
michael@0 37 }
michael@0 38 }
michael@0 39 }
michael@0 40 event = yield undefined; // testGenerator.send
michael@0 41
michael@0 42 // Now create the index.
michael@0 43 objectStore.createIndex("set", "", { unique: true });
michael@0 44 yield undefined; // success
michael@0 45
michael@0 46 let trans = db.transaction("data", "readwrite");
michael@0 47 objectStore = trans.objectStore("data");
michael@0 48 index = objectStore.index("set");
michael@0 49
michael@0 50 let request = index.get("bar");
michael@0 51 request.onerror = errorHandler;
michael@0 52 request.onsuccess = grabEventAndContinueHandler;
michael@0 53
michael@0 54 let event = yield undefined;
michael@0 55
michael@0 56 is(event.target.result, "bar", "Got correct result");
michael@0 57
michael@0 58 let request = objectStore.add("foopy", 4);
michael@0 59 request.onerror = errorHandler;
michael@0 60 request.onsuccess = grabEventAndContinueHandler;
michael@0 61
michael@0 62 yield undefined;
michael@0 63
michael@0 64 let request = index.get("foopy");
michael@0 65 request.onerror = errorHandler;
michael@0 66 request.onsuccess = grabEventAndContinueHandler;
michael@0 67
michael@0 68 let event = yield undefined;
michael@0 69
michael@0 70 is(event.target.result, "foopy", "Got correct result");
michael@0 71
michael@0 72 let request = objectStore.add("foopy", 5);
michael@0 73 request.addEventListener("error", new ExpectError("ConstraintError", true));
michael@0 74 request.onsuccess = unexpectedSuccessHandler;
michael@0 75
michael@0 76 trans.oncomplete = grabEventAndContinueHandler;
michael@0 77
michael@0 78 yield undefined;
michael@0 79 yield undefined;
michael@0 80
michael@0 81 finishTest();
michael@0 82 yield undefined;
michael@0 83 }

mercurial