<commit_before><!doctype html>
<!--
@license
Copyright (c) 2020 The Polymer Project Authors. All rights reserved. This code
may only be used under the BSD style license found at
http://polymer.github.io/LICENSE.txt The complete set of authors may be found
at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google
as part of the polymer project is also subject to an additional IP rights grant
found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<script src="../node_modules/wct-browser-legacy/browser.js"></script>
</head>
<body>
<script>
suite('watchFormdataTarget', () => {
  let iframe = undefined;
  let iframeDoc = undefined;

  setup(done => {
    iframe = document.createElement('iframe');
    iframe.src = './test-environment.html';
    iframe.addEventListener('load', function listener() {
      iframe.removeEventListener('load', listener);
      iframeDoc = iframe.contentDocument;
      done();
    });
    document.body.appendChild(iframe);
  });

  teardown(() => {
    document.body.removeChild(iframe);
    iframe = undefined;
  });

  test('Submitting a form causes a "formdata" event to be dispatched to the ' +
      'form. (listener on form)', () => {
    const form = iframeDoc.createElement('form');
    iframeDoc.body.appendChild(form);

    const submitButton = iframeDoc.createElement('input');
    submitButton.type = 'submit';
    form.appendChild(submitButton);

    let callCount = 0;
    form.addEventListener('formdata', (e) => {
      callCount++;
    });
    submitButton.click();
    assert.strictEqual(callCount, 1);

    iframeDoc.body.removeChild(form);
  });

  test('Submitting a form causes a "formdata" event to be dispatched to the ' +
      'form. (listener on window)', () => {
    const form = iframeDoc.createElement('form');
    iframeDoc.body.appendChild(form);

    const submitButton = iframeDoc.createElement('input');
    submitButton.type = 'submit';
    form.appendChild(submitButton);

    let callCount = 0;
    iframeDoc.defaultView.addEventListener('formdata', (e) => {
      callCount++;
    });
    submitButton.click();
    assert.strictEqual(callCount, 1);

    iframeDoc.body.removeChild(form);
  });
});
</script>
</body>
</html>
<commit_msg>Add comments to tests about using a submit button rather than calling the form's `submit` function.<commit_after><!doctype html>
<!--
@license
Copyright (c) 2020 The Polymer Project Authors. All rights reserved. This code
may only be used under the BSD style license found at
http://polymer.github.io/LICENSE.txt The complete set of authors may be found
at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google
as part of the polymer project is also subject to an additional IP rights grant
found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<script src="../node_modules/wct-browser-legacy/browser.js"></script>
</head>
<body>
<script>
suite('watchFormdataTarget', () => {
  let iframe = undefined;
  let iframeDoc = undefined;

  setup(done => {
    iframe = document.createElement('iframe');
    iframe.src = './test-environment.html';
    iframe.addEventListener('load', function listener() {
      iframe.removeEventListener('load', listener);
      iframeDoc = iframe.contentDocument;
      done();
    });
    document.body.appendChild(iframe);
  });

  teardown(() => {
    document.body.removeChild(iframe);
    iframe = undefined;
  });

  test('Submitting a form causes a "formdata" event to be dispatched to the ' +
      'form. (listener on form)', () => {
    const form = iframeDoc.createElement('form');
    iframeDoc.body.appendChild(form);

    // Submitting a form by calling the `<form>`'s `submit` method causes the UA
    // not to dispatch a 'submit' event. To work around this, we create a submit
    // button and call it's `click` method instead.
    //
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit
    const submitButton = iframeDoc.createElement('input');
    submitButton.type = 'submit';
    form.appendChild(submitButton);

    let callCount = 0;
    form.addEventListener('formdata', (e) => {
      callCount++;
    });
    submitButton.click();
    assert.strictEqual(callCount, 1);

    iframeDoc.body.removeChild(form);
  });

  test('Submitting a form causes a "formdata" event to be dispatched to the ' +
      'form. (listener on window)', () => {
    const form = iframeDoc.createElement('form');
    iframeDoc.body.appendChild(form);

    // Submitting a form by calling the `<form>`'s `submit` method causes the UA
    // not to dispatch a 'submit' event. To work around this, we create a submit
    // button and call it's `click` method instead.
    //
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit
    const submitButton = iframeDoc.createElement('input');
    submitButton.type = 'submit';
    form.appendChild(submitButton);

    let callCount = 0;
    iframeDoc.defaultView.addEventListener('formdata', (e) => {
      callCount++;
    });
    submitButton.click();
    assert.strictEqual(callCount, 1);

    iframeDoc.body.removeChild(form);
  });
});
</script>
</body>
</html>

{'fraction_non_alphanumeric': 0.1372110365398956, 'fraction_numerical': 0.002982848620432513, 'mean_word_length': 3.6051502145922747, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 43, 'https://': 2, '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': '672982', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1516, 'n_words': 435}