123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /**
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
- var testGenerator = testSteps();
- function testSteps()
- {
- const name = this.window ? window.location.pathname : "Splendid Test";
- let request = indexedDB.open(name, 1);
- request.onerror = errorHandler;
- request.onupgradeneeded = grabEventAndContinueHandler;
- request.onsuccess = grabEventAndContinueHandler;
- let event = yield undefined;
- let db = event.target.result;
- db.addEventListener("error", function(event) {
- event.preventDefault();
- }, false);
- let objectStore = db.createObjectStore("foo", { autoIncrement: true });
- request = objectStore.add({});
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- let key1 = event.target.result;
- request = objectStore.put({}, key1);
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.target.result, key1, "put gave the same key back");
- let key2 = 10;
- request = objectStore.put({}, key2);
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.target.result, key2, "put gave the same key back");
- key2 = 100;
- request = objectStore.add({}, key2);
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.target.result, key2, "put gave the same key back");
- try {
- objectStore.put({});
- ok(true, "put with no key should not throw with autoIncrement!");
- }
- catch (e) {
- ok(false, "put with no key threw with autoIncrement");
- }
- try {
- objectStore.put({});
- ok(true, "put with no key should not throw with autoIncrement!");
- }
- catch (e) {
- ok(false, "put with no key threw with autoIncrement");
- }
- try {
- objectStore.delete();
- ok(false, "remove with no key should throw!");
- }
- catch (e) {
- ok(true, "remove with no key threw");
- }
- objectStore = db.createObjectStore("bar");
- try {
- objectStore.add({});
- ok(false, "add with no key should throw!");
- }
- catch (e) {
- ok(true, "add with no key threw");
- }
- try {
- objectStore.put({});
- ok(false, "put with no key should throw!");
- }
- catch (e) {
- ok(true, "put with no key threw");
- }
- try {
- objectStore.put({});
- ok(false, "put with no key should throw!");
- }
- catch (e) {
- ok(true, "put with no key threw");
- }
- try {
- objectStore.delete();
- ok(false, "remove with no key should throw!");
- }
- catch (e) {
- ok(true, "remove with no key threw");
- }
- objectStore = db.createObjectStore("baz", { keyPath: "id" });
- try {
- objectStore.add({});
- ok(false, "add with no key should throw!");
- }
- catch (e) {
- ok(true, "add with no key threw");
- }
- try {
- objectStore.add({id:5}, 5);
- ok(false, "add with inline key and passed key should throw!");
- }
- catch (e) {
- ok(true, "add with inline key and passed key threw");
- }
- try {
- objectStore.put({});
- ok(false, "put with no key should throw!");
- }
- catch (e) {
- ok(true, "put with no key threw");
- }
- try {
- objectStore.put({});
- ok(false, "put with no key should throw!");
- }
- catch (e) {
- ok(true, "put with no key threw");
- }
- try {
- objectStore.delete();
- ok(false, "remove with no key should throw!");
- }
- catch (e) {
- ok(true, "remove with no key threw");
- }
- key1 = 10;
- request = objectStore.add({id:key1});
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.target.result, key1, "add gave back the same key");
- request = objectStore.put({id:10});
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.target.result, key1, "put gave back the same key");
- request = objectStore.put({id:10});
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.target.result, key1, "put gave back the same key");
- request = objectStore.add({id:10});
- request.addEventListener("error", new ExpectError("ConstraintError", true));
- request.onsuccess = unexpectedSuccessHandler;
- event = yield undefined;
- try {
- objectStore.add({}, null);
- ok(false, "add with null key should throw!");
- }
- catch (e) {
- ok(true, "add with null key threw");
- }
- try {
- objectStore.put({}, null);
- ok(false, "put with null key should throw!");
- }
- catch (e) {
- ok(true, "put with null key threw");
- }
- try {
- objectStore.put({}, null);
- ok(false, "put with null key should throw!");
- }
- catch (e) {
- ok(true, "put with null key threw");
- }
- try {
- objectStore.delete({}, null);
- ok(false, "remove with null key should throw!");
- }
- catch (e) {
- ok(true, "remove with null key threw");
- }
- objectStore = db.createObjectStore("bazing", { keyPath: "id",
- autoIncrement: true });
- request = objectStore.add({});
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- key1 = event.target.result;
- request = objectStore.put({id:key1});
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.target.result, key1, "put gave the same key back");
- key2 = 10;
- request = objectStore.put({id:key2});
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.target.result, key2, "put gave the same key back");
- try {
- objectStore.put({});
- ok(true, "put with no key should not throw with autoIncrement!");
- }
- catch (e) {
- ok(false, "put with no key threw with autoIncrement");
- }
- try {
- objectStore.put({});
- ok(true, "put with no key should not throw with autoIncrement!");
- }
- catch (e) {
- ok(false, "put with no key threw with autoIncrement");
- }
- try {
- objectStore.delete();
- ok(false, "remove with no key should throw!");
- }
- catch (e) {
- ok(true, "remove with no key threw");
- }
- try {
- objectStore.add({id:5}, 5);
- ok(false, "add with inline key and passed key should throw!");
- }
- catch (e) {
- ok(true, "add with inline key and passed key threw");
- }
- request = objectStore.delete(key2);
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- // Wait for success
- yield undefined;
- finishTest();
- yield undefined;
- }
|