How to use fetchReferrerPolicy method in wpt

Best JavaScript code snippet using wpt

assorted.window.js

Source:assorted.window.js Github

copy

Full Screen

...92 const json = await (await fetch(redirectPath + "?dump&stash=" + stash)).json();93 assert_equals(json[0], expectedOrigin);94 };95}96function fetchReferrerPolicy(referrerPolicy, destination, fetchMode, expectedOrigin, httpMethod) {97 return async function () {98 const stash = token();99 const redirectPath = "/fetch/origin/resources/redirect-and-stash.py";100 let fetchUrl =101 (destination === "same-origin" ? origins.HTTP_ORIGIN102 : origins.HTTP_REMOTE_ORIGIN) +103 redirectPath + "?stash=" + stash;104 await fetch(fetchUrl, { mode: fetchMode, method: httpMethod , "referrerPolicy": referrerPolicy});105 const json = await (await fetch(redirectPath + "?dump&stash=" + stash)).json();106 assert_equals(json[0], expectedOrigin);107 };108}109function referrerPolicyTestString(referrerPolicy, method, destination) {110 return "Origin header and " + method + " " + destination + " with Referrer-Policy " +111 referrerPolicy;112}113[114 {115 "policy": "no-referrer",116 "expectedOriginForSameOrigin": "null",117 "expectedOriginForCrossOrigin": "null"118 },119 {120 "policy": "same-origin",121 "expectedOriginForSameOrigin": origins.HTTP_ORIGIN,122 "expectedOriginForCrossOrigin": "null"123 },124 {125 "policy": "origin-when-cross-origin",126 "expectedOriginForSameOrigin": origins.HTTP_ORIGIN,127 "expectedOriginForCrossOrigin": origins.HTTP_ORIGIN128 },129 {130 "policy": "no-referrer-when-downgrade",131 "expectedOriginForSameOrigin": origins.HTTP_ORIGIN,132 "expectedOriginForCrossOrigin": origins.HTTP_ORIGIN133 },134 {135 "policy": "unsafe-url",136 "expectedOriginForSameOrigin": origins.HTTP_ORIGIN,137 "expectedOriginForCrossOrigin": origins.HTTP_ORIGIN138 },139].forEach(testObj => {140 [141 {142 "name": "same-origin",143 "expectedOrigin": testObj.expectedOriginForSameOrigin144 },145 {146 "name": "cross-origin",147 "expectedOrigin": testObj.expectedOriginForCrossOrigin148 }149 ].forEach(destination => {150 // Test form POST navigation151 promise_test(navigationReferrerPolicy(testObj.policy,152 destination.name,153 destination.expectedOrigin),154 referrerPolicyTestString(testObj.policy, "POST",155 destination.name + " navigation"));156 // Test fetch157 promise_test(fetchReferrerPolicy(testObj.policy,158 destination.name,159 "no-cors",160 destination.expectedOrigin,161 "POST"),162 referrerPolicyTestString(testObj.policy, "POST",163 destination.name + " fetch no-cors mode"));164 // Test cors mode POST165 promise_test(fetchReferrerPolicy(testObj.policy,166 destination.name,167 "cors",168 (destination.name == "same-origin") ? destination.expectedOrigin : origins.HTTP_ORIGIN,169 "POST"),170 referrerPolicyTestString(testObj.policy, "POST",171 destination.name + " fetch cors mode"));172 // Test cors mode GET173 promise_test(fetchReferrerPolicy(testObj.policy,174 destination.name,175 "cors",176 (destination.name == "same-origin") ? "no Origin header" : origins.HTTP_ORIGIN,177 "GET"),178 referrerPolicyTestString(testObj.policy, "GET",179 destination.name + " fetch cors mode"));180 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var referrerPolicy = wptReferrerPolicy.fetchReferrerPolicy();2console.log(referrerPolicy);3wptReferrerPolicy.setReferrerPolicy('no-referrer-when-downgrade');4var referrerPolicy = wptReferrerPolicy.fetchReferrerPolicy();5console.log(referrerPolicy);6wptReferrerPolicy.setReferrerPolicy('no-referrer');7var referrerPolicy = wptReferrerPolicy.fetchReferrerPolicy();8console.log(referrerPolicy);9wptReferrerPolicy.setReferrerPolicy('origin-when-cross-origin');10var referrerPolicy = wptReferrerPolicy.fetchReferrerPolicy();11console.log(referrerPolicy);12wptReferrerPolicy.setReferrerPolicy('origin');13var referrerPolicy = wptReferrerPolicy.fetchReferrerPolicy();14console.log(referrerPolicy);15wptReferrerPolicy.setReferrerPolicy('same-origin');16var referrerPolicy = wptReferrerPolicy.fetchReferrerPolicy();17console.log(referrerPolicy);18wptReferrerPolicy.setReferrerPolicy('strict-origin-when-cross-origin');19var referrerPolicy = wptReferrerPolicy.fetchReferrerPolicy();20console.log(referrerPolicy);21wptReferrerPolicy.setReferrerPolicy('strict-origin');22var referrerPolicy = wptReferrerPolicy.fetchReferrerPolicy();23console.log(referrerPolicy);24wptReferrerPolicy.setReferrerPolicy('unsafe-url');25var referrerPolicy = wptReferrerPolicy.fetchReferrerPolicy();26console.log(referrerPolicy);

Full Screen

Using AI Code Generation

copy

Full Screen

1promise_test(function(test) {2 return fetch(url).then(function(resp) {3 assert_equals(resp.url, url);4 assert_equals(resp.type, 'basic');5 assert_equals(resp.status, 200);6 assert_equals(resp.ok, true);7 assert_equals(resp.statusText, 'OK');8 assert_equals(resp.redirected, false);9 assert_equals(resp.headers.get('Content-Type'), 'text/html');10 return resp.text().then(function(body) {11 assert_equals(body, 'origin');12 });13 });14}, 'Check referrer policy: origin');15promise_test(function(test) {16 return fetch(url2).then(function(resp) {17 assert_equals(resp.url, url2);18 assert_equals(resp.type, 'basic');19 assert_equals(resp.status, 200);20 assert_equals(resp.ok, true);21 assert_equals(resp.statusText, 'OK');22 assert_equals(resp.redirected, false);23 assert_equals(resp.headers.get('Content-Type'), 'text/html');24 return resp.text().then(function(body) {25 assert_equals(body, 'origin-when-cross-origin');26 });27 });28}, 'Check referrer policy: origin-when-cross-origin');29promise_test(function(test) {30 return fetch(url, {referrerPolicy: 'no-referrer'}).then(function(resp) {31 assert_equals(resp.url, url);32 assert_equals(resp.type, 'basic');33 assert_equals(resp.status, 200);34 assert_equals(resp.ok, true);35 assert_equals(resp.statusText, 'OK');36 assert_equals(resp.redirected, false);37 assert_equals(resp.headers.get('Content-Type'), 'text/html');38 return resp.text().then(function(body) {39 assert_equals(body, 'no-referrer');40 });41 });42}, 'Check referrer policy: no-referrer');43promise_test(function(test) {44 return fetch(url, {referrerPolicy: 'no-referrer-when-downgrade'}).then(function(resp) {45 assert_equals(resp.url, url);46 assert_equals(resp.type, 'basic');47 assert_equals(resp.status, 200);48 assert_equals(resp.ok, true);49 assert_equals(resp.statusText

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const options = {3};4const wpt = new WebPageTest('www.webpagetest.org', options);5 if (err) {6 console.log('Error: ', err);7 } else {8 console.log('Test Status: ', data.statusText);9 console.log('Test ID: ', data.data.testId);10 console.log('Test URL: ', data.data.summary);11 }12});

Full Screen

Using AI Code Generation

copy

Full Screen

1promise_test(function(test) {2 return fetchReferrerPolicy(url).then(function(policy) {3 assert_equals(policy, "no-referrer");4 });5}, "Test for fetchReferrerPolicy method: default policy");6promise_test(function(test) {7 return fetchReferrerPolicy(url2).then(function(policy) {8 assert_equals(policy, "origin");9 });10}, "Test for fetchReferrerPolicy method: origin policy");11promise_test(function(test) {12 return fetchReferrerPolicy(url3).then(function(policy) {13 assert_equals(policy, "origin-when-cross-origin");14 });15}, "Test for fetchReferrerPolicy method: origin-when-cross-origin policy");16promise_test(function(test) {17 return fetchReferrerPolicy(url4).then(function(policy) {18 assert_equals(policy, "unsafe-url");19 });20}, "Test for fetchReferrerPolicy method: unsafe-url policy");21promise_test(function(test) {22 return fetchReferrerPolicy(url5).then(function(policy) {23 assert_equals(policy, "no-referrer-when-downgrade");24 });25}, "Test for fetchReferrerPolicy method: no-referrer-when-downgrade policy");26promise_test(function(test) {27 return fetchReferrerPolicy(url6).then(function(policy) {28 assert_equals(policy, "no-referrer");29 });30}, "Test for fetchReferrerPolicy method: no-referrer policy");

Full Screen

Using AI Code Generation

copy

Full Screen

1var policy = "same-origin";2var request = new Request(url, {method: "GET", referrerPolicy: policy});3fetch(request).then(function(response) {4 return response.text();5}).then(function(body) {6 document.body.appendChild(document.createTextNode(body));7});8 > + assert_equals(request.referrerPolicy, policy, "request referrer policy should be " + policy); 9 > + assert_equals(request.referrerPolicy, "no-referrer-when-downgrade", "request referrer policy should be no-referrer-when-downgrade"); 10 > + assert_equals(request.referrerPolicy, "origin", "request referrer policy should be origin"); 11 > + assert_equals(request.referrerPolicy, "origin-when-cross-origin", "request referrer policy should be origin-when-cross-origin");

Full Screen

Using AI Code Generation

copy

Full Screen

1var url = "/fetch/api/cors/cors-rp.py?pipe=sub";2var policy = "unsafe-url";3var policy2 = "no-referrer-when-downgrade";4var policy3 = "origin";5var policy4 = "origin-when-cross-origin";6var policy5 = "same-origin";7var policy6 = "strict-origin";8var policy7 = "strict-origin-when-cross-origin";9var policy8 = "no-referrer";10var policy9 = "unsafe-url";11var policy10 = "no-referrer-when-downgrade";12var policy11 = "origin";13var policy12 = "origin-when-cross-origin";14var policy13 = "same-origin";

Full Screen

Using AI Code Generation

copy

Full Screen

1function fetchReferrerPolicy(policy) {2 var url = "/common/security-features/subresource/feature-policy/resources/feature-policy-iframe.html";3 var requestInit = {"referrer": referrer, "referrerPolicy": policy};4 var request = new Request(url, requestInit);5 return fetch(request);6}7promise_test(function() {8 return fetchReferrerPolicy("no-referrer-when-downgrade")9 .then(function(response) {10 assert_equals(response.headers.get("referrer-policy"), null, "Referrer policy should not be set");11 });12}, "Referrer policy should not be set when the referrer policy is set to no-referrer-when-downgrade and the request is not a secure request");13function fetchReferrerPolicy(policy) {14 var url = "/common/security-features/subresource/feature-policy/resources/feature-policy-iframe.html";15 var requestInit = {"referrer": referrer, "referrerPolicy": policy};16 var request = new Request(url, requestInit);17 return fetch(request);18}19promise_test(function() {20 return fetchReferrerPolicy("no-referrer-when-downgrade")21 .then(function(response) {22 assert_equals(response.headers.get("referrer-policy"), null, "Referrer policy should not be set");23 });24}, "Referrer policy should not be set when the referrer policy is set to no-referrer-when-downgrade and the request is not a secure request");

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