tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

iframe_delivering.html (2691B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for delivering reports</title>
      5 </head>
      6 <body>
      7 
      8 <script type="application/javascript">
      9 
     10 function ok(a, msg) {
     11  parent.postMessage({type: "test", check: !!a, msg }, "*");
     12 }
     13 
     14 function is(a, b, msg) {
     15  ok(a === b, msg);
     16 }
     17 
     18 function finish() {
     19  parent.postMessage({type: "finish" }, "*");
     20 }
     21 
     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);
     31        }
     32      });
     33    }, 1000);
     34  });
     35 }
     36 
     37 function runTests(extraParams = "") {
     38  // Call a deprecating operation.
     39  for (let i = 0; i < 100; ++i) {
     40    new TestingDeprecatedInterface();
     41  }
     42  ok(true, "Created a deprecated interface");
     43 
     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");
     48 
     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  });
     65 }
     66 
     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");
     72 })
     73 .then(_ => {
     74  return runTests();
     75 })
     76 
     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  });
     83 })
     84 .then(_ => {
     85  return runTests("&worker=true");
     86 })
     87 
     88 .then(finish);
     89 
     90 </script>
     91 </body>
     92 </html>