Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presentation API: Sandboxing test on PresentationRequest constructor #4542

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,24 +1,24 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Sandboxing: Reconnecting a presentation from a nested context fails when allow-presentation is not set</title>
<title>Sandboxing: Creating a PresentationRequest from a nested context fails when allow-presentation is not set</title>
<link rel="author" title="Francois Daoust" href="https://www.w3.org/People/#fd">
<link rel="help" href="http://w3c.github.io/presentation-api/#dom-presentationrequest-reconnect">
<link rel="help" href="http://w3c.github.io/presentation-api/#constructing-a-presentationrequest">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function (t) {
function startWhenReady(ev) {
var startWhenReady = t.step_func(function (ev) {
var childFrame = document.getElementById('childFrame');
if (ev.data === 'ready') {
window.removeEventListener('message', startWhenReady);
childFrame.contentWindow.postMessage('reconnect', '*');
window.addEventListener('message', t.step_func(function (ev) {
assert_equals(ev.data, 'SecurityError',
'Presentation sandboxing did not work as expected.');
t.done();
}));
window.addEventListener('message', checkFinalMessage);
childFrame.contentWindow.postMessage('create', '*');
}
}
});

var checkFinalMessage = t.step_func_done(function (ev) {
assert_equals(ev.data, 'SecurityError', 'Presentation sandboxing did not work as expected.');
});

window.addEventListener('message', startWhenReady);
});
Expand Down
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Sandboxing: Creating a PresentationRequest from a nested context succeeds when allow-presentation is set</title>
<link rel="author" title="Francois Daoust" href="https://www.w3.org/People/#fd">
<link rel="help" href="http://w3c.github.io/presentation-api/#constructing-a-presentationrequest">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function (t) {
var startWhenReady = t.step_func(function (ev) {
var childFrame = document.getElementById('childFrame');
if (ev.data === 'ready') {
window.removeEventListener('message', startWhenReady);
window.addEventListener('message', checkFinalMessage);
childFrame.contentWindow.postMessage('create', '*');
}
});

var checkFinalMessage = t.step_func_done(function (ev) {
assert_equals(ev.data, 'success', 'Presentation sandboxing did not work as expected.');
});

window.addEventListener('message', startWhenReady);
});
</script>
<iframe id="childFrame" sandbox="allow-scripts allow-presentation" style="display:none" src="support/iframe.html"></iframe>

This file was deleted.

This file was deleted.

16 changes: 14 additions & 2 deletions presentation-api/controlling-ua/support/iframe.html
Expand Up @@ -17,8 +17,18 @@
return '../' + url;
}
});
var request = new PresentationRequest(urls);
if (ev.data === 'start') {
var request = null;
if (ev.data === 'create') {
try {
request = new PresentationRequest(urls);
parent.window.postMessage('success', '*');
}
catch (err) {
parent.window.postMessage(err.name, '*');
}
}
else if (ev.data === 'start') {
request = new PresentationRequest(urls);
request.start()
.then(function () {
parent.window.postMessage('success', '*');
Expand All @@ -38,6 +48,7 @@
});
}
else if (ev.data === 'reconnect') {
request = new PresentationRequest(urls);
request.reconnect('someid')
.then(function () {
parent.window.postMessage('success', '*');
Expand All @@ -47,6 +58,7 @@
});
}
else if (ev.data === 'getAvailability') {
request = new PresentationRequest(urls);
request.getAvailability()
.then(function () {
parent.window.postMessage('success', '*');
Expand Down