4 <script src="../../fast/js/resources/js-test-pre.js"></script>
5 <script src="resources/shared.js"></script>
8 <p id="description"></p>
9 <div id="console"></div>
12 description("Test IndexedDB key types");
13 if (window.layoutTestController)
14 layoutTestController.waitUntilDone();
18 evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;");
19 shouldBeFalse("indexedDB == null");
21 evalAndLog("IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;");
22 shouldBeFalse("IDBTransaction == null");
24 evalAndLog("IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;");
25 shouldBeFalse("IDBDatabaseException == null");
28 name = window.location.pathname;
29 description = "My Test Database";
30 openreq = evalAndLog("indexedDB.open(name, description)");
31 openreq.onsuccess = openSuccess;
32 openreq.onerror = unexpectedErrorCallback;
35 function openSuccess()
37 evalAndLog("db = openreq.result");
38 setverreq = evalAndLog("request = db.setVersion('1')");
39 setverreq.onsuccess = setVersionSuccess;
40 setverreq.onerror = unexpectedErrorCallback;
43 function setVersionSuccess()
45 debug("preparing database");
46 trans = setverreq.result;
47 trans.oncomplete = testValidArrayKeys;
48 deleteAllObjectStores(db);
49 objectStore = evalAndLog("db.createObjectStore('store');");
53 function testValidArrayKeys()
55 evalAndLog("trans = db.transaction('store', IDBTransaction.READ_WRITE)");
56 evalAndLog("store = trans.objectStore('store')");
59 evalAndLog("long_array = []; for (i = 0; i < 1000; ++i) { long_array.push('abc', 123, new Date(0), []); }");
62 debug("array that contains non-numeric self-reference");
63 evalAndLog("self_referrential_array = []; self_referrential_array.self = self_referrential_array;");
70 "[-Number.MAX_VALUE]",
72 "[-Number.MIN_VALUE]",
82 "[new Date('2525-01-01T00:00:00Z')]",
84 "[new Date(0), new Date('2525-01-01T00:00:00Z')]",
100 "[123, 'abc', new Date(0), []]",
101 "[[123, 'abc', new Date(0), []], [456, 'def', new Date(999), [[]]]]",
104 "self_referrential_array"
107 function testArrayPutGet(value, key, callback)
109 debug("testing array key: " + key);
110 putreq = evalAndLog("store.put('" + value + "', " + key + ");");
111 putreq.onerror = unexpectedErrorCallback;
112 putreq.onsuccess = function() {
113 getreq = evalAndLog("store.get(" + key + ");");
114 getreq.onerror = unexpectedErrorCallback;
115 getreq.onsuccess = function() {
116 shouldBeEqualToString("getreq.result", value);
125 var testcase = cases.shift();
127 testArrayPutGet("value" + (++n), testcase, nextTest);
133 trans.oncomplete = testInvalidArrayKeys;
137 function testInvalidArrayKeys()
139 evalAndLog("trans = db.transaction('store', IDBTransaction.READ_WRITE)");
140 evalAndLog("store = trans.objectStore('store')");
143 debug("array that contains itself: array = [ array ]");
144 evalAndLog("cyclic_array = []; cyclic_array.push(cyclic_array)");
145 shouldThrow("JSON.stringify(cyclic_array)");
147 debug("array that contains itself, one level down: array = [ [ array ] ]");
148 evalAndLog("cyclic_array2 = []; cyclic_array2.push([cyclic_array2])");
149 shouldThrow("JSON.stringify(cyclic_array2)");
151 debug("array that contains itself, not as first element: array = [1, 'b', [], array]");
152 evalAndLog("cyclic_array3 = [1, 'b', []]; cyclic_array3.push(cyclic_array3)");
153 shouldThrow("JSON.stringify(cyclic_array3)");
156 debug("array that contains array that contains itself");
157 evalAndLog("cyclic_array4 = [cyclic_array];");
158 shouldThrow("JSON.stringify(cyclic_array4)");
162 "[ void 0 ]", // undefined
168 "[ function () {} ]",
171 "[ window.document ]",
172 "[ window.document.body ]",
177 "Array(1000)" // sparse
180 invalidKeys.forEach(function (key) {
181 debug("testing invalid array key: " + key);
182 evalAndExpectException("store.put('value', " + key + ");", "IDBDatabaseException.DATA_ERR");
189 function makeArrayOfDepth(n)
198 function testDepthLimits()
200 shouldBe("indexedDB.cmp(makeArrayOfDepth(25), 0)", "1");
201 shouldBe("indexedDB.cmp(makeArrayOfDepth(250), 0)", "1");
202 evalAndExpectException("indexedDB.cmp(makeArrayOfDepth(2500), 0)", "IDBDatabaseException.DATA_ERR");