OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 finalTransactionCompleted() | 5 function finalTransactionCompleted() |
6 { | 6 { |
7 debug('The final transaction completed.'); | 7 debug('The final transaction completed.'); |
8 done(); | 8 done(); |
9 } | 9 } |
10 | 10 |
11 function finalTransactionAborted() | 11 function finalTransactionAborted() |
12 { | 12 { |
13 fail('The final transaction should not abort.'); | 13 fail('The final transaction should not abort.'); |
14 } | 14 } |
15 | 15 |
16 function employeeNotFound() | 16 function employeeNotFound() |
17 { | 17 { |
18 debug('Employee not found.'); | 18 debug('Employee not found.'); |
19 shouldBe("event.target.result", "undefined"); | 19 shouldBe("event.target.result", "undefined"); |
20 } | 20 } |
21 | 21 |
22 function newTransactionAborted() | 22 function newTransactionAborted() |
23 { | 23 { |
24 debug('The transaction was aborted.'); | 24 debug('The transaction was aborted.'); |
25 | 25 |
26 var finalTransaction = db.transaction([], IDBTransaction.READ_ONLY); | 26 var finalTransaction = db.transaction(['employees'], |
| 27 IDBTransaction.READ_ONLY); |
27 finalTransaction.oncomplete = finalTransactionCompleted; | 28 finalTransaction.oncomplete = finalTransactionCompleted; |
28 finalTransaction.onabort = finalTransactionAborted; | 29 finalTransaction.onabort = finalTransactionAborted; |
29 | 30 |
30 var request = finalTransaction.objectStore('employees').get(0); | 31 var request = finalTransaction.objectStore('employees').get(0); |
31 request.onsuccess = employeeNotFound; | 32 request.onsuccess = employeeNotFound; |
32 request.onerror = unexpectedErrorCallback; | 33 request.onerror = unexpectedErrorCallback; |
33 } | 34 } |
34 | 35 |
35 function newTransactionCompleted() | 36 function newTransactionCompleted() |
36 { | 37 { |
37 fail('The new transaction should not complete.'); | 38 fail('The new transaction should not complete.'); |
38 } | 39 } |
39 | 40 |
40 function employeeAdded() | 41 function employeeAdded() |
41 { | 42 { |
42 debug('Added an employee inside the transaction.'); | 43 debug('Added an employee inside the transaction.'); |
43 newTransaction.abort(); | 44 newTransaction.abort(); |
44 } | 45 } |
45 | 46 |
46 function onSetVersionComplete() | 47 function onSetVersionComplete() |
47 { | 48 { |
48 debug('Creating new transaction.'); | 49 debug('Creating new transaction.'); |
49 window.newTransaction = db.transaction([], IDBTransaction.READ_WRITE); | 50 window.newTransaction = db.transaction(['employees'], |
| 51 IDBTransaction.READ_WRITE); |
50 newTransaction.oncomplete = newTransactionCompleted; | 52 newTransaction.oncomplete = newTransactionCompleted; |
51 newTransaction.onabort = newTransactionAborted; | 53 newTransaction.onabort = newTransactionAborted; |
52 | 54 |
53 var request = newTransaction.objectStore('employees').put( | 55 var request = newTransaction.objectStore('employees').put( |
54 {id: 0, name: 'John Doe', desk: 'LON-BEL-123'}); | 56 {id: 0, name: 'John Doe', desk: 'LON-BEL-123'}); |
55 request.onsuccess = employeeAdded; | 57 request.onsuccess = employeeAdded; |
56 request.onerror = unexpectedErrorCallback; | 58 request.onerror = unexpectedErrorCallback; |
57 } | 59 } |
58 | 60 |
59 function onSetVersion() | 61 function onSetVersion() |
(...skipping 23 matching lines...) Expand all Loading... |
83 IDBCursor = webkitIDBCursor; | 85 IDBCursor = webkitIDBCursor; |
84 IDBKeyRange = webkitIDBKeyRange; | 86 IDBKeyRange = webkitIDBKeyRange; |
85 IDBTransaction = webkitIDBTransaction; | 87 IDBTransaction = webkitIDBTransaction; |
86 } | 88 } |
87 | 89 |
88 debug('Connecting to indexedDB.'); | 90 debug('Connecting to indexedDB.'); |
89 var request = indexedDB.open('name'); | 91 var request = indexedDB.open('name'); |
90 request.onsuccess = setVersion; | 92 request.onsuccess = setVersion; |
91 request.onerror = unexpectedErrorCallback; | 93 request.onerror = unexpectedErrorCallback; |
92 } | 94 } |
OLD | NEW |