How to use crossOriginRedirect method in wpt

Best JavaScript code snippet using wpt

resource-timing-sizes-redirect.js

Source:resource-timing-sizes-redirect.js Github

copy

Full Screen

1// This test code is shared between resource-timing-sizes-redirect.html and2// resource-timing-sizes-redirect-worker.html3if (typeof document === 'undefined') {4 importScripts('/resources/testharness.js',5 '/resources/get-host-info.js?pipe=sub',6 '/misc/resources/run-async-tasks-promise.js');7}8const baseUrl =9 new URL('/security/resources/cors-hello.php', location.href).href;10const expectedSize = 73;11// Because apache decrements the Keep-Alive max value on each request, the12// transferSize will vary slightly between requests for the same resource.13const fuzzFactor = 3; // bytes14const minHeaderSize = 100;15const hostInfo = get_host_info();16var directUrl, sameOriginRedirect, crossOriginRedirect, mixedRedirect;17var complexRedirect;18function checkBodySizeFields(entry) {19 assert_equals(entry.decodedBodySize, expectedSize, 'decodedBodySize');20 assert_equals(entry.encodedBodySize, expectedSize, 'encodedBodySize');21}22function checkResourceSizes() {23 var entries = performance.getEntriesByType('resource');24 var lowerBound, upperBound, withRedirectLowerBound;25 var seenCount = 0;26 for (var entry of entries) {27 switch (entry.name) {28 case directUrl:29 checkBodySizeFields(entry);30 assert_greater_than(entry.transferSize, expectedSize,31 'transferSize');32 lowerBound = entry.transferSize - fuzzFactor;33 upperBound = entry.transferSize + fuzzFactor;34 withRedirectLowerBound = entry.transferSize + minHeaderSize;35 ++seenCount;36 break;37 case sameOriginRedirect:38 checkBodySizeFields(entry);39 assert_greater_than(entry.transferSize, withRedirectLowerBound,40 'transferSize');41 ++seenCount;42 break;43 case crossOriginRedirect:44 case mixedRedirect:45 case complexRedirect:46 checkBodySizeFields(entry);47 assert_between_exclusive(entry.transferSize, lowerBound, upperBound,48 'transferSize');49 ++seenCount;50 break;51 default:52 break;53 }54 }55 assert_equals(seenCount, 5, 'seenCount');56}57function redirectUrl(redirectSourceOrigin, allowOrigin, targetUrl) {58 return redirectSourceOrigin +59 '/resources/redirect.php?cors_allow_origin=' +60 encodeURIComponent(allowOrigin) +61 '&url=' + encodeURIComponent(targetUrl);62}63promise_test(() => {64 // Use a different URL every time so that the cache behaviour does not65 // depend on execution order.66 directUrl = baseUrl + '?unique=' + Math.random().toString().substring(2) +67 '&cors=*';68 sameOriginRedirect = redirectUrl(hostInfo.HTTP_ORIGIN, '*', directUrl);69 crossOriginRedirect = redirectUrl(hostInfo.HTTP_REMOTE_ORIGIN,70 hostInfo.HTTP_ORIGIN, directUrl);71 mixedRedirect = redirectUrl(hostInfo.HTTP_REMOTE_ORIGIN,72 hostInfo.HTTP_ORIGIN, sameOriginRedirect);73 complexRedirect = redirectUrl(hostInfo.HTTP_ORIGIN,74 hostInfo.HTTP_REMOTE_ORIGIN, mixedRedirect);75 var eatBody = response => response.arrayBuffer();76 return fetch(directUrl)77 .then(eatBody)78 .then(() => fetch(sameOriginRedirect))79 .then(eatBody)80 .then(() => fetch(crossOriginRedirect))81 .then(eatBody)82 .then(() => fetch(mixedRedirect))83 .then(eatBody)84 .then(() => fetch(complexRedirect))85 .then(eatBody)86 .then(runAsyncTasks)87 .then(checkResourceSizes);88}, 'PerformanceResourceTiming sizes Fetch with redirect test');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webpagetest = require('webpagetest');2var wpt = new webpagetest('www.webpagetest.org');3var location = 'Dulles:Chrome';4var options = {5};6wpt.runTest(testUrl, options, function(err, data) {7 if (err) return console.error(err);8 console.log('Test status: ' + data.statusText);9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('wptdriver');2var options = {3};4var driver = new wptdriver(options);5driver.start(function(err, result) {6 if (err) {7 console.log(err);8 } else {9 console.log(result);10 }11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wptdriver');2 if (error) {3 console.log(error);4 } else {5 console.log(JSON.stringify(response.headers));6 }7});8var wpt = require('wptdriver');9 if (error) {10 console.log(error);11 } else {12 console.log(body);13 }14});15var wpt = require('wptdriver');16 if (error) {17 console.log(error);18 } else {19 console.log(body);20 }21});22var wpt = require('wptdriver');23 if (error) {24 console.log(error);25 } else {26 console.log(body);27 }28});29var wpt = require('wptdriver');30 if (error) {31 console.log(error);32 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var wpt = require('webpagetest');3var wptdriver = new wpt('www.webpagetest.org', 'A.4f2c0b3e8d3e3e0d3c0e1f1c8d7f9b9d');4 build();5wptdriver.crossOriginRedirect(driver, url, wptUrl, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11 driver.quit();12});

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