Bug 1645781 - Part 1: Test that form submit works with fission. r=baku

Differential Revision: https://phabricator.services.mozilla.com/D79672
This commit is contained in:
Andreas Farre 2020-07-01 14:26:01 +00:00
Родитель c6ae17ea64
Коммит e2a874acc0
3 изменённых файлов: 133 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,40 @@
"use strict";
Cu.import("resource://gre/modules/Timer.jsm");
const CC = Components.Constructor;
const BinaryInputStream = CC(
"@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream"
);
const BinaryOutputStream = CC(
"@mozilla.org/binaryoutputstream;1",
"nsIBinaryOutputStream",
"setOutputStream"
);
function log(str) {
// dump(`LOG: ${str}\n`);
}
async function handleRequest(request, response) {
if (request.method !== "POST") {
message = "bad";
} else {
log("Reading request")
let available = 0;
let inputStream = new BinaryInputStream(request.bodyInputStream);
while ((available = inputStream.available()) > 0) {
log(inputStream.readBytes(available));
}
}
log("Setting Headers")
response.setHeader("Content-Type", "text/html", false);
response.setStatusLine(request.httpVersion, "200", "OK");
log("Writing body");
response.write('<script>"use strict"; let target = opener ? opener : parent; target.postMessage("done", "*");</script>');
log("Done")
}

Просмотреть файл

@ -49,6 +49,7 @@ support-files =
file_compressed_multipart^headers^
file_pushState_after_document_open.html
historyframes.html
ping.html
start_historyframe.html
url1_historyframe.html
url2_historyframe.html
@ -119,9 +120,11 @@ support-files = file_framedhistoryframes.html
[test_windowedhistoryframes.html]
[test_triggeringprincipal_location_seturi.html]
[test_bug1507702.html]
[test_bug1645781.html]
support-files =
form_submit.sjs
[test_double_submit.html]
skip-if = fission
support-files =
clicker.html
ping.html
double_submit.sjs

Просмотреть файл

@ -0,0 +1,89 @@
<!doctype html>
<html>
<head>
<title>Test for Bug 1590762</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<form id="form" action="form_submit.sjs" method="POST" target="targetFrame">
<input id="input" type="text" name="name" value="">
<input id="button" type="submit">
</form>
<script>
"use strict";
const PATH = "/tests/docshell/test/mochitest/";
const SAME_ORIGIN = new URL(PATH, window.location.origin);;
const CROSS_ORIGIN_1 = new URL(PATH, "http://test1.example.com/");
const CROSS_ORIGIN_2 = new URL(PATH, "https://example.com/");
const TARGET = "ping.html";
const ACTION = "form_submit.sjs";
function generateBody(size) {
let data = new Uint8Array(size);
for (let i = 0; i < size; ++i) {
data[i] = 97 + Math.random() * (123 - 97);
}
return new TextDecoder().decode(data);
}
async function withFrame(url) {
info("Creating frame");
let frame = document.createElement('iframe');
frame.name = "targetFrame";
return new Promise(resolve => {
addEventListener('message', async function({source}) {
info("Frame loaded");
if (frame.contentWindow == source) {
resolve(frame);
}
}, { once: true });
frame.src = url;
document.body.appendChild(frame);
});
}
function click() {
synthesizeMouse(document.getElementById('button'), 5, 5, {});
}
function* spec() {
let urls = [SAME_ORIGIN, CROSS_ORIGIN_1, CROSS_ORIGIN_2];
for (let action of urls) {
for (let target of urls) {
yield { action: new URL(ACTION, action),
target: new URL(TARGET, target) };
}
}
}
info("Starting tests");
let form = document.getElementById('form');
// The body of the POST needs to be large to trigger this.
// 1024*1024 seems to be enough, but scaling to get a margin.
document.getElementById('input').value = generateBody(1024*1024);
for (let { target, action } of spec()) {
add_task(async function runTest() {
info(`Running test ${target} with ${action}`);
form.action = action;
let frame = await withFrame(target);
await new Promise(resolve => {
addEventListener('message', async function() {
info("Form loaded");
frame.remove();
resolve();
}, { once: true });
click();
});
ok(true, `Submitted to ${origin} with target ${action}`)
});
};
</script>
</body>
</html>