3 <script src="../../fast/js/resources/js-test-pre.js"></script>
4 <script src="resources/shared.js"></script>
7 <p id="description"></p>
8 <div id="console"></div>
11 description("Test IndexedDB key comparison using IDBFactory.cmp().");
12 if (window.layoutTestController)
13 layoutTestController.waitUntilDone();
17 indexedDB = evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;");
18 shouldBeFalse("indexedDB == null");
19 IDBDatabaseException = evalAndLog("IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;");
20 shouldBeFalse("IDBDatabaseException == null");
22 shouldBeTrue("typeof indexedDB.cmp === 'function'");
30 function testValidKeys()
33 debug("compare valid keys");
48 "new Date(1317399931023)",
57 "'\xA2'", // U+00A2 CENT SIGN
58 "'\u6C34'", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
59 "'\uD834\uDD1E'", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
60 "'\uFFFD'", // U+FFFD REPLACEMENT CHARACTER
65 "[-Number.MAX_VALUE]",
67 "[-Number.MIN_VALUE]",
76 "[new Date(1317399931023)]",
85 "['\xA2']", // U+00A2 CENT SIGN
86 "['\u6C34']", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
87 "['\uD834\uDD1E']", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
88 "['\uFFFD']", // U+FFFD REPLACEMENT CHARACTER
100 for (i = 0; i < keys.length - 1; i += 1) {
103 shouldBeTrue("indexedDB.cmp(" + key1 + "," + key2 + ") === -1");
104 shouldBeTrue("indexedDB.cmp(" + key2 + "," + key1 + ") === 1");
105 shouldBeTrue("indexedDB.cmp(" + key1 + "," + key1 + ") === 0");
106 shouldBeTrue("indexedDB.cmp(" + key2 + "," + key2 + ") === 0");
110 function testInvalidKeys()
113 debug("compare invalid keys");
116 "void 0", // undefined
126 "window.document.body"
130 for (i = 0; i < invalidKeys.length - 1; i += 1) {
131 key1 = invalidKeys[i];
132 key2 = invalidKeys[i + 1];
133 evalAndExpectException("indexedDB.cmp(" + key1 + ", " + key2 + ")", "IDBDatabaseException.DATA_ERR");
134 evalAndExpectException("indexedDB.cmp(" + key2 + ", " + key1 + ")", "IDBDatabaseException.DATA_ERR");
135 evalAndExpectException("indexedDB.cmp(" + key1 + ", 'valid')", "IDBDatabaseException.DATA_ERR");
136 evalAndExpectException("indexedDB.cmp('valid', " + key1 + ")", "IDBDatabaseException.DATA_ERR");
137 evalAndExpectException("indexedDB.cmp(" + key2 + ", 'valid')", "IDBDatabaseException.DATA_ERR");
138 evalAndExpectException("indexedDB.cmp('valid', " + key2 + ")", "IDBDatabaseException.DATA_ERR");
142 function testIdenticalKeys()
145 debug("compare identical keys");
147 shouldBeTrue("indexedDB.cmp(0, -0) === 0");