From 1373d2e69abb4587248d6735bec4b2772379ee1e Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 3 Oct 2019 21:45:21 +0000 Subject: [PATCH] Bug 1516063 [wpt PR 14637] - html, xhr: Add tests for 'formdata' event, a=testonly Automatic update from web-platform-tests html, xhr: Add tests for 'formdata' event (#14637) Specification PR: https://github.com/whatwg/html/pull/4239 -- wpt-commits: c547389199647f1736be244a7ca5a874da692430 wpt-pr: 14637 UltraBlame original commit: c71f7d3fa10b69185c90a1537bb49989a0fd4604 --- .../tests/html/dom/interfaces.https.html | 24 + .../form-submission-0/FormDataEvent.window.js | 311 ++++++++++ .../constructing-form-data-set.html | 539 ++++++++++++++++++ .../form-submission-algorithm.html | 404 +++++++++++++ .../resources/targetted-form.js | 101 ++++ .../web-platform/tests/interfaces/html.idl | 40 ++ testing/web-platform/tests/xhr/formdata.htm | 336 +++++++++++ 7 files changed, 1755 insertions(+) create mode 100644 testing/web-platform/tests/html/semantics/forms/form-submission-0/FormDataEvent.window.js create mode 100644 testing/web-platform/tests/html/semantics/forms/form-submission-0/form-submission-algorithm.html create mode 100644 testing/web-platform/tests/html/semantics/forms/form-submission-0/resources/targetted-form.js diff --git a/testing/web-platform/tests/html/dom/interfaces.https.html b/testing/web-platform/tests/html/dom/interfaces.https.html index 9810a2b0ffc01..af16929f6d422 100644 --- a/testing/web-platform/tests/html/dom/interfaces.https.html +++ b/testing/web-platform/tests/html/dom/interfaces.https.html @@ -372,6 +372,9 @@ ' dom ' +' +xhr +' ] async idlArray @@ -1853,6 +1856,27 @@ validity ' ] +FormDataEvent +: +[ +' +new +FormDataEvent +( +" +formdata +" +{ +formData +: +new +FormData +( +) +} +) +' +] HTMLDetailsElement : [ diff --git a/testing/web-platform/tests/html/semantics/forms/form-submission-0/FormDataEvent.window.js b/testing/web-platform/tests/html/semantics/forms/form-submission-0/FormDataEvent.window.js new file mode 100644 index 0000000000000..926a9177ba791 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/form-submission-0/FormDataEvent.window.js @@ -0,0 +1,311 @@ +/ +/ +https +: +/ +/ +html +. +spec +. +whatwg +. +org +/ +multipage +/ +form +- +control +- +infrastructure +. +html +# +the +- +formdataevent +- +interface +test +( +( +) += +> +{ +let +fd += +new +FormData +( +) +; +let +typeError += +new +TypeError +( +) +; +assert_throws +( +typeError +( +) += +> +{ +new +FormDataEvent +( +) +} +' +0 +arguments +' +) +; +assert_throws +( +typeError +( +) += +> +{ +new +FormDataEvent +( +' +foo +' +) +} +' +1 +argument +' +) +; +assert_throws +( +typeError +( +) += +> +{ +new +FormDataEvent +( +fd +fd +) +} +' +2 +invalid +arguments +' +) +; +assert_throws +( +typeError +( +) += +> +{ +new +FormDataEvent +( +' +foo +' +null +) +} +' +Null +dictionary +' +) +; +assert_throws +( +typeError +( +) += +> +{ +new +FormDataEvent +( +' +foo +' +undefined +) +} +' +Undefined +dictionary +' +) +; +assert_throws +( +typeError +( +) += +> +{ +new +FormDataEvent +( +' +foo +' +{ +formData +: +null +} +) +} +' +Null +formData +' +) +; +assert_throws +( +typeError +( +) += +> +{ +new +FormDataEvent +( +' +foo +' +{ +formData +: +undefined +} +) +} +' +Undefined +formData +' +) +; +assert_throws +( +typeError +( +) += +> +{ +new +FormDataEvent +( +' +foo +' +{ +formData +: +' +bar +' +} +) +} +' +Wrong +type +of +formData +' +) +; +} +' +Failing +FormDataEvent +constructor +' +) +; +test +( +( +) += +> +{ +let +fd += +new +FormData +( +) +; +let +event += +new +FormDataEvent +( +' +bar +' +{ +formData +: +fd +bubbles +: +true +} +) +; +assert_equals +( +event +. +formData +fd +) +; +assert_true +( +event +. +bubbles +) +; +} +' +Successful +FormDataEvent +constructor +' +) +; diff --git a/testing/web-platform/tests/html/semantics/forms/form-submission-0/constructing-form-data-set.html b/testing/web-platform/tests/html/semantics/forms/form-submission-0/constructing-form-data-set.html index 2763c2bdde1d2..270389f7caa66 100644 --- a/testing/web-platform/tests/html/semantics/forms/form-submission-0/constructing-form-data-set.html +++ b/testing/web-platform/tests/html/semantics/forms/form-submission-0/constructing-form-data-set.html @@ -149,6 +149,26 @@ script > < +script +src += +" +. +/ +resources +/ +targetted +- +form +. +js +" +> +< +/ +script +> +< iframe name = @@ -595,6 +615,525 @@ ' ) ; +test +( +( +) += +> +{ +let +didCallHandler += +false +; +let +wasBubbles += +false +; +let +wasCancelable += +true +; +let +form += +populateForm +( +) +; +document +. +addEventListener +( +' +formdata +' +e += +> +{ +didCallHandler += +true +; +wasBubbles += +e +. +bubbles +; +wasCancelable += +e +. +cancelable +; +} +) +; +new +FormData +( +form +) +; +assert_true +( +didCallHandler +) +; +assert_true +( +wasBubbles +) +; +assert_false +( +wasCancelable +) +; +} +' +" +formdata +" +event +bubbles +and +is +not +cancelable +. +' +) +; +test +( +( +) += +> +{ +let +didCallHandler += +false +; +let +form += +populateForm +( +) +; +let +orphanRoot += +document +. +createElement +( +' +div +' +) +; +orphanRoot +. +appendChild +( +form +) +; +orphanRoot +. +addEventListener +( +' +formdata +' +e += +> +{ +didCallHandler += +true +; +} +) +; +new +FormData +( +form +) +; +assert_true +( +didCallHandler +) +; +} +' +" +formdata +" +event +bubbles +in +an +orphan +tree +. +' +) +; +test +( +( +) += +> +{ +let +listener1ok += +false +; +let +listeern2ok += +false +; +let +form += +populateForm +( +' +< +input +name += +n1 +value += +v1 +> +' +) +; +form +. +addEventListener +( +' +formdata +' +e += +> +{ +listener1ok += +e +. +formData +. +get +( +' +n1 +' +) += += +' +v1 +' +; +e +. +formData +. +append +( +' +h1 +' +' +vh1 +' +) +; +e +. +formData +. +append +( +' +h2 +' +' +vh2 +' +) +; +} +) +; +form +. +addEventListener +( +' +formdata +' +e += +> +{ +if +( +e +. +formData +. +get +( +' +h1 +' +) += += +' +vh1 +' +& +& +e +. +formData +. +get +( +' +h2 +' +) += += +' +vh2 +' +) +listener2ok += +true +; +} +) +; +form +. +submit +( +) +; +assert_true +( +listener1ok +) +; +assert_true +( +listener2ok +) +; +} +' +" +formData +" +IDL +attribute +should +have +entries +for +form +- +associated +elements +' ++ +' +in +the +first +event +handler +and +the +second +handler +can +read +entries +' ++ +' +set +by +the +first +handler +. +' +) +; +let +t1 += +async_test +( +' +Entries +added +to +" +formData +" +IDL +attribute +should +be +submitted +. +' +) +; +t1 +. +step +( +( +) += +> +{ +let +form += +populateForm +( +' +< +input +name += +n1 +value += +v1 +> +' +) +; +form +. +addEventListener +( +' +formdata +' +e += +> +{ +e +. +formData +. +append +( +' +h1 +' +' +vh1 +' +) +; +} +) +; +let +iframe += +form +. +previousSibling +; +iframe +. +onload += +t1 +. +step_func_done +( +( +) += +> +{ +assert_true +( +iframe +. +contentWindow +. +location +. +search +. +indexOf +( +' +n1 += +v1 +& +h1 += +vh1 +' +) +! += +- +1 +) +; +} +) +; +form +. +submit +( +) +; +} +) +; < / script 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 new file mode 100644 index 0000000000000..f601c3076d081 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/form-submission-0/form-submission-algorithm.html @@ -0,0 +1,404 @@ +< +! +DOCTYPE +html +> +< +link +rel += +" +help +" +href += +" +https +: +/ +/ +html +. +spec +. +whatwg +. +org +/ +multipage +/ +form +- +control +- +infrastructure +. +html +# +form +- +submission +- +algorithm +" +> +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +script +src += +" +. +/ +resources +/ +targetted +- +form +. +js +" +> +< +/ +script +> +< +body +> +< +script +> +test +( +( +) += +> +{ +let +form += +populateForm +( +' +< +input +name += +n10 +value += +v10 +> +' +) +; +let +counter += +0 +; +form +. +addEventListener +( +' +formdata +' +e += +> +{ ++ ++ +counter +; +form +. +submit +( +) +; +} +) +; +form +. +submit +( +) +; +assert_equals +( +counter +1 +) +; +new +FormData +( +form +) +; +assert_equals +( +counter +2 +) +; +} +' +If +constructing +entry +list +flag +of +form +is +true +then +return +' +) +; +let +test10 += +async_test +( +' +Cannot +navigate +( +after +constructing +the +entry +list +) +' +) +; +test10 +. +step +( +( +) += +> +{ +let +form += +populateForm +( +' +< +input +name += +n1 +value += +v1 +> +' +) +; +form +. +onformdata += +( +e +) += +> +{ +e +. +target +. +remove +( +) +; +} +; +let +wasLoaded += +false +; +let +iframe += +form +. +previousSibling +; +/ +/ +Request +to +load +' +/ +common +/ +dummy +. +xhtml +' +and +immediately +submit +the +form +to +/ +/ +the +same +frame +. +If +the +form +submission +is +aborted +the +first +request +/ +/ +will +be +completed +. +iframe +. +onload += +test10 +. +step_func_done +( +( +) += +> +{ +wasLoaded += +true +; +assert_true +( +iframe +. +contentWindow +. +location +. +search +. +indexOf +( +' +n1 += +v1 +' +) += += +- +1 +) +; +} +) +; +iframe +. +src += +' +/ +common +/ +dummy +. +xhtml +' +; +assert_false +( +wasLoaded +' +Make +sure +the +first +loading +is +ongoing +. +' +) +; +form +. +submit +( +) +; +} +) +; +< +/ +script +> +< +/ +body +> 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 new file mode 100644 index 0000000000000..f53df0e4c0548 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/form-submission-0/resources/targetted-form.js @@ -0,0 +1,101 @@ +let +frameCounter += +0 +; +function +populateForm +( +optionalContentHtml +) +{ +if +( +! +optionalContentHtml +) +optionalContentHtml += +' +' +; +document +. +body +. +insertAdjacentHTML +( +' +afterbegin +' +< +iframe +name += +" +form +- +test +- +target +- +{ +frameCounter +} +" +> +< +/ +iframe +> ++ +< +form +action += +" +/ +common +/ +blank +. +html +" +target += +" ++ +form +- +test +- +target +- +{ +frameCounter +} +" +> +{ +optionalContentHtml +} +< +/ +form +> +) +; ++ ++ +frameCounter +; +return +document +. +body +. +firstChild +. +nextSibling +; +} diff --git a/testing/web-platform/tests/interfaces/html.idl b/testing/web-platform/tests/interfaces/html.idl index 8cdba9b3d635f..92dec584ad731 100644 --- a/testing/web-platform/tests/interfaces/html.idl +++ b/testing/web-platform/tests/interfaces/html.idl @@ -5305,6 +5305,42 @@ valid Exposed = Window +Constructor +( +DOMString +type +optional +FormDataEventInit +eventInitDict +) +] +interface +FormDataEvent +: +Event +{ +readonly +attribute +FormData +formData +; +} +; +dictionary +FormDataEventInit +: +EventInit +{ +required +FormData +formData +; +} +; +[ +Exposed += +Window HTMLConstructor ] interface @@ -8981,6 +9017,10 @@ onfocus ; attribute EventHandler +onformdata +; +attribute +EventHandler oninput ; attribute diff --git a/testing/web-platform/tests/xhr/formdata.htm b/testing/web-platform/tests/xhr/formdata.htm index 6ac2beccacc77..0089e780c4f28 100644 --- a/testing/web-platform/tests/xhr/formdata.htm +++ b/testing/web-platform/tests/xhr/formdata.htm @@ -65,6 +65,37 @@ script > < +script +src += +" +/ +html +/ +semantics +/ +forms +/ +form +- +submission +- +0 +/ +resources +/ +targetted +- +form +. +js +" +> +< +/ +script +> +< link rel = @@ -280,6 +311,49 @@ / > < +link +rel += +" +help +" +href += +" +https +: +/ +/ +html +. +spec +. +whatwg +. +org +/ +multipage +/ +form +- +control +- +infrastructure +. +html +# +constructing +- +the +- +form +- +data +- +set +" +> +< div id = @@ -655,6 +729,268 @@ ' ) ; +test +( +( +) += +> +{ +let +form += +populateForm +( +' +< +input +name += +n1 +value += +v1 +> +' +) +; +let +formDataInEvent += +null +; +form +. +addEventListener +( +' +formdata +' +e += +> +{ +e +. +formData +. +append +( +' +h1 +' +' +vh1 +' +) +; +formDataInEvent += +e +. +formData +; +} +) +; +let +formData += +new +FormData +( +form +) +; +assert_equals +( +formData +. +get +( +' +h1 +' +) +' +vh1 +' +) +; +assert_equals +( +formData +. +get +( +' +n1 +' +) +' +v1 +' +) +; +assert_not_equals +( +formData +formDataInEvent +' +" +formData +" +attribute +should +be +different +from +the +' ++ +' +FromData +object +created +by +" +new +" +' +) +; +} +' +Newly +created +FormData +contains +entries +added +to +" +formData +" +IDL +' ++ +' +attribute +of +FormDataEvent +. +' +) +; +test +( +( +) += +> +{ +let +form += +populateForm +( +' +< +input +name += +n11 +value += +v11 +> +' +) +; +let +counter += +0 +; +form +. +addEventListener +( +' +formdata +' +e += +> +{ ++ ++ +counter +; +assert_throws +( +' +InvalidStateError +' +( +) += +> +{ +new +FormData +( +e +. +target +) +} +) +; +} +) +; +new +FormData +( +form +) +; +assert_equals +( +counter +1 +) +; +form +. +submit +( +) +; +assert_equals +( +counter +2 +) +; +} +' +| +new +FormData +( +) +| +in +formdata +event +handler +should +throw +' +) +; < / script