| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 afterCommit() | 5 function afterCommit() |
| 6 { | 6 { |
| 7 try { | 7 try { |
| 8 debug("Accessing a committed transaction should throw"); | 8 debug("Accessing a committed transaction should throw"); |
| 9 var store = transaction.objectStore('storeName'); | 9 var store = transaction.objectStore('storeName'); |
| 10 } catch (e) { | 10 } catch (e) { |
| 11 exc = e; | 11 exc = e; |
| 12 shouldBe('exc.code', 'webkitIDBDatabaseException.NOT_ALLOWED_ERR'); | 12 shouldBe('exc.code', 'webkitIDBDatabaseException.NOT_ALLOWED_ERR'); |
| 13 } | 13 } |
| 14 done(); | 14 done(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 function nonExistingKey() | 17 function nonExistingKey() |
| 18 { | 18 { |
| 19 shouldBe("event.result", "undefined"); |
| 19 window.setTimeout('afterCommit()', 0); | 20 window.setTimeout('afterCommit()', 0); |
| 20 } | 21 } |
| 21 | 22 |
| 22 function gotValue() | 23 function gotValue() |
| 23 { | 24 { |
| 24 value = event.result; | 25 value = event.result; |
| 25 shouldBeEqualToString('value', 'myValue'); | 26 shouldBeEqualToString('value', 'myValue'); |
| 26 } | 27 } |
| 27 | 28 |
| 28 function startTransaction() | 29 function startTransaction() |
| 29 { | 30 { |
| 30 debug("Using get in a transaction"); | 31 debug("Using get in a transaction"); |
| 31 transaction = db.transaction(); | 32 transaction = db.transaction(); |
| 32 //transaction.onabort = unexpectedErrorCallback; | 33 //transaction.onabort = unexpectedErrorCallback; |
| 33 store = transaction.objectStore('storeName'); | 34 store = transaction.objectStore('storeName'); |
| 34 shouldBeEqualToString("store.name", "storeName"); | 35 shouldBeEqualToString("store.name", "storeName"); |
| 35 result = store.get('myKey'); | 36 result = store.get('myKey'); |
| 36 result.onsuccess = gotValue; | 37 result.onsuccess = gotValue; |
| 37 result.onerror = unexpectedErrorCallback; | 38 result.onerror = unexpectedErrorCallback; |
| 38 | 39 |
| 39 // TODO(hans): Enable this again with the new semantics after WebKit rolls. | 40 var emptyResult = store.get('nonExistingKey'); |
| 40 //var emptyResult = store.get('nonExistingKey'); | 41 emptyResult.onsuccess = nonExistingKey; |
| 41 //emptyResult.onsuccess = unexpectedSuccessCallback; | 42 emptyResult.onerror = unexpectedErrorCallback; |
| 42 //emptyResult.onerror = nonExistingKey; | |
| 43 nonExistingKey(); | |
| 44 } | 43 } |
| 45 | 44 |
| 46 function populateObjectStore() | 45 function populateObjectStore() |
| 47 { | 46 { |
| 48 deleteAllObjectStores(db); | 47 deleteAllObjectStores(db); |
| 49 window.objectStore = db.createObjectStore('storeName'); | 48 window.objectStore = db.createObjectStore('storeName'); |
| 50 var result = objectStore.add('myValue', 'myKey'); | 49 var result = objectStore.add('myValue', 'myKey'); |
| 51 result.onsuccess = startTransaction; | 50 result.onsuccess = startTransaction; |
| 52 result.onerror = unexpectedErrorCallback; | 51 result.onerror = unexpectedErrorCallback; |
| 53 } | 52 } |
| 54 | 53 |
| 55 function setVersion() | 54 function setVersion() |
| 56 { | 55 { |
| 57 window.db = event.result; | 56 window.db = event.result; |
| 58 var result = db.setVersion('new version'); | 57 var result = db.setVersion('new version'); |
| 59 result.onsuccess = populateObjectStore; | 58 result.onsuccess = populateObjectStore; |
| 60 result.onerror = unexpectedErrorCallback; | 59 result.onerror = unexpectedErrorCallback; |
| 61 } | 60 } |
| 62 | 61 |
| 63 function test() | 62 function test() |
| 64 { | 63 { |
| 65 result = webkitIndexedDB.open('name'); | 64 result = webkitIndexedDB.open('name'); |
| 66 result.onsuccess = setVersion; | 65 result.onsuccess = setVersion; |
| 67 result.onerror = unexpectedErrorCallback; | 66 result.onerror = unexpectedErrorCallback; |
| 68 } | 67 } |
| OLD | NEW |