blob: d293fe90faf1b3db0d6bb13fe8b2d060fcdc9e79 [file] [log] [blame]
<html>
<head>
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test IndexedDB key comparison using IDBFactory.cmp().");
if (window.layoutTestController)
layoutTestController.waitUntilDone();
function test()
{
indexedDB = evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;");
shouldBeFalse("indexedDB == null");
IDBDatabaseException = evalAndLog("IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;");
shouldBeFalse("IDBDatabaseException == null");
shouldBeTrue("typeof indexedDB.cmp === 'function'");
testValidKeys();
testInvalidKeys();
testIdenticalKeys();
done();
}
function testValidKeys()
{
debug("");
debug("compare valid keys");
debug("(Array keys are not yet implemented so many tests will fail)");
var keys = [
"-Infinity",
"-Number.MAX_VALUE",
"-1",
"-Number.MIN_VALUE",
"0",
"Number.MIN_VALUE",
"1",
"Number.MAX_VALUE",
"Infinity",
"new Date(0)",
"new Date(1000)",
"new Date(1317399931023)",
"''",
"'\x00'",
"'a'",
"'aa'",
"'b'",
"'ba'",
"'\xA2'", // U+00A2 CENT SIGN
"'\u6C34'", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
"'\uD834\uDD1E'", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
"'\uFFFD'", // U+FFFD REPLACEMENT CHARACTER
// FIXME: Array keys are NYI, but these should pass once implemented
"[]",
"[-Infinity]",
"[-1.7976931348623157e+308]",
"[-1]",
"[-5e-324]",
"[0]",
"[5e-324]",
"[1]",
"[1.7976931348623157e+308]",
"[Infinity]",
"[new Date(0)]",
"[new Date(1000)]",
"[new Date(1317399931023)]",
"['']",
"['\x00']",
"['a']",
"['aa']",
"['b']",
"['ba']",
"['\xA2']", // U+00A2 CENT SIGN
"['\u6C34']", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
"['\uD834\uDD1E']", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
"['\uFFFD']", // U+FFFD REPLACEMENT CHARACTER
"[[]]",
"[[], []]",
"[[], [], []]",
"[[[]]]",
"[[[[]]]]",
];
var i, key1, key2;
for (i = 0; i < keys.length - 1; i += 1) {
key1 = keys[i];
key2 = keys[i + 1];
shouldBeTrue("indexedDB.cmp(" + key1 + "," + key2 + ") === -1");
shouldBeTrue("indexedDB.cmp(" + key2 + "," + key1 + ") === 1");
shouldBeTrue("indexedDB.cmp(" + key1 + "," + key1 + ") === 0");
shouldBeTrue("indexedDB.cmp(" + key2 + "," + key2 + ") === 0");
}
}
function testInvalidKeys()
{
debug("");
debug("compare invalid keys");
var invalidKeys = [
"void 0", // undefined
"true",
"false",
"NaN",
"null",
"{}",
"function () {}",
"/regex/",
"window",
"window.document",
"window.document.body"
];
var i, key1, key2;
for (i = 0; i < invalidKeys.length - 1; i += 1) {
key1 = invalidKeys[i];
key2 = invalidKeys[i + 1];
evalAndExpectException("indexedDB.cmp(" + key1 + ", " + key2 + ")", "IDBDatabaseException.DATA_ERR");
evalAndExpectException("indexedDB.cmp(" + key2 + ", " + key1 + ")", "IDBDatabaseException.DATA_ERR");
evalAndExpectException("indexedDB.cmp(" + key1 + ", 'valid')", "IDBDatabaseException.DATA_ERR");
evalAndExpectException("indexedDB.cmp('valid', " + key1 + ")", "IDBDatabaseException.DATA_ERR");
evalAndExpectException("indexedDB.cmp(" + key2 + ", 'valid')", "IDBDatabaseException.DATA_ERR");
evalAndExpectException("indexedDB.cmp('valid', " + key2 + ")", "IDBDatabaseException.DATA_ERR");
}
}
function testIdenticalKeys()
{
debug("");
debug("compare identical keys");
shouldBeTrue("indexedDB.cmp(0, -0) === 0");
}
var successfullyParsed = true;
test();
</script>
</body>
</html>