Best JavaScript code snippet using wpt
generic-sensor-feature-policy-test.js
Source:generic-sensor-feature-policy-test.js
1const feature_policies = {2 "AmbientLightSensor" : ["ambient-light-sensor"],3 "Accelerometer" : ["accelerometer"],4 "LinearAccelerationSensor" : ["accelerometer"],5 "GravitySensor" : ["accelerometer"],6 "Gyroscope" : ["gyroscope"],7 "GeolocationSensor" : ["geolocation"],8 "Magnetometer" : ["magnetometer"],9 "UncalibratedMagnetometer" : ["magnetometer"],10 "AbsoluteOrientationSensor" : ["accelerometer", "gyroscope", "magnetometer"],11 "RelativeOrientationSensor" : ["accelerometer", "gyroscope"]12};13const same_origin_src =14 "/feature-policy/resources/feature-policy-generic-sensor.html#";15const cross_origin_src =16 "https://{{domains[www]}}:{{ports[https][0]}}" + same_origin_src;17const base_src = "/feature-policy/resources/redirect-on-load.html#";18function run_fp_tests_disabled(sensorType) {19 const sensorName = sensorType.name;20 const featureNameList = feature_policies[sensorName];21 const header = "Feature-Policy header " + featureNameList.join(" 'none';") + " 'none'";22 const desc = "'new " + sensorName + "()'";23 test(() => {24 assert_throws("SecurityError", () => {new sensorType()});25 }, `${sensorName}: ${header} disallows the top-level document.`);26 async_test(t => {27 test_feature_availability(28 desc,29 t,30 same_origin_src + sensorName,31 expect_feature_unavailable_default32 );33 }, `${sensorName}: ${header} disallows same-origin iframes.`);34 async_test(t => {35 test_feature_availability(36 desc,37 t,38 cross_origin_src + sensorName,39 expect_feature_unavailable_default40 );41 }, `${sensorName}: ${header} disallows cross-origin iframes.`);42}43function run_fp_tests_enabled(sensorType) {44 const sensorName = sensorType.name;45 const featureNameList = feature_policies[sensorName];46 const header = "Feature-Policy header " + featureNameList.join(" *;") + " *";47 const desc = "'new " + sensorName + "()'";48 test(() => {49 assert_true(sensorName in window);50 }, `${sensorName}: ${header} allows the top-level document.`);51 async_test(t => {52 test_feature_availability(53 desc,54 t,55 same_origin_src + sensorName,56 expect_feature_available_default57 );58 }, `${sensorName}: ${header} allows same-origin iframes.`);59 async_test(t => {60 test_feature_availability(61 desc,62 t,63 cross_origin_src + sensorName,64 expect_feature_available_default65 );66 }, `${sensorName}: ${header} allows cross-origin iframes.`);67}68function run_fp_tests_enabled_by_attribute(sensorType) {69 const sensorName = sensorType.name;70 const featureNameList = feature_policies[sensorName];71 const header = "Feature-Policy allow='" + featureNameList.join(" ") + "' attribute";72 const desc = "'new " + sensorName + "()'";73 async_test(t => {74 test_feature_availability(75 desc,76 t,77 same_origin_src + sensorName,78 expect_feature_available_default,79 featureNameList.join(";")80 );81 }, `${sensorName}: ${header} allows same-origin iframe`);82 async_test(t => {83 test_feature_availability(84 desc,85 t,86 cross_origin_src + sensorName,87 expect_feature_available_default,88 featureNameList.join(";")89 );90 }, `${sensorName}: ${header} allows cross-origin iframe`);91}92function run_fp_tests_enabled_by_attribute_redirect_on_load(sensorType) {93 const sensorName = sensorType.name;94 const featureNameList = feature_policies[sensorName];95 const header = "Feature-Policy allow='" + featureNameList.join(" ") + "' attribute";96 const desc = "'new " + sensorName + "()'";97 async_test(t => {98 test_feature_availability(99 desc,100 t,101 base_src + same_origin_src + sensorName,102 expect_feature_available_default,103 featureNameList.join(";")104 );105 }, `${sensorName}: ${header} allows same-origin relocation`);106 async_test(t => {107 test_feature_availability(108 desc,109 t,110 base_src + cross_origin_src + sensorName,111 expect_feature_unavailable_default,112 featureNameList.join(";")113 );114 }, `${sensorName}: ${header} disallows cross-origin relocation`);115}116function run_fp_tests_enabled_on_self_origin(sensorType) {117 const sensorName = sensorType.name;118 const featureNameList = feature_policies[sensorName];119 const header = "Feature-Policy header " + featureNameList.join(" 'self';") + " 'self'";120 const desc = "'new " + sensorName + "()'";121 test(() => {122 assert_true(sensorName in window);123 }, `${sensorName}: ${header} allows the top-level document.`);124 async_test(t => {125 test_feature_availability(126 desc,127 t,128 same_origin_src + sensorName,129 expect_feature_available_default130 );131 }, `${sensorName}: ${header} allows same-origin iframes.`);132 async_test(t => {133 test_feature_availability(134 desc,135 t,136 cross_origin_src + sensorName,137 expect_feature_unavailable_default138 );139 }, `${sensorName}: ${header} disallows cross-origin iframes.`);...
generic-sensor-feature-policy-test.sub.js
Source:generic-sensor-feature-policy-test.sub.js
1const feature_policies = {2 "AmbientLightSensor" : ["ambient-light-sensor"],3 "Accelerometer" : ["accelerometer"],4 "LinearAccelerationSensor" : ["accelerometer"],5 "GravitySensor" : ["accelerometer"],6 "Gyroscope" : ["gyroscope"],7 "GeolocationSensor" : ["geolocation"],8 "Magnetometer" : ["magnetometer"],9 "UncalibratedMagnetometer" : ["magnetometer"],10 "AbsoluteOrientationSensor" : ["accelerometer", "gyroscope", "magnetometer"],11 "RelativeOrientationSensor" : ["accelerometer", "gyroscope"]12};13const same_origin_src =14 "/feature-policy/resources/feature-policy-generic-sensor.html#";15const cross_origin_src =16 "https://{{domains[www]}}:{{ports[https][0]}}" + same_origin_src;17const base_src = "/feature-policy/resources/redirect-on-load.html#";18function run_fp_tests_disabled(sensorType) {19 const sensorName = sensorType.name;20 const featureNameList = feature_policies[sensorName];21 const header = "Feature-Policy header " + featureNameList.join(" 'none';") + " 'none'";22 const desc = "'new " + sensorName + "()'";23 test(() => {24 assert_throws("SecurityError", () => {new sensorType()});25 }, `${sensorName}: ${header} disallows the top-level document.`);26 async_test(t => {27 test_feature_availability(28 desc,29 t,30 same_origin_src + sensorName,31 expect_feature_unavailable_default32 );33 }, `${sensorName}: ${header} disallows same-origin iframes.`);34 async_test(t => {35 test_feature_availability(36 desc,37 t,38 cross_origin_src + sensorName,39 expect_feature_unavailable_default40 );41 }, `${sensorName}: ${header} disallows cross-origin iframes.`);42}43function run_fp_tests_enabled(sensorType) {44 const sensorName = sensorType.name;45 const featureNameList = feature_policies[sensorName];46 const header = "Feature-Policy header " + featureNameList.join(" *;") + " *";47 const desc = "'new " + sensorName + "()'";48 test(() => {49 assert_true(sensorName in window);50 }, `${sensorName}: ${header} allows the top-level document.`);51 async_test(t => {52 test_feature_availability(53 desc,54 t,55 same_origin_src + sensorName,56 expect_feature_available_default57 );58 }, `${sensorName}: ${header} allows same-origin iframes.`);59 async_test(t => {60 test_feature_availability(61 desc,62 t,63 cross_origin_src + sensorName,64 expect_feature_available_default65 );66 }, `${sensorName}: ${header} allows cross-origin iframes.`);67}68function run_fp_tests_enabled_by_attribute(sensorType) {69 const sensorName = sensorType.name;70 const featureNameList = feature_policies[sensorName];71 const header = "Feature-Policy allow='" + featureNameList.join(" ") + "' attribute";72 const desc = "'new " + sensorName + "()'";73 async_test(t => {74 test_feature_availability(75 desc,76 t,77 same_origin_src + sensorName,78 expect_feature_available_default,79 featureNameList.join(";")80 );81 }, `${sensorName}: ${header} allows same-origin iframe`);82 async_test(t => {83 test_feature_availability(84 desc,85 t,86 cross_origin_src + sensorName,87 expect_feature_available_default,88 featureNameList.join(";")89 );90 }, `${sensorName}: ${header} allows cross-origin iframe`);91}92function run_fp_tests_enabled_by_attribute_redirect_on_load(sensorType) {93 const sensorName = sensorType.name;94 const featureNameList = feature_policies[sensorName];95 const header = "Feature-Policy allow='" + featureNameList.join(" ") + "' attribute";96 const desc = "'new " + sensorName + "()'";97 async_test(t => {98 test_feature_availability(99 desc,100 t,101 base_src + same_origin_src + sensorName,102 expect_feature_available_default,103 featureNameList.join(";")104 );105 }, `${sensorName}: ${header} allows same-origin relocation`);106 async_test(t => {107 test_feature_availability(108 desc,109 t,110 base_src + cross_origin_src + sensorName,111 expect_feature_unavailable_default,112 featureNameList.join(";")113 );114 }, `${sensorName}: ${header} disallows cross-origin relocation`);115}116function run_fp_tests_enabled_on_self_origin(sensorType) {117 const sensorName = sensorType.name;118 const featureNameList = feature_policies[sensorName];119 const header = "Feature-Policy header " + featureNameList.join(" 'self';") + " 'self'";120 const desc = "'new " + sensorName + "()'";121 test(() => {122 assert_true(sensorName in window);123 }, `${sensorName}: ${header} allows the top-level document.`);124 async_test(t => {125 test_feature_availability(126 desc,127 t,128 same_origin_src + sensorName,129 expect_feature_available_default130 );131 }, `${sensorName}: ${header} allows same-origin iframes.`);132 async_test(t => {133 test_feature_availability(134 desc,135 t,136 cross_origin_src + sensorName,137 expect_feature_unavailable_default138 );139 }, `${sensorName}: ${header} disallows cross-origin iframes.`);...
Using AI Code Generation
1expect_feature_available_default("feature1");2expect_feature_available_default("feature1");3expect_feature_available_default("feature2");4expect_feature_available_default("feature2");5expect_feature_available_default("feature3");6expect_feature_available_default("feature3");
Using AI Code Generation
1importScripts('/resources/testharness.js');2importScripts('/resources/testharnessreport.js');3importScripts('/resources/testdriver.js');4importScripts('/resources/testdriver-vendor.js');5importScripts('/resources/testdriver-actions.js');6importScripts('/resources/wpt-test-utils.js');7test(function() {8 expect_feature_available_default('foo', 'bar');9}, 'foo feature is available');10done();11test(function() {12 return expect_feature_available_default('foo', 'bar');13}, 'foo feature is available');
Using AI Code Generation
1async_test(function() {2 test_driver.expect_feature_available_default("testFeature").then(function(result) {3 assert_true(result);4 this.done();5 }, function(error) {6 assert_unreached(error);7 });8}, "Check if testFeature is available.");9interface TestDriver {10 Promise<boolean> expect_feature_available_default(DOMString feature);11};
Using AI Code Generation
1import { expect_feature_available_default } from './wpt.js';2expect_feature_available_default("feature_name");3import { expect_feature_available_default } from './wpt.js';4expect_feature_available_default("feature_name");5import { expect_feature_available_default } from './wpt.js';6expect_feature_available_default("feature_name");7import { expect_feature_available_default } from './wpt.js';8expect_feature_available_default("feature_name");9import { expect_feature_available_default } from './wpt.js';10expect_feature_available_default("feature_name");11import { expect_feature_available_default } from './wpt.js';12expect_feature_available_default("feature_name");
Using AI Code Generation
1function test() {2 return new Promise((resolve, reject) => {3 window.wpt.expect_feature_available_default('test', resolve, reject);4 });5}6test().then(() => {7 console.log('Feature is available.');8}, () => {9 console.log('Feature is not available.');10});11function test() {12 return new Promise((resolve, reject) => {13 window.wpt.expect_feature_available_default('test2', resolve, reject);14 });15}16test().then(() => {17 console.log('Feature is available.');18}, () => {19 console.log('Feature is not available.');20});21function test() {22 return new Promise((resolve, reject) => {23 window.wpt.expect_feature_available_default('test3', resolve, reject);24 });25}26test().then(() => {27 console.log('Feature is available.');28}, () => {29 console.log('Feature is not available.');30});31function test() {32 return new Promise((resolve, reject) => {33 window.wpt.expect_feature_available_default('test4', resolve, reject);34 });35}36test().then(() => {37 console.log('Feature is available.');38}, () => {39 console.log('Feature is not available.');40});41function test() {42 return new Promise((resolve, reject) => {43 window.wpt.expect_feature_available_default('test5', resolve, reject);44 });45}46test().then(() => {47 console.log('Feature is available.');48}, () => {49 console.log('Feature is not available.');50});51function test() {52 return new Promise((resolve, reject) => {53 window.wpt.expect_feature_available_default('test6', resolve, reject);54 });55}56test().then(() => {57 console.log('Feature is available.');58}, () => {59 console.log('Feature is not available
Using AI Code Generation
1expect_feature_available_default(feature);2expect_feature_available_default(feature, 'description');3expect_feature_not_available_default(feature);4expect_feature_not_available_default(feature, 'description');5expect_feature_available_default(feature);6expect_feature_available_default(feature, 'description');7expect_feature_not_available_default(feature);8expect_feature_not_available_default(feature, 'description');9expect_feature_available_default(feature);10expect_feature_available_default(feature, 'description');11expect_feature_not_available_default(feature);12expect_feature_not_available_default(feature, 'description');13expect_feature_available_default(feature);14expect_feature_available_default(feature, 'description');15expect_feature_not_available_default(feature);16expect_feature_not_available_default(feature, 'description');
Using AI Code Generation
1function test() {2 let result = wpt_test_driver.expect_feature_available_default(3 "FeatureName", "FeatureDescription");4 if (result == "enabled") {5 } else if (result == "disabled") {6 } else {7 }8}
Using AI Code Generation
1function test() {2 var feature = "WebGL";3 var result = expect_feature_available_default(feature);4 if (!result) {5 testFailed("Feature: " + feature + " is not available by default");6 } else {7 testPassed("Feature: " + feature + " is available by default");8 }9}10function test() {11 var feature = "WebGL";12 var result = expect_feature_available_default(feature);13 if (!result) {14 testFailed("Feature: " + feature + " is not available by default");15 } else {16 testPassed("Feature: " + feature + " is available by default");17 }18}19function test() {20 var feature = "WebGL";21 var result = expect_feature_available_default(feature);22 if (!result) {23 testFailed("Feature: " + feature + " is not available by default");24 } else {25 testPassed("Feature: " + feature + " is available by default");26 }27}
Using AI Code Generation
1import {expect_feature_available_default} from './resources/test-helpers.js';2const feature = 'WebXR';3const test = await initWebGPUCase({4});5expect_feature_available_default(test, feature);6test.skip()7initWebGPUCase()8initWebGPUCase()9The test.skip() method is defined in the
Using AI Code Generation
1var wptdriver = require('wptdriver');2wptdriver.expect_feature_available_default('FileReader', true);3wptdriver.expect_feature_available_default('FileReader', true);4import wptdriver5wptdriver.expect_feature_available_default('FileReader', true)6require_once('wptdriver.php');7wptdriver_expect_feature_available_default('FileReader', true);8require_once('wptdriver.php');9wptdriver_expect_feature_available_default('FileReader', true);10require_once('wptdriver.php');11wptdriver_expect_feature_available_default('FileReader', true);12require_once('wptdriver.php');13wptdriver_expect_feature_available_default('FileReader', true);14require_once('wptdriver.php');15wptdriver_expect_feature_available_default('FileReader', true);16require_once('wptdriver.php');17wptdriver_expect_feature_available_default('FileReader', true);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!