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. 4 5 function emptyCursorSuccess() 6 { 7 debug('Empty cursor opened successfully.') 8 done(); 9 } 10 11 function openEmptyCursor() 12 { 13 debug('Opening an empty cursor.'); 14 keyRange = webkitIDBKeyRange.lowerBound('InexistentKey'); 15 request = objectStore.openCursor(keyRange); 16 request.onsuccess = emptyCursorSuccess; 17 request.onerror = unexpectedErrorCallback; 18 } 19 20 function cursorSuccess() 21 { 22 var cursor = event.target.result; 23 if (cursor === null) { 24 debug('Cursor reached end of range.'); 25 openEmptyCursor(); 26 return; 27 } 28 29 debug('Cursor opened successfully.'); 30 shouldBe("event.target.result.direction", "'next'"); 31 shouldBe("event.target.result.key", "3.14"); 32 shouldBe("event.target.result.value", "'myValue'"); 33 34 cursor.continue(); 35 } 36 37 function openCursor(objectStore) 38 { 39 debug('Opening cursor'); 40 var keyRange = webkitIDBKeyRange.lowerBound(3.12); 41 var request = objectStore.openCursor(keyRange); 42 request.onsuccess = cursorSuccess; 43 request.onerror = unexpectedErrorCallback; 44 } 45 46 function dataAddedSuccess() 47 { 48 debug('Data added'); 49 openCursor(objectStore); 50 } 51 52 function populateObjectStore() 53 { 54 debug('Populating object store'); 55 db = event.target.result; 56 deleteAllObjectStores(db); 57 window.objectStore = db.createObjectStore('test'); 58 var request = objectStore.add('myValue', 3.14); 59 request.onsuccess = dataAddedSuccess; 60 request.onerror = unexpectedErrorCallback; 61 } 62 63 function test() { 64 indexedDBTest(populateObjectStore); 65 } 66