2010-06-23 23:46:08 +04: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="/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";
|
|
|
|
const objectStoreInfo = [
|
2011-11-08 10:25:51 +04:00
|
|
|
{ name: "1", options: { keyPath: null } },
|
|
|
|
{ name: "2", options: { keyPath: null, autoIncrement: true } },
|
|
|
|
{ name: "3", options: { keyPath: null, autoIncrement: false } },
|
|
|
|
{ name: "4", options: { keyPath: null } },
|
2010-12-21 19:02:01 +03:00
|
|
|
{ name: "5", options: { keyPath: "foo" } },
|
|
|
|
{ name: "6" },
|
|
|
|
{ name: "7", options: null },
|
|
|
|
{ name: "8", options: { autoIncrement: true } },
|
|
|
|
{ name: "9", options: { autoIncrement: false } },
|
|
|
|
{ name: "10", options: { keyPath: "foo", autoIncrement: false } },
|
2011-11-08 03:37:16 +04:00
|
|
|
{ name: "11", options: { keyPath: "foo", autoIncrement: true } },
|
|
|
|
{ name: "" },
|
|
|
|
{ name: null },
|
|
|
|
{ name: undefined }
|
2010-06-23 23:46:08 +04:00
|
|
|
];
|
|
|
|
|
2012-06-29 20:48:35 +04:00
|
|
|
let request = indexedDB.open(name, 1, description);
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
2011-10-20 20:10:56 +04:00
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
2010-06-23 23:46:08 +04:00
|
|
|
let event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
let db = event.target.result;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
let count = db.objectStoreNames.length;
|
|
|
|
is(count, 0, "correct objectStoreNames length");
|
|
|
|
|
2010-12-21 19:02:01 +03:00
|
|
|
try {
|
|
|
|
db.createObjectStore("foo", "bar");
|
|
|
|
ok(false, "createObjectStore with bad options should throw");
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
ok(true, "createObjectStore with bad options");
|
|
|
|
}
|
|
|
|
|
2011-12-20 14:59:07 +04:00
|
|
|
try {
|
|
|
|
db.createObjectStore("foo", { keyPath: ["foo"], autoIncrement: true });
|
|
|
|
ok(false, "createObjectStore with keyPath-array and autoIncrement should throw");
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
ok(true, "createObjectStore with keyPath-array and autoIncrement should throw");
|
|
|
|
}
|
|
|
|
|
2011-11-08 10:25:51 +04:00
|
|
|
ok(db.createObjectStore("foo", { foo: "" }),
|
|
|
|
"createObjectStore with unknown options should not throw");
|
|
|
|
db.deleteObjectStore("foo");
|
2010-12-21 19:02:01 +03:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
for (let index in objectStoreInfo) {
|
|
|
|
index = parseInt(index);
|
2010-12-16 00:21:04 +03:00
|
|
|
const info = objectStoreInfo[index];
|
|
|
|
|
2010-12-21 19:02:01 +03:00
|
|
|
let objectStore = info.hasOwnProperty("options") ?
|
|
|
|
db.createObjectStore(info.name, info.options) :
|
|
|
|
db.createObjectStore(info.name);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
is(db.objectStoreNames.length, index + 1,
|
|
|
|
"updated objectStoreNames list");
|
|
|
|
|
2011-11-08 03:37:16 +04:00
|
|
|
let name = info.name;
|
|
|
|
if (name === null) {
|
|
|
|
name = "null";
|
|
|
|
}
|
|
|
|
else if (name === undefined) {
|
|
|
|
name = "undefined";
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
let found = false;
|
|
|
|
for (let i = 0; i <= index; i++) {
|
2011-11-08 03:37:16 +04:00
|
|
|
if (db.objectStoreNames.item(i) == name) {
|
2010-06-23 23:46:08 +04:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is(found, true, "objectStoreNames contains name");
|
|
|
|
|
2011-11-08 03:37:16 +04:00
|
|
|
is(objectStore.name, name, "Bad name");
|
2010-12-21 19:02:01 +03:00
|
|
|
is(objectStore.keyPath, info.options && info.options.keyPath ?
|
2011-12-04 21:39:01 +04:00
|
|
|
info.options.keyPath : null,
|
2010-06-23 23:46:08 +04:00
|
|
|
"Bad keyPath");
|
|
|
|
if(objectStore.indexNames.length, 0, "Bad indexNames");
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
ok(event.target.transaction, "event has a transaction");
|
|
|
|
ok(event.target.transaction.db === db, "transaction has the right db");
|
2012-03-13 08:44:45 +04:00
|
|
|
is(event.target.transaction.mode, "versionchange",
|
2010-06-23 23:46:08 +04:00
|
|
|
"transaction has the correct mode");
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.transaction.objectStoreNames.length, index + 1,
|
2010-06-23 23:46:08 +04:00
|
|
|
"transaction has correct objectStoreNames list");
|
2010-10-19 21:58:52 +04:00
|
|
|
found = false;
|
2011-01-07 09:21:36 +03:00
|
|
|
for (let j = 0; j < event.target.transaction.objectStoreNames.length;
|
|
|
|
j++) {
|
2011-11-08 03:37:16 +04:00
|
|
|
if (event.target.transaction.objectStoreNames.item(j) == name) {
|
2010-10-19 21:58:52 +04:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is(found, true, "transaction has correct objectStoreNames list");
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
finishTest();
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
|
|
|
|
</html>
|