| OLD | NEW |
| 1 library IndexedDB1Test; | 1 library IndexedDB1Test; |
| 2 import '../../pkg/unittest/lib/unittest.dart'; | 2 import '../../pkg/unittest/lib/unittest.dart'; |
| 3 import '../../pkg/unittest/lib/html_individual_config.dart'; | 3 import '../../pkg/unittest/lib/html_individual_config.dart'; |
| 4 import 'dart:html' as html; | 4 import 'dart:html' as html; |
| 5 import 'dart:indexed_db' as idb; | 5 import 'dart:indexed_db' as idb; |
| 6 | 6 |
| 7 const String DB_NAME = 'Test'; | 7 const String DB_NAME = 'Test'; |
| 8 const String STORE_NAME = 'TEST'; | 8 const String STORE_NAME = 'TEST'; |
| 9 const int VERSION = 1; | 9 const int VERSION = 1; |
| 10 | 10 |
| 11 testReadWrite(key, value, matcher, | 11 testReadWrite(key, value, matcher, |
| 12 [dbName = DB_NAME, | 12 [dbName = DB_NAME, |
| 13 storeName = STORE_NAME, | 13 storeName = STORE_NAME, |
| 14 version = VERSION]) => () { | 14 version = VERSION]) => () { |
| 15 var db; | 15 var db; |
| 16 | 16 |
| 17 fail(e) { | 17 fail(e) { |
| 18 guardAsync(() { | 18 guardAsync(() { |
| 19 throw new Exception('IndexedDB failure'); | 19 throw new Exception('IndexedDB failure'); |
| 20 }); | 20 }); |
| 21 } | 21 } |
| 22 | 22 |
| 23 createObjectStore(db) { | 23 createObjectStore(db) { |
| 24 var store = db.createObjectStore(storeName); | 24 var store = db.createObjectStore(storeName); |
| 25 expect(store, isNotNull); | 25 expect(store, isNotNull); |
| 26 } | 26 } |
| 27 | 27 |
| 28 step2(e) { | 28 step2(e) { |
| 29 var transaction = db.transaction(storeName); | 29 var transaction = db.transaction(storeName, 'readonly'); |
| 30 var request = transaction.objectStore(storeName).getObject(key); | 30 var request = transaction.objectStore(storeName).getObject(key); |
| 31 request.onSuccess.listen(expectAsync1((e) { | 31 request.onSuccess.listen(expectAsync1((e) { |
| 32 var object = e.target.result; | 32 var object = e.target.result; |
| 33 db.close(); | 33 db.close(); |
| 34 expect(object, matcher); | 34 expect(object, matcher); |
| 35 })); | 35 })); |
| 36 request.onError.listen(fail); | 36 request.onError.listen(fail); |
| 37 } | 37 } |
| 38 | 38 |
| 39 step1() { | 39 step1() { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 throw new Exception('IndexedDB failure'); | 95 throw new Exception('IndexedDB failure'); |
| 96 }); | 96 }); |
| 97 } | 97 } |
| 98 | 98 |
| 99 createObjectStore(db) { | 99 createObjectStore(db) { |
| 100 idb.ObjectStore store = db.createObjectStore(storeName); | 100 idb.ObjectStore store = db.createObjectStore(storeName); |
| 101 expect(store, isNotNull); | 101 expect(store, isNotNull); |
| 102 } | 102 } |
| 103 | 103 |
| 104 step2(e) { | 104 step2(e) { |
| 105 idb.Transaction transaction = db.transaction(storeName); | 105 idb.Transaction transaction = db.transaction(storeName, 'readonly'); |
| 106 idb.Request request = transaction.objectStore(storeName).getObject(key); | 106 idb.Request request = transaction.objectStore(storeName).getObject(key); |
| 107 request.onSuccess.listen(expectAsync1((e) { | 107 request.onSuccess.listen(expectAsync1((e) { |
| 108 var object = e.target.result; | 108 var object = e.target.result; |
| 109 db.close(); | 109 db.close(); |
| 110 expect(object, matcher); | 110 expect(object, matcher); |
| 111 })); | 111 })); |
| 112 request.onError.listen(fail); | 112 request.onError.listen(fail); |
| 113 } | 113 } |
| 114 | 114 |
| 115 step1() { | 115 step1() { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 var db = html.window.indexedDB; | 195 var db = html.window.indexedDB; |
| 196 }, expectation); | 196 }, expectation); |
| 197 }); | 197 }); |
| 198 | 198 |
| 199 // Don't bother with these tests if it's unsupported. | 199 // Don't bother with these tests if it's unsupported. |
| 200 if (idb.IdbFactory.supported) { | 200 if (idb.IdbFactory.supported) { |
| 201 tests_dynamic(); | 201 tests_dynamic(); |
| 202 tests_typed(); | 202 tests_typed(); |
| 203 } | 203 } |
| 204 } | 204 } |
| OLD | NEW |