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

Allow feature policy to be used in opaque origins. #10076

Merged
merged 1 commit into from
Apr 13, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@
test_frame_policy('fullscreen', cross_origin_src, false);
}, 'Test frame policy on cross origin iframe inherit from header policy.');

// Test that frame policy can be used for sandboxed frames
test(function() {
test_frame_policy(
'fullscreen', same_origin_src, false, undefined, false, true);
}, 'Test frame policy on sandboxed iframe with no allow attribute.');
test(function() {
test_frame_policy(
'fullscreen', same_origin_src, true, 'fullscreen', false, true);
}, 'Test frame policy on sandboxed iframe with allow="fullscreen".');
test(function() {
test_frame_policy(
'fullscreen', same_origin_src, true, 'fullscreen \'src\'', false, true);
}, 'Test frame policy on sandboxed iframe with allow="fullscreen \'src\'".');
test(function() {
test_frame_policy(
'fullscreen', cross_origin_src, false, 'fullscreen ' + cross_origin, false, true);
}, 'Test frame policy on sandboxed iframe with allow="fullscreen ' + cross_origin + '".');

// Test frame policy with allow attribute set to be one of the policies above.
for (var i = 0; i < policies.length; i++) {
test(function() {
Expand Down
7 changes: 6 additions & 1 deletion feature-policy/resources/featurepolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,10 @@ function test_subframe_header_policy(
// test_expect: boolean value of whether the feature should be allowed.
// allow: optional, the allow attribute (container policy) of the iframe.
// allowfullscreen: optional, boolean value of allowfullscreen attribute.
// sandbox: optional boolean. If true, the frame will be sandboxed (with
// allow-scripts, so that tests can run in it.)
function test_frame_policy(
feature, src, test_expect, allow, allowfullscreen) {
feature, src, test_expect, allow, allowfullscreen, sandbox) {
let frame = document.createElement('iframe');
document.body.appendChild(frame);
// frame_policy should be dynamically updated as allow and allowfullscreen is
Expand All @@ -406,6 +408,9 @@ function test_frame_policy(
if (!!allowfullscreen) {
frame.setAttribute('allowfullscreen', true);
}
if (!!sandbox) {
frame.setAttribute('sandbox', 'allow-scripts');
}
frame.src = src;
if (test_expect) {
assert_true(frame_policy.allowedFeatures().includes(feature));
Expand Down