tor-browser

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

cross-origin-reports-isolated.https.sub.html (1713B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test that reports from different origins are not sent together</title>
      5  <script src='/resources/testharness.js'></script>
      6  <script src='/resources/testharnessreport.js'></script>
      7  <script src='resources/report-helper.js'></script>
      8 </head>
      9 <body>
     10  <script>
     11    const base_url = `${location.protocol}//${location.host}`;
     12    const endpoint = `${base_url}/reporting/resources/report.py`;
     13    const id = 'd0d517bf-891b-457a-b970-8b2b2c81a0bf';
     14 
     15    promise_test(async t => {
     16 
     17      // Attach a cross-origin iframe which should post back here immediately
     18      // before generating a CSP error. That error should be reported to the
     19      // same endpoint that this frame reports to.
     20      await new Promise(resolve => {
     21        const iframe = document.createElement('iframe');
     22        iframe.src = "https://{{domains[www]}}:{{ports[https][0]}}/reporting/resources/csp-error.https.sub.html";
     23        addEventListener('message', resolve);
     24        document.body.appendChild(iframe);
     25      });
     26 
     27      // Trigger a CSP error and report in this frame as well.
     28      await new Promise(resolve => {
     29        const img = document.createElement('img');
     30        img.src = "/reporting/resources/fail.png";
     31        img.addEventListener('error', resolve);
     32        document.body.appendChild(img);
     33      });
     34 
     35      // Wait for 2 reports to be received.
     36      const reports = await pollReports(endpoint, id, 2);
     37      assert_equals(reports.length, 2);
     38 
     39      // Validate that reports were sent in separate requests.
     40      const request_count = await pollNumResults(endpoint, id);
     41      assert_equals(request_count, 2);
     42    }, "Reports were sent in two requests.");
     43  </script>
     44 </body>
     45 </html>