1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 indexedDBTest(prepareDatabase, testValidKeys);
9 function prepareDatabase()
11 db = event.target.result;
12 db.createObjectStore('store');
28 "new Date(1317399931023)",
38 "'\xA2'", // U+00A2 CENT SIGN
39 "'\u6C34'", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
40 "'\uD834\uDD1E'", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
41 "'\uFFFD'", // U+FFFD REPLACEMENT CHARACTER
46 "[-Number.MAX_VALUE]",
48 "[-Number.MIN_VALUE]",
57 "[new Date(1317399931023)]",
66 "['\xA2']", // U+00A2 CENT SIGN
67 "['\u6C34']", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
68 "['\uD834\uDD1E']", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
69 "['\uFFFD']", // U+FFFD REPLACEMENT CHARACTER
82 "void 0", // undefined
92 "window.document.body",
93 "(function() { var cyclic = []; cyclic.push(cyclic); return cyclic; }())"
97 function testValidKeys() {
98 var test_keys = valid_keys.slice(); // make a copy
99 var count = 0, when_complete = testInvalidKeys;
102 function testNextKey() {
103 var key = test_keys.shift();
109 key = eval("(" + key + ")");
110 var value = 'value' + (count++);
111 var trans = db.transaction('store', 'readwrite');
112 var store = trans.objectStore('store');
113 var putreq = store.put(value, key);
114 putreq.onerror = unexpectedErrorCallback;
115 putreq.onsuccess = function() {
116 getreq = store.get(key);
117 getreq.onerror = unexpectedErrorCallback;
118 getreq.onsuccess = function() {
119 shouldBeEqualToString('getreq.result', value);
122 trans.oncomplete = testNextKey;
126 function testInvalidKeys() {
128 var trans = db.transaction('store', 'readwrite');
129 var store = trans.objectStore('store');
131 invalid_keys.forEach(
134 key = eval("(" + key + ")");
135 var putreq = store.put('value', key);
136 putreq.onerror = unexpectedErrorCallback;
137 putreq.onsuccess = unexpectedSuccessCallback;
141 shouldBe("ex.code", "0");
142 shouldBe("ex.name", "'DataError'");
148 function testKeyOrdering() {
150 for (var i = 0; i < valid_keys.length - 1; ++i) {
151 var key1 = valid_keys[i];
152 var key2 = valid_keys[i + 1];
154 shouldBe("indexedDB.cmp(" + key1 + "," + key2 + ")", "-1");
155 shouldBe("indexedDB.cmp(" + key2 + "," + key1 + ")", "1");
156 shouldBe("indexedDB.cmp(" + key1 + "," + key1 + ")", "0");
157 shouldBe("indexedDB.cmp(" + key2 + "," + key2 + ")", "0");