Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test input element directionality is only submitted for text and search type #39664

Merged
merged 7 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,19 @@
<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="dirname-ltr-iframe.html" method=get target="iframe">
<form action="resources/dirname-iframe.html" method=get target="iframe">
<p><label>Comment: <input type=text name="comment" dirname="comment.dir" required></label></p>
<p><button type=submit>Post Comment</button></p>
</form>
<iframe name="iframe"></iframe>
<script>
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(document.querySelector("iframe").contentWindow.location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var t = async_test("submit element directionality");
document.querySelector("input").value = "foobar";
document.querySelector("button").click();

var iframe = document.querySelector("iframe");
iframe.onload = t.step_func(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; }

assert_equals(getParameterByName("comment.dir"), "ltr");

t.done();
onIframeLoadedDone(t, function(params) {
assert_equals(params.get("comment.dir"), "ltr");
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<!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><button id="btn-submit" type=submit>Submit</button></p>
</form>
<iframe name="iframe"></iframe>

<script>
const types_applies = ["text", "search"];
const types_not = [
"hidden", "tel", "url", "email", "password", "date", "month", "week", "time",
"datetime-local", "number", "range", "color", "checkbox", "radio", "file", "submit",
"image", "reset", "button"
];
const types = [...types_applies, ...types_not];
let form = document.querySelector("form");
for (const type of types) {
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 data = new FormData(form);
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.");

document.getElementById("btn-submit").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>
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,20 @@
<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="dirname-ltr-iframe.html" method=get target="iframe">
<form action="resources/dirname-iframe.html" method=get target="iframe">
<p><label>Comment: <input type=text name="comment" dir="auto" dirname="comment.dir" required/></label></p>
<p><button type=submit>Post Comment</button></p>
</form>
<iframe name="iframe"></iframe>
<script>
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(document.querySelector("iframe").contentWindow.location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var t = async_test("submit element directionality");
var rtlValue = "مرحبا";
document.querySelector("input").value = rtlValue;
document.querySelector("button").click();

var iframe = document.querySelector("iframe");
iframe.onload = t.step_func(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; }

assert_equals(getParameterByName("comment.dir"), "rtl");

t.done();
onIframeLoadedDone(t, function(params) {
assert_equals(params.get("comment.dir"), "rtl");
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,21 @@
<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="dirname-ltr-iframe.html" method=get target="iframe">
<form action="resources/dirname-iframe.html" method=get target="iframe">
<p><label>Comment: <input type=text name="comment" dirname="comment.dir" required/></label></p>
<p><button type=submit>Post Comment</button></p>
</form>
</div>
<iframe name="iframe"></iframe>
<script>
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(document.querySelector("iframe").contentWindow.location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var t = async_test("submit element directionality");
document.querySelector("input").value = "foobar";
document.querySelector("button").click();

var iframe = document.querySelector("iframe");
iframe.onload = t.step_func(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; }

assert_equals(getParameterByName("comment.dir"), "rtl");

t.done();
onIframeLoadedDone(t, function(params) {
assert_equals(params.get("comment.dir"), "rtl");
});
</script>
Original file line number Diff line number Diff line change
@@ -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();
});
}