tor-browser

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

test_link_rel_preload.html (2401B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4  <title>Bug 1599791 - Test link rel=preload</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 <iframe id=testframe></iframe>
     10 <script class="testbody" type="text/javascript">
     11 
     12 // Please note that 'fakeServer' does not exist because the test relies
     13 // on "csp-on-violate-policy" , and "specialpowers-http-notify-request"
     14 // which fire if either the request is blocked or fires. The test does
     15 // not rely on the result of the load.
     16 
     17 let TOTAL_TESTS = 3; // script, style, image
     18 let seenTests = 0;
     19 
     20 function examiner() {
     21  SpecialPowers.addObserver(this, "csp-on-violate-policy");
     22  SpecialPowers.addObserver(this, "specialpowers-http-notify-request");
     23 }
     24 examiner.prototype  = {
     25  observe(subject, topic, data) {
     26    if (topic === "csp-on-violate-policy") {
     27      let asciiSpec = SpecialPowers.getPrivilegedProps(
     28                       SpecialPowers.do_QueryInterface(subject, "nsIURI"),
     29                       "asciiSpec");
     30      if (asciiSpec.includes("fakeServer?script") ||
     31          asciiSpec.includes("fakeServer?style") ||
     32          asciiSpec.includes("fakeServer?fetch") ||
     33          asciiSpec.includes("fakeServer?font") ||
     34          asciiSpec.includes("fakeServer?image")) {
     35        let type = asciiSpec.substring(asciiSpec.indexOf("?") + 1);
     36        ok (true, type + " should be blocked by CSP");
     37        checkFinished();
     38      }
     39    }
     40 
     41    if (topic === "specialpowers-http-notify-request") {
     42      if (data.includes("fakeServer?script") ||
     43          data.includes("fakeServer?style") ||
     44          data.includes("fakeServer?fetch") ||
     45          data.includes("fakeServer?font") ||
     46          data.includes("fakeServer?image")) {
     47        let type = data.substring(data.indexOf("?") + 1);
     48        ok (false, type + " should not be loaded");
     49        checkFinished();
     50      }
     51    }
     52  },
     53  remove() {
     54    SpecialPowers.removeObserver(this, "csp-on-violate-policy");
     55    SpecialPowers.removeObserver(this, "specialpowers-http-notify-request");
     56  }
     57 }
     58 
     59 window.examiner = new examiner();
     60 
     61 function checkFinished() {
     62  seenTests++;
     63  if (seenTests == TOTAL_TESTS) {
     64    window.examiner.remove();
     65    SimpleTest.finish();
     66  }
     67 }
     68 
     69 SimpleTest.waitForExplicitFinish();
     70 document.getElementById("testframe").src = "file_link_rel_preload.html";
     71 </script>
     72 </body>
     73 </html>