dom/indexedDB/test/unit/test_put_get_values_autoIncrement.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 name = this.window ? window.location.pathname : "Splendid Test";
michael@0 11 const objectStoreName = "Objects";
michael@0 12
michael@0 13 let testString = { value: "testString" };
michael@0 14 let testInt = { value: 1002 };
michael@0 15
michael@0 16 let request = indexedDB.open(name, 1);
michael@0 17 request.onerror = errorHandler;
michael@0 18 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 19 let event = yield undefined;
michael@0 20
michael@0 21 let db = event.target.result;
michael@0 22
michael@0 23 let objectStore = db.createObjectStore(objectStoreName,
michael@0 24 { autoIncrement: 1 });
michael@0 25
michael@0 26 request = objectStore.put(testString.value);
michael@0 27 request.onerror = errorHandler;
michael@0 28 request.onsuccess = function(event) {
michael@0 29 testString.key = event.target.result;
michael@0 30 request = objectStore.get(testString.key);
michael@0 31 request.onerror = errorHandler;
michael@0 32 request.onsuccess = function(event) {
michael@0 33 is(event.target.result, testString.value, "Got the right value");
michael@0 34 };
michael@0 35 };
michael@0 36
michael@0 37 request = objectStore.put(testInt.value);
michael@0 38 request.onerror = errorHandler;
michael@0 39 request.onsuccess = function(event) {
michael@0 40 testInt.key = event.target.result;
michael@0 41 request = objectStore.get(testInt.key);
michael@0 42 request.onerror = errorHandler;
michael@0 43 request.onsuccess = function(event) {
michael@0 44 is(event.target.result, testInt.value, "Got the right value");
michael@0 45 finishTest();
michael@0 46 };
michael@0 47 }
michael@0 48
michael@0 49 yield undefined;
michael@0 50 }

mercurial