Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #library('NativeGCTest'); | 1 #library('NativeGCTest'); |
| 2 #import('../../lib/unittest/unittest.dart'); | 2 #import('../../lib/unittest/unittest.dart'); |
| 3 #import('../../lib/unittest/html_config.dart'); | 3 #import('../../lib/unittest/html_config.dart'); |
| 4 #import('dart:html'); | 4 #import('dart:html'); |
| 5 | 5 |
| 6 main() { | 6 main() { |
| 7 useHtmlConfiguration(); | 7 useHtmlConfiguration(); |
| 8 | 8 |
| 9 Element testDiv = new DivElement(); | |
| 10 testDiv.id = '#TestDiv'; | |
| 11 document.body.nodes.add(testDiv); | |
| 12 window.on.message.add((e) => testDiv.click()); | |
| 13 | |
| 9 test('EventListener', () { | 14 test('EventListener', () { |
| 10 final int N = 1000000; | 15 final int N = 1000000; |
| 11 final int M = 1000; | 16 final int M = 1000; |
| 12 | 17 |
| 13 var div; | 18 var div; |
| 14 for (int i = 0; i < M; ++i) { | 19 for (int i = 0; i < M; ++i) { |
| 15 // This memory should be freed when the listener below is | 20 // This memory should be freed when the listener below is |
| 16 // collected. | 21 // collected. |
| 17 List l = new List(N); | 22 List l = new List(N); |
| 18 | 23 |
| 19 // Record the iteration number. | 24 // Record the iteration number. |
| 20 l[N - 1] = i; | 25 l[N - 1] = i; |
| 21 | 26 |
| 22 div = new Element.tag('div'); | 27 div = new Element.tag('div'); |
| 23 div.on['test'].add((_) { | 28 div.on['test'].add((_) { |
| 24 // Only the final iteration's listener should be invoked. | 29 // Only the final iteration's listener should be invoked. |
| 25 // Note: the reference to l keeps the entire list alive. | 30 // Note: the reference to l keeps the entire list alive. |
| 26 Expect.equals(M - 1, l[N - 1]); | 31 Expect.equals(M - 1, l[N - 1]); |
| 27 }, false); | 32 }, false); |
| 28 } | 33 } |
| 29 | 34 |
| 30 final event = new Event('test'); | 35 final event = new Event('test'); |
| 31 div.on['test'].dispatch(event); | 36 div.on['test'].dispatch(event); |
| 32 }); | 37 }); |
| 38 | |
| 39 test('WindowEventListener', () { | |
| 40 testDiv.on.click.add(expectAsync1((e) {})); | |
|
Anton Muhin
2012/07/06 15:06:15
isn't it too fragile to depend on the test order?
podivilov
2012/07/06 16:08:19
Done.
| |
| 41 window.postMessage('test', '*'); | |
| 42 }); | |
| 33 } | 43 } |
| OLD | NEW |