dom/security/test/csp/test_link_rel_preload.html
author Gerald Squelart <gsquelart@mozilla.com>
Wed, 02 Dec 2020 00:17:46 +0000
changeset 558992 273d6825ba4740e6220f51dd6092058533e77f97
parent 544269 e5816310d6890da627ef1ee5f76daf86a48be4ec
permissions -rw-r--r--
Bug 1500811 - Variant::as()&&, match()&& - r=sg `as<...>()` on an rvalue variant returns the contained value as rvalue-reference. `match()` on an rvalue variant forwards the contained value as rvalue-reference. So now the contained values can be efficiently moved-from. There are also equivalents for `const&&`, which should be rare. For `match(2+ matchers)`, the static_assert for same return types has been moved to `Impl::matchN`. Also, it doesn't rely on `FunctionTypeTraits` anymore, which has the added benefit of allowing `auto` in individual matchers. Differential Revision: https://phabricator.services.mozilla.com/D98050

<!doctype html>
<html>
<head>
  <title>Bug 1599791 - Test link rel=preload</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<iframe id=testframe></iframe>
<script class="testbody" type="text/javascript">

// Please note that 'fakeServer' does not exist because the test relies
// on "csp-on-violate-policy" , and "specialpowers-http-notify-request"
// which fire if either the request is blocked or fires. The test does
// not rely on the result of the load.

let TOTAL_TESTS = 3; // script, style, image
let seenTests = 0;

function examiner() {
  SpecialPowers.addObserver(this, "csp-on-violate-policy");
  SpecialPowers.addObserver(this, "specialpowers-http-notify-request");
}
examiner.prototype  = {
  observe(subject, topic, data) {
    if (topic === "csp-on-violate-policy") {
      let asciiSpec = SpecialPowers.getPrivilegedProps(
                       SpecialPowers.do_QueryInterface(subject, "nsIURI"),
                       "asciiSpec");
      if (asciiSpec.includes("fakeServer?script") ||
          asciiSpec.includes("fakeServer?style") ||
          asciiSpec.includes("fakeServer?fetch") ||
          asciiSpec.includes("fakeServer?font") ||
          asciiSpec.includes("fakeServer?image")) {
        let type = asciiSpec.substring(asciiSpec.indexOf("?") + 1);
        ok (true, type + " should be blocked by CSP");
        checkFinished();
      }
    }

    if (topic === "specialpowers-http-notify-request") {
      if (data.includes("fakeServer?script") ||
          data.includes("fakeServer?style") ||
          data.includes("fakeServer?fetch") ||
          data.includes("fakeServer?font") ||
          data.includes("fakeServer?image")) {
        let type = data.substring(data.indexOf("?") + 1);
        ok (false, type + " should not be loaded");
        checkFinished();
      }
    }
  },
  remove() {
    SpecialPowers.removeObserver(this, "csp-on-violate-policy");
    SpecialPowers.removeObserver(this, "specialpowers-http-notify-request");
  }
}

window.examiner = new examiner();

function checkFinished() {
  seenTests++;
  if (seenTests == TOTAL_TESTS) {
    window.examiner.remove();
    SimpleTest.finish();
    return;
  }
}

SimpleTest.waitForExplicitFinish();

SpecialPowers.pushPrefEnv(
  {'set':[["network.preload", true]]},
  function() {
    document.getElementById("testframe").src = "file_link_rel_preload.html";
  });

</script>
</body>
</html>