Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 library streams_test; | 1 library streams_test; |
| 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:async'; | 4 import 'dart:async'; |
| 5 import 'dart:html'; | 5 import 'dart:html'; |
| 6 | 6 |
| 7 class StreamHelper { | 7 class StreamHelper { |
| 8 var _a; | 8 var _a; |
| 9 var _b; | |
| 10 StreamHelper() { | 9 StreamHelper() { |
| 11 _a = new TextInputElement(); | 10 _a = new TextInputElement(); |
| 12 document.body.append(_a); | 11 document.body.append(_a); |
| 13 _b = new TextInputElement(); | |
| 14 document.body.append(_b); | |
| 15 } | 12 } |
| 16 | 13 |
| 14 Element get element => _a; | |
| 17 Stream<Event> get stream => _a.onFocus; | 15 Stream<Event> get stream => _a.onFocus; |
| 18 | 16 |
| 19 // Causes an event on a to be fired. | 17 // Causes an event on a to be fired. |
| 20 void pulse() { | 18 void pulse() { |
| 21 _b.focus(); | 19 var event = new Event('focus'); |
| 22 _a.focus(); | 20 _a.$dom_dispatchEvent(event); |
|
Jennifer Messerly
2013/01/14 21:56:51
is there a way to do this without $dom_?
blois
2013/01/14 22:00:05
Currently it's on the old events API, but I need t
| |
| 23 } | 21 } |
| 24 } | 22 } |
| 25 | 23 |
| 26 main() { | 24 main() { |
| 27 useHtmlConfiguration(); | 25 useHtmlConfiguration(); |
| 28 | 26 |
| 29 test('simple', () { | 27 test('simple', () { |
| 30 var a = new TextInputElement(); | 28 var helper = new StreamHelper(); |
| 31 document.body.append(a); | |
| 32 | 29 |
| 33 var callCount = 0; | 30 var callCount = 0; |
| 34 a.onFocus.listen((Event e) { | 31 helper.stream.listen((Event e) { |
| 35 ++callCount; | 32 ++callCount; |
| 36 }); | 33 }); |
| 37 | 34 |
| 38 a.focus(); | 35 helper.pulse(); |
| 39 expect(callCount, 1); | 36 expect(callCount, 1); |
| 40 }); | 37 }); |
| 41 | 38 |
| 42 // Validates that capturing events fire on parent before child. | 39 // Validates that capturing events fire on parent before child. |
| 43 test('capture', () { | 40 test('capture', () { |
| 44 var parent = new DivElement(); | 41 var parent = new DivElement(); |
| 45 document.body.append(parent); | 42 document.body.append(parent); |
| 46 | 43 |
| 47 var child = new TextInputElement(); | 44 var helper = new StreamHelper(); |
| 48 parent.append(child); | 45 parent.append(helper.element); |
| 49 | 46 |
| 50 var childCallCount = 0; | 47 var childCallCount = 0; |
| 51 var parentCallCount = 0; | 48 var parentCallCount = 0; |
| 52 Element.focusEvent.forTarget(parent, useCapture: true).listen((Event e) { | 49 Element.focusEvent.forTarget(parent, useCapture: true).listen((Event e) { |
| 53 ++parentCallCount; | 50 ++parentCallCount; |
| 54 expect(childCallCount, 0); | 51 expect(childCallCount, 0); |
| 55 }); | 52 }); |
| 56 | 53 |
| 57 Element.focusEvent.forTarget(child, useCapture: true).listen((Event e) { | 54 Element.focusEvent.forTarget(helper.element, useCapture: true).listen( |
| 58 ++childCallCount; | 55 (Event e) { |
| 59 expect(parentCallCount, 1); | 56 ++childCallCount; |
| 60 }); | 57 expect(parentCallCount, 1); |
| 58 }); | |
| 61 | 59 |
| 62 child.focus(); | 60 helper.pulse(); |
| 63 expect(childCallCount, 1); | 61 expect(childCallCount, 1); |
| 64 expect(parentCallCount, 1); | 62 expect(parentCallCount, 1); |
| 65 }); | 63 }); |
| 66 | 64 |
| 67 test('cancel', () { | 65 test('cancel', () { |
| 68 var helper = new StreamHelper(); | 66 var helper = new StreamHelper(); |
| 69 | 67 |
| 70 var callCount = 0; | 68 var callCount = 0; |
| 71 var subscription = helper.stream.listen((_) { | 69 var subscription = helper.stream.listen((_) { |
| 72 ++callCount; | 70 ++callCount; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 ++callCountOne; | 163 ++callCountOne; |
| 166 }); | 164 }); |
| 167 helper.pulse(); | 165 helper.pulse(); |
| 168 expect(callCountOne, 1); | 166 expect(callCountOne, 1); |
| 169 | 167 |
| 170 subscription.onData(null); | 168 subscription.onData(null); |
| 171 helper.pulse(); | 169 helper.pulse(); |
| 172 expect(callCountOne, 1); | 170 expect(callCountOne, 1); |
| 173 }); | 171 }); |
| 174 } | 172 } |
| OLD | NEW |