How to use testSizedRange method in wpt

Best JavaScript code snippet using wpt

sw.https.window.js

Source:sw.https.window.js Github

copy

Full Screen

...125 const length = 100;126 const count = 3;127 const counts = {};128 // test a single range request size129 async function testSizedRange(size, partialResponseCode) {130 const rangeId = Math.random() + '';131 const rangeBroadcast = awaitMessage(w.navigator.serviceWorker, rangeId);132 // Create a bogus audo element to trick the browser into sending133 // cross-origin range requests that can be manipulated by the service worker.134 const sound_url = new URL('partial-text.py', w.location);135 sound_url.hostname = REMOTE_HOST;136 sound_url.searchParams.set('action', 'record-media-range-request');137 sound_url.searchParams.set('length', length);138 sound_url.searchParams.set('size', size);139 sound_url.searchParams.set('partial', partialResponseCode);140 sound_url.searchParams.set('id', rangeId);141 appendAudio(w.document, sound_url);142 // wait for the range requests to happen143 await rangeBroadcast;144 // Create multiple preload requests and count the number of resource timing145 // entries that get created to make sure 206 and 416 range responses are treated146 // the same.147 const url = new URL('partial-text.py', w.location);148 url.searchParams.set('action', 'use-media-range-request');149 url.searchParams.set('size', size);150 counts['size' + size] = 0;151 for (let i = 0; i < count; i++) {152 await preloadImage(url, { doc: w.document });153 }154 }155 // Test range requests from 1 smaller than the correct size to 1 larger than156 // the correct size to exercise the various permutations using the default 206157 // response code for successful range requests.158 for (let size = length - 1; size <= length + 1; size++) {159 await testSizedRange(size, '206');160 }161 // Test a successful range request using a 200 response.162 await testSizedRange(length - 2, '200');163 // Check the resource timing entries and count the reported number of fetches of each type164 const resources = w.performance.getEntriesByType("resource");165 for (const entry of resources) {166 const url = new URL(entry.name);167 if (url.searchParams.has('action') &&168 url.searchParams.get('action') == 'use-media-range-request' &&169 url.searchParams.has('size')) {170 counts['size' + url.searchParams.get('size')]++;171 }172 }173 // Make sure there are a non-zero number of preload requests and they are all the same174 let counts_valid = true;175 const first = 'size' + (length - 2);176 for (let size = length - 2; size <= length + 1; size++) {...

Full Screen

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