commit-queue@webkit.org | a8ef767 | 2011-10-11 19:22:14 +0000 | [diff] [blame] | 1 | <html> |
| 2 | <head> |
commit-queue@webkit.org | a8ef767 | 2011-10-11 19:22:14 +0000 | [diff] [blame] | 3 | <script src="../../fast/js/resources/js-test-pre.js"></script> |
commit-queue@webkit.org | a8ef767 | 2011-10-11 19:22:14 +0000 | [diff] [blame] | 4 | <script src="resources/shared.js"></script> |
| 5 | </head> |
| 6 | <body> |
| 7 | <p id="description"></p> |
| 8 | <div id="console"></div> |
| 9 | <script> |
| 10 | |
| 11 | description("Test IndexedDB key comparison using IDBFactory.cmp()."); |
| 12 | if (window.layoutTestController) |
| 13 | layoutTestController.waitUntilDone(); |
| 14 | |
| 15 | function test() |
| 16 | { |
| 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"); |
| 21 | |
| 22 | shouldBeTrue("typeof indexedDB.cmp === 'function'"); |
| 23 | |
| 24 | testValidKeys(); |
| 25 | testInvalidKeys(); |
| 26 | testIdenticalKeys(); |
| 27 | done(); |
| 28 | } |
| 29 | |
| 30 | function testValidKeys() |
| 31 | { |
| 32 | debug(""); |
| 33 | debug("compare valid keys"); |
| 34 | |
| 35 | debug("(Array keys are not yet implemented so many tests will fail)"); |
| 36 | |
| 37 | var keys = [ |
| 38 | "-Infinity", |
| 39 | "-Number.MAX_VALUE", |
| 40 | "-1", |
| 41 | "-Number.MIN_VALUE", |
| 42 | "0", |
| 43 | "Number.MIN_VALUE", |
| 44 | "1", |
| 45 | "Number.MAX_VALUE", |
| 46 | "Infinity", |
| 47 | |
| 48 | "new Date(0)", |
| 49 | "new Date(1000)", |
| 50 | "new Date(1317399931023)", |
| 51 | |
| 52 | "''", |
| 53 | "'\x00'", |
| 54 | "'a'", |
| 55 | "'aa'", |
| 56 | "'b'", |
| 57 | "'ba'", |
| 58 | |
| 59 | "'\xA2'", // U+00A2 CENT SIGN |
| 60 | "'\u6C34'", // U+6C34 CJK UNIFIED IDEOGRAPH (water) |
| 61 | "'\uD834\uDD1E'", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair) |
| 62 | "'\uFFFD'", // U+FFFD REPLACEMENT CHARACTER |
| 63 | |
| 64 | // FIXME: Array keys are NYI, but these should pass once implemented |
| 65 | "[]", |
| 66 | |
| 67 | "[-Infinity]", |
| 68 | "[-1.7976931348623157e+308]", |
| 69 | "[-1]", |
| 70 | "[-5e-324]", |
| 71 | "[0]", |
| 72 | "[5e-324]", |
| 73 | "[1]", |
| 74 | "[1.7976931348623157e+308]", |
| 75 | "[Infinity]", |
| 76 | |
| 77 | "[new Date(0)]", |
| 78 | "[new Date(1000)]", |
| 79 | "[new Date(1317399931023)]", |
| 80 | |
| 81 | "['']", |
| 82 | "['\x00']", |
| 83 | "['a']", |
| 84 | "['aa']", |
| 85 | "['b']", |
| 86 | "['ba']", |
| 87 | |
| 88 | "['\xA2']", // U+00A2 CENT SIGN |
| 89 | "['\u6C34']", // U+6C34 CJK UNIFIED IDEOGRAPH (water) |
| 90 | "['\uD834\uDD1E']", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair) |
| 91 | "['\uFFFD']", // U+FFFD REPLACEMENT CHARACTER |
| 92 | |
| 93 | "[[]]", |
| 94 | |
| 95 | "[[], []]", |
| 96 | "[[], [], []]", |
| 97 | |
| 98 | "[[[]]]", |
| 99 | "[[[[]]]]", |
| 100 | ]; |
| 101 | |
| 102 | var i, key1, key2; |
| 103 | for (i = 0; i < keys.length - 1; i += 1) { |
| 104 | key1 = keys[i]; |
| 105 | key2 = keys[i + 1]; |
| 106 | shouldBeTrue("indexedDB.cmp(" + key1 + "," + key2 + ") === -1"); |
| 107 | shouldBeTrue("indexedDB.cmp(" + key2 + "," + key1 + ") === 1"); |
| 108 | shouldBeTrue("indexedDB.cmp(" + key1 + "," + key1 + ") === 0"); |
| 109 | shouldBeTrue("indexedDB.cmp(" + key2 + "," + key2 + ") === 0"); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | function testInvalidKeys() |
| 114 | { |
| 115 | debug(""); |
| 116 | debug("compare invalid keys"); |
| 117 | |
| 118 | var invalidKeys = [ |
| 119 | "void 0", // undefined |
| 120 | "true", |
| 121 | "false", |
| 122 | "NaN", |
| 123 | "null", |
| 124 | "{}", |
| 125 | "function () {}", |
| 126 | "/regex/", |
| 127 | "window", |
| 128 | "window.document", |
| 129 | "window.document.body" |
| 130 | ]; |
| 131 | |
| 132 | var i, key1, key2; |
| 133 | for (i = 0; i < invalidKeys.length - 1; i += 1) { |
| 134 | key1 = invalidKeys[i]; |
| 135 | key2 = invalidKeys[i + 1]; |
| 136 | evalAndExpectException("indexedDB.cmp(" + key1 + ", " + key2 + ")", "IDBDatabaseException.DATA_ERR"); |
| 137 | evalAndExpectException("indexedDB.cmp(" + key2 + ", " + key1 + ")", "IDBDatabaseException.DATA_ERR"); |
| 138 | evalAndExpectException("indexedDB.cmp(" + key1 + ", 'valid')", "IDBDatabaseException.DATA_ERR"); |
| 139 | evalAndExpectException("indexedDB.cmp('valid', " + key1 + ")", "IDBDatabaseException.DATA_ERR"); |
| 140 | evalAndExpectException("indexedDB.cmp(" + key2 + ", 'valid')", "IDBDatabaseException.DATA_ERR"); |
| 141 | evalAndExpectException("indexedDB.cmp('valid', " + key2 + ")", "IDBDatabaseException.DATA_ERR"); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | function testIdenticalKeys() |
| 146 | { |
| 147 | debug(""); |
| 148 | debug("compare identical keys"); |
| 149 | |
| 150 | shouldBeTrue("indexedDB.cmp(0, -0) === 0"); |
| 151 | } |
| 152 | |
| 153 | var successfullyParsed = true; |
| 154 | |
| 155 | test(); |
| 156 | |
| 157 | </script> |
| 158 | </body> |
| 159 | </html> |