tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

resource_timing_content_length.html (2005B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <meta charset="utf-8" />
      5 <title>This test validates the value of encodedBodySize in certain situations.</title>
      6 <link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 
     10 <script>
     11    function test_resource_timing_for_content_length({actualContentLength, lengthHeader}, title) {
     12        promise_test(async t => {
     13            const content = new Array(actualContentLength).fill('x').join('')
     14            const url = `resources/resource-timing-content-length.py?content=${content}&length=${lengthHeader}`
     15            fetch(url)
     16            const entry = await new Promise(resolve => new PerformanceObserver((entryList, observer) => {
     17                observer.disconnect()
     18                resolve(entryList.getEntries()[0])
     19            }).observe({entryTypes: ['resource']}))
     20 
     21            const expectedContentLength = Number.isInteger(lengthHeader) ? Math.min(actualContentLength, lengthHeader) : actualContentLength
     22            assert_equals(entry.encodedBodySize, expectedContentLength)
     23        }, title);
     24    }
     25 
     26    test_resource_timing_for_content_length({actualContentLength: 3, lengthHeader: 'auto'},
     27        "encodedBodySize should be equal to the actual byte size of the content")
     28    test_resource_timing_for_content_length({actualContentLength: 13, lengthHeader: 'none'},
     29        "encodedBodySize should be equal to the actual byte size of the content when no header present")
     30    test_resource_timing_for_content_length({actualContentLength: 7, lengthHeader: 3},
     31        "encodedBodySize should be equal to the actual byte size of the content when header value is lower than actual content")
     32    test_resource_timing_for_content_length({actualContentLength: 8, lengthHeader: 40},
     33        "encodedBodySize should be equal to the actual byte size of the content when header value is higher than actual content")
     34 </script>
     35 </html>