blob: 5af24019164f1a47300f67ebfc51ca6582e7104c [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 KeyRange.");
if (window.layoutTestController)
layoutTestController.waitUntilDone();
function checkSingleKeyRange(value)
{
keyRange = evalAndLog("webkitIDBKeyRange.only(" + value + ")");
shouldBe("keyRange.lower", "" + value);
shouldBe("keyRange.upper", "" + value);
shouldBeFalse("keyRange.lowerOpen");
shouldBeFalse("keyRange.upperOpen");
}
function checkLowerBoundKeyRange(value, open)
{
keyRange = evalAndLog("webkitIDBKeyRange.lowerBound(" + value + "," + open + ")");
shouldBe("keyRange.lower", "" + value);
if (open === undefined)
open = false;
shouldBe("keyRange.lowerOpen", "" + open);
shouldBeNull("keyRange.upper");
shouldBeFalse("keyRange.upperOpen");
}
function checkUpperBoundKeyRange(value, open)
{
keyRange = evalAndLog("webkitIDBKeyRange.upperBound(" + value + "," + open + ")");
shouldBe("keyRange.upper", "" + value);
if (open === undefined)
open = false;
shouldBe("keyRange.upperOpen", "" + open);
shouldBeNull("keyRange.lower");
shouldBeFalse("keyRange.lowerOpen");
}
function checkBoundKeyRange(lower, upper, lowerOpen, upperOpen)
{
keyRange = evalAndLog("webkitIDBKeyRange.bound(" + lower + "," + upper + ", " + lowerOpen + ", " + upperOpen + ")");
shouldBe("keyRange.lower", "" + lower);
shouldBe("keyRange.upper", "" + upper);
if (lowerOpen === undefined)
lowerOpen = false;
if (upperOpen === undefined)
upperOpen = false;
shouldBe("keyRange.lowerOpen", "" + lowerOpen);
shouldBe("keyRange.upperOpen", "" + upperOpen);
}
function test()
{
shouldBeFalse("'lower' in webkitIDBKeyRange");
shouldBeFalse("'upper' in webkitIDBKeyRange");
shouldBeFalse("'lowerOpen' in webkitIDBKeyRange");
shouldBeFalse("'upperOpen' in webkitIDBKeyRange");
shouldBeTrue("'only' in webkitIDBKeyRange");
shouldBeTrue("'lowerBound' in webkitIDBKeyRange");
shouldBeTrue("'upperBound' in webkitIDBKeyRange");
shouldBeTrue("'bound' in webkitIDBKeyRange");
debug("");
var instance = evalAndLog("instance = webkitIDBKeyRange.only(1)");
shouldBeTrue("'lower' in instance");
shouldBeTrue("'upper' in instance");
shouldBeTrue("'lowerOpen' in instance");
shouldBeTrue("'upperOpen' in instance");
shouldBeFalse("'only' in instance");
shouldBeFalse("'lowerBound' in instance");
shouldBeFalse("'upperBound' in instance");
shouldBeFalse("'bound' in instance");
debug("");
checkSingleKeyRange(1);
checkSingleKeyRange(3.14);
checkSingleKeyRange("'a'");
checkLowerBoundKeyRange(10, true);
checkLowerBoundKeyRange(11, false);
checkLowerBoundKeyRange(12);
checkLowerBoundKeyRange(10.1, true);
checkLowerBoundKeyRange(11.2, false);
checkLowerBoundKeyRange(12.3);
checkLowerBoundKeyRange("'aa'", true);
checkLowerBoundKeyRange("'ab'", false);
checkLowerBoundKeyRange("'ac'");
checkUpperBoundKeyRange(20, true);
checkUpperBoundKeyRange(21, false);
checkUpperBoundKeyRange(22);
checkUpperBoundKeyRange(20.2, true);
checkUpperBoundKeyRange(21.3, false);
checkUpperBoundKeyRange(22.4);
checkUpperBoundKeyRange("'ba'", true);
checkUpperBoundKeyRange("'bb'", false);
checkUpperBoundKeyRange("'bc'");
checkBoundKeyRange(30, 40);
checkBoundKeyRange(31, 41, false, false);
checkBoundKeyRange(32, 42, false, true);
checkBoundKeyRange(33, 43, true, false);
checkBoundKeyRange(34, 44, true, true);
checkBoundKeyRange(30.1, 40.2);
checkBoundKeyRange(31.3, 41.4, false, false);
checkBoundKeyRange(32.5, 42.6, false, true);
checkBoundKeyRange(33.7, 43.8, true, false);
checkBoundKeyRange(34.9, 44.0, true, true);
checkBoundKeyRange("'aaa'", "'aba'", false, false);
checkBoundKeyRange("'aab'", "'abb'");
checkBoundKeyRange("'aac'", "'abc'", false, false);
checkBoundKeyRange("'aad'", "'abd'", false, true);
checkBoundKeyRange("'aae'", "'abe'", true, false);
checkBoundKeyRange("'aaf'", "'abf'", true, true);
try {
debug("Passing an invalid key into only([])");
webkitIDBKeyRange.only([]);
testFailed("No exception thrown");
} catch (e) {
testPassed("Caught exception: " + e.toString());
}
try {
debug("Passing an invalid key into upperBound([])");
webkitIDBKeyRange.upperBound([]);
testFailed("No exception thrown");
} catch (e) {
testPassed("Caught exception: " + e.toString());
}
try {
debug("Passing an invalid key into lowerBound([])");
webkitIDBKeyRange.lowerBound([]);
testFailed("No exception thrown");
} catch (e) {
testPassed("Caught exception: " + e.toString());
}
try {
debug("Passing an invalid key into bound(null, [])");
webkitIDBKeyRange.bound(null, []);
testFailed("No exception thrown");
} catch (e) {
testPassed("Caught exception: " + e.toString());
}
try {
debug("Passing an invalid key into bound([],null)");
webkitIDBKeyRange.bound([], null);
testFailed("No exception thrown");
} catch (e) {
testPassed("Caught exception: " + e.toString());
}
try {
debug("Passing an invalid key into bound([], [])");
webkitIDBKeyRange.bound([], []);
testFailed("No exception thrown");
} catch (e) {
testPassed("Caught exception: " + e.toString());
}
}
test();
var successfullyParsed = true;
done();
</script>
</body>
</html>