Skip to content

Commit

Permalink
Reland "Add WPT tests for feature policy"
Browse files Browse the repository at this point in the history
This is a reland of 6252427ab5415839618a0d25e4f6e61becce3923.

Original change's description:
> Add WPT tests for feature policy
>
> 1. Added tests for header policy.
>     a. document.policy shows correctly parsed policy
>     b. local / remote iframes without allow attribute correctly inherit
>        document.policy
>     c. dynamically update allow attribute updates the policy correctly.
>
> 2. Added tests for nested policies.
>
> Bug: 732003
> Change-Id: I869449f6bba89fc58997355df27249f403d76808
> Reviewed-on: https://chromium-review.googlesource.com/796952
> Commit-Queue: Luna Lu <[email protected]>
> Reviewed-by: Ian Clelland <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#531698}

Bug: 732003
Change-Id: I46065efff8c5af2d5279721f3c759580b0807e05
Reviewed-on: https://chromium-review.googlesource.com/887324
Reviewed-by: Ian Clelland <[email protected]>
Commit-Queue: Luna Lu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#538904}
  • Loading branch information
loonybear authored and foolip committed Feb 25, 2018
1 parent cd2eda7 commit e494987
Show file tree
Hide file tree
Showing 17 changed files with 564 additions and 0 deletions.
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

0 comments on commit e494987

Please sign in to comment.