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.
5 function finalTransactionCompleted()
7 debug('The final transaction completed.');
11 function finalTransactionAborted()
13 fail('The final transaction should not abort.');
16 function employeeNotFound()
18 debug('Employee not found.');
19 shouldBe("event.target.result", "undefined");
22 function newTransactionAborted()
24 debug('The transaction was aborted.');
26 var finalTransaction = db.transaction(['employees'],
28 finalTransaction.oncomplete = finalTransactionCompleted;
29 finalTransaction.onabort = finalTransactionAborted;
31 var request = finalTransaction.objectStore('employees').get(0);
32 request.onsuccess = employeeNotFound;
33 request.onerror = unexpectedErrorCallback;
36 function newTransactionCompleted()
38 fail('The new transaction should not complete.');
41 function employeeAdded()
43 debug('Added an employee inside the transaction.');
44 newTransaction.abort();
47 function onSetVersionComplete()
49 debug('Creating new transaction.');
50 window.newTransaction = db.transaction(['employees'],
52 newTransaction.oncomplete = newTransactionCompleted;
53 newTransaction.onabort = newTransactionAborted;
55 var request = newTransaction.objectStore('employees').put(
56 {id: 0, name: 'John Doe', desk: 'LON-BEL-123'});
57 request.onsuccess = employeeAdded;
58 request.onerror = unexpectedErrorCallback;
61 function onSetVersion()
63 // We are now in a set version transaction.
64 window.db = event.target.result;
65 debug('Creating object store.');
66 deleteAllObjectStores(db);
67 db.createObjectStore('employees', {keyPath: 'id'});
72 indexedDBTest(onSetVersion, onSetVersionComplete);