summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-only-if-applies.html
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-only-if-applies.html')
-rw-r--r--testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/dirname-only-if-applies.html80
1 files changed, 80 insertions, 0 deletions
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>