gecko/dom/indexedDB/test/test_key_requirements.html

284 lines
7.0 KiB
HTML
Raw Normal View History

<!--
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;
db.addEventListener("error", function(event) {
event.preventDefault();
}, false);
request = db.setVersion("1");
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield;
let objectStore = db.createObjectStore("foo", "", true);
request = objectStore.add({});
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let key1 = event.result;
request = objectStore.put({}, key1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, key1, "put gave the same key back");
let key2 = 10;
request = objectStore.put({}, key2);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, key2, "put gave the same key back");
key2 = 100;
request = objectStore.add({}, key2);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, key2, "put gave the same key back");
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("bar", "", false);
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", "id", false);
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");
}
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");
request = objectStore.put({id:10});
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, key1, "put gave back the same key");
request = objectStore.put({id:10});
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, key1, "put gave back the same key");
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 {
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", "id", true);
request = objectStore.add({});
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
key1 = event.result;
request = objectStore.put({id:key1});
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, key1, "put gave the same key back");
key2 = 10;
request = objectStore.put({id:key2});
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, key2, "put gave the same key back");
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");
}
request = objectStore.delete(key2);
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>