| OLD | NEW |
| 1 #library('IndexedDB4Test'); | 1 #library('IndexedDB4Test'); |
| 2 #import('../../pkg/unittest/unittest.dart'); | 2 #import('../../pkg/unittest/unittest.dart'); |
| 3 #import('../../pkg/unittest/html_config.dart'); | 3 #import('../../pkg/unittest/html_config.dart'); |
| 4 #import('dart:html'); | 4 #import('dart:html'); |
| 5 | 5 |
| 6 // Test for IDBKeyRange and IDBCursor. | 6 // Test for IDBKeyRange and IDBCursor. |
| 7 | 7 |
| 8 const String DB_NAME = 'Test'; | 8 const String DB_NAME = 'Test'; |
| 9 const String STORE_NAME = 'TEST'; | 9 const String STORE_NAME = 'TEST'; |
| 10 const int VERSION = 1; | 10 const int VERSION = 1; |
| 11 | 11 |
| 12 class Test { | 12 class Test { |
| 13 fail(message) => (e) { | 13 fail(message) => (e) { |
| 14 guardAsync(() { | 14 guardAsync(() { |
| 15 Expect.fail('IndexedDB failure: $message'); | 15 expect(false, isTrue, reason: 'IndexedDB failure: $message'); |
| 16 }); | 16 }); |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 _createObjectStore(db) { | 19 _createObjectStore(db) { |
| 20 try { | 20 try { |
| 21 // Nuke object store if it already exists. | 21 // Nuke object store if it already exists. |
| 22 db.deleteObjectStore(STORE_NAME); | 22 db.deleteObjectStore(STORE_NAME); |
| 23 } | 23 } |
| 24 on IDBDatabaseException catch(e) { } // Chrome | 24 on IDBDatabaseException catch(e) { } // Chrome |
| 25 on DOMException catch(e) { } // Firefox | 25 on DOMException catch(e) { } // Firefox |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 IDBRequest cursorRequest = objectStore.openCursor(range); | 92 IDBRequest 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.on.success.add(expectAsync1((e) { | 96 cursorRequest.on.success.add(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; |
| 101 itemCount += 1; | 101 itemCount += 1; |
| 102 Expect.equals('Item ${cursor.key}', cursor.value); | 102 expect(cursor.value, 'Item ${cursor.key}'); |
| 103 cursor.continueFunction(); | 103 cursor.continueFunction(); |
| 104 } else { | 104 } else { |
| 105 // Done | 105 // Done |
| 106 Expect.equals(expectedFirst, firstKey); | 106 expect(firstKey, expectedFirst); |
| 107 Expect.equals(expectedLast, lastKey); | 107 expect(lastKey, expectedLast); |
| 108 if (expectedFirst == null) { | 108 if (expectedFirst == null) { |
| 109 Expect.equals(0, itemCount); | 109 expect(itemCount, isZero); |
| 110 } else { | 110 } else { |
| 111 Expect.equals(expectedLast - expectedFirst + 1, itemCount); | 111 expect(itemCount, expectedLast - expectedFirst + 1); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 }, | 114 }, |
| 115 count: 1 + ((expectedFirst == null) ? | 115 count: 1 + ((expectedFirst == null) ? |
| 116 0 : (expectedLast - expectedFirst + 1)))); | 116 0 : (expectedLast - expectedFirst + 1)))); |
| 117 cursorRequest.on.error.add(fail('openCursor')); | 117 cursorRequest.on.error.add(fail('openCursor')); |
| 118 } | 118 } |
| 119 | 119 |
| 120 only1() => testRange(new IDBKeyRange.only(55), 55, 55); | 120 only1() => testRange(new IDBKeyRange.only(55), 55, 55); |
| 121 only2() => testRange(new IDBKeyRange.only(100), null, null); | 121 only2() => testRange(new IDBKeyRange.only(100), null, null); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 test('upper1', test_.upper1); | 171 test('upper1', test_.upper1); |
| 172 test('upper2', test_.upper2); | 172 test('upper2', test_.upper2); |
| 173 test('upper3', test_.upper3); | 173 test('upper3', test_.upper3); |
| 174 | 174 |
| 175 test('bound1', test_.bound1); | 175 test('bound1', test_.bound1); |
| 176 test('bound2', test_.bound2); | 176 test('bound2', test_.bound2); |
| 177 test('bound3', test_.bound3); | 177 test('bound3', test_.bound3); |
| 178 test('bound4', test_.bound4); | 178 test('bound4', test_.bound4); |
| 179 test('bound5', test_.bound5); | 179 test('bound5', test_.bound5); |
| 180 } | 180 } |
| OLD | NEW |