Best JavaScript code snippet using wpt
cors-preflight-referrer.any.js
Source:cors-preflight-referrer.any.js
1// META: script=/common/utils.js2// META: script=../resources/utils.js3// META: script=/common/get-host-info.sub.js4function corsPreflightReferrer(desc, corsUrl, referrerPolicy, referrer, expectedReferrer) {5 var uuid_token = token();6 var url = corsUrl;7 var urlParameters = "?token=" + uuid_token + "&max_age=0";8 var requestInit = {"mode": "cors", "referrerPolicy": referrerPolicy};9 if (referrer)10 requestInit.referrer = referrer;11 /* Force preflight */12 requestInit["headers"] = {"x-force-preflight": ""};13 urlParameters += "&allow_headers=x-force-preflight";14 promise_test(function(test) {15 return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {16 assert_equals(resp.status, 200, "Clean stash response's status is 200");17 return fetch(url + urlParameters, requestInit).then(function(resp) {18 assert_equals(resp.status, 200, "Response's status is 200");19 assert_equals(resp.headers.get("x-did-preflight"), "1", "Preflight request has been made");20 assert_equals(resp.headers.get("x-preflight-referrer"), expectedReferrer, "Preflight's referrer is correct");21 assert_equals(resp.headers.get("x-referrer"), expectedReferrer, "Request's referrer is correct");22 assert_equals(resp.headers.get("x-control-request-headers"), "", "Access-Control-Allow-Headers value");23 });24 });25 }, desc + " and referrer: " + (referrer ? "'" + referrer + "'" : "default"));26}27var corsUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";28var origin = get_host_info().HTTP_ORIGIN + "/";29corsPreflightReferrer("Referrer policy: no-referrer", corsUrl, "no-referrer", undefined, "");30corsPreflightReferrer("Referrer policy: no-referrer", corsUrl, "no-referrer", "myreferrer", "");31corsPreflightReferrer("Referrer policy: \"\"", corsUrl, "", undefined, origin);32corsPreflightReferrer("Referrer policy: \"\"", corsUrl, "", "myreferrer", origin);33corsPreflightReferrer("Referrer policy: no-referrer-when-downgrade", corsUrl, "no-referrer-when-downgrade", undefined, location.toString())34corsPreflightReferrer("Referrer policy: no-referrer-when-downgrade", corsUrl, "no-referrer-when-downgrade", "myreferrer", new URL("myreferrer", location).toString());35corsPreflightReferrer("Referrer policy: origin", corsUrl, "origin", undefined, origin);36corsPreflightReferrer("Referrer policy: origin", corsUrl, "origin", "myreferrer", origin);37corsPreflightReferrer("Referrer policy: origin-when-cross-origin", corsUrl, "origin-when-cross-origin", undefined, origin);38corsPreflightReferrer("Referrer policy: origin-when-cross-origin", corsUrl, "origin-when-cross-origin", "myreferrer", origin);39corsPreflightReferrer("Referrer policy: unsafe-url", corsUrl, "unsafe-url", undefined, location.toString());...
Using AI Code Generation
1var wptdriver = require('wptdriver');2var wptdriver = require('wptdriver');3var wptdriver = require('wptdriver');4wptdriver.corsPreflightCredentials(true);5var wptdriver = require('wptdriver');6wptdriver.corsPreflightHeaders('Content-Type');7var wptdriver = require('wptdriver');8wptdriver.corsPreflightMethods('GET');9var wptdriver = require('wptdriver');10wptdriver.corsPreflightMaxAge(100);11var wptdriver = require('wptdriver');12var wptdriver = require('wptdriver');13var wptdriver = require('wptdriver');14var wptdriver = require('wptdriver');15var wptdriver = require('wptdriver');
Using AI Code Generation
1var wpt = require('wpt-api');2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8 wpt.corsPreflightOrigin(url, callback)9var wpt = require('wpt-api');10 if (err) {11 console.log(err);12 } else {13 console.log(data);14 }15});16 wpt.corsPreflightCredentials(url, callback)17var wpt = require('wpt-api');18 if (err) {19 console.log(err);20 } else {21 console.log(data);22 }23});24 wpt.corsPreflightMethod(url, callback)
Using AI Code Generation
1var wptdriver = require('wptdriver');2wptdriver.corsPreflightReferrer(function(err, result) {3 console.log(result);4});5window.onload = function() {6 var wptdriver = require('wptdriver');7 wptdriver.corsPreflightReferrer(function(err, result) {8 console.log(result);9 });10}11{12 "requestHeaders": {13 "accept-language": "en-US,en;q=0.8",14 "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36"15 },16 "responseHeaders": {17 "content-type": "text/html; charset=UTF-8",18 "x-xss-protection": "1; mode=block"19 },20}21var wptdriver = require('
Using AI Code Generation
1var wptb = require('wptb');2 console.log("Result: " + result);3});4var wptb = require('wptb');5 console.log("Result: " + result);6});7var wptb = require('wptb');8 console.log("Result: " + result);9});10var wptb = require('wptb');11 console.log("Result: " + result);12});13var wptb = require('wptb');14 console.log("Result: " + result);15});16var wptb = require('wptb');17 console.log("Result: " + result);18});19var wptb = require('wptb');20 console.log("Result: " + result);21});22var wptb = require('wptb');23 console.log("Result: " + result);24});
Using AI Code Generation
1function testCorsPreflightReferrer(){2}3function corsPreflightReferrer(origin, referer, url, expected){4 var xhr = new XMLHttpRequest();5 xhr.open('GET', url, false);6 xhr.setRequestHeader('Origin', origin);7 xhr.setRequestHeader('Referer', referer);8 xhr.send();9 if (xhr.status == 200) {10 if (xhr.getResponseHeader('access-control-allow-origin') == origin) {11 if (xhr.getResponseHeader('access-control-allow-credentials') == 'true') {12 if (xhr.getResponseHeader('access-control-allow-headers') == 'referer') {13 if (xhr.getResponseHeader('access-control-allow-methods') == 'GET') {14 if (xhr.getResponseHeader('access-control-expose-headers') == 'referer') {15 if (xhr.getResponseHeader('access-control-max-age') == '3600') {16 if (xhr.getResponseHeader('referer') == expected) {17 log("PASS: CORS preflight with referrer");18 } else {19 log("FAIL: CORS preflight with referrer: Unexpected referrer " + xhr.getResponseHeader('referer'));20 }21 } else {22 log("FAIL: CORS preflight with referrer: Unexpected access-control-max-age " + xhr.getResponseHeader('access-control-max-age'));23 }24 } else {25 log("FAIL: CORS preflight with referrer: Unexpected access-control-expose-headers " + xhr.getResponseHeader('access-control-expose-headers'));26 }27 } else {28 log("FAIL: CORS preflight with referrer: Unexpected access-control-allow-methods " + xhr.getResponseHeader('access-control-allow-methods'));29 }30 } else {31 log("FAIL: CORS preflight with referrer: Unexpected access-control-allow-headers " + xhr.getResponseHeader('access-control-allow-headers'));32 }33 } else {34 log("FAIL: CORS preflight with referrer: Unexpected access-control-allow-credentials " + xhr.getResponseHeader('access-control-allow-credentials'));
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!!