How to use feature_promise_factory method in wpt

Best JavaScript code snippet using wpt

featurepolicy.js

Source:featurepolicy.js Github

copy

Full Screen

...70// tests the feature availability and posts the result back to the parent.71// Otherwise, does nothing.72function test_feature_in_iframe(feature_name, feature_promise_factory) {73 if (location.hash.includes(feature_name)) {74 feature_promise_factory().then(75 () => window.parent.postMessage('#OK', '*'),76 (e) => window.parent.postMessage('#' + e.name, '*'));77 }78}79// Returns true if the URL for this page indicates that it is embedded in an80// iframe.81function page_loaded_in_iframe() {82 return location.hash.startsWith('#iframe');83}84// Returns a same-origin (relative) URL suitable for embedding in an iframe for85// testing the availability of the feature.86function same_origin_url(feature_name) {87 // Append #iframe to the URL so we can detect the iframe'd version of the88 // page.89 return location.pathname + '#iframe#' + feature_name;90}91// Returns a cross-origin (absolute) URL suitable for embedding in an iframe for92// testing the availability of the feature.93function cross_origin_url(base_url, feature_name) {94 return base_url + same_origin_url(feature_name);95}96// This function runs all feature policy tests for a particular feature that97// has a default policy of "self". This includes testing:98// 1. Feature usage succeeds by default in the top level frame.99// 2. Feature usage succeeds by default in a same-origin iframe.100// 3. Feature usage fails by default in a cross-origin iframe.101// 4. Feature usage suceeds when an allow attribute is specified on a102// cross-origin iframe.103//104// The same page which called this function will be loaded in the iframe in105// order to test feature usage there. When this function is called in that106// context it will simply run the feature and return a result back via107// postMessage.108//109// Arguments:110// cross_origin: A cross-origin URL base to be used to load the page which111// called into this function.112// feature_name: The name of the feature as it should be specified in an113// allow attribute.114// error_name: If feature usage does not succeed, this is the string115// representation of the error that will be passed in the rejected116// promise.117// feature_promise_factory: A function which returns a promise which tests118// feature usage. If usage succeeds, the promise should resolve. If it119// fails, the promise should reject with an error that can be120// represented as a string.121function run_all_fp_tests_allow_self(122 cross_origin, feature_name, error_name, feature_promise_factory) {123 // This may be the version of the page loaded up in an iframe. If so, just124 // post the result of running the feature promise back to the parent.125 if (page_loaded_in_iframe()) {126 test_feature_in_iframe(feature_name, feature_promise_factory);127 return;128 }129 // Run the various tests.130 // 1. Allowed in top-level frame.131 promise_test(132 () => feature_promise_factory(),133 'Default "' + feature_name +134 '" feature policy ["self"] allows the top-level document.');135 // 2. Allowed in same-origin iframe.136 const same_origin_frame_pathname = same_origin_url(feature_name);137 async_test(138 t => {139 test_feature_availability_with_post_message_result(140 t, same_origin_frame_pathname, '#OK');141 },142 'Default "' + feature_name +143 '" feature policy ["self"] allows same-origin iframes.');144 // 3. Blocked in cross-origin iframe.145 const cross_origin_frame_url = cross_origin_url(cross_origin, feature_name);146 async_test(147 t => {148 test_feature_availability_with_post_message_result(149 t, cross_origin_frame_url, '#' + error_name);150 },151 'Default "' + feature_name +152 '" feature policy ["self"] disallows cross-origin iframes.');153 // 4. Allowed in cross-origin iframe with "allow" attribute.154 async_test(155 t => {156 test_feature_availability_with_post_message_result(157 t, cross_origin_frame_url, '#OK', feature_name);158 },159 'Feature policy "' + feature_name +160 '" can be enabled in cross-origin iframes using "allow" attribute.');161}162// This function runs all feature policy tests for a particular feature that163// has a default policy of "*". This includes testing:164// 1. Feature usage succeeds by default in the top level frame.165// 2. Feature usage succeeds by default in a same-origin iframe.166// 3. Feature usage succeeds by default in a cross-origin iframe.167// 4. Feature usage fails when an allow attribute is specified on a168// cross-origin iframe with a value of "feature-name 'none'".169//170// The same page which called this function will be loaded in the iframe in171// order to test feature usage there. When this function is called in that172// context it will simply run the feature and return a result back via173// postMessage.174//175// Arguments:176// cross_origin: A cross-origin URL base to be used to load the page which177// called into this function.178// feature_name: The name of the feature as it should be specified in an179// allow attribute.180// error_name: If feature usage does not succeed, this is the string181// representation of the error that will be passed in the rejected182// promise.183// feature_promise_factory: A function which returns a promise which tests184// feature usage. If usage succeeds, the promise should resolve. If it185// fails, the promise should reject with an error that can be186// represented as a string.187function run_all_fp_tests_allow_all(188 cross_origin, feature_name, error_name, feature_promise_factory) {189 // This may be the version of the page loaded up in an iframe. If so, just190 // post the result of running the feature promise back to the parent.191 if (page_loaded_in_iframe()) {192 test_feature_in_iframe(feature_name, feature_promise_factory);193 return;194 }195 // Run the various tests.196 // 1. Allowed in top-level frame.197 promise_test(198 () => feature_promise_factory(),199 'Default "' + feature_name +200 '" feature policy ["*"] allows the top-level document.');201 // 2. Allowed in same-origin iframe.202 const same_origin_frame_pathname = same_origin_url(feature_name);203 async_test(204 t => {205 test_feature_availability_with_post_message_result(206 t, same_origin_frame_pathname, '#OK');207 },208 'Default "' + feature_name +209 '" feature policy ["*"] allows same-origin iframes.');210 // 3. Allowed in cross-origin iframe.211 const cross_origin_frame_url = cross_origin_url(cross_origin, feature_name);212 async_test(...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const test = wpt('API_KEY');3 features: test.feature_promise_factory('firstPaint')4}, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11const wpt = require('webpagetest');12const test = wpt('API_KEY');13 features: test.feature_promise_factory('firstPaint', 'SpeedIndex')14}, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21const wpt = require('webpagetest');22const test = wpt('API_KEY');23 features: test.feature_promise_factory(['firstPaint', 'SpeedIndex'])24}, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wpt = new wpt('your api key');3var params = {4};5wpt.feature_promise_factory('getLocations', params).then(function (data) {6 console.log(data);7}).catch(function (err) {8 console.log(err);9});10var WebPageTest = require('webpagetest');11var Promise = require('bluebird');12var Wpt = function (apiKey) {13 this.apiKey = apiKey;14 this.wpt = Promise.promisifyAll(new WebPageTest('www.webpagetest.org', this.apiKey));15};16Wpt.prototype.feature_promise_factory = function (feature, params) {17 return this.wpt[feature + 'Async'](params);18};19module.exports = Wpt;

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