Bug 1945965 – remove new tab April Fools logo. r=home-newtab-reviewers,reemhamz
[gecko.git] / dom / reporting / tests / iframe_delivering.html
blobaf5b4fd228fc92165168807123a629dd39f628af
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test for delivering reports</title>
5 </head>
6 <body>
8 <script type="application/javascript">
10 function ok(a, msg) {
11 parent.postMessage({type: "test", check: !!a, msg }, "*");
14 function is(a, b, msg) {
15 ok(a === b, msg);
18 function finish() {
19 parent.postMessage({type: "finish" }, "*");
22 function checkReport() {
23 return new Promise(resolve => {
24 let id = setInterval(_ => {
25 fetch("delivering.sjs?task=check&min=3")
26 .then(r => r.text())
27 .then(text => {
28 if (text) {
29 resolve(JSON.parse(text));
30 clearInterval(id);
32 });
33 }, 1000);
34 });
37 function runTests(extraParams = "") {
38 // Call a deprecating operation.
39 for (let i = 0; i < 100; ++i) {
40 new TestingDeprecatedInterface();
42 ok(true, "Created a deprecated interface");
44 // Check if the report has been received.
45 return checkReport()
46 .then(reports => {
47 ok(reports.length >= 3, "We should have received a minimum of 3 reports");
49 let report = reports[0];
50 is(report.contentType, "application/reports+json", "Correct mime-type");
51 is(report.origin, "https://example.org", "Origin correctly set");
52 is(report.url, "https://example.org/tests/dom/reporting/tests/delivering.sjs" + extraParams, "URL is correctly set");
53 ok(!!report.body, "We have a report.body");
54 ok(report.body.age > 0, "Age is correctly set");
55 is(report.body.url, window.location.href, "URL is correctly set");
56 is(report.body.user_agent, navigator.userAgent, "User-agent matches");
57 ok(report.body.type, "deprecation", "Type is fine.");
58 ok(!!report.body.body, "We have the real report.body");
59 is(report.body.body.id, "DeprecatedTestingInterface", "Correct report.body.id");
60 is(report.body.body.message, "TestingDeprecatedInterface is a testing-only interface and this is its testing deprecation message.", "We have a report.body.message");
61 is(report.body.body.sourceFile, "https://example.org/tests/dom/reporting/tests/iframe_delivering.html", "report.body.sourceFile");
62 is(report.body.body.lineNumber, 40, "report.body.lineNumber");
63 is(report.body.body.columnNumber, 5, "report.body.columnNumber");
64 });
67 // Let's register a group + endpoint
68 fetch("delivering.sjs?task=header")
69 .then(r => r.text())
70 .then(text => {
71 is(text, "OK", "Report-to header sent");
73 .then(_ => {
74 return runTests();
77 // Let's register a group + endpoint from a worker
78 .then(_ => {
79 return new Promise(resolve => {
80 let w = new Worker("worker_delivering.js");
81 w.onmessage = () => resolve();
82 });
84 .then(_ => {
85 return runTests("&worker=true");
88 .then(finish);
90 </script>
91 </body>
92 </html>