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 afterCommit() 6{ 7 try { 8 debug("Accessing a committed transaction should throw"); 9 var store = transaction.objectStore('storeName'); 10 } catch (e) { 11 exc = e; 12 shouldBe('exc.code', 'DOMException.INVALID_STATE_ERR'); 13 } 14 done(); 15} 16 17function nonExistingKey() 18{ 19 shouldBe("event.target.result", "undefined"); 20 transaction.oncomplete = afterCommit; 21} 22 23function gotValue() 24{ 25 value = event.target.result; 26 shouldBeEqualToString('value', 'myValue'); 27} 28 29function startTransaction() 30{ 31 debug("Using get in a transaction"); 32 transaction = db.transaction('storeName'); 33 //transaction.onabort = unexpectedErrorCallback; 34 store = transaction.objectStore('storeName'); 35 shouldBeEqualToString("store.name", "storeName"); 36 request = store.get('myKey'); 37 request.onsuccess = gotValue; 38 request.onerror = unexpectedErrorCallback; 39 40 var emptyRequest = store.get('nonExistingKey'); 41 emptyRequest.onsuccess = nonExistingKey; 42 emptyRequest.onerror = unexpectedErrorCallback; 43} 44 45function populateObjectStore() 46{ 47 db = event.target.result; 48 deleteAllObjectStores(db); 49 window.objectStore = db.createObjectStore('storeName'); 50 var request = objectStore.add('myValue', 'myKey'); 51 request.onerror = unexpectedErrorCallback; 52} 53 54function test() { 55 indexedDBTest(populateObjectStore, startTransaction); 56} 57