How to use assert_permissions_policy_supported method in wpt

Best JavaScript code snippet using wpt

permissions-policy.js

Source:permissions-policy.js Github

copy

Full Screen

1// Feature test to avoid timeouts2function assert_permissions_policy_supported() {3 assert_not_equals(document.featurePolicy, undefined,4 'permissions policy is supported');5}6// Tests whether a feature that is enabled/disabled by permissions policy works7// as expected.8// Arguments:9// feature_description: a short string describing what feature is being10// tested. Examples: "usb.GetDevices()", "PaymentRequest()".11// test: test created by testharness. Examples: async_test, promise_test.12// src: URL where a feature's availability is checked. Examples:13// "/permissions-policy/resources/permissions-policy-payment.html",14// "/permissions-policy/resources/permissions-policy-usb.html".15// expect_feature_available: a callback(data, feature_description) to16// verify if a feature is available or unavailable as expected.17// The file under the path "src" defines what "data" is sent back as a18// pistMessage. Inside the callback, some tests (e.g., EXPECT_EQ,19// EXPECT_TRUE, etc) are run accordingly to test a feature's20// availability.21// Example: expect_feature_available_default(data, feature_description).22// feature_name: Optional argument, only provided when testing iframe allow23// attribute. "feature_name" is the feature name of a policy controlled24// feature (https://wicg.github.io/permissions-policy/#features).25// See examples at:26// https://github.com/WICG/permissions-policy/blob/master/features.md27// allow_attribute: Optional argument, only used for testing fullscreen or28// payment: either "allowfullscreen" or "allowpaymentrequest" is passed.29function test_feature_availability(30 feature_description, test, src, expect_feature_available, feature_name,31 allow_attribute) {32 let frame = document.createElement('iframe');33 frame.src = src;34 if (typeof feature_name !== 'undefined') {35 frame.allow = frame.allow.concat(";" + feature_name);36 }37 if (typeof allow_attribute !== 'undefined') {38 frame.setAttribute(allow_attribute, true);39 }40 window.addEventListener('message', test.step_func(function handler(evt) {41 if (evt.source === frame.contentWindow) {42 expect_feature_available(evt.data, feature_description);43 document.body.removeChild(frame);44 window.removeEventListener('message', handler);45 test.done();46 }47 }));48 document.body.appendChild(frame);49}50// Default helper functions to test a feature's availability:51function expect_feature_available_default(data, feature_description) {52 assert_true(data.enabled, feature_description);53}54function expect_feature_unavailable_default(data, feature_description) {55 assert_false(data.enabled, feature_description);56}57// This is the same as test_feature_availability() but instead of passing in a58// function to check the result of the message sent back from an iframe, instead59// just compares the result to an expected result passed in.60// Arguments:61// test: test created by testharness. Examples: async_test, promise_test.62// src: the URL to load in an iframe in which to test the feature.63// expected_result: the expected value to compare to the data passed back64// from the src page by postMessage.65// allow_attribute: Optional argument, only provided when an allow66// attribute should be specified on the iframe.67function test_feature_availability_with_post_message_result(68 test, src, expected_result, allow_attribute) {69 var test_result = function(data, feature_description) {70 assert_equals(data, expected_result);71 };72 test_feature_availability(null, test, src, test_result, allow_attribute);73}74// If this page is intended to test the named feature (according to the URL),75// tests the feature availability and posts the result back to the parent.76// Otherwise, does nothing.77function test_feature_in_iframe(feature_name, feature_promise_factory) {78 if (location.hash.endsWith(`#${feature_name}`)) {79 feature_promise_factory().then(80 () => window.parent.postMessage('#OK', '*'),81 (e) => window.parent.postMessage('#' + e.name, '*'));82 }83}84// Returns true if the URL for this page indicates that it is embedded in an85// iframe.86function page_loaded_in_iframe() {87 return location.hash.startsWith('#iframe');88}89// Returns a same-origin (relative) URL suitable for embedding in an iframe for90// testing the availability of the feature.91function same_origin_url(feature_name) {92 // Append #iframe to the URL so we can detect the iframe'd version of the93 // page.94 return location.pathname + '#iframe#' + feature_name;95}96// Returns a cross-origin (absolute) URL suitable for embedding in an iframe for97// testing the availability of the feature.98function cross_origin_url(base_url, feature_name) {99 return base_url + same_origin_url(feature_name);100}101// This function runs all permissions policy tests for a particular feature that102// has a default policy of "self". This includes testing:103// 1. Feature usage succeeds by default in the top level frame.104// 2. Feature usage succeeds by default in a same-origin iframe.105// 3. Feature usage fails by default in a cross-origin iframe.106// 4. Feature usage succeeds when an allow attribute is specified on a107// cross-origin iframe.108//109// The same page which called this function will be loaded in the iframe in110// order to test feature usage there. When this function is called in that111// context it will simply run the feature and return a result back via112// postMessage.113//114// Arguments:115// cross_origin: A cross-origin URL base to be used to load the page which116// called into this function.117// feature_name: The name of the feature as it should be specified in an118// allow attribute.119// error_name: If feature usage does not succeed, this is the string120// representation of the error that will be passed in the rejected121// promise.122// feature_promise_factory: A function which returns a promise which tests123// feature usage. If usage succeeds, the promise should resolve. If it124// fails, the promise should reject with an error that can be125// represented as a string.126function run_all_fp_tests_allow_self(127 cross_origin, feature_name, error_name, feature_promise_factory) {128 // This may be the version of the page loaded up in an iframe. If so, just129 // post the result of running the feature promise back to the parent.130 if (page_loaded_in_iframe()) {131 test_feature_in_iframe(feature_name, feature_promise_factory);132 return;133 }134 // Run the various tests.135 // 1. Allowed in top-level frame.136 promise_test(137 () => feature_promise_factory(),138 'Default "' + feature_name +139 '" permissions policy ["self"] allows the top-level document.');140 // 2. Allowed in same-origin iframe.141 const same_origin_frame_pathname = same_origin_url(feature_name);142 async_test(143 t => {144 test_feature_availability_with_post_message_result(145 t, same_origin_frame_pathname, '#OK');146 },147 'Default "' + feature_name +148 '" permissions policy ["self"] allows same-origin iframes.');149 // 3. Blocked in cross-origin iframe.150 const cross_origin_frame_url = cross_origin_url(cross_origin, feature_name);151 async_test(152 t => {153 test_feature_availability_with_post_message_result(154 t, cross_origin_frame_url, '#' + error_name);155 },156 'Default "' + feature_name +157 '" permissions policy ["self"] disallows cross-origin iframes.');158 // 4. Allowed in cross-origin iframe with "allow" attribute.159 async_test(160 t => {161 test_feature_availability_with_post_message_result(162 t, cross_origin_frame_url, '#OK', feature_name);163 },164 'permissions policy "' + feature_name +165 '" can be enabled in cross-origin iframes using "allow" attribute.');166}167// This function runs all permissions policy tests for a particular feature that168// has a default policy of "*". This includes testing:169// 1. Feature usage succeeds by default in the top level frame.170// 2. Feature usage succeeds by default in a same-origin iframe.171// 3. Feature usage succeeds by default in a cross-origin iframe.172// 4. Feature usage fails when an allow attribute is specified on a173// cross-origin iframe with a value of "feature-name 'none'".174//175// The same page which called this function will be loaded in the iframe in176// order to test feature usage there. When this function is called in that177// context it will simply run the feature and return a result back via178// postMessage.179//180// Arguments:181// cross_origin: A cross-origin URL base to be used to load the page which182// called into this function.183// feature_name: The name of the feature as it should be specified in an184// allow attribute.185// error_name: If feature usage does not succeed, this is the string186// representation of the error that will be passed in the rejected187// promise.188// feature_promise_factory: A function which returns a promise which tests189// feature usage. If usage succeeds, the promise should resolve. If it190// fails, the promise should reject with an error that can be191// represented as a string.192function run_all_fp_tests_allow_all(193 cross_origin, feature_name, error_name, feature_promise_factory) {194 // This may be the version of the page loaded up in an iframe. If so, just195 // post the result of running the feature promise back to the parent.196 if (page_loaded_in_iframe()) {197 test_feature_in_iframe(feature_name, feature_promise_factory);198 return;199 }200 // Run the various tests.201 // 1. Allowed in top-level frame.202 promise_test(203 () => feature_promise_factory(),204 'Default "' + feature_name +205 '" permissions policy ["*"] allows the top-level document.');206 // 2. Allowed in same-origin iframe.207 const same_origin_frame_pathname = same_origin_url(feature_name);208 async_test(209 t => {210 test_feature_availability_with_post_message_result(211 t, same_origin_frame_pathname, '#OK');212 },213 'Default "' + feature_name +214 '" permissions policy ["*"] allows same-origin iframes.');215 // 3. Allowed in cross-origin iframe.216 const cross_origin_frame_url = cross_origin_url(cross_origin, feature_name);217 async_test(218 t => {219 test_feature_availability_with_post_message_result(220 t, cross_origin_frame_url, '#OK');221 },222 'Default "' + feature_name +223 '" permissions policy ["*"] allows cross-origin iframes.');224 // 4. Blocked in cross-origin iframe with "allow" attribute set to 'none'.225 async_test(226 t => {227 test_feature_availability_with_post_message_result(228 t, cross_origin_frame_url, '#' + error_name,229 feature_name + " 'none'");230 },231 'permissions policy "' + feature_name +232 '" can be disabled in cross-origin iframes using "allow" attribute.');233 // 5. Blocked in same-origin iframe with "allow" attribute set to 'none'.234 async_test(235 t => {236 test_feature_availability_with_post_message_result(237 t, same_origin_frame_pathname, '#' + error_name,238 feature_name + " 'none'");239 },240 'permissions policy "' + feature_name +241 '" can be disabled in same-origin iframes using "allow" attribute.');242}243// This function tests that a subframe's document policy allows a given feature.244// A feature is allowed in a frame either through inherited policy or specified245// by iframe allow attribute.246// Arguments:247// test: test created by testharness. Examples: async_test, promise_test.248// feature: feature name that should be allowed in the frame.249// src: the URL to load in the frame.250// allow: the allow attribute (container policy) of the iframe251function test_allowed_feature_for_subframe(message, feature, src, allow) {252 let frame = document.createElement('iframe');253 if (typeof allow !== 'undefined') {254 frame.allow = allow;255 }256 promise_test(function() {257 assert_permissions_policy_supported();258 frame.src = src;259 return new Promise(function(resolve, reject) {260 window.addEventListener('message', function handler(evt) {261 resolve(evt.data);262 }, { once: true });263 document.body.appendChild(frame);264 }).then(function(data) {265 assert_true(data.includes(feature), feature);266 });267 }, message);268}269// This function tests that a subframe's document policy disallows a given270// feature. A feature is allowed in a frame either through inherited policy or271// specified by iframe allow attribute.272// Arguments:273// test: test created by testharness. Examples: async_test, promise_test.274// feature: feature name that should not be allowed in the frame.275// src: the URL to load in the frame.276// allow: the allow attribute (container policy) of the iframe277function test_disallowed_feature_for_subframe(message, feature, src, allow) {278 let frame = document.createElement('iframe');279 if (typeof allow !== 'undefined') {280 frame.allow = allow;281 }282 promise_test(function() {283 assert_permissions_policy_supported();284 frame.src = src;285 return new Promise(function(resolve, reject) {286 window.addEventListener('message', function handler(evt) {287 resolve(evt.data);288 }, { once: true });289 document.body.appendChild(frame);290 }).then(function(data) {291 assert_false(data.includes(feature), feature);292 });293 }, message);294}295// This function tests that a subframe with header policy defined on a given296// feature allows and disallows the feature as expected.297// Arguments:298// feature: feature name.299// frame_header_policy: either *, self or \\(\\), defines the frame300// document's header policy on |feature|.301// '(' and ')' need to be escaped because of server end302// header parameter syntax limitation.303// src: the URL to load in the frame.304// test_expects: contains 6 expected results of either |feature| is allowed305// or not inside of a local or remote iframe nested inside306// the subframe given the header policy to be either *,307// self, or ().308// test_name: name of the test.309function test_subframe_header_policy(310 feature, frame_header_policy, src, test_expects, test_name) {311 let frame = document.createElement('iframe');312 promise_test(function() {313 assert_permissions_policy_supported()314 frame.src = src + '?pipe=sub|header(Permissions-Policy,' + feature + '='315 + frame_header_policy + ')';316 return new Promise(function(resolve) {317 window.addEventListener('message', function handler(evt) {318 resolve(evt.data);319 });320 document.body.appendChild(frame);321 }).then(function(results) {322 for (var j = 0; j < results.length; j++) {323 var data = results[j];324 function test_result(message, test_expect) {325 if (test_expect) {326 assert_true(data.allowedfeatures.includes(feature), message);327 } else {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert_permissions_policy_supported = wpt_test_utils.assert_permissions_policy_supported;2assert_permissions_policy_supported();3const assert_permissions_policy_supported = wpt_test_utils.assert_permissions_policy_supported;4assert_permissions_policy_supported();5const assert_permissions_policy_supported = wpt_test_utils.assert_permissions_policy_supported;6assert_permissions_policy_supported();7const assert_permissions_policy_supported = wpt_test_utils.assert_permissions_policy_supported;8assert_permissions_policy_supported();9const assert_permissions_policy_supported = wpt_test_utils.assert_permissions_policy_supported;10assert_permissions_policy_supported();11const assert_permissions_policy_supported = wpt_test_utils.assert_permissions_policy_supported;12assert_permissions_policy_supported();13const assert_permissions_policy_supported = wpt_test_utils.assert_permissions_policy_supported;14assert_permissions_policy_supported();15const assert_permissions_policy_supported = wpt_test_utils.assert_permissions_policy_supported;16assert_permissions_policy_supported();17const assert_permissions_policy_supported = wpt_test_utils.assert_permissions_policy_supported;18assert_permissions_policy_supported();

Full Screen

Using AI Code Generation

copy

Full Screen

1test(function() {2 assert_permissions_policy_supported();3}, "Permissions-Policy header is supported");4test(function() {5 assert_permissions_policy_supported(false);6}, "Permissions-Policy header is not supported");7test(function() {8 assert_permissions_policy_supported();9 assert_true(true);10}, "Permissions-Policy header is supported");11test(function() {12 assert_permissions_policy_supported(false);13 assert_true(true);14}, "Permissions-Policy header is not supported");15test(function() {16 assert_permissions_policy_supported();17 assert_permissions_policy_supported();18}, "Permissions-Policy header is supported");19test(function() {20 assert_permissions_policy_supported(false);21 assert_permissions_policy_supported(false);22}, "Permissions-Policy header is not supported");

Full Screen

Using AI Code Generation

copy

Full Screen

1promise_test(async t => {2 assert_permissions_policy_supported();3}, 'Permissions Policy HTTP header is supported');4promise_test(async t => {5 assert_not_equals(6 'assert_permissions_policy_supported method is not supported');7}, 'Permissions Policy HTTP header is not supported');8promise_test(async t => {9 assert_permissions_policy_supported();10}, 'Permissions Policy HTTP header is supported');11promise_test(async t => {12 assert_not_equals(13 'assert_permissions_policy_supported method is not supported');14}, 'Permissions Policy HTTP header is not supported');15promise_test(async t => {16 assert_permissions_policy_supported();17}, 'Permissions Policy HTTP header is supported');18promise_test(async t => {19 assert_not_equals(20 'assert_permissions_policy_supported method is not supported');21}, 'Permissions Policy HTTP header is not supported');22promise_test(async t => {23 assert_permissions_policy_supported();24}, 'Permissions Policy HTTP header is supported');25promise_test(async t => {26 assert_not_equals(27 'assert_permissions_policy_supported method is not supported');28}, 'Permissions Policy HTTP header is not supported');29promise_test(async t => {30 assert_permissions_policy_supported();31}, 'Permissions Policy HTTP header is supported');32promise_test(async t => {33 assert_not_equals(34 'assert_permissions_policy_supported method is not supported');35}, 'Permissions Policy HTTP header is not supported');36promise_test(async t => {37 assert_permissions_policy_supported();38}, 'Permissions Policy HTTP header is supported');39promise_test(async t => {40 assert_not_equals(

Full Screen

Using AI Code Generation

copy

Full Screen

1function assert_permissions_policy_supported() {2 assert_true(3 self.test_driver.is_test_supported(),4 );5}6function assert_permissions_policy_supported() {7 assert_true(8 self.test_driver.is_test_supported(),9 );10}11function assert_permissions_policy_supported() {12 assert_true(13 self.test_driver.is_test_supported(),14 );15}

Full Screen

Using AI Code Generation

copy

Full Screen

1import {assert_permissions_policy_supported} from '/resources/testdriver-vendor.js';2const feature = 'geolocation';3const feature2 = 'camera';4async function runTest() {5 await assert_permissions_policy_supported(feature);6 await assert_permissions_policy_supported(feature2);7}8runTest();

Full Screen

Using AI Code Generation

copy

Full Screen

1setup({explicit_done: true});2assert_permissions_policy_supported();3assert_permissions_policy_supported();4assert_permissions_policy_supported();5assert_permissions_policy_supported();6assert_permissions_policy_supported();7assert_permissions_policy_supported();8assert_permissions_policy_supported();9assert_permissions_policy_supported();10assert_permissions_policy_supported();11assert_permissions_policy_supported();12assert_permissions_policy_supported();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful