Best JavaScript code snippet using wpt
resource-timing-sizes-redirect.js
Source:resource-timing-sizes-redirect.js
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');...
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org', 'A.12345678901234567890123456789012');3}, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6 test.getTestStatus(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10});11var wpt = require('webpagetest');12var test = wpt('www.webpagetest.org', 'A.12345678901234567890123456789012');13}, function(err, data) {14 if (err) return console.error(err);15 console.log(data);16 test.getTestStatus(data.data.testId, function(err, data) {17 if (err) return console.error(err);18 console.log(data);19 });20});21var wpt = require('webpagetest');22var test = wpt('www.webpagetest.org', 'A.12345678901234567890123456789012');23}, function(err, data) {24 if (err) return console.error(err);25 console.log(data);26 test.getTestStatus(data.data.testId, function(err, data) {27 if (err) return console.error(err);28 console.log(data);29 });30});
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 mobileUserAgent: 'Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4) Build/MPJ24.139-64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36',4}, function(err, data) {5 if (err) {6 console.error('Error: ' + err);7 } else {8 console.log('Test status: ' + data.statusCode);9 console.log('Test statusText: ' + data.statusText);10 console.log('Test ID: ' + data.data.testId);11 console.log('Test owner: ' + data.data.ownerKey);12 console.log('Test URL: ' + data.data.summary);13 console.log('Test jsonUrl: ' + data.data.jsonUrl);14 console.log('Test xmlUrl: ' + data.data.xmlUrl);15 console.log('Test userUrl: ' + data.data.userUrl);16 console.log('Test summaryCSV: ' + data.data.summaryCSV);17 }18});19var wpt = require('webpagetest');20var test = new wpt('www.webpagetest.org', 'A.1234567890
Using AI Code Generation
1var wptools = require('wptools');2var wiki = wptools.page('Albert Einstein');3wiki.mixedRedirect(function(err, resp) {4 if (!err) {5 console.log(resp);6 }7});8var wptools = require('wptools');9var wiki = wptools.page('Albert Einstein');10wiki.mixedRedirect(function(err, resp) {11 if (!err) {12 console.log(resp);13 }14});
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools('Barack Obama');3page.mixedRedirect(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools('Barack Obama');8page.mixedRedirect(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools('Barack Obama');13page.mixedRedirect(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools('Barack Obama');18page.mixedRedirect(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools('Barack Obama');23page.mixedRedirect(function(err, resp) {24 console.log(resp);25});26var wptools = require('wptools');27var page = wptools('Barack Obama');28page.mixedRedirect(function(err, resp) {29 console.log(resp);30});31var wptools = require('wptools');32var page = wptools('Barack Obama');33page.mixedRedirect(function(err, resp) {34 console.log(resp);35});
Using AI Code Generation
1wpt.mixedRedirect(url, options, callback)2wpt.mixedRedirect(url, options, callback)3wpt.mixedRedirect(url, options, callback)4wpt.mixedRedirect(url, options, callback)5wpt.mixedRedirect(url, options, callback)6wpt.mixedRedirect(url, options, callback)7wpt.mixedRedirect(url, options, callback)8wpt.mixedRedirect(url, options, callback)9wpt.mixedRedirect(url, options, callback)10wpt.mixedRedirect(url, options, callback)
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!!