diff --git a/feature-policy/feature-policy-for-sandbox/resources/helper.js b/feature-policy/feature-policy-for-sandbox/resources/helper.js index 0d82811bcee613..09a8aa7846cd72 100644 --- a/feature-policy/feature-policy-for-sandbox/resources/helper.js +++ b/feature-policy/feature-policy-for-sandbox/resources/helper.js @@ -3,13 +3,18 @@ const all_features = document.featurePolicy.allowedFeatures(); // 'popups' is nonsensical in this test and it is not possible to test 'scripts' // within this test model. -const ignore_features = ["popups", "scripts"]; +const ignore_features_for_auxilary_context = ["popups", "scripts"]; + +// Feature-policies that represent specific sandbox flags. +const sandbox_features = [ + "forms", "modals", "orientation-lock", "pointer-lock", "popups", + "presentation", "scripts", "top-navigation"]; // TODO(ekaramad): Figure out different inheritance requirements for different // policies. // Features which will be tested for propagation to auxiliary contexts. const features_that_propagate = all_features.filter( - (feature) => !ignore_features.includes(feature)); + (feature) => !ignore_features_for_auxilary_context.includes(feature)); var last_feature_message = null; var on_new_feature_callback = null; @@ -29,10 +34,28 @@ function add_iframe(options) { }); } +// Resolves after |c| animation frames. +function wait_for_raf_count(c) { + let count = c; + let callback = null; + function on_raf() { + if (--count === 0) { + callback(); + return; + } + window.requestAnimationFrame(on_raf); + } + return new Promise( r => { + callback = r; + window.requestAnimationFrame(on_raf); + }); +} + // Returns a promise which is resolved with the next/already received message // with feature update for |feature|. The resolved value is the state of the -// feature |feature|. -function feature_update(feature) { +// feature |feature|. If |optional_timeout| is provided, after the given delay +// (in terms of rafs) the promise is resolved with false. +function feature_update(feature, optional_timeout_rafs) { function reset_for_next_update() { return new Promise((r) => { const state = last_feature_message.state; @@ -43,6 +66,13 @@ function feature_update(feature) { if (last_feature_message && last_feature_message.feature === feature) return reset_for_next_update(); + if (optional_timeout_rafs) { + wait_for_raf_count(optional_timeout_rafs).then (() => { + last_feature_message = {state: false}; + on_new_feature_callback(); + }); + } + return new Promise((r) => on_new_feature_callback = r) .then(() => reset_for_next_update()); } diff --git a/feature-policy/feature-policy-for-sandbox/sandbox-policies-in-allow-attribute.html b/feature-policy/feature-policy-for-sandbox/sandbox-policies-in-allow-attribute.html new file mode 100644 index 00000000000000..a29d43e5fccabe --- /dev/null +++ b/feature-policy/feature-policy-for-sandbox/sandbox-policies-in-allow-attribute.html @@ -0,0 +1,46 @@ + +
+ + + + + + + + \ No newline at end of file