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.
7 var cursor = event.target.result;
9 debug('Reached end of object cursor.');
10 if (!gotObjectThroughCursor) {
11 fail('Did not get object through cursor.');
18 debug('Got object through cursor.');
19 shouldBe('event.target.result.key', '55');
20 shouldBe('event.target.result.value.aValue', '"foo"');
21 gotObjectThroughCursor = true;
26 function onKeyCursor()
28 var cursor = event.target.result;
29 if (cursor === null) {
30 debug('Reached end of key cursor.');
31 if (!gotKeyThroughCursor) {
32 fail('Did not get key through cursor.');
36 var request = index.openCursor(IDBKeyRange.only(55));
37 request.onsuccess = onCursor;
38 request.onerror = unexpectedErrorCallback;
39 gotObjectThroughCursor = false;
43 debug('Got key through cursor.');
44 shouldBe('event.target.result.key', '55');
45 shouldBe('event.target.result.primaryKey', '1');
46 gotKeyThroughCursor = true;
53 debug('Successfully got object through key in index.');
55 shouldBe('event.target.result.aKey', '55');
56 shouldBe('event.target.result.aValue', '"foo"');
58 var request = index.openKeyCursor(IDBKeyRange.only(55));
59 request.onsuccess = onKeyCursor;
60 request.onerror = unexpectedErrorCallback;
61 gotKeyThroughCursor = false;
64 function getKeySuccess()
66 debug('Successfully got key.');
67 shouldBe('event.target.result', '1');
69 var request = index.get(55);
70 request.onsuccess = getSuccess;
71 request.onerror = unexpectedErrorCallback;
74 function moreDataAdded()
76 debug('Successfully added more data.');
78 var request = index.getKey(55);
79 request.onsuccess = getKeySuccess;
80 request.onerror = unexpectedErrorCallback;
83 function indexErrorExpected()
85 debug('Existing index triggered on error as expected.');
87 var request = objectStore.put({'aKey': 55, 'aValue': 'foo'}, 1);
88 request.onsuccess = moreDataAdded;
89 request.onerror = unexpectedErrorCallback;
92 function indexSuccess()
94 debug('Index created successfully.');
96 shouldBe("index.name", "'myIndex'");
97 shouldBe("index.objectStore.name", "'test'");
98 shouldBe("index.keyPath", "'aKey'");
99 shouldBe("index.unique", "true");
102 request = objectStore.createIndex('myIndex', 'aKey', {unique: true});
103 fail('Re-creating an index must throw an exception');
105 indexErrorExpected();
109 function createIndex(expect_error)
111 debug('Creating an index.');
113 window.index = objectStore.createIndex('myIndex', 'aKey', {unique: true});
116 unexpectedErrorCallback();
120 function dataAddedSuccess()
126 function populateObjectStore()
128 debug('Populating object store');
129 db = event.target.result;
130 window.objectStore = db.createObjectStore('test');
131 var myValue = {'aKey': 21, 'aValue': '!42'};
132 var request = objectStore.add(myValue, 0);
133 request.onsuccess = dataAddedSuccess;
134 request.onerror = unexpectedErrorCallback;
138 indexedDBTest(populateObjectStore);