diff options
Diffstat (limited to 'testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls')
10 files changed, 437 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-ltr.html b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-ltr.html new file mode 100644 index 0000000000..7bb7aae3b9 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-ltr.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Submitting element directionality: the dirname attribute</title> +<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> +<link rel=help href="https://html.spec.whatwg.org/multipage/#submitting-element-directionality:-the-dirname-attribute"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/dirname.js"></script> +<div id="log"></div> +<form action="resources/dirname-iframe.html" method=get target="iframe"> + <p><label>User: <input type=text name="user" dirname="user.dir" required></label></p> + <p><label>Comment: <textarea name="comment" dirname="comment.dir" required></textarea></label></p> + <p><button type=submit>Post Comment</button></p> +</form> +<iframe name="iframe"></iframe> +<script> + document.querySelector("input").value = "foobar"; + document.querySelector("textarea").value = "foobar"; + document.querySelector("button").click(); + + var t_inp = async_test("submit input element directionality"); + onIframeLoadedDone(t_inp, function(params) { + assert_equals(params.get("user.dir"), "ltr"); + }); + + var t_ta = async_test("submit textarea element directionality"); + onIframeLoadedDone(t_ta, function(params) { + assert_equals(params.get("comment.dir"), "ltr"); + }); +</script> diff --git a/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-only-if-applies.html b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-only-if-applies.html new file mode 100644 index 0000000000..8af6826fa1 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-only-if-applies.html @@ -0,0 +1,80 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset=utf-8> + <title>Submitting element directionality: the dirname attribute</title> + <link rel="author" title="Vincent Hilla" href="mailto:vhilla@mozilla.com"> + <link rel=help href="https://html.spec.whatwg.org/multipage/#submitting-element-directionality:-the-dirname-attribute"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="resources/dirname.js"></script> + </head> + <body> + <div id="log"></div> + <form action="resources/dirname-iframe.html" method=get target="iframe"> + <textarea name="textarea" dirname="textarea.dir"></textarea> + <p><input id="btn-submit" type=submit name=submit dirname=submit.dir value=Submit></p> + </form> + <iframe name="iframe"></iframe> + + <script> + const types_applies = [ + "hidden", "text", "search", "tel", "url", "email", "password", "submit" + ]; + const types_not = [ + "date", "month", "week", "time", "datetime-local", "number", "range", "color", "checkbox", + "radio", "file", "image", "reset", "button" + ]; + const types = [...types_applies, ...types_not]; + let form = document.querySelector("form"); + for (const type of types) { + if (type === "submit") { + continue; + } + let p = document.createElement("p"); + let lbl = document.createElement("label"); + let txt = document.createTextNode(type + ": "); + let inp = document.createElement("input"); + inp.type = type; + inp.name = type; + inp.dirName = type + ".dir"; + inp.id = "testelement." + type + lbl.appendChild(txt); + lbl.appendChild(inp); + p.appendChild(lbl); + form.appendChild(p); + } + // Avoid continue in https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set:attr-fe-dirname + document.getElementById("testelement.checkbox").checked = true; + document.getElementById("testelement.radio").checked = true; + + function assertInputSubmission(data) { + for (const type of types_applies) { + assert_equals(data.get(type + ".dir"), "ltr", "Submit ltr for input type=" + type); + } + for (const type of types_not) { + assert_false(data.has(type + ".dir"), "Do not submit dir for input type=" + type); + } + } + + const submitter = document.getElementById("btn-submit"); + const data = new FormData(form, submitter); + test(function() { + assertInputSubmission(data); + }, "Submit input element directionality to FormData, if dirname applies."); + test(function() { + assert_equals(data.get("textarea.dir"), "ltr", "Submit ltr for textarea"); + }, "Submit textarea element directionality to FormData."); + + submitter.click(); + const t_inp = async_test("Submit input element directionality, if dirname applies."); + onIframeLoadedDone(t_inp, function(params) { + assertInputSubmission(params); + }); + const t_ta = async_test("Submit textarea element directionality."); + onIframeLoadedDone(t_ta, function(params) { + assert_equals(params.get("textarea.dir"), "ltr", "Submit ltr for textarea"); + }); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-rtl-auto.html b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-rtl-auto.html new file mode 100644 index 0000000000..02aeb79176 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-rtl-auto.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Submitting element directionality: the dirname attribute</title> +<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> +<link rel=help href="https://html.spec.whatwg.org/multipage/#submitting-element-directionality:-the-dirname-attribute"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/dirname.js"></script> +<div id="log"></div> +<form action="resources/dirname-iframe.html" method=get target="iframe"> + <p><label>User: <input type=text name="user" dir="auto" dirname="user.dir" required/></label></p> + <p><label>Comment: <textarea name="comment" dir="auto" dirname="comment.dir" required></textarea></label></p> + <p><button type=submit>Post Comment</button></p> +</form> +<iframe name="iframe"></iframe> +<script> + var rtlValue = "مرحبا"; + document.querySelector("input").value = rtlValue; + document.querySelector("textarea").value = rtlValue; + document.querySelector("button").click(); + + var t_inp = async_test("submit input element directionality"); + onIframeLoadedDone(t_inp, function(params) { + assert_equals(params.get("user.dir"), "rtl"); + }); + + var t_ta = async_test("submit textarea element directionality"); + onIframeLoadedDone(t_ta, function(params) { + assert_equals(params.get("comment.dir"), "rtl"); + }); +</script> diff --git a/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-rtl-inherited.html b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-rtl-inherited.html new file mode 100644 index 0000000000..0c5331f0ac --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-rtl-inherited.html @@ -0,0 +1,32 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Submitting element directionality: the dirname attribute</title> +<link rel="author" title="Kolupaev Dmitry" href="mailto:dmitry.klpv@gmail.com"> +<link rel=help href="https://html.spec.whatwg.org/multipage/#submitting-element-directionality:-the-dirname-attribute"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/dirname.js"></script> +<div id="log"></div> +<div dir="rtl"> + <form action="resources/dirname-iframe.html" method=get target="iframe"> + <p><label>User: <input type=text name="user" dirname="user.dir" required/></label></p> + <p><label>Comment: <textarea name="comment" dirname="comment.dir" required></textarea></label></p> + <p><button type=submit>Post Comment</button></p> + </form> +</div> +<iframe name="iframe"></iframe> +<script> + document.querySelector("input").value = "foobar"; + document.querySelector("textarea").value = "foobar"; + document.querySelector("button").click(); + + var t_inp = async_test("submit input element directionality"); + onIframeLoadedDone(t_inp, function(params) { + assert_equals(params.get("user.dir"), "rtl"); + }); + + var t_ta = async_test("submit textarea element directionality"); + onIframeLoadedDone(t_ta, function(params) { + assert_equals(params.get("comment.dir"), "rtl"); + }); +</script> diff --git a/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-rtl-manual.html b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-rtl-manual.html new file mode 100644 index 0000000000..c5f683101d --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-rtl-manual.html @@ -0,0 +1,29 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Submitting element directionality: the dirname attribute (rtl)</title> +<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> +<link rel=help href="https://html.spec.whatwg.org/multipage/#submitting-element-directionality:-the-dirname-attribute"> +<form action="dirname-rtl-manual.html" method=get> + <p><label>User: <input type=text name="user" dirname="user.dir" required></label></p> + <p><label>Comment: <textarea name="comment" dirname="comment.dir" required></textarea></label></p> + <p><button type=submit>Post Comment</button></p> +</form> +<p>Switch to a right-to-left writing direction, enter a text in the input and textarea, and submit the form.</p> +<p>Test passes if the word "PASS" appears below</p> +<script> + function getParameterByName(name) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), + results = regex.exec(location.search); + return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); + } + + var userDir = getParameterByName("user.dir"); + var commentDir = getParameterByName("comment.dir"); + if (commentDir && userDir) { + var p = document.createElement("p"); + var success = (commentDir == "rtl" && userDir == "rtl") + p.textContent = success ? "PASS" : "FAIL"; + document.body.appendChild(p); + } +</script> diff --git a/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/disabled-elements-01.html b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/disabled-elements-01.html new file mode 100644 index 0000000000..14443e4099 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/disabled-elements-01.html @@ -0,0 +1,84 @@ +<!DOCTYPE html> +<title>HTMLFormElement: the disabled attribute</title> +<link rel="author" title="Eric Casler" href="mailto:ericorange@gmail.com"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#enabling-and-disabling-form-controls:-the-disabled-attribute"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id="log"></div> +<div id="root"></div> +<script> +// Elements tested for in this file +var types = ["button", "input", "select", "textarea"]; +// no tests for: optgroup, option, fieldset + +var root = document.getElementById("root"); +for (var element_type = 0; element_type < types.length; element_type++) { + test(function() { + root.innerHTML = "<"+types[element_type]+" + id='elem'></"+types[element_type]+">"; + + var elem = document.getElementById("elem"); + assert_false(elem.disabled); + }, + "Test ["+types[element_type]+"]: default behaviour is NOT disabled"); + + test(function() { + var formats = ["disabled", + "disabled=disabled", "disabled='disabled'", + "disabled='true'", "disabled=true", + "disabled='false'", "disabled=false"]; + + for (var f = 0; f < formats.length; f++) { + root.innerHTML = "<"+types[element_type]+" id='elem' " + formats[f] + "></"+types[element_type]+">"; + + var elem = document.getElementById("elem"); + assert_true(elem.disabled); + } + }, + "Test ["+types[element_type]+"]: verify disabled acts as boolean attribute"); + + test(function() { + root.innerHTML = "<"+types[element_type]+" id='elem'></"+types[element_type]+"><input id='other' value='no event dispatched'></input>"; + var elem = document.getElementById("elem"), + other = document.getElementById("other"); + + assert_equals(other.value, "no event dispatched"); + + elem.disabled = true; + assert_true(elem.disabled); + + elem.onclick = function () { + // change value of other element, to avoid *.value returning "" for disabled elements + document.getElementById("other").value = "event dispatched"; + }; + + // Check if dispatched event executes + var evObj = document.createEvent('Events'); + evObj.initEvent("click", true, false); + elem.dispatchEvent(evObj); + assert_equals(other.value, "event dispatched"); + }, + "Test ["+types[element_type]+"]: synthetic click events should be dispatched"); + + test(function() { + root.innerHTML = "<"+types[element_type]+" id='elem'></"+types[element_type]+"><input id='other' value='no event dispatched'></input>"; + var elem = document.getElementById("elem"), + other = document.getElementById("other"); + + assert_equals(other.value, "no event dispatched"); + + elem.disabled = true; + assert_true(elem.disabled); + + elem.onclick = function () { + // change value of other element, to avoid *.value returning "" for disabled elements + document.getElementById("other").value = "event dispatched"; + }; + + // Check that click() on a disabled element doesn't dispatch a click event. + elem.click(); + assert_equals(other.value, "no event dispatched"); + }, + "Test ["+types[element_type]+"]: click() should not dispatch a click event"); +} +root.innerHTML = ""; +</script> diff --git a/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html new file mode 100644 index 0000000000..4510807c2c --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html @@ -0,0 +1,93 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <title>HTML Test: formAction_document_address</title> + <link rel="author" title="Intel" href="http://www.intel.com/"> + <link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-fs-formaction"> + <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-document's-address"> + <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-button-element"> + <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-input-element"> + <meta name="assert" content="On getting the formAction IDL attribute, when the content attribute is missing or its value is the empty string, the document's address must be returned instead."> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <div id="log"></div> + + <div id="missing" style="display:none"> + <button type="submit">Submit</button> + <input type="submit"> + </div> + + <div id="empty_string" style="display:none"> + <button type="submit" formaction="">Submit</button> + <input type="submit" formaction=""> + </div> + + <div id="no_assigned_value" style="display:none"> + <button type="submit" formaction>Submit</button> + <input type="submit" formaction> + </div> + + <script> + // formaction content attribute is missing + test(function() { + var formAction = document.querySelector('#missing button').formAction; + var address = document.location.href; + assert_equals(formAction, address); + }, "Check if button.formAction is the document's address when formaction content attribute is missing"); + + test(function() { + var formAction = document.querySelector('#missing input').formAction; + var address = document.location.href; + assert_equals(formAction, address); + }, "Check if input.formAction is the document's address when formaction content attribute is missing"); + + // formaction content attribute value is empty string + test(function() { + var formAction = document.querySelector('#empty_string button').formAction; + var address = document.location.href; + assert_equals(formAction, address); + }, "Check if button.formAction is the document's address when formaction content attribute value is empty string"); + + test(function() { + var formAction = document.querySelector('#empty_string input').formAction; + var address = document.location.href; + assert_equals(formAction, address); + }, "Check if input.formAction is the document's address when formaction content attribute value is empty string"); + + // formaction content attribute value is not assigned, just for comparison with empty string above + test(function() { + var formAction = document.querySelector('#no_assigned_value button').formAction; + var address = document.location.href; + assert_equals(formAction, address); + }, "Check if button.formAction is the document's address when formaction content attribute value is not assigned"); + + test(function() { + var formAction = document.querySelector('#no_assigned_value input').formAction; + var address = document.location.href; + assert_equals(formAction, address); + }, "Check if input.formAction is the document's address when formaction content attribute value is not assigned"); + + var newUrl = location.href.replace(/\/[^\/]*$/,'\/dummy.html'); + history.pushState('','','dummy.html'); + + test(function() { + assert_equals(document.location.href, newUrl); + + var formAction = document.querySelector('#missing button').formAction; + var address = document.location.href; + assert_equals(formAction, address); + }, "Check if button.formAction is the document's new address when formaction content attribute is missing and pushState has been used"); + + test(function() { + assert_equals(document.location.href, newUrl); + + var formAction = document.querySelector('#missing input').formAction; + var address = document.location.href; + assert_equals(formAction, address); + }, "Check if input.formAction is the document's new address when formaction content attribute is missing and pushState has been used"); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/formaction.html b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/formaction.html new file mode 100644 index 0000000000..82798eaa84 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/formaction.html @@ -0,0 +1,42 @@ +<!DOCTYPE html> +<html><head> + <title>formaction on button element</title> + <meta content="text/html; charset=UTF-8" http-equiv="content-type"> + <meta content="formaction on button element" name="description"> + <link href="https://html.spec.whatwg.org/multipage/#dom-fs-formaction" rel="help"> +</head> + <body> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + + <div id="log"></div> + <button formaction="http://www.example.com/" style="display: none" type="submit">Submit</button> + <input formaction="http://www.example.com/" style="display: none" type="submit" value="submit"> + <input style="display: none" type="submit" value="submit"> + <input formaction="" style="display: none" type="submit" value="submit"> + + <script type="text/javascript"> + function relativeToAbsolute(relativeURL) { + var a = document.createElement('a'); + a.href = relativeURL; + return a.href; + } + test(function() {assert_equals(document.getElementsByTagName("button")[0].formAction, "http://www.example.com/")}, "formAction on button support"); + test(function() {assert_equals(document.getElementsByTagName("input")[0].formAction, "http://www.example.com/")}, "formAction on input support"); + + var testElem = document.getElementsByTagName("input")[0]; + testElem.formAction = "http://www.example.com/page2.html"; + + test(function() {assert_equals(document.getElementsByTagName("input")[0].formAction, "http://www.example.com/page2.html")}, "formaction absolute URL value on input reflects correct value after being updated by the DOM"); + test(function() {assert_equals(document.getElementsByTagName("input")[0].getAttribute("formaction"), "http://www.example.com/page2.html")}, "formAction absolute URL value is correct using getAttribute"); + + var testElem = document.getElementsByTagName("input")[0]; + testElem.formAction = "../page3.html"; + + test(function() {assert_equals(document.getElementsByTagName("input")[0].formAction, relativeToAbsolute('../page3.html'))}, "formAction relative URL value on input reflects correct value after being updated by the DOM"); + test(function() {assert_equals(document.getElementsByTagName("input")[0].getAttribute("formaction"), "../page3.html")}, "formAction relative URL value is correct using getAttribute"); + + test(function() {assert_equals(document.getElementsByTagName("input")[1].formAction, document.URL)}, "On getting, when formaction is missing, the document's address must be returned"); + test(function() {assert_equals(document.getElementsByTagName("input")[2].formAction, document.URL)}, "On getting, when formaction value is the empty string, the document's address must be returned"); + </script> +</body></html> diff --git a/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/resources/dirname-iframe.html b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/resources/dirname-iframe.html new file mode 100644 index 0000000000..b5ed7e3d9a --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/resources/dirname-iframe.html @@ -0,0 +1,4 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Submitting element directionality: the dirname attribute support</title> +<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> diff --git a/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/resources/dirname.js b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/resources/dirname.js new file mode 100644 index 0000000000..f0e97bc301 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/resources/dirname.js @@ -0,0 +1,12 @@ +function onIframeLoadedDone(t, cb, selector="iframe") { + const iframe = document.querySelector(selector); + iframe.addEventListener("load", function() { + // The initial about:blank load event can be fired before the form navigation occurs. + // See https://github.com/whatwg/html/issues/490 for more information. + if(iframe.contentWindow.location.href == "about:blank") { return; } + + const params = new URLSearchParams(iframe.contentWindow.location.search); + t.step(() => cb(params)) + t.done(); + }); +} |