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('webpagetest');2var options = {3};4var test = wpt(options);5var options = {6};7test.runTest(url, options, function(err, data) {8 if (err) return console.error(err);9 test.control_request_url(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 console.log(data);12 });13});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if(err) console.log(err);4 else console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8 if(err) console.log(err);9 else console.log(data);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13 if(err) console.log(err);14 else console.log(data);15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org');18 if(err) console.log(err);19 else console.log(data);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23 if(err) console.log(err);24 else console.log(data);25});26var wpt = require('webpagetest');27var wpt = new WebPageTest('www.webpagetest.org');28 if(err) console.log(err);29 else console.log(data);30});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test submitted to WebPagetest for: ' + data.data.url);5 console.log('Test ID: ' + data.data.testId);6 if (err) return console.error(err);7 console.log('Control request url: ' + data);8 });9});10### wpt.control_test_url(testId, callback)11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13 if (err) return console.error(err);14 console.log('Test submitted to WebPagetest for: ' + data.data.url);15 console.log('Test ID: ' + data.data.testId);16 wpt.control_test_url(data.data.testId, function(err, data) {17 if (err) return console.error(err);18 console.log('Control test url: ' + data);19 });20});21### wpt.getLocations(callback)22var wpt = require('webpagetest');23var wpt = new WebPageTest('www.webpagetest.org');24wpt.getLocations(function(err, data) {25 if (err) return console.error(err);26 console.log(data);27});28### wpt.getTesters(callback)
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if(err) return console.log(err);4 console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8wpt.get_locations(function(err, data) {9 if(err) return console.log(err);10 console.log(data);11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14wpt.get_status('150711_3V_1f3', function(err, data) {15 if(err) return console.log(err);16 console.log(data);17});18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org');20wpt.get_testers(function(err, data) {21 if(err) return console.log(err);22 console.log(data);23});24var wpt = require('webpagetest');25var wpt = new WebPageTest('www.webpagetest.org');26wpt.get_testers(function(err, data) {27 if(err) return console.log(err);28 console.log(data);29});30var wpt = require('webpagetest');31var wpt = new WebPageTest('www.webpagetest.org');32wpt.get_testers(function(err, data) {33 if(err) return console.log(err);34 console.log(data);35});
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!!