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 values = [ "a", "1", 1, "foo", 300, true, false, 4.5, null ];
|
|
|
|
|
2011-01-03 23:03:06 +03:00
|
|
|
let request = mozIndexedDB.open(name, description);
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
let event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
let db = event.target.result;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
request = db.setVersion("1");
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-12-21 19:02:01 +03:00
|
|
|
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
request = objectStore.getAll();
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 0, "No elements");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
let addedCount = 0;
|
|
|
|
|
|
|
|
for (let i in values) {
|
|
|
|
request = objectStore.add(values[i]);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = function(event) {
|
|
|
|
if (++addedCount == values.length) {
|
|
|
|
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yield;
|
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo").objectStore("foo").getAll();
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, values.length, "Same length");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
is(event.target.result[i], values[i], "Same value");
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo").objectStore("foo").getAll(null, 5);
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 5, "Correct length");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
is(event.target.result[i], values[i], "Same value");
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-11-11 02:26:00 +03:00
|
|
|
let keyRange = IDBKeyRange.bound(1, 9);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, values.length, "Correct length");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
is(event.target.result[i], values[i], "Same value");
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-11-11 02:26:00 +03:00
|
|
|
keyRange = IDBKeyRange.bound(4, 7);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 4, "Correct length");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
2010-12-16 00:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get should take a key range also.
|
|
|
|
request = db.transaction("foo").objectStore("foo").get(keyRange);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 4, "Correct length");
|
2010-12-16 00:21:20 +03:00
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-11-11 02:26:00 +03:00
|
|
|
keyRange = IDBKeyRange.bound(4, 7);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 2);
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 2, "Correct length");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-11-11 02:26:00 +03:00
|
|
|
keyRange = IDBKeyRange.bound(4, 7);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 50);
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 4, "Correct length");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-11-11 02:26:00 +03:00
|
|
|
keyRange = IDBKeyRange.bound(4, 7);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 0);
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 0, "Correct length");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-11-11 02:26:00 +03:00
|
|
|
keyRange = IDBKeyRange.bound(4, 7, true, true);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
|
2010-06-23 23:46:08 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 2, "Correct length");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
is(event.target.result[i], values[parseInt(i) + 4], "Same value");
|
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>
|