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

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

Issue 12040059: Converting tests over to using event streams. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
OLDNEW
1 library NativeGCTest; 1 library NativeGCTest;
2 import '../../pkg/unittest/lib/unittest.dart'; 2 import '../../pkg/unittest/lib/unittest.dart';
3 import '../../pkg/unittest/lib/html_config.dart'; 3 import '../../pkg/unittest/lib/html_config.dart';
4 import 'dart:html'; 4 import 'dart:html';
5 5
6 var testEvent = new EventStreamProvider<Event>('test');
7
6 main() { 8 main() {
7 useHtmlConfiguration(); 9 useHtmlConfiguration();
8 10
9 test('EventListener', () { 11 test('EventListener', () {
10 final int N = 1000000; 12 final int N = 1000000;
11 final int M = 1000; 13 final int M = 1000;
12 14
13 var div; 15 var div;
14 for (int i = 0; i < M; ++i) { 16 for (int i = 0; i < M; ++i) {
15 // This memory should be freed when the listener below is 17 // This memory should be freed when the listener below is
16 // collected. 18 // collected.
17 List l = new List.fixedLength(N); 19 List l = new List.fixedLength(N);
18 20
19 // Record the iteration number. 21 // Record the iteration number.
20 l[N - 1] = i; 22 l[N - 1] = i;
21 23
22 div = new Element.tag('div'); 24 div = new Element.tag('div');
23 div.on['test'].add((_) { 25 testEvent.forTarget(div).listen((_) {
24 // Only the final iteration's listener should be invoked. 26 // Only the final iteration's listener should be invoked.
25 // Note: the reference to l keeps the entire list alive. 27 // Note: the reference to l keeps the entire list alive.
26 expect(l[N - 1], M - 1); 28 expect(l[N - 1], M - 1);
27 }, false); 29 });
28 } 30 }
29 31
30 final event = new Event('test'); 32 final event = new Event('test');
31 div.on['test'].dispatch(event); 33 div.dispatchEvent(event);
32 }); 34 });
33 35
34 test('WindowEventListener', () { 36 test('WindowEventListener', () {
35 String message = 'WindowEventListenerTestPingMessage'; 37 String message = 'WindowEventListenerTestPingMessage';
36 38
37 Element testDiv = new DivElement(); 39 Element testDiv = new DivElement();
38 testDiv.id = '#TestDiv'; 40 testDiv.id = '#TestDiv';
39 document.body.nodes.add(testDiv); 41 document.body.nodes.add(testDiv);
40 window.on.message.add((e) { 42 window.onMessage.listen((e) {
41 if (e.data == message) testDiv.click(); 43 if (e.data == message) testDiv.click();
42 }); 44 });
43 45
44 for (int i = 0; i < 100; ++i) { 46 for (int i = 0; i < 100; ++i) {
45 triggerMajorGC(); 47 triggerMajorGC();
46 } 48 }
47 49
48 testDiv.on.click.add(expectAsync1((e) {})); 50 testDiv.onClick.listen(expectAsync1((e) {}));
49 window.postMessage(message, '*'); 51 window.postMessage(message, '*');
50 }); 52 });
51 } 53 }
52 54
53 void triggerMajorGC() { 55 void triggerMajorGC() {
54 List list = new List.fixedLength(1000000); 56 List list = new List.fixedLength(1000000);
55 Element div = new DivElement(); 57 Element div = new DivElement();
56 div.on.click.add((e) => print(list[0])); 58 div.onClick.listen((e) => print(list[0]));
57 } 59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698