| OLD | NEW |
| 1 library IndexedDB4Test; | 1 library IndexedDB4Test; |
| 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 // Test for KeyRange and Cursor. | 7 // Test for KeyRange and 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'; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 _createAndOpenDb(afterOpen()) { | 68 _createAndOpenDb(afterOpen()) { |
| 69 var request = window.indexedDB.deleteDatabase(DB_NAME); | 69 var request = window.indexedDB.deleteDatabase(DB_NAME); |
| 70 request.onSuccess.listen(expectAsync1((e) { _openDb(afterOpen); })); | 70 request.onSuccess.listen(expectAsync1((e) { _openDb(afterOpen); })); |
| 71 request.onError.listen(fail('delete old Db')); | 71 request.onError.listen(fail('delete old Db')); |
| 72 } | 72 } |
| 73 | 73 |
| 74 writeItems(int index) { | 74 writeItems(int index) { |
| 75 if (index < 100) { | 75 if (index < 100) { |
| 76 var transaction = db.transaction([STORE_NAME], mode : 'readwrite'); | 76 var transaction = db.transaction([STORE_NAME], 'readwrite'); |
| 77 var request = transaction.objectStore(STORE_NAME) | 77 var request = transaction.objectStore(STORE_NAME) |
| 78 .put('Item $index', index); | 78 .put('Item $index', index); |
| 79 request.onSuccess.listen(expectAsync1((e) { | 79 request.onSuccess.listen(expectAsync1((e) { |
| 80 writeItems(index + 1); | 80 writeItems(index + 1); |
| 81 } | 81 } |
| 82 )); | 82 )); |
| 83 request.onError.listen(fail('put')); | 83 request.onError.listen(fail('put')); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 setupDb() { _createAndOpenDb(() => writeItems(0)); } | 87 setupDb() { _createAndOpenDb(() => writeItems(0)); } |
| 88 | 88 |
| 89 testRange(range, expectedFirst, expectedLast) { | 89 testRange(range, expectedFirst, expectedLast) { |
| 90 Transaction txn = db.transaction(STORE_NAME, mode : 'readonly'); | 90 Transaction txn = db.transaction(STORE_NAME, 'readonly'); |
| 91 ObjectStore objectStore = txn.objectStore(STORE_NAME); | 91 ObjectStore objectStore = txn.objectStore(STORE_NAME); |
| 92 Request cursorRequest = objectStore.openCursor(range); | 92 Request cursorRequest = objectStore.openCursor(range); |
| 93 int itemCount = 0; | 93 int itemCount = 0; |
| 94 int firstKey = null; | 94 int firstKey = null; |
| 95 int lastKey = null; | 95 int lastKey = null; |
| 96 cursorRequest.onSuccess.listen(expectAsync1((e) { | 96 cursorRequest.onSuccess.listen(expectAsync1((e) { |
| 97 var cursor = e.target.result; | 97 var cursor = e.target.result; |
| 98 if (cursor != null) { | 98 if (cursor != null) { |
| 99 if (firstKey == null) firstKey = cursor.key; | 99 if (firstKey == null) firstKey = cursor.key; |
| 100 lastKey = cursor.key; | 100 lastKey = cursor.key; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 test('upper2', test_.upper2); | 175 test('upper2', test_.upper2); |
| 176 test('upper3', test_.upper3); | 176 test('upper3', test_.upper3); |
| 177 | 177 |
| 178 test('bound1', test_.bound1); | 178 test('bound1', test_.bound1); |
| 179 test('bound2', test_.bound2); | 179 test('bound2', test_.bound2); |
| 180 test('bound3', test_.bound3); | 180 test('bound3', test_.bound3); |
| 181 test('bound4', test_.bound4); | 181 test('bound4', test_.bound4); |
| 182 test('bound5', test_.bound5); | 182 test('bound5', test_.bound5); |
| 183 } | 183 } |
| 184 } | 184 } |
| OLD | NEW |