Skip to content

Instantly share code, notes, and snippets.

@mikewest
Created September 26, 2016 09:14
Show Gist options
  • Save mikewest/557a0e08dd10bad6854683739492bc0a to your computer and use it in GitHub Desktop.
Save mikewest/557a0e08dd10bad6854683739492bc0a to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// IDL stuff.
test(t => {
var i = document.createElement('iframe');
assert_equals("string", i.csp);
}, "<iframe> has a 'csp' attibute which is a string.");
test(t => {
var i = document.createElement('iframe');
i.setAttribute('csp', 'value');
assert_equals('value', i.csp);
}, "<iframe> has a 'csp' attibute.");
test(t => {
var i = document.createElement('iframe');
i.csp = 'value';
assert_equals('value', i.getAttribute('csp'));
}, "<iframe> has a 'csp' attibute.");
</script>
<script>
// Loading stuff.
async_test(t => {
var i = document.createElement('iframe');
i.csp = 'value';
i.src = 'resources/post-header.php';
window.addEventListener('message', t.step_func(e => {
if (e.source != i.contentWindow)
return;
assert_equals('value', e.data['embedding-csp']);
t.done();
}));
document.body.appendChild('i');
}, "<iframe csp> sends a request header");
</script>
// Some other file:
<?php
$headers = //php goes here;
?>
<script>
var headers = // something something $headers;
window.top.postMessage(headers, '*');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment