summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_bug1472426.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/html/test/test_bug1472426.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/html/test/test_bug1472426.html')
-rw-r--r--dom/html/test/test_bug1472426.html120
1 files changed, 120 insertions, 0 deletions
diff --git a/dom/html/test/test_bug1472426.html b/dom/html/test/test_bug1472426.html
new file mode 100644
index 0000000000..6f891184b8
--- /dev/null
+++ b/dom/html/test/test_bug1472426.html
@@ -0,0 +1,120 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1472426
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1472426</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script type="application/javascript">
+
+ /** Test for Bug 1472426 **/
+
+ var shadowIframe;
+ var targetIframe;
+ var form;
+ var sr;
+
+ function checkMPSubmission(sub, expected, test) {
+ function getPropCount(o) {
+ var x, l = 0;
+ for (x in o) ++l;
+ return l;
+ }
+ function mpquote(s) {
+ return s.replace(/\r\n/g, " ")
+ .replace(/\r/g, " ")
+ .replace(/\n/g, " ")
+ .replace(/\"/g, "\\\"");
+ }
+
+ is(sub.length, expected.length,
+ "Correct number of multipart items in " + test);
+
+ if (sub.length != expected.length) {
+ alert(JSON.stringify(sub));
+ }
+
+ var i;
+ for (i = 0; i < expected.length; ++i) {
+ if (!("fileName" in expected[i])) {
+ is(sub[i].headers["Content-Disposition"],
+ "form-data; name=\"" + mpquote(expected[i].name) + "\"",
+ "Correct name in " + test);
+ is (getPropCount(sub[i].headers), 1,
+ "Wrong number of headers in " + test);
+ is(sub[i].body,
+ expected[i].value.replace(/\r\n|\r|\n/, "\r\n"),
+ "Correct value in " + test);
+ }
+ else {
+ is(sub[i].headers["Content-Disposition"],
+ "form-data; name=\"" + mpquote(expected[i].name) + "\"; filename=\"" +
+ mpquote(expected[i].fileName) + "\"",
+ "Correct name in " + test);
+ is(sub[i].headers["Content-Type"],
+ expected[i].contentType,
+ "Correct content type in " + test);
+ is (getPropCount(sub[i].headers), 2,
+ "Wrong number of headers in " + test);
+ is(sub[i].body,
+ expected[i].value,
+ "Correct value in " + test);
+ }
+ }
+ }
+
+ function testFormSubmissionInShadowDOM() {
+ targetIframe = document.getElementById("target_iframe");
+ shadowIframe = document.createElement("iframe");
+ shadowIframe.src = "about:blank";
+ shadowIframe.onload = shadowFrameCreated;
+ document.body.appendChild(shadowIframe);
+ }
+
+ function shadowFrameCreated() {
+ var doc = shadowIframe.contentDocument;
+ var body = doc.body;
+ var host = doc.createElement("div");
+ body.appendChild(host);
+ sr = host.attachShadow({ mode: "open" });
+ sr.appendChild(document.getElementById('template').content.cloneNode(true));
+ targetIframe.onload = checkSubmitValues;
+ sr.getElementById("form").submit();
+ }
+
+ function checkSubmitValues() {
+ submission = JSON.parse(targetIframe.contentDocument.documentElement.textContent);
+ var expected = [
+ { name: "text", value: "textvalue" },
+ { name: "hidden", value: "hiddenvalue" },
+ { name: "select", value: "selectvalue" },
+ { name: "textarea", value: "textareavalue" }
+ ];
+ checkMPSubmission(submission, expected, "form submission inside shadow DOM");
+ SimpleTest.finish();
+ }
+
+ window.onload = function() {
+ SimpleTest.waitForExplicitFinish();
+ testFormSubmissionInShadowDOM();
+ }
+
+ </script>
+ <template id="template">
+ <form action="form_submit_server.sjs" target="target_iframe" id="form"
+ method="POST" enctype="multipart/form-data">
+ <input name="text" value="textvalue">
+ <input name="hidden" value="hiddenvalue" type="hidden">
+ <select name="select"><option selected>selectvalue</option></select>
+ <textarea name="textarea">textareavalue</textarea>
+ </form>
+ </template>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1472426">Mozilla Bug 1472426</a>
+<iframe name="target_iframe" id="target_iframe"></iframe>
+</body>
+</html>