2010-06-23 12:46:08 -07:00
|
|
|
<!--
|
|
|
|
Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
-->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Indexed Database Property Test</title>
|
|
|
|
|
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
|
|
|
|
<script type="text/javascript;version=1.7">
|
|
|
|
function testSteps()
|
|
|
|
{
|
|
|
|
const name = window.location.pathname;
|
|
|
|
const description = "My Test Database";
|
|
|
|
|
|
|
|
let request = moz_indexedDB.open(name, description);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
let event = yield;
|
|
|
|
|
|
|
|
let db = event.result;
|
2010-11-10 15:26:03 -08:00
|
|
|
db.addEventListener("error", function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
}, false);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
request = db.setVersion("1");
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
let event = yield;
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
let objectStore = db.createObjectStore("foo", "", true);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
request = objectStore.add({});
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
|
|
|
let key1 = event.result;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
request = objectStore.put({}, key1);
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
is(event.result, key1, "put gave the same key back");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
let key2 = 10;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
request = objectStore.put({}, key2);
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
is(event.result, key2, "put gave the same key back");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
key2 = 100;
|
|
|
|
|
|
|
|
request = objectStore.add({}, key2);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
is(event.result, key2, "put gave the same key back");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
try {
|
2010-08-26 13:57:28 -07:00
|
|
|
objectStore.put({});
|
|
|
|
ok(false, "put with no key should throw!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-08-26 13:57:28 -07:00
|
|
|
ok(true, "put with no key threw");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-08-26 13:57:28 -07:00
|
|
|
objectStore.put({});
|
|
|
|
ok(false, "put with no key should throw!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-08-26 13:57:28 -07:00
|
|
|
ok(true, "put with no key threw");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-11-10 15:25:57 -08:00
|
|
|
objectStore.delete();
|
2010-06-23 12:46:08 -07:00
|
|
|
ok(false, "remove with no key should throw!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "remove with no key threw");
|
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
objectStore = db.createObjectStore("bar", "", false);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
objectStore.add({});
|
|
|
|
ok(false, "add with no key should throw!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "add with no key threw");
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-08-26 13:57:28 -07:00
|
|
|
objectStore.put({});
|
|
|
|
ok(false, "put with no key should throw!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-08-26 13:57:28 -07:00
|
|
|
ok(true, "put with no key threw");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-08-26 13:57:28 -07:00
|
|
|
objectStore.put({});
|
|
|
|
ok(false, "put with no key should throw!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-08-26 13:57:28 -07:00
|
|
|
ok(true, "put with no key threw");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-11-10 15:25:57 -08:00
|
|
|
objectStore.delete();
|
2010-06-23 12:46:08 -07:00
|
|
|
ok(false, "remove with no key should throw!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "remove with no key threw");
|
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
objectStore = db.createObjectStore("baz", "id", false);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
objectStore.add({});
|
|
|
|
ok(false, "add with no key should throw!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "add with no key threw");
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-08-26 13:57:28 -07:00
|
|
|
objectStore.put({});
|
|
|
|
ok(false, "put with no key should throw!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-08-26 13:57:28 -07:00
|
|
|
ok(true, "put with no key threw");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-08-26 13:57:28 -07:00
|
|
|
objectStore.put({});
|
|
|
|
ok(false, "put with no key should throw!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-08-26 13:57:28 -07:00
|
|
|
ok(true, "put with no key threw");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-11-10 15:25:57 -08:00
|
|
|
objectStore.delete();
|
2010-06-23 12:46:08 -07:00
|
|
|
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;
|
|
|
|
|
|
|
|
is(event.result, key1, "add gave back the same key");
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
request = objectStore.put({id:10});
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
is(event.result, key1, "put gave back the same key");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
request = objectStore.put({id:10});
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
is(event.result, key1, "put gave back the same key");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
request = objectStore.add({id:10});
|
|
|
|
request.onerror = grabEventAndContinueHandler;
|
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
|
|
|
yield;
|
|
|
|
|
|
|
|
request = objectStore.add({}, null);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
|
|
|
is(typeof(event.result), "string", "Good generated key");
|
|
|
|
|
|
|
|
try {
|
2010-08-26 13:57:28 -07:00
|
|
|
objectStore.put({}, null);
|
|
|
|
ok(false, "put with null key should throw!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-08-26 13:57:28 -07:00
|
|
|
ok(true, "put with null key threw");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-08-26 13:57:28 -07:00
|
|
|
objectStore.put({}, null);
|
|
|
|
ok(false, "put with null key should throw!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-08-26 13:57:28 -07:00
|
|
|
ok(true, "put with null key threw");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-11-10 15:25:57 -08:00
|
|
|
objectStore.delete({}, null);
|
2010-06-23 12:46:08 -07:00
|
|
|
ok(false, "remove with null key should throw!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "remove with null key threw");
|
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
objectStore = db.createObjectStore("bazing", "id", true);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
request = objectStore.add({});
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
|
|
|
key1 = event.result;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
request = objectStore.put({id:key1});
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
is(event.result, key1, "put gave the same key back");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
key2 = 10;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
request = objectStore.put({id:key2});
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-08-26 13:57:28 -07:00
|
|
|
is(event.result, key2, "put gave the same key back");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
try {
|
2010-08-26 13:57:28 -07:00
|
|
|
objectStore.put({});
|
|
|
|
ok(false, "put with no key should throw!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-08-26 13:57:28 -07:00
|
|
|
ok(true, "put with no key threw");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-08-26 13:57:28 -07:00
|
|
|
objectStore.put({});
|
|
|
|
ok(false, "put with no key should throw!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-08-26 13:57:28 -07:00
|
|
|
ok(true, "put with no key threw");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-11-10 15:25:57 -08:00
|
|
|
objectStore.delete();
|
2010-06-23 12:46:08 -07:00
|
|
|
ok(false, "remove with no key should throw!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "remove with no key threw");
|
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:57 -08:00
|
|
|
request = objectStore.delete(key2);
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
|
|
|
finishTest();
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
|
|
|
|
</html>
|