gecko/dom/indexedDB/test/test_getAll.html
Ben Turner 8802ea7670 Bug 694145 - 'IndexedDB: various methods should accept both keys and KeyRanges'. r=sicking.
--HG--
extra : transplant_source : R%0C%DA%D7%EF%8D3U%7DQ%1A%05%1A3%94%1E%F8%B0%A3k
2011-11-03 08:59:17 -07:00

174 lines
5.7 KiB
HTML

<!--
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 ];
let request = mozIndexedDB.open(name, 1, description);
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
let event = yield;
let db = event.target.result;
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
request.onsuccess = grabEventAndContinueHandler;
request = objectStore.getAll();
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 0, "No elements");
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;
yield;
request = db.transaction("foo").objectStore("foo").getAll();
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, values.length, "Same length");
for (let i in event.target.result) {
is(event.target.result[i], values[i], "Same value");
}
request = db.transaction("foo").objectStore("foo").getAll(null, 5);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 5, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], values[i], "Same value");
}
let keyRange = IDBKeyRange.bound(1, 9);
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, values.length, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], values[i], "Same value");
}
keyRange = IDBKeyRange.bound(4, 7);
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 4, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
}
// Get should take a key range also but it doesn't return an array.
request = db.transaction("foo").objectStore("foo").get(keyRange);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.target.result instanceof Array, false, "Not an array object");
is(event.target.result, values[3], "Correct value");
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 2);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 2, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
}
keyRange = IDBKeyRange.bound(4, 7);
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 50);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 4, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
}
keyRange = IDBKeyRange.bound(4, 7);
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 0);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 0, "Correct length");
keyRange = IDBKeyRange.bound(4, 7, true, true);
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 2, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], values[parseInt(i) + 4], "Same value");
}
finishTest();
yield;
}
</script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>