Best JavaScript code snippet using wpt
script.https.window.js
Source:script.https.window.js
1// META: script=/common/get-host-info.sub.js2// META: script=/common/utils.js3// META: script=/common/dispatcher/dispatcher.js4// META: script=./resources/common.js5window.onload = function() {6 promise_test_parallel(async test => {7 const same_origin = get_host_info().HTTPS_ORIGIN;8 const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;9 const cookie_key = "coep_credentialless_script";10 const cookie_same_origin = "same_origin";11 const cookie_cross_origin = "cross_origin";12 await Promise.all([13 setCookie(same_origin, cookie_key, cookie_same_origin +14 cookie_same_site_none),15 setCookie(cross_origin, cookie_key, cookie_cross_origin +16 cookie_same_site_none),17 ]);18 // One window with COEP:none. (control)19 const w_control_token = token();20 const w_control_url = same_origin + executor_path +21 coep_none + `&uuid=${w_control_token}`22 const w_control = window.open(w_control_url);23 add_completion_callback(() => w_control.close());24 // One window with COEP:credentialless. (experiment)25 const w_credentialless_token = token();26 const w_credentialless_url = same_origin + executor_path +27 coep_credentialless + `&uuid=${w_credentialless_token}`;28 const w_credentialless = window.open(w_credentialless_url);29 add_completion_callback(() => w_credentialless.close());30 let scriptTest = function(31 description, origin, mode,32 expected_cookies_control,33 expected_cookies_credentialless)34 {35 promise_test_parallel(async test => {36 const token_1 = token();37 const token_2 = token();38 send(w_control_token, `39 let script = document.createElement("script");40 script.src = "${showRequestHeaders(origin, token_1)}";41 ${mode};42 document.body.appendChild(script);43 `);44 send(w_credentialless_token, `45 let script = document.createElement("script");46 script.src = "${showRequestHeaders(origin, token_2)}";47 ${mode};48 document.body.appendChild(script);49 `);50 const headers_control = JSON.parse(await receive(token_1));51 const headers_credentialless = JSON.parse(await receive(token_2));52 assert_equals(parseCookies(headers_control)[cookie_key],53 expected_cookies_control,54 "coep:none => ");55 assert_equals(parseCookies(headers_credentialless)[cookie_key],56 expected_cookies_credentialless,57 "coep:credentialless => ");58 }, `script ${description}`)59 };60 // Same-origin request always contains Cookies:61 scriptTest("same-origin + undefined",62 same_origin, '',63 cookie_same_origin,64 cookie_same_origin);65 scriptTest("same-origin + anonymous",66 same_origin, 'script.crossOrigin="anonymous"',67 cookie_same_origin,68 cookie_same_origin);69 scriptTest("same-origin + use-credentials",70 same_origin, 'script.crossOrigin="use-credentials"',71 cookie_same_origin,72 cookie_same_origin);73 // Cross-origin request contains cookies in the following cases:74 // - COEP:credentialless is not set.75 // - script.crossOrigin is `use-credentials`.76 scriptTest("cross-origin + undefined",77 cross_origin, '',78 cookie_cross_origin,79 undefined);80 scriptTest("cross-origin + anonymous",81 cross_origin, 'script.crossOrigin="anonymous"',82 undefined,83 undefined);84 scriptTest("cross-origin + use-credentials",85 cross_origin, 'script.crossOrigin="use-credentials"',86 cookie_cross_origin,87 cookie_cross_origin);88 }, "Main");...
script.tentative.https.window.js
Source:script.tentative.https.window.js
1// META: script=/common/get-host-info.sub.js2// META: script=/common/utils.js3// META: script=/common/dispatcher/dispatcher.js4// META: script=./resources/common.js5promise_test_parallel(async test => {6 const same_origin = get_host_info().HTTPS_ORIGIN;7 const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;8 const cookie_key = "coep_credentialless_script";9 const cookie_same_origin = "same_origin";10 const cookie_cross_origin = "cross_origin";11 await Promise.all([12 setCookie(same_origin, cookie_key, cookie_same_origin +13 cookie_same_site_none),14 setCookie(cross_origin, cookie_key, cookie_cross_origin +15 cookie_same_site_none),16 ]);17 // One window with COEP:none. (control)18 const w_control_token = token();19 const w_control_url = same_origin + executor_path +20 coep_none + `&uuid=${w_control_token}`21 const w_control = window.open(w_control_url);22 add_completion_callback(() => w_control.close());23 // One window with COEP:credentialless. (experiment)24 const w_credentialless_token = token();25 const w_credentialless_url = same_origin + executor_path +26 coep_credentialless + `&uuid=${w_credentialless_token}`;27 const w_credentialless = window.open(w_credentialless_url);28 add_completion_callback(() => w_credentialless.close());29 let scriptTest = function(30 description, origin, mode,31 expected_cookies_control,32 expected_cookies_credentialless)33 {34 promise_test_parallel(async test => {35 const token_1 = token();36 const token_2 = token();37 send(w_control_token, `38 let script = document.createElement("script");39 script.src = "${showRequestHeaders(origin, token_1)}";40 ${mode};41 document.body.appendChild(script);42 `);43 send(w_credentialless_token, `44 let script = document.createElement("script");45 script.src = "${showRequestHeaders(origin, token_2)}";46 ${mode};47 document.body.appendChild(script);48 `);49 const headers_control = JSON.parse(await receive(token_1));50 const headers_credentialless = JSON.parse(await receive(token_2));51 assert_equals(parseCookies(headers_control)[cookie_key],52 expected_cookies_control,53 "coep:none => ");54 assert_equals(parseCookies(headers_credentialless)[cookie_key],55 expected_cookies_credentialless,56 "coep:credentialless => ");57 }, `script ${description}`)58 };59 // Same-origin request always contains Cookies:60 scriptTest("same-origin + undefined",61 same_origin, '',62 cookie_same_origin,63 cookie_same_origin);64 scriptTest("same-origin + anonymous",65 same_origin, 'script.crossOrigin="anonymous"',66 cookie_same_origin,67 cookie_same_origin);68 scriptTest("same-origin + use-credentials",69 same_origin, 'script.crossOrigin="use-credentials"',70 cookie_same_origin,71 cookie_same_origin);72 // Cross-origin request contains cookies in the following cases:73 // - COEP:credentialless is not set.74 // - script.crossOrigin is `use-credentials`.75 scriptTest("cross-origin + undefined",76 cross_origin, '',77 cookie_cross_origin,78 undefined);79 scriptTest("cross-origin + anonymous",80 cross_origin, 'script.crossOrigin="anonymous"',81 undefined,82 undefined);83 scriptTest("cross-origin + use-credentials",84 cross_origin, 'script.crossOrigin="use-credentials"',85 cookie_cross_origin,86 cookie_cross_origin);...
image.https.window.js
Source:image.https.window.js
1// META: script=/common/get-host-info.sub.js2// META: script=/common/utils.js3// META: script=/common/dispatcher/dispatcher.js4// META: script=./resources/common.js5promise_test_parallel(async test => {6 const same_origin = get_host_info().HTTPS_ORIGIN;7 const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;8 const cookie_key = "coep_credentialless_image";9 const cookie_same_origin = "same_origin";10 const cookie_cross_origin = "cross_origin";11 await Promise.all([12 setCookie(same_origin, cookie_key, cookie_same_origin +13 cookie_same_site_none),14 setCookie(cross_origin, cookie_key, cookie_cross_origin +15 cookie_same_site_none),16 ]);17 // One window with COEP:none. (control)18 const w_control_token = token();19 const w_control_url = same_origin + executor_path +20 coep_none + `&uuid=${w_control_token}`21 const w_control = window.open(w_control_url);22 add_completion_callback(() => w_control.close());23 // One window with COEP:credentialless. (experiment)24 const w_credentialless_token = token();25 const w_credentialless_url = same_origin + executor_path +26 coep_credentialless + `&uuid=${w_credentialless_token}`;27 const w_credentialless = window.open(w_credentialless_url);28 add_completion_callback(() => w_credentialless.close());29 let imgTest = function(30 description, origin, mode,31 expected_cookies_control,32 expected_cookies_credentialless)33 {34 promise_test_parallel(async test => {35 const token_1 = token();36 const token_2 = token();37 send(w_control_token, `38 let img = document.createElement("img");39 img.src = "${showRequestHeaders(origin, token_1)}";40 ${mode};41 document.body.appendChild(img);42 `);43 send(w_credentialless_token, `44 let img = document.createElement("img");45 img.src = "${showRequestHeaders(origin, token_2)}";46 ${mode};47 document.body.appendChild(img);48 `);49 const headers_control = JSON.parse(await receive(token_1));50 const headers_credentialless = JSON.parse(await receive(token_2));51 assert_equals(parseCookies(headers_control)[cookie_key],52 expected_cookies_control,53 "coep:none => ");54 assert_equals(parseCookies(headers_credentialless)[cookie_key],55 expected_cookies_credentialless,56 "coep:credentialless => ");57 }, `image ${description}`)58 };59 // Same-origin request always contains Cookies:60 imgTest("same-origin + undefined",61 same_origin, '',62 cookie_same_origin,63 cookie_same_origin);64 imgTest("same-origin + anonymous",65 same_origin, 'img.crossOrigin="anonymous"',66 cookie_same_origin,67 cookie_same_origin);68 imgTest("same-origin + use-credentials",69 same_origin, 'img.crossOrigin="use-credentials"',70 cookie_same_origin,71 cookie_same_origin);72 // Cross-origin request contains cookies in the following cases:73 // - COEP:credentialless is not set.74 // - img.crossOrigin is `use-credentials`.75 imgTest("cross-origin + undefined",76 cross_origin, '',77 cookie_cross_origin,78 undefined);79 imgTest("cross-origin + anonymous",80 cross_origin, 'img.crossOrigin="anonymous"',81 undefined,82 undefined);83 imgTest("cross-origin + use-credentials",84 cross_origin, 'img.crossOrigin="use-credentials"',85 cookie_cross_origin,86 cookie_cross_origin);...
Using AI Code Generation
1async_test(function(t) {2 var headers = new Headers();3 headers.append('X-Test', 'test');4 fetch(url, {headers: headers}).then(function(r) {5 assert_equals(r.headers.get('x-test'), null);6 assert_equals(r.headers.get('x-test2'), 'test2');7 assert_equals(r.headers.get('x-test3'), null);8 assert_equals(r.headers.get('x-test4'), null);9 assert_equals(r.headers.get('x-test5'), null);10 assert_equals(r.headers.get('x-test6'), null);11 assert_equals(r.headers.get('x-test7'), null);12 assert_equals(r.headers.get('x-test8'), null);13 assert_equals(r.headers.get('x-test9'), null);14 assert_equals(r.headers.get('x-test10'), null);15 assert_equals(r.headers.get('x-test11'), null);16 assert_equals(r.headers.get('x-test12'), null);17 assert_equals(r.headers.get('x-test13'), null);18 assert_equals(r.headers.get('x-test14'), null);19 assert_equals(r.headers.get('x-test15'), null);20 assert_equals(r.headers.get('x-test16'), null);21 assert_equals(r.headers.get('x-test17'), null);22 assert_equals(r.headers.get('x-test18'), null);23 assert_equals(r.headers.get('x-test19'), null);24 assert_equals(r.headers.get('x-test20'), null);25 assert_equals(r.headers.get('x-test21'), null);26 assert_equals(r.headers.get('x-test22'), null);27 assert_equals(r.headers.get('x-test23'), null);28 assert_equals(r.headers.get('x-test24'), null);29 assert_equals(r.headers.get('x-test25'), null);
Using AI Code Generation
1var wpt = require('wptdriver');2var options = {3};4wpt.runTest(options, function(err, data) {5 if(err) {6 console.log('Error: ' + err.message);7 } else {8 console.log('Test Complete');9 console.log('First View: ' + data.data.runs[1].firstView.TTFB);10 console.log('Repeat View: ' + data.data.runs[1].repeatView.TTFB);11 }12});13var wpt = require('wptdriver');14var options = {15};16wpt.runTest(options, function(err, data) {17 if(err) {18 console.log('Error: ' + err.message);19 } else {20 console.log('Test Complete');21 console.log('First View: ' + data.data.runs[1].firstView.TTFB);22 console.log('Repeat View: ' + data.data.runs[1].repeatView.TTFB);23 }24});25var wpt = require('wptdriver');26var options = {27};28wpt.runTest(options, function(err, data) {29 if(err) {30 console.log('Error: ' + err.message);31 } else {32 console.log('Test Complete');33 console.log('First View: ' + data.data.runs[1].firstView.TTFB);34 console.log('Repeat View: ' + data.data.runs[
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!!