How to use testReferrerPolicy method in wpt

Best JavaScript code snippet using wpt

referrer-policy-same-origin.h2.window.js

Source:referrer-policy-same-origin.h2.window.js Github

copy

Full Screen

1// META: script=/common/utils.js2// META: script=resources/early-hints-helpers.sub.js...

Full Screen

Full Screen

referrer-policy-unsafe-url.h2.window.js

Source:referrer-policy-unsafe-url.h2.window.js Github

copy

Full Screen

1// META: script=/common/utils.js2// META: script=resources/early-hints-helpers.sub.js...

Full Screen

Full Screen

referrer-policy-origin.h2.window.js

Source:referrer-policy-origin.h2.window.js Github

copy

Full Screen

1// META: script=/common/utils.js2// META: script=resources/early-hints-helpers.sub.js...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var testReferrerPolicy = function (referrerPolicy) {2 var xhr = new XMLHttpRequest();3 xhr.open("GET", "/common/blank.html", false);4 xhr.setRequestHeader("Referrer-Policy", referrerPolicy);5 xhr.send();6 return xhr.getResponseHeader("Referrer-Policy");7}8var referrerPolicy = testReferrerPolicy("no-referrer");9if (referrerPolicy != "no-referrer")10 throw "Referrer-Policy is not set to no-referrer";11referrerPolicy = testReferrerPolicy("same-origin");12if (referrerPolicy != "same-origin")13 throw "Referrer-Policy is not set to same-origin";14referrerPolicy = testReferrerPolicy("origin-when-cross-origin");15if (referrerPolicy != "origin-when-cross-origin")16 throw "Referrer-Policy is not set to origin-when-cross-origin";17referrerPolicy = testReferrerPolicy("no-referrer-when-downgrade");18if (referrerPolicy != "no-referrer-when-downgrade")19 throw "Referrer-Policy is not set to no-referrer-when-downgrade";20referrerPolicy = testReferrerPolicy("origin");21if (referrerPolicy != "origin")22 throw "Referrer-Policy is not set to origin";23referrerPolicy = testReferrerPolicy("strict-origin");24if (referrerPolicy != "strict-origin")25 throw "Referrer-Policy is not set to strict-origin";26referrerPolicy = testReferrerPolicy("strict-origin-when-cross-origin");27if (referrerPolicy != "strict-origin-when-cross-origin")28 throw "Referrer-Policy is not set to strict-origin-when-cross-origin";29referrerPolicy = testReferrerPolicy("unsafe-url");30if (referrerPolicy != "unsafe-url")31 throw "Referrer-Policy is not set to unsafe-url";

Full Screen

Using AI Code Generation

copy

Full Screen

1function testReferrerPolicy(expectedPolicy, expectedReferrer) {2 var policy = document.referrerPolicy;3 var referrer = document.referrer;4 var result = policy === expectedPolicy && referrer === expectedReferrer;5 var response = result ? "PASS" : "FAIL";6 response += " Expected policy: " + expectedPolicy + " Referrer: " + expectedReferrer;7 response += " Actual policy: " + policy + " Referrer: " + referrer;8 return response;9}

Full Screen

Using AI Code Generation

copy

Full Screen

1function testReferrerPolicy(test, policy, url, expected, description) {2 var url = URL + url;3 var policy = "referrer-policy:" + policy;4 var description = description || "Test " + policy;5 var expected = expected || "no-referrer";6 var requestInit = {"headers": [[policy, ""]]};7 var request = new Request(url, requestInit);8 var requestURL = request.url;9 var requestReferrer = request.referrer;10 var requestMode = request.mode;11 var requestCredentials = request.credentials;12 var requestCache = request.cache;13 var requestRedirect = request.redirect;14 var requestReferrerPolicy = request.referrerPolicy;15 var expectedRequestInit = {"headers": [[policy, ""]]};16 var expectedRequest = new Request(url, expectedRequestInit);17 var expectedRequestURL = expectedRequest.url;18 var expectedRequestReferrer = expectedRequest.referrer;19 var expectedRequestMode = expectedRequest.mode;20 var expectedRequestCredentials = expectedRequest.credentials;21 var expectedRequestCache = expectedRequest.cache;22 var expectedRequestRedirect = expectedRequest.redirect;23 var expectedRequestReferrerPolicy = expectedRequest.referrerPolicy;24 var expectedResponseInit = {"referrer": expected};25 var expectedResponse = new Response(null, expectedResponseInit);26 var expectedResponseReferrer = expectedResponse.referrer;27 var requestInitString = JSON.stringify(requestInit);28 var expectedRequestInitString = JSON.stringify(expectedRequestInit);29 var expectedResponseInitString = JSON.stringify(expectedResponseInit);30 test.step(function() {31 assert_equals(requestURL, expectedRequestURL, "request.url");32 assert_equals(requestReferrer, expectedRequestReferrer, "request.referrer");33 assert_equals(requestMode, expectedRequestMode, "request.mode");34 assert_equals(requestCredentials, expectedRequestCredentials, "request.credentials");35 assert_equals(requestCache, expectedRequestCache, "request.cache");36 assert_equals(requestRedirect, expectedRequestRedirect, "request.redirect");37 assert_equals(requestReferrerPolicy, expectedRequestReferrerPolicy, "request.referrerPolicy");38 assert_equals(requestInitString, expectedRequestInitString, "requestInit");39 assert_equals(expectedResponseReferrer, expected, "response.referrer");40 assert_equals(expectedResponseInitString, expectedResponseInitString, "expectedResponseInit");41 });42 test.done();43}

Full Screen

Using AI Code Generation

copy

Full Screen

1var url = "/referrer-policy/resources/referrer-policy.py";2 "strict-origin-when-cross-origin", "unsafe-url"];3function testReferrerPolicy(test, policy, url, expected) {4 var url = url + "?policy=" + policy + "&url=" + encodeURIComponent(expected);5 var requestInit = {"referrerPolicy": policy};6 var request = new Request(url, requestInit);7 fetch(request).then(function(resp) {8 return resp.text();9 }).then(function(text) {10 test.step(function() {11 assert_equals(text, expected);12 });13 test.done();14 });15}16for (var i = 0; i < policy.length; i++) {17 async_test(function(test) {18 testReferrerPolicy(test, policy[i], url, "about:blank");19 }, "Referrer Policy: " + policy[i]);20}21import urlparse22from wptserve.utils import isomorphic_decode23def main(request, response):24 url = urlparse.urlparse(request.GET["url"])25 url = url.geturl()26 return policy, [("Referrer", url)], ""27 return "FAIL", [("Content-Type", "text/plain")], "FAIL"

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