tor-browser

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

generateTestReport-honors-endpoint.https.sub.html (2020B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4  <title>Test that the reporting-api generate_test_report feature honors endpoints</title>
      5  <link rel="author" title="Brent Fulgham" href="bfulgham@apple.com">
      6  <script src='/resources/testharness.js'></script>
      7  <script src='/resources/testharnessreport.js'></script>
      8  <script src="/resources/testdriver.js"></script>
      9  <script src="/resources/testdriver-vendor.js"></script>
     10  <script src='resources/report-helper.js'></script>
     11 </head>
     12 <body>
     13  <script>
     14    const base_url = `${location.protocol}//${location.host}`;
     15    const endpoint = `${base_url}/reporting/resources/report.py`;
     16    const id = '41534b09-65b2-498a-9fd3-104281ed63ce';
     17 
     18    function checkReportIsValid(reports, type, url) {
     19      for (const report of reports) {
     20        if (report.type !== type) continue;
     21        if (report.url.endsWith("reporting/generateTestReport-honors-endpoint.https.sub.html"))
     22          return true;
     23      }
     24      assert_unreached(`A report of ${type} from ${url} was not found.`);
     25    }
     26 
     27    async_test(function(test) {
     28      var observer = new ReportingObserver(function(reports) {
     29        test.step(function() {
     30          assert_equals(reports.length, 1);
     31          // Ensure that the contents of the report are valid.
     32          assert_equals(reports[0].type, "test");
     33          assert_true(reports[0].url.endsWith("reporting/generateTestReport-honors-endpoint.https.sub.html"));
     34          assert_equals(reports[0].body.message, "Test message.");
     35        });
     36        test.done();
     37      });
     38      observer.observe();
     39 
     40      // This should result in a "test" type report being generated and observed.
     41      test_driver.generate_test_report("Test message.")
     42        .catch(test.unreached_func('generate test report failed'));
     43    }, "Generate Test Report");
     44 
     45    promise_test(async t => {
     46      const reports = await pollReports(endpoint, id);
     47      checkReportIsValid(reports, 'test', location.href);
     48    }, "Reporting-Endpoints target received the test report.");
     49 </script>
     50 </body>
     51 </html>