diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/reporting/tests/iframe_delivering.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/reporting/tests/iframe_delivering.html')
-rw-r--r-- | dom/reporting/tests/iframe_delivering.html | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/dom/reporting/tests/iframe_delivering.html b/dom/reporting/tests/iframe_delivering.html new file mode 100644 index 0000000000..e8c5e9e3a4 --- /dev/null +++ b/dom/reporting/tests/iframe_delivering.html @@ -0,0 +1,92 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test for delivering reports</title> +</head> +<body> + +<script type="application/javascript"> + +function ok(a, msg) { + parent.postMessage({type: "test", check: !!a, msg }, "*"); +} + +function is(a, b, msg) { + ok(a === b, msg); +} + +function finish() { + parent.postMessage({type: "finish" }, "*"); +} + +function checkReport() { + return new Promise(resolve => { + let id = setInterval(_ => { + fetch("delivering.sjs?task=check&min=3") + .then(r => r.text()) + .then(text => { + if (text) { + resolve(JSON.parse(text)); + clearInterval(id); + } + }); + }, 1000); + }); +} + +function runTests(extraParams = "") { + // Call a deprecating operation. + for (let i = 0; i < 100; ++i) { + new TestingDeprecatedInterface(); + } + ok(true, "Created a deprecated interface"); + + // Check if the report has been received. + return checkReport() + .then(reports => { + is(reports.length, 3, "We have 1 report"); + + let report = reports[0]; + is(report.contentType, "application/reports+json", "Correct mime-type"); + is(report.origin, "https://example.org", "Origin correctly set"); + is(report.url, "https://example.org/tests/dom/reporting/tests/delivering.sjs" + extraParams, "URL is correctly set"); + ok(!!report.body, "We have a report.body"); + ok(report.body.age > 0, "Age is correctly set"); + is(report.body.url, window.location.href, "URL is correctly set"); + is(report.body.user_agent, navigator.userAgent, "User-agent matches"); + ok(report.body.type, "deprecation", "Type is fine."); + ok(!!report.body.body, "We have the real report.body"); + is(report.body.body.id, "DeprecatedTestingInterface", "Correct report.body.id"); + is(report.body.body.message, "TestingDeprecatedInterface is a testing-only interface and this is its testing deprecation message.", "We have a report.body.message"); + is(report.body.body.sourceFile, "https://example.org/tests/dom/reporting/tests/iframe_delivering.html", "report.body.sourceFile"); + is(report.body.body.lineNumber, 40, "report.body.lineNumber"); + is(report.body.body.columnNumber, 5, "report.body.columnNumber"); + }); +} + +// Let's register a group + endpoint +fetch("delivering.sjs?task=header") +.then(r => r.text()) +.then(text => { + is(text, "OK", "Report-to header sent"); +}) +.then(_ => { + return runTests(); +}) + +// Let's register a group + endpoint from a worker +.then(_ => { + return new Promise(resolve => { + let w = new Worker("worker_delivering.js"); + w.onmessage = e => resolve(); + }); +}) +.then(_ => { + return runTests("&worker=true"); +}) + +.then(finish); + +</script> +</body> +</html> |