From 33bcc12ba8cf365bdfd300a78b5d6471000b067f Mon Sep 17 00:00:00 2001 From: Luna Lu Date: Tue, 13 Mar 2018 10:34:49 -0700 Subject: [PATCH] Add WPT tests for feature policy frame policy 1. Without specifying allow attribute, frame policy inherits correctly. 2. With allow attribute, frame policy inherits from and overrides header policy correctly. Updating allowfullscreen and allowpaymentrequest correctly updates frame policy. 3. Frame policy is not affected by the frame's document policy. Bug: 732003 Change-Id: Ib41f883a779f11c564c91cfc03ff1224330108f5 Reviewed-on: https://chromium-review.googlesource.com/850896 Commit-Queue: Luna Lu Reviewed-by: Ian Clelland Cr-Commit-Position: refs/heads/master@{#542837} --- ...rame-policy-allowed-for-all.https.sub.html | 84 ++++++++++++++ ...allowed-for-all.https.sub.html.sub.headers | 1 + ...ame-policy-allowed-for-self.https.sub.html | 84 ++++++++++++++ ...llowed-for-self.https.sub.html.sub.headers | 1 + ...ame-policy-allowed-for-some.https.sub.html | 109 ++++++++++++++++++ ...llowed-for-some.https.sub.html.sub.headers | 1 + ...e-policy-disallowed-for-all.https.sub.html | 84 ++++++++++++++ ...allowed-for-all.https.sub.html.sub.headers | 1 + feature-policy/resources/featurepolicy.js | 30 +++++ 9 files changed, 395 insertions(+) create mode 100644 feature-policy/feature-policy-frame-policy-allowed-for-all.https.sub.html create mode 100644 feature-policy/feature-policy-frame-policy-allowed-for-all.https.sub.html.sub.headers create mode 100644 feature-policy/feature-policy-frame-policy-allowed-for-self.https.sub.html create mode 100644 feature-policy/feature-policy-frame-policy-allowed-for-self.https.sub.html.sub.headers create mode 100644 feature-policy/feature-policy-frame-policy-allowed-for-some.https.sub.html create mode 100644 feature-policy/feature-policy-frame-policy-allowed-for-some.https.sub.html.sub.headers create mode 100644 feature-policy/feature-policy-frame-policy-disallowed-for-all.https.sub.html create mode 100644 feature-policy/feature-policy-frame-policy-disallowed-for-all.https.sub.html.sub.headers diff --git a/feature-policy/feature-policy-frame-policy-allowed-for-all.https.sub.html b/feature-policy/feature-policy-frame-policy-allowed-for-all.https.sub.html new file mode 100644 index 00000000000000..defe06ffedbb88 --- /dev/null +++ b/feature-policy/feature-policy-frame-policy-allowed-for-all.https.sub.html @@ -0,0 +1,84 @@ + + + + + + + + diff --git a/feature-policy/feature-policy-frame-policy-allowed-for-all.https.sub.html.sub.headers b/feature-policy/feature-policy-frame-policy-allowed-for-all.https.sub.html.sub.headers new file mode 100644 index 00000000000000..111121a52fbdc9 --- /dev/null +++ b/feature-policy/feature-policy-frame-policy-allowed-for-all.https.sub.html.sub.headers @@ -0,0 +1 @@ +Feature-Policy: fullscreen *; diff --git a/feature-policy/feature-policy-frame-policy-allowed-for-self.https.sub.html b/feature-policy/feature-policy-frame-policy-allowed-for-self.https.sub.html new file mode 100644 index 00000000000000..d757d4c4cf518e --- /dev/null +++ b/feature-policy/feature-policy-frame-policy-allowed-for-self.https.sub.html @@ -0,0 +1,84 @@ + + + + + + + + diff --git a/feature-policy/feature-policy-frame-policy-allowed-for-self.https.sub.html.sub.headers b/feature-policy/feature-policy-frame-policy-allowed-for-self.https.sub.html.sub.headers new file mode 100644 index 00000000000000..0cc259b24f3829 --- /dev/null +++ b/feature-policy/feature-policy-frame-policy-allowed-for-self.https.sub.html.sub.headers @@ -0,0 +1 @@ +Feature-Policy: fullscreen 'self'; diff --git a/feature-policy/feature-policy-frame-policy-allowed-for-some.https.sub.html b/feature-policy/feature-policy-frame-policy-allowed-for-some.https.sub.html new file mode 100644 index 00000000000000..f10c66fe0e6133 --- /dev/null +++ b/feature-policy/feature-policy-frame-policy-allowed-for-some.https.sub.html @@ -0,0 +1,109 @@ + + + + + + + + diff --git a/feature-policy/feature-policy-frame-policy-allowed-for-some.https.sub.html.sub.headers b/feature-policy/feature-policy-frame-policy-allowed-for-some.https.sub.html.sub.headers new file mode 100644 index 00000000000000..c2493a089031aa --- /dev/null +++ b/feature-policy/feature-policy-frame-policy-allowed-for-some.https.sub.html.sub.headers @@ -0,0 +1 @@ +Feature-Policy: fullscreen 'self' https://{{domains[www]}}:{{ports[https][0]}} https://www.example.com; diff --git a/feature-policy/feature-policy-frame-policy-disallowed-for-all.https.sub.html b/feature-policy/feature-policy-frame-policy-disallowed-for-all.https.sub.html new file mode 100644 index 00000000000000..e1178e797d5257 --- /dev/null +++ b/feature-policy/feature-policy-frame-policy-disallowed-for-all.https.sub.html @@ -0,0 +1,84 @@ + + + + + + + + diff --git a/feature-policy/feature-policy-frame-policy-disallowed-for-all.https.sub.html.sub.headers b/feature-policy/feature-policy-frame-policy-disallowed-for-all.https.sub.html.sub.headers new file mode 100644 index 00000000000000..961d40336aeb3e --- /dev/null +++ b/feature-policy/feature-policy-frame-policy-disallowed-for-all.https.sub.html.sub.headers @@ -0,0 +1 @@ +Feature-Policy: fullscreen 'none'; diff --git a/feature-policy/resources/featurepolicy.js b/feature-policy/resources/featurepolicy.js index 925408ea8a4e50..be8629d153dc08 100644 --- a/feature-policy/resources/featurepolicy.js +++ b/feature-policy/resources/featurepolicy.js @@ -383,3 +383,33 @@ function test_subframe_header_policy( }); }, test_name); } + +// This function tests that frame policy allows a given feature correctly. A +// feature is allowed in a frame either through inherited policy or specified +// by iframe allow attribute. +// Arguments: +// feature: feature name. +// src: the URL to load in the frame. +// 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. +function test_frame_policy( + feature, src, test_expect, allow, allowfullscreen) { + let frame = document.createElement('iframe'); + document.body.appendChild(frame); + // frame_policy should be dynamically updated as allow and allowfullscreen is + // updated. + var frame_policy = frame.policy; + if (typeof allow !== 'undefined') { + frame.setAttribute('allow', allow); + } + if (!!allowfullscreen) { + frame.setAttribute('allowfullscreen', true); + } + frame.src = src; + if (test_expect) { + assert_true(frame_policy.allowedFeatures().includes(feature)); + } else { + assert_false(frame_policy.allowedFeatures().includes(feature)); + } +}