1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB keys ordering and readback from cursors.");
8 indexedDBTest(prepareDatabase, populateStore);
9 function prepareDatabase()
11 db = event.target.result;
12 evalAndLog("db.createObjectStore('store')");
28 "new Date(1317399931023)",
37 "'\xA2'", // U+00A2 CENT SIGN
38 "'\u6C34'", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
39 "'\uD834\uDD1E'", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
40 "'\uFFFD'", // U+FFFD REPLACEMENT CHARACTER
45 "[-Number.MAX_VALUE]",
47 "[-Number.MIN_VALUE]",
56 "[new Date(1317399931023)]",
65 "['\xA2']", // U+00A2 CENT SIGN
66 "['\u6C34']", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
67 "['\uD834\uDD1E']", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
68 "['\uFFFD']", // U+FFFD REPLACEMENT CHARACTER
79 function compare(a, b)
81 if (typeof a !== typeof b) {
86 case 'undefined': // Not valid keys, but compare anyway.
87 case 'boolean': // Not valid keys, but compare anyway.
92 return (a !== 0) || (1 / a === 1 / b); // 0 isn't -0
94 return a !== a && b !== b; // NaN is NaN
97 if (a instanceof Date && b instanceof Date) {
99 } else if (a instanceof Array && b instanceof Array) {
100 if (a.length !== b.length) {
103 for (var i = 0; i < a.length; i++) {
104 if (!compare(a[i], b[i])) {
110 // For the purposes of this test, other objects don't count
117 function populateStore()
120 debug("populating store...");
121 evalAndLog("trans = db.transaction('store', 'readwrite')");
122 evalAndLog("store = trans.objectStore('store');");
123 trans.onerror = unexpectedErrorCallback;
124 trans.onabort = unexpectedAbortCallback;
126 keys.forEach(function(key) {
127 evalAndLog("store.put(" + (count++) + ", " + key + ")");
129 trans.oncomplete = checkStore;
132 function checkStore()
135 debug("iterating cursor...");
136 evalAndLog("trans = db.transaction('store', 'readonly')");
137 evalAndLog("store = trans.objectStore('store');");
138 trans.onerror = unexpectedErrorCallback;
139 trans.onabort = unexpectedAbortCallback;
140 evalAndLog("count = 0");
141 curreq = evalAndLog("curreq = store.openCursor()");
142 curreq.onerror = unexpectedErrorCallback;
143 curreq.onsuccess = function() {
145 evalAndLog("cursor = curreq.result");
146 shouldBeTrue("compare(cursor.key, " + keys[count] + ")");
147 evalAndLog("getreq = store.get(cursor.key)");
148 getreq.onerror = unexpectedErrorCallback;
149 getreq.onsuccess = function() {
150 shouldBe("getreq.result", "count++");
154 shouldBe("count", "keys.length");
166 function testKeyCompare()
169 debug("validate compare function");
198 for (var i = 0; i < cases.length; ++i) {
199 for (var j = 0; j < cases.length; ++j) {
201 shouldBeTrue("compare(" + cases[i] + ", " + cases[j] + ")");
203 shouldBeFalse("compare(" + cases[i] + ", " + cases[j] + ")");