| OLD | NEW |
| 1 #library('IndexedDB3Test'); | 1 #library('IndexedDB3Test'); |
| 2 #import('../../lib/unittest/unittest.dart'); | 2 #import('../../lib/unittest/unittest.dart'); |
| 3 #import('../../lib/unittest/html_config.dart'); | 3 #import('../../lib/unittest/html_config.dart'); |
| 4 #import('dart:html'); | 4 #import('dart:html'); |
| 5 | 5 |
| 6 // Read with cursor. | 6 // Read with cursor. |
| 7 | 7 |
| 8 final String DB_NAME = 'Test'; | 8 final String DB_NAME = 'Test'; |
| 9 final String STORE_NAME = 'TEST'; | 9 final String STORE_NAME = 'TEST'; |
| 10 final String VERSION = '1'; | 10 final String VERSION = '1'; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } catch (IDBDatabaseException e) { } | 33 } catch (IDBDatabaseException e) { } |
| 34 db.createObjectStore(STORE_NAME); | 34 db.createObjectStore(STORE_NAME); |
| 35 writeItems(0); | 35 writeItems(0); |
| 36 }) | 36 }) |
| 37 ); | 37 ); |
| 38 request.on.error.add(fail('setVersion error')); | 38 request.on.error.add(fail('setVersion error')); |
| 39 } | 39 } |
| 40 | 40 |
| 41 writeItems(int index) { | 41 writeItems(int index) { |
| 42 if (index < 100) { | 42 if (index < 100) { |
| 43 var transaction = db.transaction([STORE_NAME], IDBTransaction.READ_WRITE); | 43 var transaction = db.transaction([STORE_NAME], 'readwrite'); |
| 44 var request = transaction.objectStore(STORE_NAME) | 44 var request = transaction.objectStore(STORE_NAME) |
| 45 .put('Item $index', index); | 45 .put('Item $index', index); |
| 46 request.on.success.add(expectAsync1((e) { | 46 request.on.success.add(expectAsync1((e) { |
| 47 writeItems(index + 1); | 47 writeItems(index + 1); |
| 48 } | 48 } |
| 49 )); | 49 )); |
| 50 request.on.error.add(fail('put')); | 50 request.on.error.add(fail('put')); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 fail(message) => (e) { | 54 fail(message) => (e) { |
| 55 guardAsync(() { | 55 guardAsync(() { |
| 56 Expect.fail('IndexedDB failure: $message'); | 56 Expect.fail('IndexedDB failure: $message'); |
| 57 }); | 57 }); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 readAllViaCursor() { | 60 readAllViaCursor() { |
| 61 IDBTransaction txn = db.transaction(STORE_NAME, IDBTransaction.READ_ONLY); | 61 IDBTransaction txn = db.transaction(STORE_NAME, 'readonly'); |
| 62 IDBObjectStore objectStore = txn.objectStore(STORE_NAME); | 62 IDBObjectStore objectStore = txn.objectStore(STORE_NAME); |
| 63 IDBRequest cursorRequest = objectStore.openCursor(); | 63 IDBRequest cursorRequest = objectStore.openCursor(); |
| 64 int itemCount = 0; | 64 int itemCount = 0; |
| 65 int sumKeys = 0; | 65 int sumKeys = 0; |
| 66 int lastKey = null; | 66 int lastKey = null; |
| 67 cursorRequest.on.success.add(expectAsync1((e) { | 67 cursorRequest.on.success.add(expectAsync1((e) { |
| 68 var cursor = e.target.result; | 68 var cursor = e.target.result; |
| 69 if (cursor != null) { | 69 if (cursor != null) { |
| 70 lastKey = cursor.key; | 70 lastKey = cursor.key; |
| 71 itemCount += 1; | 71 itemCount += 1; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 main() { | 112 main() { |
| 113 useHtmlConfiguration(); | 113 useHtmlConfiguration(); |
| 114 | 114 |
| 115 var test_ = new Test(); | 115 var test_ = new Test(); |
| 116 test('prepare', test_.start); | 116 test('prepare', test_.start); |
| 117 test('readAll1', test_.readAllViaCursor); | 117 test('readAll1', test_.readAllViaCursor); |
| 118 test('readAll2', test_.readAllReversedViaCursor); | 118 test('readAll2', test_.readAllReversedViaCursor); |
| 119 } | 119 } |
| OLD | NEW |