testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-csp-iframe.html
author James Graham <james@hoppipolla.co.uk>
Thu, 25 Jun 2015 16:10:50 -0700
changeset 250330 a03152790896f9304cf6b79e48de91cc0388cc64
child 259872 681ee47b9ea8add7cf47d87cae0d85364f5df1fb
permissions -rw-r--r--
Bug 1120505 - Add Blink service-worker tests to local wpt tests, rs=Ms2ger

<script src="../resources/get-host-info.sub.js"></script>
<script src="test-helpers.sub.js?pipe=sub"></script>
<script>
var image_path = base_path() + 'fetch-access-control.py?PNGIMAGE';
var host_info = get_host_info();
var results = '';
var port = undefined;

var meta = document.createElement('meta');
meta.setAttribute('http-equiv', 'Content-Security-Policy');
meta.setAttribute('content', 'img-src ' + host_info['HTTP_ORIGIN'] +
                  '; script-src \'unsafe-inline\'');
document.head.appendChild(meta);

function test1() {
  var img = document.createElement('img');
  document.body.appendChild(img);
  img.onload = function() {
    test2();
  };
  img.onerror = function() {
    results += 'FAIL(1)';
    test2();
  };
  img.src = host_info['HTTP_ORIGIN'] + image_path;
}

function test2() {
  var img = document.createElement('img');
  document.body.appendChild(img);
  img.onload = function() {
    results += 'FAIL(2)';
    test3();
  };
  img.onerror = function() {
    test3();
  };
  img.src = host_info['HTTP_REMOTE_ORIGIN'] + image_path;
}

function test3() {
  var img = document.createElement('img');
  document.body.appendChild(img);
  img.onload = function() {
    test4();
  };
  img.onerror = function() {
    results += 'FAIL(3)';
    test4();
  };
  img.src = './dummy?url=' +
            encodeURIComponent(host_info['HTTP_ORIGIN'] + image_path);
}

function test4() {
  var img = document.createElement('img');
  document.body.appendChild(img);
  img.onload = function() {
    results += 'FAIL(4)';
    finish();
  };
  img.onerror = function() {
    finish();
  };
  img.src = './dummy?mode=no-cors&url=' +
            encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + image_path);
}

function finish() {
  results += 'finish';
  port.postMessage({results: results});
}

window.addEventListener('message', function(evt) {
    port = evt.ports[0];
    test1();
  }, false);
</script>