Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 library EventsTest; | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 import '../../pkg/unittest/lib/unittest.dart'; | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 import '../../pkg/unittest/lib/html_config.dart'; | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 library tests.html.events_test; | |
| 6 | |
| 7 import 'dart:async'; | |
| 4 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'package:unittest/unittest.dart'; | |
| 10 import 'package:unittest/html_config.dart'; | |
| 5 | 11 |
| 6 main() { | 12 main() { |
| 7 useHtmlConfiguration(); | 13 useHtmlConfiguration(); |
| 8 | 14 |
| 9 test('TimeStamp', () { | 15 test('TimeStamp', () { |
| 10 Event event = new Event('test'); | 16 Event event = new Event('test'); |
| 11 | 17 |
| 12 int timeStamp = event.timeStamp; | 18 int timeStamp = event.timeStamp; |
| 13 expect(timeStamp, greaterThan(0)); | 19 expect(timeStamp, greaterThan(0)); |
| 14 }); | 20 }); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 provider.forTarget(element).listen(handler); | 71 provider.forTarget(element).listen(handler); |
| 66 invocationCounter = 0; | 72 invocationCounter = 0; |
| 67 element.dispatchEvent(event); | 73 element.dispatchEvent(event); |
| 68 expect(invocationCounter, 1); | 74 expect(invocationCounter, 1); |
| 69 }); | 75 }); |
| 70 | 76 |
| 71 test('InitMouseEvent', () { | 77 test('InitMouseEvent', () { |
| 72 DivElement div = new Element.tag('div'); | 78 DivElement div = new Element.tag('div'); |
| 73 MouseEvent event = new MouseEvent('zebra', relatedTarget: div); | 79 MouseEvent event = new MouseEvent('zebra', relatedTarget: div); |
| 74 }); | 80 }); |
| 81 | |
| 82 test('DOM event callbacks are associated with the correct zone', () { | |
| 83 var callbacks = []; | |
| 84 // runZoned executes the function synchronously, but we don't want to | |
| 85 // rely on this. We therefore wrap it into an expectAsync0. | |
| 86 runZoned(expectAsync0(() { | |
| 87 Zone zone = Zone.current; | |
| 88 expect(zone, isNot(equals(Zone.ROOT))); | |
| 89 | |
| 90 final element = new Element.tag('test'); | |
| 91 element.id = 'eventtarget'; | |
| 92 document.body.append(element); | |
| 93 | |
| 94 var sub; | |
| 95 | |
| 96 void handler(Event e) { | |
| 97 expect(Zone.current, equals(zone)); | |
| 98 | |
| 99 runAsync(expectAsync0(() { | |
| 100 expect(Zone.current, equals(zone)); | |
| 101 sub.cancel(); | |
| 102 })); | |
| 103 } | |
| 104 | |
| 105 var provider = new EventStreamProvider<CustomEvent>('test'); | |
| 106 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.
| |
| 107 element.dispatchEvent(new Event('test')); | |
| 108 })); | |
| 109 }); | |
| 75 } | 110 } |
| OLD | NEW |