<commit_before>// Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.


expectLargeRect(ClientRect rect) {
  Expect.equals(rect.top, 0);
  Expect.equals(rect.left, 0);
  Expect.isTrue(rect.width > 100);
  Expect.isTrue(rect.height > 100);
  Expect.equals(rect.bottom, rect.top + rect.height);
  Expect.equals(rect.right, rect.left + rect.width);
}

void testEventHelper(EventListenerList listenerList, String type,
    [Function registerOnEventListener = null]) {
  bool firedWhenAddedToListenerList = false;
  bool firedOnEvent = false;
  listenerList.add((e) {
    firedWhenAddedToListenerList = true;
  });
  if (registerOnEventListener != null) {
    registerOnEventListener((e) {
      firedOnEvent = true;
    });
  }
  final event = new Event(type);
  listenerList.dispatch(event);

  Expect.isTrue(firedWhenAddedToListenerList);
  if (registerOnEventListener != null) {
    Expect.isTrue(firedOnEvent);
  }
}

void testConstructorHelper(String tag, String htmlSnippet,
    String expectedText, Function isExpectedClass) {
  Expect.isTrue(isExpectedClass(new Element.tag(tag)));
  final elementFromSnippet = new Element.html(htmlSnippet);
  Expect.isTrue(isExpectedClass(elementFromSnippet));
  Expect.equals(elementFromSnippet.text, expectedText);
}

void testElement() { 
  asyncTest('computedStyle', 1, () {
    final element = document.body;
    element.computedStyle.then((style) {
      Expect.equals(style.getPropertyValue('left'), 'auto');
      callbackDone();
    });
  });

  asyncTest('rect', 1, () {
    final element = document.body;
    element.rect.then((rect) {
      expectLargeRect(rect.client);
      expectLargeRect(rect.offset);
      expectLargeRect(rect.scroll);
      Expect.equals(rect.bounding.left, 8);
      Expect.equals(rect.bounding.top, 8);
      Expect.isTrue(rect.clientRects.length > 0);
      callbackDone();
    });
  });

  group('constructors', () {
    test('a', () => testConstructorHelper('a', '<a>foo</a>', 'foo',
        (element) => element is AnchorElement));
    test('area', () => testConstructorHelper('area', '<area>foo</area>', '',
        (element) => element is AreaElement));
    // TODO(jacobr): audio tags cause tests to segfault when using dartium.
    // b/5522106.
    // test('audio', () => testConstructorHelper('audio',
    //     '<audio>foo</audio>', 'foo',
    //     (element) => element is AudioElement));
    test('br', () => testConstructorHelper('br', '<br>', '',
        (element) => element is BRElement));
    test('base', () => testConstructorHelper('base', '<base>foo</base>', '',
        (element) => element is BaseElement));          
    test('blockquote', () => testConstructorHelper('blockquote',
        '<blockquote>foo</blockquote>', 'foo',
        (element) => element is QuoteElement));
    test('body', () => testConstructorHelper('body',
        '<body><div>foo</div></body>', 'foo',
        (element) => element is BodyElement));
    test('button', () => testConstructorHelper('button',
        '<button>foo</button>', 'foo',
        (element) => element is ButtonElement));<commit_msg>Make ElementTests independent of the existing HTML markup.<commit_after>// Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.


expectLargeRect(ClientRect rect) {
  Expect.equals(rect.top, 0);
  Expect.equals(rect.left, 0);
  Expect.isTrue(rect.width > 100);
  Expect.isTrue(rect.height > 100);
  Expect.equals(rect.bottom, rect.top + rect.height);
  Expect.equals(rect.right, rect.left + rect.width);
}

void testEventHelper(EventListenerList listenerList, String type,
    [Function registerOnEventListener = null]) {
  bool firedWhenAddedToListenerList = false;
  bool firedOnEvent = false;
  listenerList.add((e) {
    firedWhenAddedToListenerList = true;
  });
  if (registerOnEventListener != null) {
    registerOnEventListener((e) {
      firedOnEvent = true;
    });
  }
  final event = new Event(type);
  listenerList.dispatch(event);

  Expect.isTrue(firedWhenAddedToListenerList);
  if (registerOnEventListener != null) {
    Expect.isTrue(firedOnEvent);
  }
}

void testConstructorHelper(String tag, String htmlSnippet,
    String expectedText, Function isExpectedClass) {
  Expect.isTrue(isExpectedClass(new Element.tag(tag)));
  final elementFromSnippet = new Element.html(htmlSnippet);
  Expect.isTrue(isExpectedClass(elementFromSnippet));
  Expect.equals(elementFromSnippet.text, expectedText);
}

void testElement() { 
  asyncTest('computedStyle', 1, () {
    final element = document.body;
    element.computedStyle.then((style) {
      Expect.equals(style.getPropertyValue('left'), 'auto');
      callbackDone();
    });
  });

  asyncTest('rect', 1, () {
    final container = new Element.tag("div");
    container.style.position = 'absolute';
    final element = new Element.tag("div");
    element.style.width = '200px';
    element.style.height = '200px';
    container.elements.add(element);
    document.body.elements.add(container);

    element.rect.then((rect) {
      expectLargeRect(rect.client);
      expectLargeRect(rect.offset);
      expectLargeRect(rect.scroll);
      Expect.equals(rect.bounding.left, 8);
      Expect.equals(rect.bounding.top, 8);
      Expect.isTrue(rect.clientRects.length > 0);
      container.remove();
      callbackDone();
    });
  });

  group('constructors', () {
    test('a', () => testConstructorHelper('a', '<a>foo</a>', 'foo',
        (element) => element is AnchorElement));
    test('area', () => testConstructorHelper('area', '<area>foo</area>', '',
        (element) => element is AreaElement));
    // TODO(jacobr): audio tags cause tests to segfault when using dartium.
    // b/5522106.
    // test('audio', () => testConstructorHelper('audio',
    //     '<audio>foo</audio>', 'foo',
    //     (element) => element is AudioElement));
    test('br', () => testConstructorHelper('br', '<br>', '',
        (element) => element is BRElement));
    test('base', () => testConstructorHelper('base', '<base>foo</base>', '',
        (element) => element is BaseElement));          
    test('blockquote', () => testConstructorHelper('blockquote',
        '<blockquote>foo</blockquote>', 'foo',
        (element) => element is QuoteElement));
    test('body', () => testConstructorHelper('body',
        '<body><div>foo</div></body>', 'foo',
        (element) => element is BodyElement));
    test('button', () => testConstructorHelper('button',
        '<button>foo</button>', 'foo',
        (element) => element is ButtonElement));
{'fraction_non_alphanumeric': 0.1596416507563519, 'fraction_numerical': 0.007930679982376267, 'mean_word_length': 3.799154334038055, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7648025', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1994, 'n_words': 428}