| OLD | NEW |
| 1 library IndexedDB3Test; | 1 library IndexedDB3Test; |
| 2 import '../../pkg/unittest/lib/unittest.dart'; | 2 import '../../pkg/unittest/lib/unittest.dart'; |
| 3 import '../../pkg/unittest/lib/html_config.dart'; | 3 import '../../pkg/unittest/lib/html_config.dart'; |
| 4 import 'dart:html'; | 4 import 'dart:html'; |
| 5 import 'dart:indexed_db'; | 5 import 'dart:indexed_db'; |
| 6 | 6 |
| 7 // Read with cursor. | 7 // Read with cursor. |
| 8 | 8 |
| 9 const String DB_NAME = 'Test'; | 9 const String DB_NAME = 'Test'; |
| 10 const String STORE_NAME = 'TEST'; | 10 const String STORE_NAME = 'TEST'; |
| 11 const int VERSION = 1; | 11 const int VERSION = 1; |
| 12 | 12 |
| 13 class Test { | 13 class Test { |
| 14 fail(message) => (e) { | 14 fail(message) => (e) { |
| 15 guardAsync(() { | 15 guardAsync(() { |
| 16 expect(false, isTrue, reason: 'IndexedDB failure: $message'); | 16 expect(false, isTrue, reason: 'IndexedDB failure: $message'); |
| 17 }); | 17 }); |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 _createObjectStore(db) { | 20 _createObjectStore(db) { |
| 21 try { | 21 try { |
| 22 // Nuke object store if it already exists. | 22 // Nuke object store if it already exists. |
| 23 db.deleteObjectStore(STORE_NAME); | 23 db.deleteObjectStore(STORE_NAME); |
| 24 } | 24 } |
| 25 on DatabaseException catch(e) { } // Chrome | 25 on DatabaseException catch(e) { } // Chrome |
| 26 on DOMException catch(e) { } // Firefox | 26 on DomException catch(e) { } // Firefox |
| 27 db.createObjectStore(STORE_NAME); | 27 db.createObjectStore(STORE_NAME); |
| 28 } | 28 } |
| 29 | 29 |
| 30 var db; | 30 var db; |
| 31 | 31 |
| 32 _openDb(afterOpen()) { | 32 _openDb(afterOpen()) { |
| 33 var request = window.indexedDB.open(DB_NAME, VERSION); | 33 var request = window.indexedDB.open(DB_NAME, VERSION); |
| 34 if (request is OpenDBRequest) { | 34 if (request is OpenDBRequest) { |
| 35 // New upgrade protocol. FireFox 15, Chrome 24, hopefully IE10. | 35 // New upgrade protocol. FireFox 15, Chrome 24, hopefully IE10. |
| 36 request.on.success.add(expectAsync1((e) { | 36 request.on.success.add(expectAsync1((e) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 141 } |
| 142 | 142 |
| 143 main() { | 143 main() { |
| 144 useHtmlConfiguration(); | 144 useHtmlConfiguration(); |
| 145 | 145 |
| 146 var test_ = new Test(); | 146 var test_ = new Test(); |
| 147 test('prepare', test_.setupDb); | 147 test('prepare', test_.setupDb); |
| 148 test('readAll1', test_.readAllViaCursor); | 148 test('readAll1', test_.readAllViaCursor); |
| 149 test('readAll2', test_.readAllReversedViaCursor); | 149 test('readAll2', test_.readAllReversedViaCursor); |
| 150 } | 150 } |
| OLD | NEW |