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

Reland "Add WPT tests for feature policy" #9238

Merged
merged 1 commit into from
Feb 25, 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
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/feature-policy/resources/featurepolicy.js></script>
<!-- Feature-Policy: fullscreen *; -->
<script>
'use strict';
var same_origin = 'https://{{domains[]}}:{{ports[https][0]}}';
var cross_origin = 'https://{{domains[www]}}:{{ports[https][0]}}';
var same_origin_src = '/feature-policy/resources/feature-policy-allowedfeatures.html';
var cross_origin_src = cross_origin + same_origin_src;
var header_policy = 'Feature-Policy: fullscreen *';

// Test that fullscreen's allowlist is ['*']
test(function() {
assert_array_equals(
document.policy.getAllowlistForFeature('fullscreen'),
['*']);
}, header_policy + ' -- test allowlist is ['*']');

// Test that fullscreen is allowed on all subframes.
test_allowed_feature_for_subframe(
header_policy + ' -- test fullscreen is allowed on same-origin subframe',
'fullscreen',
same_origin_src);
test_allowed_feature_for_subframe(
header_policy + ' -- test fullscreen is allowed on cross-origin subframe',
'fullscreen',
cross_origin_src);

// Dynamically update sub frame's container policy
var allow = "fullscreen 'self';"
test_allowed_feature_for_subframe(
header_policy + ', iframe.allow = ' + allow + ' -- test fullscreen is allowed on same-origin subframe',
'fullscreen',
same_origin_src,
allow);

test_disallowed_feature_for_subframe(
header_policy + ', iframe.allow = ' + allow + ' -- test fullscreen is disallowed on cross-origin subframe',
'fullscreen',
cross_origin_src,
allow);
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feature-Policy: fullscreen *;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/feature-policy/resources/featurepolicy.js></script>
<!-- Feature-Policy: fullscreen 'self'; -->
<script>
'use strict';
var same_origin = 'https://{{domains[]}}:{{ports[https][0]}}';
var cross_origin = 'https://{{domains[www]}}:{{ports[https][0]}}';
var same_origin_src = '/feature-policy/resources/feature-policy-allowedfeatures.html';
var cross_origin_src = cross_origin + same_origin_src;
var header_policy = 'Feature-Policy: fullscreen \'self\'';

// Test that fullscreen's allowlist is ['same_origin']
test(function() {
assert_array_equals(
document.policy.getAllowlistForFeature('fullscreen'),
[same_origin]);
}, header_policy + ' -- test allowlist is [same_origin]');

// Test that fullscreen is only allowed on same-origin subframe.
test_allowed_feature_for_subframe(
header_policy + ' -- test fullscreen is allowed on same-origin subframe',
'fullscreen',
same_origin_src);
test_disallowed_feature_for_subframe(
header_policy + ' -- test fullscreen is disallowed on cross-origin subframe',
'fullscreen',
cross_origin_src);

// Dynamically update sub frame's container policy
var allow = "fullscreen 'src';"
test_allowed_feature_for_subframe(
header_policy + ', iframe.allow = ' + allow + ' -- test fullscreen is allowed on same-origin subframe',
'fullscreen',
same_origin_src,
allow);

test_allowed_feature_for_subframe(
header_policy + ', iframe.allow = ' + allow + ' -- test fullscreen is allowed on cross-origin subframe',
'fullscreen',
same_origin_src,
allow);
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feature-Policy: fullscreen 'self';
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/feature-policy/resources/featurepolicy.js></script>
<!-- Feature-Policy: fullscreen 'self' cross_origin https://www.example.com; -->
<script>
'use strict';
var same_origin = 'https://{{domains[]}}:{{ports[https][0]}}';
var cross_origin = 'https://{{domains[www]}}:{{ports[https][0]}}';
var same_origin_src = '/feature-policy/resources/feature-policy-allowedfeatures.html';
var cross_origin_src = cross_origin + same_origin_src;
var header_policy = 'Feature-Policy: fullscreen \'self\' ' + cross_origin +
' https://www.example.com;';

// Test that fullscreen's allowlist is [same_origin, cross_origin, 'https://www.example.com']
test(function() {
assert_array_equals(
document.policy.getAllowlistForFeature('fullscreen'),
[same_origin, cross_origin, 'https://www.example.com']);
}, header_policy + ' -- test allowlist is [same_origin, cross_origin, https://www.example.com]');

// Test that fullscreen is allowed on same_origin, some cross_origin subframes.
test_allowed_feature_for_subframe(
header_policy + ' -- test fullscreen is allowed on same-origin subframe',
'fullscreen',
same_origin_src);
test_allowed_feature_for_subframe(
header_policy + ' -- test fullscreen is allowed on cross-origin ' + cross_origin_src + ' subframe',
'fullscreen',
cross_origin_src);
var cross_origin_src1 = 'https://{{domains[www1]}}:{{ports[https][0]}}' + same_origin_src;
test_disallowed_feature_for_subframe(
header_policy + ' -- test fullscreen is disallowed on cross-origin ' + cross_origin_src1 + ' subframe',
'fullscreen',
cross_origin_src1);

// dynamically update sub frame's container policy
var allow = "fullscreen 'none';"
test_disallowed_feature_for_subframe(
header_policy + ', iframe.allow = ' + allow + ' -- test fullscreen is disallowed on same-origin subframe',
'fullscreen',
same_origin_src,
allow);

test_disallowed_feature_for_subframe(
header_policy + 'iframe.allow = ' + allow + ' -- test fullscreen is disallowed on cross-origin subframe',
'fullscreen',
cross_origin_src,
allow);
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feature-Policy: fullscreen 'self' https://{{domains[www]}}:{{ports[https][0]}} https://www.example.com;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/feature-policy/resources/featurepolicy.js></script>
<!-- Feature-Policy: fullscreen 'none'; -->
<script>
'use strict';
var same_origin = 'https://{{domains[]}}:{{ports[https][0]}}';
var cross_origin = 'https://{{domains[www]}}:{{ports[https][0]}}';
var same_origin_src = '/feature-policy/resources/feature-policy-allowedfeatures.html';
var cross_origin_src = cross_origin + same_origin_src;
var header_policy = 'Feature-Policy: fullscreen \'none\'';

// Test that fullscreen's allowlist is []
test(function() {
assert_array_equals(
document.policy.getAllowlistForFeature('fullscreen'),
[]);
}, header_policy + ' -- test allowlist is []');

// Test that fullscreen is disallowed on all subframes.
test_disallowed_feature_for_subframe(
header_policy + ' -- test fullscreen is disallowed on same-origin subframe',
'fullscreen',
same_origin_src);
test_disallowed_feature_for_subframe(
header_policy + ' -- test fullscreen is disallowed on cross-origin subframe',
'fullscreen',
cross_origin_src);

// Dynamically update sub frame's container policy
var allow = "fullscreen 'src';"
test_disallowed_feature_for_subframe(
header_policy + ', iframe.allow = ' + allow + ' -- test fullscreen is disallowed on same-origin subframe',
'fullscreen',
same_origin_src,
allow);

test_disallowed_feature_for_subframe(
header_policy + ', iframe.allow = ' + allow + ' -- test fullscreen is disallowed on cross-origin subframe',
'fullscreen',
cross_origin_src,
allow);
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Feature-Policy: fullscreen 'none';

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/feature-policy/resources/featurepolicy.js></script>
<script>
/*
fullscreen is allowed for all at the top-level document. It can be disabled by
subframes.
*/
'use strict';
const same_origin = 'https://{{domains[]}}:{{ports[https][0]}}';
const cross_origin = 'https://{{domains[www]}}:{{ports[https][0]}}';
const same_origin_src = '/feature-policy/resources/feature-policy-nested-subframe-policy.https.sub.html';
const cross_origin_src = cross_origin + same_origin_src;

/* ------------------------------------------
| top-level document |
| ------------------------------------ |
| | same-origin iframe | |
| | ------------------------------ | |
| | | local and remote iframes | | |
| | ------------------------------ | |
| ------------------------------------ |
------------------------------------------ */
test_subframe_header_policy('fullscreen', '*', same_origin_src,
{local_all: true, local_self: true, local_none: false,
remote_all: true, remote_self: true, remote_none: false},
'Test nested header policy with local iframe on policy "fullscreen *"');
test_subframe_header_policy('fullscreen', '\'self\'', same_origin_src,
{local_all: true, local_self: true, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with local iframe on policy "fullscreen \'self\'"');
test_subframe_header_policy('fullscreen', '\'none\'', same_origin_src,
{local_all: false, local_self: false, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with local iframe on policy "fullscreen \'none\'"');

/* -------------------------------------------
| top-level document |
| ------------------------------------- |
| | cross-origin iframe | |
| | ------------------------------- | |
| | | local and remote iframes | | |
| | ------------------------------- | |
| ------------------------------------- |
------------------------------------------- */
test_subframe_header_policy('fullscreen', '*', cross_origin_src,
{local_all: true, local_self: true, local_none: false,
remote_all: true, remote_self: true, remote_none: false},
'Test nested header policy with remote iframe on policy "fullscreen *"');
test_subframe_header_policy('fullscreen', '\'self\'', cross_origin_src,
{local_all: true, local_self: true, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with remote iframe on policy "fullscreen \'self\'"');
test_subframe_header_policy('fullscreen', '\'none\'', cross_origin_src,
{local_all: false, local_self: false, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with remote iframe on policy "fullscreen \'none\'"');
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feature-Policy: fullscreen *;
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/feature-policy/resources/featurepolicy.js></script>
<script>
/*
fullscreen is allowed for 'self' at the top-level document and through the
chain of same-origin iframes. It can be enabled by subframes, but otherwise
is disallowed everywhere else.
*/
'use strict';
const same_origin = 'https://{{domains[]}}:{{ports[https][0]}}';
const cross_origin = 'https://{{domains[www]}}:{{ports[https][0]}}';
const same_origin_src = '/feature-policy/resources/feature-policy-nested-subframe-policy.https.sub.html';
const cross_origin_src = cross_origin + same_origin_src;

/* ------------------------------------------
| top-level document |
| ------------------------------------ |
| | same-origin iframe | |
| | ------------------------------ | |
| | | local and remote iframes | | |
| | ------------------------------ | |
| ------------------------------------ |
------------------------------------------ */
test_subframe_header_policy('fullscreen', '*', same_origin_src,
{local_all: true, local_self: true, local_none: false,
remote_all: true, remote_self: true, remote_none: false},
'Test nested header policy with local iframe on policy "fullscreen *"');
test_subframe_header_policy('fullscreen', '\'self\'', same_origin_src,
{local_all: true, local_self: true, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with local iframe on policy "fullscreen \'self\'"');
test_subframe_header_policy('fullscreen', '\'none\'', same_origin_src,
{local_all: false, local_self: false, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with local iframe on policy "fullscreen \'none\'"');

/* -------------------------------------------
| top-level document |
| ------------------------------------- |
| | cross-origin iframe | |
| | ------------------------------- | |
| | | local and remote iframes | | |
| | ------------------------------- | |
| ------------------------------------- |
------------------------------------------- */
test_subframe_header_policy('fullscreen', '*', cross_origin_src,
{local_all: false, local_self: false, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with remote iframe on policy "fullscreen *"');
test_subframe_header_policy('fullscreen', '\'self\'', cross_origin_src,
{local_all: false, local_self: false, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with remote iframe on policy "fullscreen \'self\'"');
test_subframe_header_policy('fullscreen', '\'none\'', cross_origin_src,
{local_all: false, local_self: false, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with remote iframe on policy "fullscreen \'none\'"');
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feature-Policy: fullscreen 'self';
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/feature-policy/resources/featurepolicy.js></script>
<script>
/*
fullscreen is disabled at the top-level document, therefore disabled
everywhere throughout inheritance.
*/
'use strict';
const same_origin = 'https://{{domains[]}}:{{ports[https][0]}}';
const cross_origin = 'https://{{domains[www]}}:{{ports[https][0]}}';
const same_origin_src = '/feature-policy/resources/feature-policy-nested-subframe-policy.https.sub.html';
const cross_origin_src = cross_origin + same_origin_src;
const policies = ['*', '\'self\'', '\'none\''];

for (var i = 0; i < policies.length; i++) {
/* ------------------------------------------
| top-level document |
| ------------------------------------ |
| | same-origin iframe | |
| | ------------------------------ | |
| | | local and remote iframes | | |
| | ------------------------------ | |
| ------------------------------------ |
------------------------------------------ */
test_subframe_header_policy('fullscreen', policies[i], same_origin_src,
{local_all: false, local_self: false, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with local iframe on policy "fullscreen '
+ policies[i] + '".');

/* -------------------------------------------
| top-level document |
| ------------------------------------- |
| | cross-origin iframe | |
| | ------------------------------- | |
| | | local and remote iframes | | |
| | ------------------------------- | |
| ------------------------------------- |
------------------------------------------- */
test_subframe_header_policy('fullscreen', policies[i], cross_origin_src,
{local_all: false, local_self: false, local_none: false,
remote_all: false, remote_self: false, remote_none: false},
'Test nested header policy with remote iframe on policy "fullscreen '
+ policies[i] + '".');
}
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feature-Policy: fullscreen 'none';
7 changes: 7 additions & 0 deletions feature-policy/resources/feature-policy-allowedfeatures.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
'use strict';

window.onload = function() {
parent.postMessage(document.policy.allowedFeatures(), '*');
}
</script>
Loading