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 5function emptyCursorSuccess() 6{ 7 debug('Empty cursor opened successfully.'); 8 done(); 9} 10 11function openEmptyCursor() 12{ 13 debug('Opening an empty cursor.'); 14 keyRange = IDBKeyRange.lowerBound('InexistentKey'); 15 request = objectStore.openCursor(keyRange); 16 request.onsuccess = emptyCursorSuccess; 17 request.onerror = unexpectedErrorCallback; 18} 19 20function 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 37function openCursor(objectStore) 38{ 39 debug('Opening cursor'); 40 var keyRange = IDBKeyRange.lowerBound(3.12); 41 var request = objectStore.openCursor(keyRange); 42 request.onsuccess = cursorSuccess; 43 request.onerror = unexpectedErrorCallback; 44} 45 46function dataAddedSuccess() 47{ 48 debug('Data added'); 49 openCursor(objectStore); 50} 51 52function 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 63function test() { 64 indexedDBTest(populateObjectStore); 65} 66