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

Unified Diff: tests/html/events_test.dart

Issue 24509004: Run DOM callbacks in the zone they are coming from. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Wrap into expectAsync0. Created 7 years, 3 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
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tools/dom/src/EventStreamProvider.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/events_test.dart
diff --git a/tests/html/events_test.dart b/tests/html/events_test.dart
index 8451c893d6363a04d452f576541e060cb3574ef7..6e0579cf66c476b3186b175a141ad7822a49e83a 100644
--- a/tests/html/events_test.dart
+++ b/tests/html/events_test.dart
@@ -1,7 +1,13 @@
-library EventsTest;
-import '../../pkg/unittest/lib/unittest.dart';
-import '../../pkg/unittest/lib/html_config.dart';
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library tests.html.events_test;
+
+import 'dart:async';
import 'dart:html';
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_config.dart';
main() {
useHtmlConfiguration();
@@ -72,4 +78,33 @@ main() {
DivElement div = new Element.tag('div');
MouseEvent event = new MouseEvent('zebra', relatedTarget: div);
});
+
+ test('DOM event callbacks are associated with the correct zone', () {
+ var callbacks = [];
+ // runZoned executes the function synchronously, but we don't want to
+ // rely on this. We therefore wrap it into an expectAsync0.
+ runZoned(expectAsync0(() {
+ Zone zone = Zone.current;
+ expect(zone, isNot(equals(Zone.ROOT)));
+
+ final element = new Element.tag('test');
+ element.id = 'eventtarget';
+ document.body.append(element);
+
+ var sub;
+
+ void handler(Event e) {
+ expect(Zone.current, equals(zone));
+
+ runAsync(expectAsync0(() {
+ expect(Zone.current, equals(zone));
+ sub.cancel();
+ }));
+ }
+
+ var provider = new EventStreamProvider<CustomEvent>('test');
+ sub = provider.forTarget(element).listen(expectAsync1(handler));
blois 2013/09/26 16:41:27 can also do: element.on['test'].listen(...)
floitsch 2013/09/26 16:49:46 Done.
+ element.dispatchEvent(new Event('test'));
+ }));
+ });
}
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tools/dom/src/EventStreamProvider.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698