dom/indexedDB/test/unit/test_odd_result_order.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

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 data = { key: 5, index: 10 };
michael@0 11
michael@0 12 let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
michael@0 13 request.onerror = errorHandler;
michael@0 14 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 15 let event = yield undefined;
michael@0 16
michael@0 17 let db = event.target.result;
michael@0 18
michael@0 19 ok(db instanceof IDBDatabase, "Got a real database");
michael@0 20
michael@0 21 db.onerror = errorHandler;
michael@0 22
michael@0 23 let objectStore = db.createObjectStore("foo", { keyPath: "key",
michael@0 24 autoIncrement: true });
michael@0 25 let index = objectStore.createIndex("foo", "index");
michael@0 26
michael@0 27 event.target.onsuccess = continueToNextStep;
michael@0 28 yield undefined;
michael@0 29
michael@0 30 objectStore = db.transaction("foo", "readwrite")
michael@0 31 .objectStore("foo");
michael@0 32 request = objectStore.add(data);
michael@0 33 request.onsuccess = grabEventAndContinueHandler;
michael@0 34 event = yield undefined;
michael@0 35
michael@0 36 let key;
michael@0 37 executeSoon(function() {
michael@0 38 key = request.result;
michael@0 39 continueToNextStep();
michael@0 40 });
michael@0 41 yield undefined;
michael@0 42
michael@0 43 is(key, data.key, "Got the right key");
michael@0 44
michael@0 45 objectStore = db.transaction("foo").objectStore("foo");
michael@0 46 objectStore.get(data.key).onsuccess = grabEventAndContinueHandler;
michael@0 47 event = yield undefined;
michael@0 48
michael@0 49 let obj;
michael@0 50 executeSoon(function() {
michael@0 51 obj = event.target.result;
michael@0 52 continueToNextStep();
michael@0 53 });
michael@0 54 yield undefined;
michael@0 55
michael@0 56 is(obj.key, data.key, "Got the right key");
michael@0 57 is(obj.index, data.index, "Got the right property value");
michael@0 58
michael@0 59 objectStore = db.transaction("foo", "readwrite")
michael@0 60 .objectStore("foo");
michael@0 61 request = objectStore.delete(data.key);
michael@0 62 request.onsuccess = grabEventAndContinueHandler;
michael@0 63 event = yield undefined;
michael@0 64
michael@0 65 key = undefined;
michael@0 66 executeSoon(function() {
michael@0 67 key = request.result;
michael@0 68 continueToNextStep();
michael@0 69 }, 0);
michael@0 70 yield undefined;
michael@0 71
michael@0 72 ok(key === undefined, "Got the right value");
michael@0 73
michael@0 74 finishTest();
michael@0 75 yield undefined;
michael@0 76 }

mercurial