Files
sdk/tests/html/native_gc_test.dart
T
Jacob Richman 2dcd56ef43 Format all tests.
There are far too many files here to review everyone carefully.
Spot checking most of the diffs look good as test code is generally written
with less care than application code so lots of ugly formatting get through.
If people notice files where the automated formatting bothers them feel free
to comment indicating file names and I'll move spaces within comments to make
the formatting cleaner and use comments to force block formatting as I have
done for other case where formatting looked bad.

BUG=
R=efortuna@google.com

Review-Url: https://codereview.chromium.org/2771453003 .
2017-04-17 14:53:02 -07:00

61 lines
1.4 KiB
Dart

library NativeGCTest;
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'dart:html';
var testEvent = new EventStreamProvider<Event>('test');
main() {
useHtmlConfiguration();
test('EventListener', () {
final int N = 1000000;
final int M = 1000;
var div;
for (int i = 0; i < M; ++i) {
// This memory should be freed when the listener below is
// collected.
List l = new List(N);
// Record the iteration number.
l[N - 1] = i;
div = new Element.tag('div');
testEvent.forTarget(div).listen((_) {
// Only the final iteration's listener should be invoked.
// Note: the reference to l keeps the entire list alive.
expect(l[N - 1], M - 1);
});
}
final event = new Event('test');
div.dispatchEvent(event);
});
test('WindowEventListener', () {
String message = 'WindowEventListenerTestPingMessage';
Element testDiv = new DivElement();
testDiv.id = '#TestDiv';
document.body.append(testDiv);
window.onMessage.listen((e) {
if (e.data == message) testDiv.click();
});
for (int i = 0; i < 100; ++i) {
triggerMajorGC();
}
testDiv.onClick.listen(expectAsync((e) {}));
window.postMessage(message, '*');
});
}
void triggerMajorGC() {
List list = new List(1000000);
Element div = new DivElement();
div.onClick.listen((e) => print(list[0]));
}