How to use credFetch method in wpt

Best JavaScript code snippet using wpt

cookie-helper.sub.js

Source:cookie-helper.sub.js Github

copy

Full Screen

...21 if (window.location.hostname != HOST)22 window.location.hostname = HOST;23})();24// A tiny helper which returns the result of fetching |url| with credentials.25function credFetch(url) {26 return fetch(url, {"credentials": "include"});27}28// Returns a URL on |origin| which redirects to a given absolute URL.29function redirectTo(origin, url) {30 return origin + "/cookies/resources/redirectWithCORSHeaders.py?status=307&location=" + encodeURIComponent(url);31}32// Asserts that `document.cookie` contains or does not contain (according to33// the value of |present|) a cookie named |name| with a value of |value|.34function assert_dom_cookie(name, value, present) {35 var re = new RegExp("(?:^|; )" + name + "=" + value + "(?:$|;)");36 assert_equals(re.test(document.cookie), present, "`" + name + "=" + value + "` in `document.cookie`");37}38function assert_cookie(origin, obj, name, value, present) {39 assert_equals(obj[name], present ? value : undefined, "`" + name + "=" + value + "` in request to `" + origin + "`.");40}41// Remove the cookie named |name| from |origin|, then set it on |origin| anew.42// If |origin| matches `self.origin`, also assert (via `document.cookie`) that43// the cookie was correctly removed and reset.44function create_cookie(origin, name, value, extras) {45 alert("Create_cookie: " + origin + "/cookies/resources/drop.py?name=" + name);46 return credFetch(origin + "/cookies/resources/drop.py?name=" + name)47 .then(_ => {48 if (origin == self.origin)49 assert_dom_cookie(name, value, false);50 })51 .then(_ => {52 return credFetch(origin + "/cookies/resources/set.py?" + name + "=" + value + ";path=/;" + extras)53 .then(_ => {54 if (origin == self.origin)55 assert_dom_cookie(name, value, true);56 });57 });58}59//60// Prefix-specific test helpers61//62function set_prefixed_cookie_via_dom_test(options) {63 promise_test(t => {64 var name = options.prefix + "prefixtestcookie";65 erase_cookie_from_js(name);66 var value = "" + Math.random();67 document.cookie = name + "=" + value + ";" + options.params;68 assert_dom_cookie(name, value, options.shouldExistInDOM);69 return credFetch("/cookies/resources/list.py")70 .then(r => r.json())71 .then(cookies => assert_equals(cookies[name], options.shouldExistViaHTTP ? value : undefined));72 }, options.title);73}74function set_prefixed_cookie_via_http_test(options) {75 promise_test(t => {76 var postDelete = _ => {77 var value = "" + Math.random();78 return credFetch(options.origin + "/cookies/resources/set.py?" + name + "=" + value + ";" + options.params)79 .then(_ => credFetch(options.origin + "/cookies/resources/list.py"))80 .then(r => r.json())81 .then(cookies => assert_equals(cookies[name], options.shouldExistViaHTTP ? value : undefined));82 };83 var name = options.prefix + "prefixtestcookie";84 if (!options.origin) {85 options.origin = self.origin;86 erase_cookie_from_js(name);87 return postDelete;88 } else {89 return credFetch(options.origin + "/cookies/resources/drop.py?name=" + name)90 .then(_ => postDelete());91 }92 }, options.title);93}94//95// SameSite-specific test helpers:96//97window.SameSiteStatus = {98 CROSS_SITE: "cross-site",99 LAX: "lax",100 STRICT: "strict"101};102// Reset SameSite test cookies on |origin|. If |origin| matches `self.origin`, assert103// (via `document.cookie`) that they were properly removed and reset.104function resetSameSiteCookies(origin, value) {105 return credFetch(origin + "/cookies/resources/dropSameSite.py")106 .then(_ => {107 if (origin == self.origin) {108 assert_dom_cookie("samesite_strict", value, false);109 assert_dom_cookie("samesite_lax", value, false);110 assert_dom_cookie("samesite_none", value, false);111 }112 })113 .then(_ => {114 return credFetch(origin + "/cookies/resources/setSameSite.py?" + value)115 .then(_ => {116 if (origin == self.origin) {117 assert_dom_cookie("samesite_strict", value, true);118 assert_dom_cookie("samesite_lax", value, true);119 assert_dom_cookie("samesite_none", value, true);120 }121 })122 })123}124// Given an |expectedStatus| and |expectedValue|, assert the |cookies| contains the125// proper set of cookie names and values.126function verifySameSiteCookieState(expectedStatus, expectedValue, cookies) {127 assert_equals(cookies["samesite_none"], expectedValue, "Non-SameSite cookies are always sent.");128 if (expectedStatus == SameSiteStatus.CROSS_SITE) {129 assert_not_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are not sent with cross-site requests.");130 assert_not_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are not sent with cross-site requests.");131 } else if (expectedStatus == SameSiteStatus.LAX) {132 assert_not_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are not sent with lax requests.");133 assert_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are sent with lax requests.");134 } else if (expectedStatus == SameSiteStatus.STRICT) {135 assert_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are sent with strict requests.");136 assert_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are sent with strict requests.");137 }138}139//140// LeaveSecureCookiesAlone-specific test helpers:141//142window.SecureStatus = {143 INSECURE_COOKIE_ONLY: "1",144 BOTH_COOKIES: "2",145};146//Reset SameSite test cookies on |origin|. If |origin| matches `self.origin`, assert147//(via `document.cookie`) that they were properly removed and reset.148function resetSecureCookies(origin, value) {149return credFetch(origin + "/cookies/resources/dropSecure.py")150 .then(_ => {151 if (origin == self.origin) {152 assert_dom_cookie("alone_secure", value, false);153 assert_dom_cookie("alone_insecure", value, false);154 }155 })156 .then(_ => {157 return credFetch(origin + "/cookie/resources/setSecure.py?" + value)158 })159}160//161// DOM based cookie manipulation APIs162//163// erase cookie value and set for expiration164function erase_cookie_from_js(name) {165 let secure = self.location.protocol == "https:" ? "Secure" : "";166 document.cookie = `${name}=0; path=/; expires=${new Date(0).toUTCString()}; ${secure}`;167 var re = new RegExp("(?:^|; )" + name);168 assert_equals(re.test(document.cookie), false, "Sanity check: " + name + " has been deleted.");...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');3 if(err) console.log(err);4 else console.log(data);5});6var wpt = require('wpt');7var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');8wpt.getLocations(function(err, data) {9 if(err) console.log(err);10 else console.log(data);11});12var wpt = require('wpt');13var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');14wpt.getTestResults('140223_9X_1S', function(err, data) {15 if(err) console.log(err);16 else console.log(data);17});18var wpt = require('wpt');19var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');20wpt.getTestStatus('140223_9X_1S', function(err, data) {21 if(err) console.log(err);22 else console.log(data);23});24var wpt = require('wpt');25var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');26wpt.getTesters(function(err, data) {27 if(err) console.log(err);28 else console.log(data);29});30var wpt = require('wpt');31var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');32 if(err) console.log(err);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) return console.log(err);6 console.log(data);7});8var wpt = require('wpt');9var wpt = new WebPageTest('www.webpagetest.org');10var options = {11};12 if (err) return console.log(err);13 console.log(data);14});15wpt.getLocations(function(err, data) {16 if (err) return console.log(err);17 console.log(data);18});19wpt.getTesters(function(err, data) {20 if (err) return console.log(err);21 console.log(data);22});23wpt.getLocations(function(err, data) {24 if (err) return console.log(err);25 console.log(data);26});27wpt.getTesters(function(err, data) {28 if (err) return console.log(err);29 console.log(data);30});31wpt.getTesters(function(err, data) {

Full Screen

Using AI Code Generation

copy

Full Screen

1const credFetch = require('wpt-api').credFetch;2 console.log(data);3});4#### `wpt-api.credFetch(url, [options])`5| `options` | `object` | `{}` | Options to pass to `fetch` |6#### `wpt-api.credFetch.json(url, [options])`7| `options` | `object` | `{}` | Options to pass to `fetch` |8#### `wpt-api.credFetch.text(url, [options])`9| `options` | `object` | `{}` | Options to pass to `fetch` |10#### `wpt-api.agent(url, [options])`11| `options` | `object` | `{}` | Options to pass to `fetch` |12#### `wpt-api.agent.json(url, [options])`13| `options` | `object` | `{}` | Options to pass to `fetch` |14#### `wpt-api.agent.text(url, [options])`

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