https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 58557410c1cbc06bf18d056498cc0cdb40c9cb53 authored by Luke Bjerring on 09 April 2018, 21:41:12 UTC
Improve error message for failed wptserve
Tip revision: 5855741
iframe.html
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<meta http-equiv="Content-Security-Policy" content="img-src 'none'">

<body>

<script>
  function wait_for_error_from_frame(frame, test) {
    window.addEventListener('message', test.step_func(e => {
      if (e.source != frame.contentWindow)
        return;
      assert_equals(e.data, "error");
      frame.remove();
      test.done();
    }));
  }

  async_test(t => {
    var i = document.createElement('iframe');
    document.body.appendChild(i);

    var img = document.createElement('img');
    img.onerror = t.step_func_done(_ => i.remove());
    img.onload = t.unreached_func();
    i.contentDocument.body.appendChild(img);
    img.src = "/images/red-16x16.png";
  }, "<iframe>'s about:blank inherits policy.");

  async_test(t => {
    var i = document.createElement('iframe');
    i.srcdoc = `
      <img src='/images/red-16x16.png'
        onload='window.top.postMessage("load", "*");'
        onerror='window.top.postMessage("error", "*");'
      >
    `;

    wait_for_error_from_frame(i, t);

    document.body.appendChild(i);
  }, "<iframe srcdoc>'s inherits policy.");

  async_test(t => {
    var i = document.createElement('iframe');
    var b = new Blob(
      [`
        <img src='${window.origin}/images/red-16x16.png'
          onload='window.top.postMessage("load", "*");'
          onerror='window.top.postMessage("error", "*");'
        >
      `], {type:"text/html"});
    i.src = URL.createObjectURL(b);

    wait_for_error_from_frame(i, t);

    document.body.appendChild(i);
  }, "<iframe src='blob:...'>'s inherits policy.");

  async_test(t => {
    var i = document.createElement('iframe');
    i.src = `data:text/html,<img src='${window.origin}/images/red-16x16.png'
      onload='window.top.postMessage("load", "*");'
      onerror='window.top.postMessage("error", "*");'
    >`;

    wait_for_error_from_frame(i, t);

    document.body.appendChild(i);
  }, "<iframe src='data:...'>'s inherits policy.");

  async_test(t => {
    var i = document.createElement('iframe');
    i.src = `javascript:"<img src='${window.origin}/images/red-16x16.png'
      onload='window.top.postMessage(\\"load\\", \\"*\\");'
      onerror='window.top.postMessage(\\"error\\", \\"*\\");'
    >"`;

    wait_for_error_from_frame(i, t);

    document.body.appendChild(i);
  }, "<iframe src='javascript:...'>'s inherits policy.");
</script>
back to top