Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: tests/html/streams_test.dart

Issue 11824072: Adding streams to dart:html. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/html/streams_test.dart
diff --git a/tests/html/streams_test.dart b/tests/html/streams_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c0b3b4cac79427a9b6ef250ffcdab2eb8a6e4fdb
--- /dev/null
+++ b/tests/html/streams_test.dart
@@ -0,0 +1,85 @@
+library streams_test;
+import '../../pkg/unittest/lib/unittest.dart';
+import '../../pkg/unittest/lib/html_config.dart';
+import 'dart:async';
+import 'dart:html';
+
+main() {
+ useHtmlConfiguration();
+
+ test('simple', () {
+ var a = new TextInputElement();
+ document.body.append(a);
+
+ var callCount = 0;
+ a.onFocus.listen((Event e) {
+ ++callCount;
+ });
+
+ a.focus();
+ expect(callCount, 1);
+ });
+
+ // Validates that events are not automatically unsubscribed.
+ test('unsubscribeOnError', () {
+ var a = new TextInputElement();
+ document.body.append(a);
+
+ var b = new TextInputElement();
+ document.body.append(b);
+
+ var callCountOne = 0;
+ var callCountTwo = 0;
+ var callCountThree = 0;
+ // 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!
+ a.onFocus.listen((Event e) {
+ ++callCountOne;
+ throw 'this error should not cause any problems.';
+ }, 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.
+
+ // Handler which throws an exception should still get events.
+ a.onFocus.listen((Event e) {
+ ++callCountTwo;
+ if (callCountTwo == 0) {
+ throw 'this error should not cause any problems.';
+ }
+ });
+
+ // Standard handler should still always get events
+ a.onFocus.listen((Event e) {
+ ++callCountThree;
+ });
+
+ a.focus();
+ b.focus();
+ a.focus();
+ expect(callCountOne, 2);
+ expect(callCountTwo, 2);
+ expect(callCountThree, 2);
+ });
+
+ // Validates that capturing events fire on parent before child.
+ test('capture', () {
+ var parent = new DivElement();
+ document.body.append(parent);
+
+ var child = new TextInputElement();
+ parent.append(child);
+
+ var childCallCount = 0;
+ var parentCallCount = 0;
+ Element.focusEvent.forTarget(parent, useCapture:true).listen((Event e) {
+ ++parentCallCount;
+ expect(childCallCount, 0);
+ });
+
+ Element.focusEvent.forTarget(child, useCapture:true).listen((Event e) {
+ ++childCallCount;
+ expect(parentCallCount, 1);
+ });
+
+ child.focus();
+ expect(childCallCount, 1);
+ expect(parentCallCount, 1);
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698