Chromium Code Reviews| 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')); |
| + })); |
| + }); |
| } |