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: let request = indexedDB.open(name, 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: let event = yield undefined; michael@0: michael@0: let db = event.target.result; michael@0: db.addEventListener("error", function(event) { michael@0: event.preventDefault(); michael@0: }, false); michael@0: michael@0: let objectStore = db.createObjectStore("foo", { autoIncrement: true }); michael@0: michael@0: request = objectStore.add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: let key1 = event.target.result; michael@0: michael@0: request = objectStore.put({}, key1); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, key1, "put gave the same key back"); michael@0: michael@0: let key2 = 10; michael@0: michael@0: request = objectStore.put({}, key2); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, key2, "put gave the same key back"); michael@0: michael@0: key2 = 100; michael@0: michael@0: request = objectStore.add({}, key2); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, key2, "put gave the same key back"); michael@0: michael@0: try { michael@0: objectStore.put({}); michael@0: ok(true, "put with no key should not throw with autoIncrement!"); michael@0: } michael@0: catch (e) { michael@0: ok(false, "put with no key threw with autoIncrement"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.put({}); michael@0: ok(true, "put with no key should not throw with autoIncrement!"); michael@0: } michael@0: catch (e) { michael@0: ok(false, "put with no key threw with autoIncrement"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.delete(); michael@0: ok(false, "remove with no key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "remove with no key threw"); michael@0: } michael@0: michael@0: objectStore = db.createObjectStore("bar"); michael@0: michael@0: try { michael@0: objectStore.add({}); michael@0: ok(false, "add with no key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "add with no key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.put({}); michael@0: ok(false, "put with no key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "put with no key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.put({}); michael@0: ok(false, "put with no key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "put with no key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.delete(); michael@0: ok(false, "remove with no key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "remove with no key threw"); michael@0: } michael@0: michael@0: objectStore = db.createObjectStore("baz", { keyPath: "id" }); michael@0: michael@0: try { michael@0: objectStore.add({}); michael@0: ok(false, "add with no key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "add with no key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.add({id:5}, 5); michael@0: ok(false, "add with inline key and passed key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "add with inline key and passed key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.put({}); michael@0: ok(false, "put with no key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "put with no key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.put({}); michael@0: ok(false, "put with no key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "put with no key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.delete(); michael@0: ok(false, "remove with no key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "remove with no key threw"); michael@0: } michael@0: michael@0: key1 = 10; michael@0: michael@0: request = objectStore.add({id:key1}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, key1, "add gave back the same key"); michael@0: michael@0: request = objectStore.put({id:10}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, key1, "put gave back the same key"); michael@0: michael@0: request = objectStore.put({id:10}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, key1, "put gave back the same key"); michael@0: michael@0: request = objectStore.add({id:10}); michael@0: request.addEventListener("error", new ExpectError("ConstraintError", true)); michael@0: request.onsuccess = unexpectedSuccessHandler; michael@0: event = yield undefined; michael@0: michael@0: try { michael@0: objectStore.add({}, null); michael@0: ok(false, "add with null key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "add with null key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.put({}, null); michael@0: ok(false, "put with null key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "put with null key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.put({}, null); michael@0: ok(false, "put with null key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "put with null key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.delete({}, null); michael@0: ok(false, "remove with null key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "remove with null key threw"); michael@0: } michael@0: michael@0: objectStore = db.createObjectStore("bazing", { keyPath: "id", michael@0: autoIncrement: true }); michael@0: michael@0: request = objectStore.add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: key1 = event.target.result; michael@0: michael@0: request = objectStore.put({id:key1}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, key1, "put gave the same key back"); michael@0: michael@0: key2 = 10; michael@0: michael@0: request = objectStore.put({id:key2}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, key2, "put gave the same key back"); michael@0: michael@0: try { michael@0: objectStore.put({}); michael@0: ok(true, "put with no key should not throw with autoIncrement!"); michael@0: } michael@0: catch (e) { michael@0: ok(false, "put with no key threw with autoIncrement"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.put({}); michael@0: ok(true, "put with no key should not throw with autoIncrement!"); michael@0: } michael@0: catch (e) { michael@0: ok(false, "put with no key threw with autoIncrement"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.delete(); michael@0: ok(false, "remove with no key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "remove with no key threw"); michael@0: } michael@0: michael@0: try { michael@0: objectStore.add({id:5}, 5); michael@0: ok(false, "add with inline key and passed key should throw!"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "add with inline key and passed key threw"); michael@0: } michael@0: michael@0: request = objectStore.delete(key2); 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: }