OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 function emptyCursorSuccess() | 5 function emptyCursorSuccess() |
6 { | 6 { |
7 debug('Empty cursor opened successfully.') | 7 debug('Empty cursor opened successfully.'); |
8 done(); | 8 done(); |
9 } | 9 } |
10 | 10 |
11 function openEmptyCursor() | 11 function openEmptyCursor() |
12 { | 12 { |
13 debug('Opening an empty cursor.'); | 13 debug('Opening an empty cursor.'); |
14 keyRange = webkitIDBKeyRange.lowerBound('InexistentKey'); | 14 keyRange = IDBKeyRange.lowerBound('InexistentKey'); |
15 request = objectStore.openCursor(keyRange); | 15 request = objectStore.openCursor(keyRange); |
16 request.onsuccess = emptyCursorSuccess; | 16 request.onsuccess = emptyCursorSuccess; |
17 request.onerror = unexpectedErrorCallback; | 17 request.onerror = unexpectedErrorCallback; |
18 } | 18 } |
19 | 19 |
20 function cursorSuccess() | 20 function cursorSuccess() |
21 { | 21 { |
22 var cursor = event.target.result; | 22 var cursor = event.target.result; |
23 if (cursor === null) { | 23 if (cursor === null) { |
24 debug('Cursor reached end of range.'); | 24 debug('Cursor reached end of range.'); |
25 openEmptyCursor(); | 25 openEmptyCursor(); |
26 return; | 26 return; |
27 } | 27 } |
28 | 28 |
29 debug('Cursor opened successfully.'); | 29 debug('Cursor opened successfully.'); |
30 shouldBe("event.target.result.direction", "'next'"); | 30 shouldBe("event.target.result.direction", "'next'"); |
31 shouldBe("event.target.result.key", "3.14"); | 31 shouldBe("event.target.result.key", "3.14"); |
32 shouldBe("event.target.result.value", "'myValue'"); | 32 shouldBe("event.target.result.value", "'myValue'"); |
33 | 33 |
34 cursor.continue(); | 34 cursor.continue(); |
35 } | 35 } |
36 | 36 |
37 function openCursor(objectStore) | 37 function openCursor(objectStore) |
38 { | 38 { |
39 debug('Opening cursor'); | 39 debug('Opening cursor'); |
40 var keyRange = webkitIDBKeyRange.lowerBound(3.12); | 40 var keyRange = IDBKeyRange.lowerBound(3.12); |
41 var request = objectStore.openCursor(keyRange); | 41 var request = objectStore.openCursor(keyRange); |
42 request.onsuccess = cursorSuccess; | 42 request.onsuccess = cursorSuccess; |
43 request.onerror = unexpectedErrorCallback; | 43 request.onerror = unexpectedErrorCallback; |
44 } | 44 } |
45 | 45 |
46 function dataAddedSuccess() | 46 function dataAddedSuccess() |
47 { | 47 { |
48 debug('Data added'); | 48 debug('Data added'); |
49 openCursor(objectStore); | 49 openCursor(objectStore); |
50 } | 50 } |
51 | 51 |
52 function populateObjectStore() | 52 function populateObjectStore() |
53 { | 53 { |
54 debug('Populating object store'); | 54 debug('Populating object store'); |
55 db = event.target.result; | 55 db = event.target.result; |
56 deleteAllObjectStores(db); | 56 deleteAllObjectStores(db); |
57 window.objectStore = db.createObjectStore('test'); | 57 window.objectStore = db.createObjectStore('test'); |
58 var request = objectStore.add('myValue', 3.14); | 58 var request = objectStore.add('myValue', 3.14); |
59 request.onsuccess = dataAddedSuccess; | 59 request.onsuccess = dataAddedSuccess; |
60 request.onerror = unexpectedErrorCallback; | 60 request.onerror = unexpectedErrorCallback; |
61 } | 61 } |
62 | 62 |
63 function test() { | 63 function test() { |
64 indexedDBTest(populateObjectStore); | 64 indexedDBTest(populateObjectStore); |
65 } | 65 } |
OLD | NEW |