tor-browser

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

load-from-mem-cache-transfer-size.html (2307B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 
      4 <head>
      5  <meta charset="utf-8" />
      6  <title>This tests transfer size of resource timing when loaded from memory cache.</title>
      7  <script src="/resources/testharness.js"></script>
      8  <script src="/resources/testharnessreport.js"></script>
      9  <script src="resources/entry-invariants.js"></script>
     10 </head>
     11 
     12 <body>
     13  <script>
     14    function getScript(url) {
     15      const script = document.createElement("script");
     16      const loaded = new Promise(resolve => {
     17        script.onload = script.onerror = resolve;
     18      });
     19      script.src = url;
     20      document.body.appendChild(script);
     21      return loaded;
     22    }
     23    function add_iframe(url) {
     24      return new Promise(function (resolve) {
     25        var frame = document.createElement('iframe');
     26        frame.src = url;
     27        frame.onload = function () { resolve(frame); };
     28        document.body.appendChild(frame);
     29      });
     30    }
     31    promise_test(async t => {
     32      // Add unique token to url so that each run the url is different to avoid
     33      // flakiness.
     34      let url = 'resources/resource_timing_test0.js?unique=' +
     35        Math.random().toString().substr(2);
     36      let frame;
     37      return add_iframe('resources/iframe-load-from-mem-cache-transfer-size.html')
     38        .then((f) => {
     39          frame = f;
     40          // Load script onto iframe in order to get it into the memory cache.
     41          return frame.contentWindow.getScript(url.split('/')[1])
     42        })
     43        .then(() => {
     44          // Verify that the transferSize in case of normal load is greater than
     45          // 0.
     46          assert_positive_(
     47            frame.contentWindow.performance.getEntriesByType('resource')
     48              .filter(e => e.name.includes(url))[0], ['transferSize']);
     49 
     50          // Load the same script onto the parent document. This time the script
     51          // is coming from memory cache.
     52          return getScript(url);
     53        })
     54        .then(() => {
     55          // Verify that the transferSize in case of memory cache load is 0.
     56          assert_zeroed_(
     57            window.performance.getEntriesByType('resource')
     58              .filter(e => e.name.includes(url))[0], ['transferSize']);
     59        });
     60    }, "The transferSize of resource timing entries should be 0 when resource \
     61    is loaded from memory cache.");
     62  </script>
     63 </body>
     64 
     65 </html>