#library('NativeGCTest');
#import('../../lib/unittest/unittest.dart');
#import('../../lib/unittest/html_config.dart');
#import('dart:html');

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');
        div.on['test'].add((_) {
            // Only the final iteration's listener should be invoked.
            // Note: the reference to l keeps the entire list alive.
            Expect.equals(M - 1, l[N - 1]);
          }, false);
      }

      final event = new Event('test');
      div.on['test'].dispatch(event);
  });
}

#library('NativeGCTest');
#import('../../lib/unittest/unittest.dart');
#import('../../lib/unittest/html_config.dart');
#import('dart:html');

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');
        div.on['test'].add((_) {
            // Only the final iteration's listener should be invoked.
            // Note: the reference to l keeps the entire list alive.
            Expect.equals(M - 1, l[N - 1]);
          }, false);
      }

      final event = new Event('test');
      div.on['test'].dispatch(event);
  });

  test('WindowEventListener', () {
    Element testDiv = new DivElement();
    testDiv.id = '#TestDiv';
    document.body.nodes.add(testDiv);
    window.on.message.add((e) => testDiv.click());

    for (int i = 0; i < 100; ++i) {
      triggerMajorGC();
    }

    testDiv.on.click.add(expectAsync1((e) {}));
    window.postMessage('test', '*');
  });
}

void triggerMajorGC() {
  List list = new List(1000000);
  Element div = new DivElement();
  div.on.click.add((e) => print(list[0]));
}

Add test for garbage collected window event listeners issue.
Add test for garbage collected window event listeners issue.

R=antonm@google.com

Review URL: https://chromiumcodereview.appspot.com//10689120

git-svn-id: c93d8a2297af3b929165606efe145742a534bc71@9497 260f80e4-7a28-3924-810f-c04153c831b5
