OLD | NEW |
---|---|
(Empty) | |
1 library streams_test; | |
2 import '../../pkg/unittest/lib/unittest.dart'; | |
3 import '../../pkg/unittest/lib/html_config.dart'; | |
4 import 'dart:async'; | |
5 import 'dart:html'; | |
6 | |
7 main() { | |
8 useHtmlConfiguration(); | |
9 | |
10 test('simple', () { | |
11 var a = new TextInputElement(); | |
12 document.body.append(a); | |
13 | |
14 var callCount = 0; | |
15 a.onFocus.listen((Event e) { | |
16 ++callCount; | |
17 }); | |
18 | |
19 a.focus(); | |
20 expect(callCount, 1); | |
21 }); | |
22 | |
23 // Validates that events are not automatically unsubscribed. | |
24 test('unsubscribeOnError', () { | |
25 var a = new TextInputElement(); | |
26 document.body.append(a); | |
27 | |
28 var b = new TextInputElement(); | |
29 document.body.append(b); | |
30 | |
31 var callCountOne = 0; | |
32 var callCountTwo = 0; | |
33 var callCountThree = 0; | |
34 // Unsubscribe on error handlers still get their events. | |
Jennifer Messerly
2013/01/11 21:57:17
Q: what is the effect of unsubscribeOnError? I thi
blois
2013/01/11 22:51:30
We have no way of triggering unsubscribeOnError fo
floitsch
2013/01/11 22:55:45
Correct. unsubscribeOnError (similar to the onErro
Jennifer Messerly
2013/01/11 23:30:14
Makes sense. Thanks for clarifying!
| |
35 a.onFocus.listen((Event e) { | |
36 ++callCountOne; | |
37 throw 'this error should not cause any problems.'; | |
38 }, unsubscribeOnError:true); | |
Jennifer Messerly
2013/01/11 21:57:17
I think we usually have space after : in named arg
blois
2013/01/11 22:51:30
Done.
| |
39 | |
40 // Handler which throws an exception should still get events. | |
41 a.onFocus.listen((Event e) { | |
42 ++callCountTwo; | |
43 if (callCountTwo == 0) { | |
44 throw 'this error should not cause any problems.'; | |
45 } | |
46 }); | |
47 | |
48 // Standard handler should still always get events | |
49 a.onFocus.listen((Event e) { | |
50 ++callCountThree; | |
51 }); | |
52 | |
53 a.focus(); | |
54 b.focus(); | |
55 a.focus(); | |
56 expect(callCountOne, 2); | |
57 expect(callCountTwo, 2); | |
58 expect(callCountThree, 2); | |
59 }); | |
60 | |
61 // Validates that capturing events fire on parent before child. | |
62 test('capture', () { | |
63 var parent = new DivElement(); | |
64 document.body.append(parent); | |
65 | |
66 var child = new TextInputElement(); | |
67 parent.append(child); | |
68 | |
69 var childCallCount = 0; | |
70 var parentCallCount = 0; | |
71 Element.focusEvent.forTarget(parent, useCapture:true).listen((Event e) { | |
72 ++parentCallCount; | |
73 expect(childCallCount, 0); | |
74 }); | |
75 | |
76 Element.focusEvent.forTarget(child, useCapture:true).listen((Event e) { | |
77 ++childCallCount; | |
78 expect(parentCallCount, 1); | |
79 }); | |
80 | |
81 child.focus(); | |
82 expect(childCallCount, 1); | |
83 expect(parentCallCount, 1); | |
84 }); | |
85 } | |
OLD | NEW |