diff --git a/testing/web-platform/tests/html/semantics/forms/form-submission-0/SubmitEvent.window.js b/testing/web-platform/tests/html/semantics/forms/form-submission-0/SubmitEvent.window.js new file mode 100644 index 0000000000000..93dbabb866bee --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/form-submission-0/SubmitEvent.window.js @@ -0,0 +1,36 @@ +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#the-submitevent-interface + +test(() => { + let button = document.createElement('button'); + let typeError = new TypeError(); + assert_throws(typeError, () => { new SubmitEvent() }, '0 arguments'); + assert_throws(typeError, () => { new SubmitEvent('bar', button) }, '1 invalid arguments'); + assert_throws(typeError, () => { new SubmitEvent(button, button) }, '2 invalid arguments'); + assert_throws(typeError, () => { new SubmitEvent('foo', null) }, 'Null dictionary'); + assert_throws(typeError, () => { new SubmitEvent('foo', undefined) }, 'Undefined dictionary'); + assert_throws(typeError, () => { new SubmitEvent('foo', { submitter: null }) }, 'Null submitter'); + assert_throws(typeError, () => { new SubmitEvent('foo', { submitter: undefined }) }, 'Undefined submitter'); + assert_throws(typeError, () => { new SubmitEvent('foo', { submitter: 'bar' }) }, 'Wrong type of submitter'); +}, 'Failing SubmitEvent constructor'); + +test(() => { + let button = document.createElement('button'); + let event = new SubmitEvent('bar', { submitter: button, bubbles: true }); + assert_equals(event.submitter, button); + assert_true(event.bubbles); +}, 'Successful SubmitEvent constructor'); + +test(() => { + let event = new SubmitEvent('bar', { submitter: null}); + assert_equals(event.submitter, null); +}, 'Successful SubmitEvent constructor; null submitter'); + +test(() => { + let event = new SubmitEvent('baz', {}); + assert_equals(event.submitter, null); +}, 'Successful SubmitEvent constructor; empty dictionary'); + +test(() => { + let event = new SubmitEvent('baz'); + assert_equals(event.submitter, null); +}, 'Successful SubmitEvent constructor; missing dictionary'); diff --git a/testing/web-platform/tests/html/semantics/forms/form-submission-0/form-submission-algorithm.html b/testing/web-platform/tests/html/semantics/forms/form-submission-0/form-submission-algorithm.html index 8f61cbc18c951..df39b57353c67 100644 --- a/testing/web-platform/tests/html/semantics/forms/form-submission-0/form-submission-algorithm.html +++ b/testing/web-platform/tests/html/semantics/forms/form-submission-0/form-submission-algorithm.html @@ -50,6 +50,60 @@ }); }, "If form's firing submission events is true, then return; 'submit' event"); +promise_test(async () => { + let form = populateForm(''); + let iframe = form.previousSibling; + let submitter = form.querySelector('input[type=submit]'); + let event; + form.addEventListener('submit', e => { event = e; }); + submitter.click(); + await loadPromise(iframe); + assert_true(event.bubbles); + assert_true(event.cancelable); + assert_equals(event.submitter, submitter); + assert_true(event instanceof SubmitEvent); +}, 'firing an event named submit; clicking a submit button'); + +promise_test(async () => { + let form = populateForm(''); + let iframe = form.previousSibling; + let event; + form.addEventListener('submit', e => { event = e; }); + form.requestSubmit(); + await loadPromise(iframe); + assert_true(event.bubbles); + assert_true(event.cancelable); + assert_equals(event.submitter, null); + assert_true(event instanceof SubmitEvent); +}, 'firing an event named submit; form.requestSubmit()'); + +promise_test(async () => { + let form = populateForm(''); + let iframe = form.previousSibling; + let event; + form.addEventListener('submit', e => { event = e; }); + form.requestSubmit(null); + await loadPromise(iframe); + assert_true(event.bubbles); + assert_true(event.cancelable); + assert_equals(event.submitter, null); + assert_true(event instanceof SubmitEvent); +}, 'firing an event named submit; form.requestSubmit(null)'); + +promise_test(async () => { + let form = populateForm(''); + let iframe = form.previousSibling; + let submitter = form.querySelector('button'); + let event; + form.addEventListener('submit', e => { event = e; }); + form.requestSubmit(submitter); + await loadPromise(iframe); + assert_true(event.bubbles); + assert_true(event.cancelable); + assert_equals(event.submitter, submitter); + assert_true(event instanceof SubmitEvent); +}, 'firing an event named submit; form.requestSubmit(submitter)'); + async_test(t => { let form = populateForm(''); form.onformdata = (e) => { e.target.remove(); }; diff --git a/testing/web-platform/tests/html/semantics/forms/form-submission-0/implicit-submission.optional.html b/testing/web-platform/tests/html/semantics/forms/form-submission-0/implicit-submission.optional.html new file mode 100644 index 0000000000000..109d3b901a535 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/form-submission-0/implicit-submission.optional.html @@ -0,0 +1,39 @@ + + + + + + + +
+ + diff --git a/testing/web-platform/tests/html/semantics/forms/form-submission-0/resources/targetted-form.js b/testing/web-platform/tests/html/semantics/forms/form-submission-0/resources/targetted-form.js index 6b6685291d2bd..291251b7e8037 100644 --- a/testing/web-platform/tests/html/semantics/forms/form-submission-0/resources/targetted-form.js +++ b/testing/web-platform/tests/html/semantics/forms/form-submission-0/resources/targetted-form.js @@ -19,3 +19,10 @@ function submitPromise(form, iframe) { form.submit(); }); } + +function loadPromise(iframe) { + return new Promise((resolve, reject) => { + iframe.onload = resolve; + iframe.onerror = () => reject(new Error('iframe onerror fired')); + }); +}