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

Side by Side Diff: tests/html/events_test.dart

Issue 23054006: for discussion: support for zones in DOM events (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tools/dom/src/EventStreamProvider.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 callbaccks are associated with the correct zone', () {
83 var callbacks = [];
84 runZonedExperimental(expectAsync0(() {
85 final element = new Element.tag('test');
86 element.id = 'eventtarget';
87 document.body.append(element);
88
89 int asyncCounter = 0;
90 var asyncCallback = expectAsync0(() {
91 asyncCounter++;
92 });
93
94 void handler(Event e) {
95 expect(e.type, equals('test'));
96 Element target = e.target;
97 expect(element, equals(target));
98
99 runAsync(asyncCallback);
100 }
101
102 var provider = new EventStreamProvider<CustomEvent>('test');
103 var sub = provider.forTarget(element).listen(expectAsync1(handler));
104 element.dispatchEvent(new Event('test'));
105
106 expect(callbacks.length, 1, reason: 'event was run in a zone.');
107 expect(asyncCounter, 0, reason: 'callback was not invoked yet.');
108 callbacks.first();
109 expect(asyncCounter, 1, reason: 'callback was invoked.');
110 sub.cancel();
111 }), onRunAsync: (x) {
112 callbacks.add(x);
113 return x;
114 });
115 });
75 } 116 }
OLDNEW
« 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