| 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 recordNotFound() | 5 function recordNotFound() |
| 6 { | 6 { |
| 7 debug('Removed data can no longer be found'); | 7 debug('Removed data can no longer be found'); |
| 8 | 8 |
| 9 debug('Retrieving an index'); | 9 debug('Retrieving an index'); |
| 10 shouldBe("objectStore.index('fname_index').name", "'fname_index'"); | 10 shouldBe("objectStore.index('fname_index').name", "'fname_index'"); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 shouldBe("event.result.fname", "'John'"); | 34 shouldBe("event.result.fname", "'John'"); |
| 35 shouldBe("event.result.lname", "'Doe'"); | 35 shouldBe("event.result.lname", "'Doe'"); |
| 36 shouldBe("event.result.id", "1"); | 36 shouldBe("event.result.id", "1"); |
| 37 | 37 |
| 38 var result = objectStore.delete(1); | 38 var result = objectStore.delete(1); |
| 39 result.onsuccess = removeSuccess; | 39 result.onsuccess = removeSuccess; |
| 40 result.onerror = unexpectedErrorCallback; | 40 result.onerror = unexpectedErrorCallback; |
| 41 } | 41 } |
| 42 | 42 |
| 43 function addWithSameKeyFailed() |
| 44 { |
| 45 debug('Adding a record with same key failed'); |
| 46 shouldBe("event.code", "webkitIDBDatabaseException.CONSTRAINT_ERR"); |
| 47 |
| 48 var result = objectStore.get(1); |
| 49 result.onsuccess = getSuccess; |
| 50 result.onerror = unexpectedErrorCallback; |
| 51 } |
| 52 |
| 43 function dataAddedSuccess() | 53 function dataAddedSuccess() |
| 44 { | 54 { |
| 45 debug('Data added'); | 55 debug('Data added'); |
| 46 | 56 |
| 47 var result = objectStore.get(1); | 57 debug('Try to add employee with same id'); |
| 48 result.onsuccess = getSuccess; | 58 var result = objectStore.add({fname: "Tom", lname: "Jones", id: 1}); |
| 49 result.onerror = unexpectedErrorCallback; | 59 result.onsuccess = unexpectedSuccessCallback; |
| 60 result.onerror = addWithSameKeyFailed; |
| 50 } | 61 } |
| 51 | 62 |
| 52 function populateObjectStore() | 63 function populateObjectStore() |
| 53 { | 64 { |
| 54 debug('Populating object store'); | 65 debug('Populating object store'); |
| 55 deleteAllObjectStores(db); | 66 deleteAllObjectStores(db); |
| 56 window.objectStore = db.createObjectStore('employees', {keyPath: 'id'}); | 67 window.objectStore = db.createObjectStore('employees', {keyPath: 'id'}); |
| 57 shouldBe("objectStore.name", "'employees'"); | 68 shouldBe("objectStore.name", "'employees'"); |
| 58 shouldBe("objectStore.keyPath", "'id'"); | 69 shouldBe("objectStore.keyPath", "'id'"); |
| 59 | 70 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 77 result.onerror = unexpectedErrorCallback; | 88 result.onerror = unexpectedErrorCallback; |
| 78 } | 89 } |
| 79 | 90 |
| 80 function test() | 91 function test() |
| 81 { | 92 { |
| 82 debug('Connecting to indexedDB'); | 93 debug('Connecting to indexedDB'); |
| 83 var result = webkitIndexedDB.open('name'); | 94 var result = webkitIndexedDB.open('name'); |
| 84 result.onsuccess = setVersion; | 95 result.onsuccess = setVersion; |
| 85 result.onerror = unexpectedErrorCallback; | 96 result.onerror = unexpectedErrorCallback; |
| 86 } | 97 } |
| OLD | NEW |