blob: ce4d4364df2276a02660acbac56d3cf74457a0d4 [file] [log] [blame]
<html>
<head>
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="../../fast/js/resources/js-test-post-function.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test IndexedDB's IDBCursor.continue() with a key parameter.");
if (window.layoutTestController)
layoutTestController.waitUntilDone();
var date = new Date();
// In order of how it should be sorted by IndexedDB.
window.testData = [
0,
1,
1,
3.14159,
3.14159,
10,
11,
12,
13,
date,
date,
new Date(date.valueOf() + 1000),
"A big string",
"A big string",
"A bit1",
"A bit2",
"A bit3",
"the BIGGEST string"
];
function openDatabase()
{
result = evalAndLog("webkitIndexedDB.open('cursor-continue')");
result.onsuccess = setVersion;
result.onerror = unexpectedErrorCallback;
}
function setVersion()
{
window.db = evalAndLog("db = event.target.result");
result = evalAndLog("db.setVersion('new version')");
result.onsuccess = deleteExisting;
result.onerror = unexpectedErrorCallback;
}
function deleteExisting()
{
window.trans = evalAndLog("trans = event.target.result");
shouldBeTrue("trans !== null");
trans.onabort = unexpectedAbortCallback;
deleteAllObjectStores(db);
window.objectStore = evalAndLog("db.createObjectStore('someObjectStore')");
window.indexObject = evalAndLog("objectStore.createIndex('someIndex', 'x')");
window.nextToAdd = 0;
addData();
}
function addData()
{
result = evalAndLog("objectStore.add({'x': testData[nextToAdd]}, nextToAdd)");
result.onsuccess = ++window.nextToAdd < testData.length ? addData : ascendingTest;
result.onerror = unexpectedErrorCallback;
}
function ascendingTest()
{
debug("");
var request = evalAndLog("indexObject.openKeyCursor(null, webkitIDBCursor.NEXT)");
request.onsuccess = ascendingCallback;
request.onerror = unexpectedErrorCallback;
window.stage = 0;
}
function ascendingCallback()
{
if (window.stage == 0) {
shouldBe("event.target.result.primaryKey", "0");
evalAndLog("event.target.result.continue(3.14159)");
} else if (window.stage == 1) {
shouldBe("event.target.result.primaryKey", "3");
evalAndLog("event.target.result.continue(3.14159)");
} else if (window.stage == 2) {
shouldBe("event.target.result.primaryKey", "4");
evalAndLog("event.target.result.continue(3.14159)");
} else if (window.stage == 3) {
shouldBe("event.target.result.primaryKey", "5");
evalAndLog("event.target.result.continue(12)");
} else if (window.stage == 4) {
shouldBe("event.target.result.primaryKey", "7");
evalAndLog("event.target.result.continue(date)");
} else if (window.stage == 5) {
shouldBe("event.target.result.primaryKey", "9");
evalAndLog("event.target.result.continue(date)");
} else if (window.stage == 6) {
shouldBe("event.target.result.primaryKey", "10");
evalAndLog("event.target.result.continue(date)");
} else if (window.stage == 7) {
shouldBe("event.target.result.primaryKey", "11");
evalAndLog("event.target.result.continue('A bit1')");
} else if (window.stage == 8) {
shouldBe("event.target.result.primaryKey", "14");
evalAndLog("event.target.result.continue('A bit3')");
} else if (window.stage == 9) {
shouldBe("event.target.result.primaryKey", "16");
evalAndLog("event.target.result.continue('the BIGGEST string')");
} else if (window.stage == 10) {
shouldBe("event.target.result.primaryKey", "17");
evalAndLog("event.target.result.continue('the BIGGEST string')");
} else if (window.stage == 11) {
shouldBeNull("event.target.result");
descendingTest();
return;
} else {
testFailed("Illegal stage.");
}
window.stage++;
}
function descendingTest()
{
debug("");
var request = evalAndLog("indexObject.openKeyCursor(null, webkitIDBCursor.PREV)");
request.onsuccess = descendingCallback;
request.onerror = unexpectedErrorCallback;
window.stage = 0;
}
function descendingCallback()
{
if (window.stage == 0) {
shouldBe("event.target.result.primaryKey", "17");
evalAndLog("event.target.result.continue('A bit2')");
} else if (window.stage == 1) {
shouldBe("event.target.result.primaryKey", "15");
evalAndLog("event.target.result.continue('A bit2')");
} else if (window.stage == 2) {
shouldBe("event.target.result.primaryKey", "14");
evalAndLog("event.target.result.continue(date)");
} else if (window.stage == 3) {
shouldBe("event.target.result.primaryKey", "10");
evalAndLog("event.target.result.continue(date)");
} else if (window.stage == 4) {
shouldBe("event.target.result.primaryKey", "9");
evalAndLog("event.target.result.continue(1)");
} else if (window.stage == 5) {
shouldBe("event.target.result.primaryKey", "2");
evalAndLog("event.target.result.continue(1)");
} else if (window.stage == 6) {
shouldBe("event.target.result.primaryKey", "1");
evalAndLog("event.target.result.continue(1)");
} else if (window.stage == 7) {
shouldBe("event.target.result.primaryKey", "0");
evalAndLog("event.target.result.continue(1)");
} else if (window.stage == 8) {
shouldBeNull("event.target.result");
done();
return;
} else {
testFailed("Illegal stage.");
}
window.stage++;
}
openDatabase(); // The first step.
var successfullyParsed = true;
</script>
</body>
</html>