2012-01-04 19:43:33 +04:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
var testGenerator = testSteps();
|
2012-01-04 19:43:33 +04:00
|
|
|
|
2016-12-01 12:11:32 +03:00
|
|
|
function* testSteps()
|
2012-01-04 19:43:33 +04:00
|
|
|
{
|
|
|
|
const name = this.window ? window.location.pathname : "Splendid Test";
|
|
|
|
|
2012-07-13 09:37:28 +04:00
|
|
|
let request = indexedDB.open(name, 1);
|
2012-01-04 19:43:33 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
2015-06-20 19:08:30 +03:00
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
let event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
let db = event.target.result;
|
|
|
|
db.addEventListener("error", function(event) {
|
|
|
|
event.preventDefault();
|
2017-01-17 13:50:25 +03:00
|
|
|
});
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
|
|
|
|
|
|
|
request = objectStore.add({});
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
let key1 = event.target.result;
|
|
|
|
|
|
|
|
request = objectStore.put({}, key1);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
is(event.target.result, key1, "put gave the same key back");
|
|
|
|
|
|
|
|
let key2 = 10;
|
|
|
|
|
|
|
|
request = objectStore.put({}, key2);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
is(event.target.result, key2, "put gave the same key back");
|
|
|
|
|
|
|
|
key2 = 100;
|
|
|
|
|
|
|
|
request = objectStore.add({}, key2);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
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 {
|
2017-05-03 19:30:48 +03:00
|
|
|
objectStore.add({id: 5}, 5);
|
2012-01-04 19:43:33 +04:00
|
|
|
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;
|
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
request = objectStore.add({id: key1});
|
2012-01-04 19:43:33 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
is(event.target.result, key1, "add gave back the same key");
|
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
request = objectStore.put({id: 10});
|
2012-01-04 19:43:33 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
is(event.target.result, key1, "put gave back the same key");
|
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
request = objectStore.put({id: 10});
|
2012-01-04 19:43:33 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
is(event.target.result, key1, "put gave back the same key");
|
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
request = objectStore.add({id: 10});
|
2012-08-31 07:45:16 +04:00
|
|
|
request.addEventListener("error", new ExpectError("ConstraintError", true));
|
2012-01-04 19:43:33 +04:00
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
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;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
key1 = event.target.result;
|
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
request = objectStore.put({id: key1});
|
2012-01-04 19:43:33 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
is(event.target.result, key1, "put gave the same key back");
|
|
|
|
|
|
|
|
key2 = 10;
|
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
request = objectStore.put({id: key2});
|
2012-01-04 19:43:33 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
|
|
|
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 {
|
2017-05-03 19:30:48 +03:00
|
|
|
objectStore.add({id: 5}, 5);
|
2012-01-04 19:43:33 +04:00
|
|
|
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;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-01-04 19:43:33 +04:00
|
|
|
|
2015-06-20 19:08:30 +03:00
|
|
|
// Wait for success
|
|
|
|
yield undefined;
|
|
|
|
|
2012-01-04 19:43:33 +04:00
|
|
|
finishTest();
|
2015-06-20 19:08:30 +03:00
|
|
|
}
|