зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1508310 - Implement Report-to header support - part 10 - delivering tests, r=smaug
This commit is contained in:
Родитель
3adbdc9ee7
Коммит
500de750aa
|
@ -0,0 +1,73 @@
|
|||
<!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")
|
||||
.then(r => r.text())
|
||||
.then(text => {
|
||||
if (text) {
|
||||
resolve(JSON.parse(text));
|
||||
clearInterval(id);
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
// Let's register a group + endpoint
|
||||
fetch("delivering.sjs?task=header")
|
||||
.then(r => r.text())
|
||||
.then(text => {
|
||||
is(text, "OK", "Report-to header sent");
|
||||
})
|
||||
|
||||
// Call a deprecating operation.
|
||||
.then(_ => {
|
||||
let testingInterface = new TestingDeprecatedInterface();
|
||||
ok(true, "Created a deprecated interface");
|
||||
})
|
||||
|
||||
// Check if the report has been received.
|
||||
.then(_ => {
|
||||
return checkReport();
|
||||
})
|
||||
.then(report => {
|
||||
is(report.contentType, "application/reports+json", "Correct mime-type");
|
||||
is(report.origin, "https://example.org", "Origin correctly set");
|
||||
ok(!!report.body, "We have a report.body");
|
||||
ok(report.body.age > 0, "Age 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, 46, "report.body.lineNumber");
|
||||
is(report.body.body.columnNumber, 25, "report.body.columnNumber");
|
||||
})
|
||||
|
||||
.then(finish);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,7 +1,10 @@
|
|||
[DEFAULT]
|
||||
prefs =
|
||||
dom.reporting.enabled=true
|
||||
dom.reporting.header.enabled=true
|
||||
dom.reporting.testing.enabled=true
|
||||
|
||||
[test_deprecated.html]
|
||||
[test_memoryPressure.html]
|
||||
[test_delivering.html]
|
||||
support-files = delivering.sjs iframe_delivering.html
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for delivering reports</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="application/javascript">
|
||||
|
||||
// Setting prefs.
|
||||
SpecialPowers.pushPrefEnv({ set: [
|
||||
["dom_reporting_delivering_timeout", 1],
|
||||
["dom_reporting_delivering_maxFailures", 2],
|
||||
]})
|
||||
|
||||
// Tests run in iframes because the origin must be secure for report-to header.
|
||||
.then(_ => {
|
||||
window.addEventListener("message", e => {
|
||||
if (e.data.type == "finish") {
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.data.type == "test") {
|
||||
ok(e.data.check, e.data.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
ok(false, "Invalid message");
|
||||
});
|
||||
|
||||
let ifr = document.createElement("iframe");
|
||||
ifr.src = "https://example.org/tests/dom/reporting/tests/iframe_delivering.html";
|
||||
|
||||
document.body.appendChild(ifr);
|
||||
});
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче