From ebed1c66306a9fc5f60d2c6315198e18bc9e4dd0 Mon Sep 17 00:00:00 2001 From: Luna Lu Date: Tue, 13 Mar 2018 08:52:39 -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 --- ...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 000000000000000..defe06ffedbb883 --- /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 000000000000000..111121a52fbdc9d --- /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 000000000000000..d757d4c4cf518ee --- /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 000000000000000..0cc259b24f3829f --- /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 000000000000000..f10c66fe0e6133e --- /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 000000000000000..c2493a089031aa8 --- /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 000000000000000..e1178e797d5257c --- /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 000000000000000..961d40336aeb3ed --- /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 925408ea8a4e50e..be8629d153dc084 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)); + } +}