Best JavaScript code snippet using wpt
service-worker.https.window.js
Source:service-worker.https.window.js
1// META: timeout=long2// META: script=/common/get-host-info.sub.js3// META: script=/common/utils.js4// META: script=/common/dispatcher/dispatcher.js5// META: script=/service-workers/service-worker/resources/test-helpers.sub.js6// META: script=./resources/common.js7const same_origin = get_host_info().HTTPS_ORIGIN;8const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;9const cookie_key = "credentialless_service_worker";10const cookie_same_origin = "same_origin";11const cookie_cross_origin = "cross_origin";12promise_test(async t => {13 await Promise.all([14 setCookie(same_origin, cookie_key, cookie_same_origin +15 cookie_same_site_none),16 setCookie(cross_origin, cookie_key, cookie_cross_origin +17 cookie_same_site_none),18 ]);19 // One iframe with COEP:none. (control)20 const w_control_token = token();21 const w_control_url = same_origin + executor_path +22 coep_none + `&uuid=${w_control_token}`23 const w_control = document.createElement("iframe");24 w_control.src = w_control_url;25 document.body.appendChild(w_control);26 // One iframe with COEP:credentialless. (experiment)27 const w_credentialless_token = token();28 const w_credentialless_url = same_origin + executor_path +29 coep_credentialless + `&uuid=${w_credentialless_token}`;30 const w_credentialless = document.createElement("iframe");31 w_credentialless.src = w_credentialless_url;32 document.body.appendChild(w_credentialless);33 const serviceWorkerTest = function(34 description, origin, coep_for_worker,35 expected_cookies_control,36 expected_cookies_credentialless)37 {38 promise_test(async test => {39 // Create workers for both window.40 const control_worker_token = token();41 const credentialless_worker_token = token();42 const w_control_worker_src = same_origin + executor_worker_path +43 coep_for_worker + `&uuid=${control_worker_token}`;44 const w_control_worker_reg =45 await service_worker_unregister_and_register(46 test, w_control_worker_src, w_control_url);47 const w_credentialless_worker_src = same_origin + executor_worker_path +48 coep_for_worker + `&uuid=${credentialless_worker_token}`;49 const w_credentialless_worker_reg =50 await service_worker_unregister_and_register(51 test, w_credentialless_worker_src, w_credentialless_url);52 // Fetch resources from the workers.53 const control_request_token = token();54 const credentialless_request_token = token();55 const control_request_url = showRequestHeaders(origin, control_request_token);56 const credentialless_request_url = showRequestHeaders(origin, credentialless_request_token);57 send(control_worker_token, `58 fetch("${control_request_url}", {59 mode: 'no-cors',60 credentials: 'include'61 })62 `);63 send(credentialless_worker_token, `64 fetch("${credentialless_request_url}", {65 mode: 'no-cors',66 credentials: 'include'67 })68 `);69 // Retrieve the resource request headers.70 const headers_control = JSON.parse(await receive(control_request_token));71 const headers_credentialless = JSON.parse(await receive(credentialless_request_token));72 assert_equals(parseCookies(headers_control)[cookie_key],73 expected_cookies_control,74 "coep:none => ");75 assert_equals(parseCookies(headers_credentialless)[cookie_key],76 expected_cookies_credentialless,77 "coep:credentialless => ");78 w_control_worker_reg.unregister();79 w_credentialless_worker_reg.unregister();80 }, `fetch ${description}`)81 };82 serviceWorkerTest("same-origin",83 same_origin, coep_none,84 cookie_same_origin,85 cookie_same_origin);86 serviceWorkerTest("same-origin + credentialless worker",87 same_origin, coep_credentialless,88 cookie_same_origin,89 cookie_same_origin);90 serviceWorkerTest("cross-origin",91 cross_origin, coep_none,92 cookie_cross_origin,93 cookie_cross_origin);94 serviceWorkerTest("cross-origin + credentialless worker",95 cross_origin, coep_credentialless,96 undefined,97 undefined);...
service-worker.tentative.https.window.js
Source:service-worker.tentative.https.window.js
1// META: timeout=long2// META: script=/common/get-host-info.sub.js3// META: script=/common/utils.js4// META: script=/common/dispatcher/dispatcher.js5// META: script=/service-workers/service-worker/resources/test-helpers.sub.js6// META: script=./resources/common.js7const same_origin = get_host_info().HTTPS_ORIGIN;8const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;9const cookie_key = "credentialless_service_worker";10const cookie_same_origin = "same_origin";11const cookie_cross_origin = "cross_origin";12promise_test(async t => {13 await Promise.all([14 setCookie(same_origin, cookie_key, cookie_same_origin +15 cookie_same_site_none),16 setCookie(cross_origin, cookie_key, cookie_cross_origin +17 cookie_same_site_none),18 ]);19 // One iframe with COEP:none. (control)20 const w_control_token = token();21 const w_control_url = same_origin + executor_path +22 coep_none + `&uuid=${w_control_token}`23 const w_control = document.createElement("iframe");24 w_control.src = w_control_url;25 document.body.appendChild(w_control);26 // One iframe with COEP:credentialless. (experiment)27 const w_credentialless_token = token();28 const w_credentialless_url = same_origin + executor_path +29 coep_credentialless + `&uuid=${w_credentialless_token}`;30 const w_credentialless = document.createElement("iframe");31 w_credentialless.src = w_credentialless_url;32 document.body.appendChild(w_credentialless);33 const serviceWorkerTest = function(34 description, origin, coep_for_worker,35 expected_cookies_control,36 expected_cookies_credentialless)37 {38 promise_test(async test => {39 // Create workers for both window.40 const control_worker_token = token();41 const credentialless_worker_token = token();42 const w_control_worker_src = same_origin + executor_worker_path +43 coep_for_worker + `&uuid=${control_worker_token}`;44 const w_control_worker_reg =45 await service_worker_unregister_and_register(46 test, w_control_worker_src, w_control_url);47 const w_credentialless_worker_src = same_origin + executor_worker_path +48 coep_for_worker + `&uuid=${credentialless_worker_token}`;49 const w_credentialless_worker_reg =50 await service_worker_unregister_and_register(51 test, w_credentialless_worker_src, w_credentialless_url);52 // Fetch resources from the workers.53 const control_request_token = token();54 const credentialless_request_token = token();55 const control_request_url = showRequestHeaders(origin, control_request_token);56 const credentialless_request_url = showRequestHeaders(origin, credentialless_request_token);57 send(control_worker_token, `58 fetch("${control_request_url}", {59 mode: 'no-cors',60 credentials: 'include'61 })62 `);63 send(credentialless_worker_token, `64 fetch("${credentialless_request_url}", {65 mode: 'no-cors',66 credentials: 'include'67 })68 `);69 // Retrieve the resource request headers.70 const headers_control = JSON.parse(await receive(control_request_token));71 const headers_credentialless = JSON.parse(await receive(credentialless_request_token));72 assert_equals(parseCookies(headers_control)[cookie_key],73 expected_cookies_control,74 "coep:none => ");75 assert_equals(parseCookies(headers_credentialless)[cookie_key],76 expected_cookies_credentialless,77 "coep:credentialless => ");78 w_control_worker_reg.unregister();79 w_credentialless_worker_reg.unregister();80 }, `fetch ${description}`)81 };82 serviceWorkerTest("same-origin",83 same_origin, coep_none,84 cookie_same_origin,85 cookie_same_origin);86 serviceWorkerTest("same-origin + credentialless worker",87 same_origin, coep_credentialless,88 cookie_same_origin,89 cookie_same_origin);90 serviceWorkerTest("cross-origin",91 cross_origin, coep_none,92 cookie_cross_origin,93 cookie_cross_origin);94 serviceWorkerTest("cross-origin + credentialless worker",95 cross_origin, coep_credentialless,96 undefined,97 undefined);...
Using AI Code Generation
1var Wpt = require('wpt');2var wpt = new Wpt('API_KEY');3wpt.controlRequestToken('test', function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});10### new Wpt(apiKey, [options])11### wpt.getLocations([callback])12### wpt.getTests([callback])
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.controlRequestToken('token', 'status', function(err, data) {4 console.log(data);5});6var wpt = require('wpt');7var wpt = new WebPageTest('www.webpagetest.org');8wpt.controlTest('testId', 'action', function(err, data) {9 console.log(data);10});11var wpt = require('wpt');12var wpt = new WebPageTest('www.webpagetest.org');13wpt.getLocations(function(err, data) {14 console.log(data);15});16var wpt = require('wpt');17var wpt = new WebPageTest('www.webpagetest.org');18wpt.getTesters(function(err, data) {19 console.log(data);20});21var wpt = require('wpt');22var wpt = new WebPageTest('www.webpagetest.org');23wpt.getTesters(function(err, data) {24 console.log(data);25});26var wpt = require('wpt');27var wpt = new WebPageTest('www.webpagetest.org');28wpt.getTesters(function(err, data) {29 console.log(data);30});31var wpt = require('wpt');32var wpt = new WebPageTest('www.webpagetest.org');33wpt.getTesters(function(err, data) {34 console.log(data);35});36var wpt = require('wpt');37var wpt = new WebPageTest('www.webpagetest.org');38wpt.getTesters(function(err, data) {39 console.log(data);40});41var wpt = require('wpt');
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!!