| OLD | NEW |
| 1 #library('IndexedDB4Test'); | 1 #library('IndexedDB4Test'); |
| 2 #import('../../lib/unittest/unittest.dart'); | 2 #import('../../lib/unittest/unittest.dart'); |
| 3 #import('../../lib/unittest/dom_config.dart'); | 3 #import('../../lib/unittest/html_config.dart'); |
| 4 #import('dart:dom'); | 4 #import('dart:html'); |
| 5 | 5 |
| 6 // Test for IDBKeyRange and IDBCursor. | 6 // Test for IDBKeyRange and IDBCursor. |
| 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'; |
| 11 | 11 |
| 12 class Test { | 12 class Test { |
| 13 var db; | 13 var db; |
| 14 | 14 |
| 15 start() { | 15 start() { |
| 16 var request = window.webkitIndexedDB.open(DB_NAME); | 16 var request = window.webkitIndexedDB.open(DB_NAME); |
| 17 Expect.isNotNull(request); | 17 Expect.isNotNull(request); |
| 18 request.addEventListener('success', initDb); | 18 request.on.success.add(initDb); |
| 19 request.addEventListener('error', fail('open')); | 19 request.on.error.add(fail('open')); |
| 20 } | 20 } |
| 21 | 21 |
| 22 initDb(e) { | 22 initDb(e) { |
| 23 db = e.target.result; | 23 db = e.target.result; |
| 24 // TODO. Some browsers do this the w3 way - passing the VERSION to the | 24 // TODO. Some browsers do this the w3 way - passing the VERSION to the |
| 25 // open call and listening to onversionchange. Can we feature-detect the | 25 // open call and listening to onversionchange. Can we feature-detect the |
| 26 // difference and make it work? | 26 // difference and make it work? |
| 27 var request = db.setVersion(VERSION); | 27 var request = db.setVersion(VERSION); |
| 28 request.addEventListener('success', (e) { | 28 request.on.success.add((e) { |
| 29 try { | 29 try { |
| 30 // Nuke object store if it already exists. | 30 // Nuke object store if it already exists. |
| 31 db.deleteObjectStore(STORE_NAME); | 31 db.deleteObjectStore(STORE_NAME); |
| 32 } catch (IDBDatabaseException e) { } | 32 } catch (IDBDatabaseException e) { } |
| 33 db.createObjectStore(STORE_NAME); | 33 db.createObjectStore(STORE_NAME); |
| 34 writeItems(0); | 34 writeItems(0); |
| 35 }); | 35 }); |
| 36 request.addEventListener('blocked', fail('setVersion blocked')); | 36 request.on.blocked.add(fail('setVersion blocked')); |
| 37 request.addEventListener('error', fail('setVersion error')); | 37 request.on.error.add(fail('setVersion error')); |
| 38 } | 38 } |
| 39 | 39 |
| 40 writeItems(int index) { | 40 writeItems(int index) { |
| 41 if (index < 100) { | 41 if (index < 100) { |
| 42 var transaction = db.transaction([STORE_NAME], IDBTransaction.READ_WRITE); | 42 var transaction = db.transaction([STORE_NAME], IDBTransaction.READ_WRITE); |
| 43 var request = transaction.objectStore(STORE_NAME) | 43 var request = transaction.objectStore(STORE_NAME) |
| 44 .put('Item $index', index); | 44 .put('Item $index', index); |
| 45 request.addEventListener('success', (e) { writeItems(index + 1); }); | 45 request.on.success.add((e) { writeItems(index + 1); }); |
| 46 request.addEventListener('error', fail('put')); | 46 request.on.error.add(fail('put')); |
| 47 } else { | 47 } else { |
| 48 callbackDone(); | 48 callbackDone(); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 fail(message) => (e) { | 52 fail(message) => (e) { |
| 53 callbackDone(); | 53 callbackDone(); |
| 54 Expect.fail('IndexedDB failure: $message'); | 54 Expect.fail('IndexedDB failure: $message'); |
| 55 }; | 55 }; |
| 56 | 56 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 74 Expect.equals(expectedFirst, firstKey); | 74 Expect.equals(expectedFirst, firstKey); |
| 75 Expect.equals(expectedLast, lastKey); | 75 Expect.equals(expectedLast, lastKey); |
| 76 if (expectedFirst == null) { | 76 if (expectedFirst == null) { |
| 77 Expect.equals(0, itemCount); | 77 Expect.equals(0, itemCount); |
| 78 } else { | 78 } else { |
| 79 Expect.equals(expectedLast - expectedFirst + 1, itemCount); | 79 Expect.equals(expectedLast - expectedFirst + 1, itemCount); |
| 80 } | 80 } |
| 81 callbackDone(); | 81 callbackDone(); |
| 82 } | 82 } |
| 83 }); | 83 }); |
| 84 cursorRequest.addEventListener('error', fail('openCursor')); | 84 cursorRequest.on.error.add(fail('openCursor')); |
| 85 } | 85 } |
| 86 | 86 |
| 87 only1() => testRange(new IDBKeyRange.only(55), 55, 55); | 87 only1() => testRange(new IDBKeyRange.only(55), 55, 55); |
| 88 only2() => testRange(new IDBKeyRange.only(100), null, null); | 88 only2() => testRange(new IDBKeyRange.only(100), null, null); |
| 89 only3() => testRange(new IDBKeyRange.only(-1), null, null); | 89 only3() => testRange(new IDBKeyRange.only(-1), null, null); |
| 90 | 90 |
| 91 lower1() => testRange(new IDBKeyRange.lowerBound(40), 40, 99); | 91 lower1() => testRange(new IDBKeyRange.lowerBound(40), 40, 99); |
| 92 lower2() => testRange(new IDBKeyRange.lowerBound(40, open: true), 41, 99); | 92 lower2() => testRange(new IDBKeyRange.lowerBound(40, open: true), 41, 99); |
| 93 lower3() => testRange(new IDBKeyRange.lowerBound(40, open: false), 40, 99); | 93 lower3() => testRange(new IDBKeyRange.lowerBound(40, open: false), 40, 99); |
| 94 | 94 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 testRange(new IDBKeyRange.bound(20, 30, lowerOpen: true), | 108 testRange(new IDBKeyRange.bound(20, 30, lowerOpen: true), |
| 109 21, 30); | 109 21, 30); |
| 110 | 110 |
| 111 bound5() => | 111 bound5() => |
| 112 testRange(new IDBKeyRange.bound(20, 30, lowerOpen: true, upperOpen: true), | 112 testRange(new IDBKeyRange.bound(20, 30, lowerOpen: true, upperOpen: true), |
| 113 21, 29); | 113 21, 29); |
| 114 | 114 |
| 115 } | 115 } |
| 116 | 116 |
| 117 main() { | 117 main() { |
| 118 useDomConfiguration(); | 118 useHtmlConfiguration(); |
| 119 | 119 |
| 120 var test = new Test(); | 120 var test = new Test(); |
| 121 asyncTest('prepare', 1, test.start); | 121 asyncTest('prepare', 1, test.start); |
| 122 | 122 |
| 123 asyncTest('only1', 1, test.only1); | 123 asyncTest('only1', 1, test.only1); |
| 124 asyncTest('only2', 1, test.only2); | 124 asyncTest('only2', 1, test.only2); |
| 125 asyncTest('only3', 1, test.only3); | 125 asyncTest('only3', 1, test.only3); |
| 126 | 126 |
| 127 asyncTest('lower1', 1, test.lower1); | 127 asyncTest('lower1', 1, test.lower1); |
| 128 asyncTest('lower2', 1, test.lower2); | 128 asyncTest('lower2', 1, test.lower2); |
| 129 asyncTest('lower3', 1, test.lower3); | 129 asyncTest('lower3', 1, test.lower3); |
| 130 | 130 |
| 131 asyncTest('upper1', 1, test.upper1); | 131 asyncTest('upper1', 1, test.upper1); |
| 132 asyncTest('upper2', 1, test.upper2); | 132 asyncTest('upper2', 1, test.upper2); |
| 133 asyncTest('upper3', 1, test.upper3); | 133 asyncTest('upper3', 1, test.upper3); |
| 134 | 134 |
| 135 asyncTest('bound1', 1, test.bound1); | 135 asyncTest('bound1', 1, test.bound1); |
| 136 asyncTest('bound2', 1, test.bound2); | 136 asyncTest('bound2', 1, test.bound2); |
| 137 asyncTest('bound3', 1, test.bound3); | 137 asyncTest('bound3', 1, test.bound3); |
| 138 asyncTest('bound4', 1, test.bound4); | 138 asyncTest('bound4', 1, test.bound4); |
| 139 asyncTest('bound5', 1, test.bound5); | 139 asyncTest('bound5', 1, test.bound5); |
| 140 | 140 |
| 141 } | 141 } |
| OLD | NEW |