mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
170 lines
6.1 KiB
HTML
170 lines
6.1 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="/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";
|
|
const objectStoreName = "People";
|
|
|
|
const objectStoreData = [
|
|
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
|
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
|
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
|
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
|
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
|
{ key: "237-23-7737", value: { name: "Pat", height: 65 } }
|
|
];
|
|
|
|
const indexData = [
|
|
{ name: "name", keyPath: "name", options: { unique: true } },
|
|
{ name: "height", keyPath: "height", options: { unique: false } },
|
|
{ name: "weight", keyPath: "weight", options: { unique: false } }
|
|
];
|
|
|
|
const objectStoreDataNameSort = [
|
|
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
|
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
|
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
|
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
|
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
|
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }
|
|
];
|
|
|
|
const objectStoreDataWeightSort = [
|
|
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
|
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
|
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
|
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
|
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
|
];
|
|
|
|
const objectStoreDataHeightSort = [
|
|
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
|
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
|
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
|
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
|
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
|
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
|
];
|
|
|
|
let request = moz_indexedDB.open(name, description);
|
|
request.onerror = errorHandler;
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
let event = yield;
|
|
|
|
let db = event.result;
|
|
|
|
request = db.setVersion("1");
|
|
request.onerror = errorHandler;
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield;
|
|
|
|
let objectStore = db.createObjectStore(objectStoreName);
|
|
|
|
// First, add all our data to the object store.
|
|
let addedData = 0;
|
|
for (let i in objectStoreData) {
|
|
request = objectStore.add(objectStoreData[i].value,
|
|
objectStoreData[i].key);
|
|
request.onerror = errorHandler;
|
|
request.onsuccess = function(event) {
|
|
if (++addedData == objectStoreData.length) {
|
|
testGenerator.send(event);
|
|
}
|
|
}
|
|
}
|
|
event = yield;
|
|
ok(true, "1");
|
|
|
|
// Now create the indexes.
|
|
for (let i in indexData) {
|
|
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
|
|
indexData[i].options);
|
|
}
|
|
|
|
is(objectStore.indexNames.length, indexData.length, "Good index count");
|
|
continueToNextStep();
|
|
yield;
|
|
|
|
ok(true, "2");
|
|
objectStore = db.transaction(objectStoreName)
|
|
.objectStore(objectStoreName);
|
|
|
|
request = objectStore.index("height").getAllKeys(65);
|
|
request.onerror = errorHandler;
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield;
|
|
ok(true, "3");
|
|
|
|
is(event.result instanceof Array, true, "Got an array object");
|
|
is(event.result.length, 2, "Correct length");
|
|
|
|
for (let i in event.result) {
|
|
is(event.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
|
|
"Correct key");
|
|
}
|
|
|
|
request = objectStore.index("height").getAllKeys();
|
|
request.onerror = errorHandler;
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield;
|
|
ok(true, "4");
|
|
|
|
is(event.result instanceof Array, true, "Got an array object");
|
|
is(event.result.length, objectStoreDataHeightSort.length,
|
|
"Correct length");
|
|
|
|
for (let i in event.result) {
|
|
is(event.result[i], objectStoreDataHeightSort[i].key, "Correct key");
|
|
}
|
|
|
|
request = objectStore.index("height").getAllKeys(null, 4);
|
|
request.onerror = errorHandler;
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield;
|
|
|
|
ok(true, "5");
|
|
is(event.result instanceof Array, true, "Got an array object");
|
|
is(event.result.length, 4, "Correct length");
|
|
|
|
for (let i in event.result) {
|
|
is(event.result[i], objectStoreDataHeightSort[i].key, "Correct key");
|
|
}
|
|
|
|
request = objectStore.index("height").getAllKeys(65, 1);
|
|
request.onerror = errorHandler;
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield;
|
|
|
|
ok(true, "6");
|
|
is(event.result instanceof Array, true, "Got an array object");
|
|
is(event.result.length, 1, "Correct length");
|
|
|
|
for (let i in event.result) {
|
|
is(event.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
|
|
"Correct key");
|
|
}
|
|
|
|
finishTest();
|
|
yield;
|
|
}
|
|
</script>
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
</head>
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
</html>
|