michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: var testGenerator = testSteps(); michael@0: michael@0: function testSteps() michael@0: { michael@0: const name = this.window ? window.location.pathname : "Splendid Test"; michael@0: michael@0: const objectStoreName = "Foo"; michael@0: michael@0: const data = { key: 1, value: "bar" }; michael@0: michael@0: let request = indexedDB.open(name, 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: let event = yield undefined; michael@0: michael@0: is(event.type, "upgradeneeded", "Got correct event type"); michael@0: michael@0: let db = event.target.result; michael@0: db.onerror = errorHandler; michael@0: michael@0: let objectStore = db.createObjectStore(objectStoreName, { }); michael@0: michael@0: event = yield undefined; michael@0: michael@0: is(event.type, "success", "Got correct event type"); michael@0: michael@0: objectStore = db.transaction([objectStoreName], "readwrite") michael@0: .objectStore(objectStoreName); michael@0: michael@0: request = objectStore.get(data.key); michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, null, "Got no data"); michael@0: michael@0: request = objectStore.add(data.value, data.key); michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, data.key, "Got correct key"); michael@0: michael@0: let uri = Components.classes["@mozilla.org/network/io-service;1"] michael@0: .getService(Components.interfaces.nsIIOService) michael@0: .newURI("http://appdata.example.com", null, null); michael@0: let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"] michael@0: .getService(Components.interfaces.nsIScriptSecurityManager) michael@0: .getNoAppCodebasePrincipal(uri); michael@0: michael@0: request = indexedDB.openForPrincipal(principal, name, 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: let event = yield undefined; michael@0: michael@0: is(event.type, "upgradeneeded", "Got correct event type"); michael@0: michael@0: db = event.target.result; michael@0: db.onerror = errorHandler; michael@0: michael@0: objectStore = db.createObjectStore(objectStoreName, { }); michael@0: michael@0: event = yield undefined; michael@0: michael@0: is(event.type, "success", "Got correct event type"); michael@0: michael@0: objectStore = db.transaction([objectStoreName]) michael@0: .objectStore(objectStoreName); michael@0: michael@0: request = objectStore.get(data.key); michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, null, "Got no data"); michael@0: michael@0: db.close(); michael@0: michael@0: request = indexedDB.deleteForPrincipal(principal, name); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler michael@0: event = yield undefined; michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }