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: if (!this.window) { michael@0: this.runTest = function() { michael@0: todo(false, "Test disabled in xpcshell test suite for now"); michael@0: finishTest(); michael@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: const osName = "foo"; 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: let db = event.target.result; michael@0: is(db.objectStoreNames.length, 0, "Correct objectStoreNames list"); michael@0: michael@0: db.createObjectStore(osName, { autoIncrement: "true" }); michael@0: michael@0: yield undefined; michael@0: michael@0: let key1, key2; michael@0: michael@0: request = db.transaction([osName], "readwrite") michael@0: .objectStore(osName) michael@0: .add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(event.target.transaction.mode, "readwrite", "Correct mode"); michael@0: key1 = event.target.result; michael@0: testGenerator.next(); michael@0: } michael@0: yield undefined; michael@0: michael@0: request = db.transaction(osName, "readwrite").objectStore(osName).add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(event.target.transaction.mode, "readwrite", "Correct mode"); michael@0: key2 = event.target.result; michael@0: testGenerator.next(); michael@0: } michael@0: yield undefined; michael@0: michael@0: request = db.transaction([osName], "readwrite") michael@0: .objectStore(osName) michael@0: .put({}, key1); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(event.target.transaction.mode, "readwrite", "Correct mode"); michael@0: testGenerator.next(); michael@0: } michael@0: yield undefined; michael@0: michael@0: request = db.transaction(osName, "readwrite") michael@0: .objectStore(osName) michael@0: .put({}, key2); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(event.target.transaction.mode, "readwrite", "Correct mode"); michael@0: testGenerator.next(); michael@0: } michael@0: yield undefined; michael@0: michael@0: request = db.transaction([osName], "readwrite") michael@0: .objectStore(osName) michael@0: .put({}, key1); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(event.target.transaction.mode, "readwrite", "Correct mode"); michael@0: testGenerator.next(); michael@0: } michael@0: yield undefined; michael@0: michael@0: request = db.transaction(osName, "readwrite") michael@0: .objectStore(osName) michael@0: .put({}, key1); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(event.target.transaction.mode, "readwrite", "Correct mode"); michael@0: testGenerator.next(); michael@0: } michael@0: yield undefined; michael@0: michael@0: request = db.transaction([osName], "readwrite") michael@0: .objectStore(osName) michael@0: .delete(key1); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(event.target.transaction.mode, "readwrite", "Correct mode"); michael@0: testGenerator.next(); michael@0: } michael@0: yield undefined; michael@0: michael@0: request = db.transaction(osName, "readwrite") michael@0: .objectStore(osName) michael@0: .delete(key2); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(event.target.transaction.mode, "readwrite", "Correct mode"); michael@0: testGenerator.next(); michael@0: } michael@0: yield undefined; michael@0: michael@0: try { michael@0: request = db.transaction([osName]).objectStore(osName).add({}); michael@0: ok(false, "Adding to a readonly transaction should fail!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "Adding to a readonly transaction failed"); michael@0: } michael@0: michael@0: try { michael@0: request = db.transaction(osName).objectStore(osName).add({}); michael@0: ok(false, "Adding to a readonly transaction should fail!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "Adding to a readonly transaction failed"); michael@0: } michael@0: michael@0: try { michael@0: request = db.transaction([osName]).objectStore(osName).put({}); michael@0: ok(false, "Adding or modifying a readonly transaction should fail!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "Adding or modifying a readonly transaction failed"); michael@0: } michael@0: michael@0: try { michael@0: request = db.transaction(osName).objectStore(osName).put({}); michael@0: ok(false, "Adding or modifying a readonly transaction should fail!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "Adding or modifying a readonly transaction failed"); michael@0: } michael@0: michael@0: try { michael@0: request = db.transaction([osName]).objectStore(osName).put({}, key1); michael@0: ok(false, "Modifying a readonly transaction should fail!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "Modifying a readonly transaction failed"); michael@0: } michael@0: michael@0: try { michael@0: request = db.transaction(osName).objectStore(osName).put({}, key1); michael@0: ok(false, "Modifying a readonly transaction should fail!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "Modifying a readonly transaction failed"); michael@0: } michael@0: michael@0: try { michael@0: request = db.transaction([osName]).objectStore(osName).delete(key1); michael@0: ok(false, "Removing from a readonly transaction should fail!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "Removing from a readonly transaction failed"); michael@0: } michael@0: michael@0: try { michael@0: request = db.transaction(osName).objectStore(osName).delete(key2); michael@0: ok(false, "Removing from a readonly transaction should fail!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "Removing from a readonly transaction failed"); michael@0: } michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }