| 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 |
| 85 final element = new Element.tag('test'); |
| 86 element.id = 'eventtarget'; |
| 87 document.body.append(element); |
| 88 |
| 89 // runZoned executes the function synchronously, but we don't want to |
| 90 // rely on this. We therefore wrap it into an expectAsync0. |
| 91 runZoned(expectAsync0(() { |
| 92 Zone zone = Zone.current; |
| 93 expect(zone, isNot(equals(Zone.ROOT))); |
| 94 |
| 95 var sub; |
| 96 |
| 97 void handler(Event e) { |
| 98 expect(Zone.current, equals(zone)); |
| 99 |
| 100 runAsync(expectAsync0(() { |
| 101 expect(Zone.current, equals(zone)); |
| 102 sub.cancel(); |
| 103 })); |
| 104 } |
| 105 |
| 106 sub = element.on['test'].listen(expectAsync1(handler)); |
| 107 })); |
| 108 element.dispatchEvent(new Event('test')); |
| 109 }); |
| 75 } | 110 } |
| OLD | NEW |