tor-browser

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

image-src-change.html (2589B)


      1 <!DOCTYPE HTML>
      2 <meta charset=utf-8>
      3 <title>Element Timing: src change triggers new entry</title>
      4 
      5 <body>
      6  <style>
      7    body {
      8      margin: 0;
      9    }
     10 
     11  </style>
     12  <script src="/resources/testharness.js"></script>
     13  <script src="/resources/testharnessreport.js"></script>
     14  <script src="resources/element-timing-helpers.js"></script>
     15  <img elementtiming='my_image' id='my_id' />
     16  <script>
     17    setup({"hide_test_state": true});
     18 
     19    const performanceEntryPromise = (pathname) => {
     20      return new Promise(resolve => {
     21        new PerformanceObserver((entryList, observer) => {
     22          assert_equals(entryList.getEntries().length, 1);
     23          if (entryList.getEntries()[0].url == pathname) {
     24            observer.disconnect();
     25            resolve(entryList.getEntries()[0]);
     26          }
     27        }).observe({ type: 'element' });
     28      });
     29    }
     30 
     31    promise_test(async (t) => {
     32      assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");
     33 
     34      // Take beforeRender timestamp.
     35      const beforeRender1 = performance.now();
     36 
     37      const img = document.getElementById('my_id');
     38 
     39      const url1 = 'resources/square100.png';
     40 
     41      const pathname1 = (new URL(url1, document.location)).href
     42 
     43      // Register performance observer.
     44      const promise1 = performanceEntryPromise(pathname1);
     45 
     46      //Load image
     47      await new Promise(resolve => {
     48        img.addEventListener('load', resolve);
     49        img.src = url1;
     50      });
     51 
     52      // Get element entry.
     53      const entry1 = await promise1;
     54 
     55      // Check entry.
     56      checkElement(entry1, pathname1, 'my_image', 'my_id', beforeRender1, img);
     57      checkRect(entry1, [0, 100, 0, 100]);
     58      checkNaturalSize(entry1, 100, 100);
     59 
     60      // Take beforeRender timestamp before changing image src.
     61      const beforeRender2 = performance.now();
     62 
     63      // Set the src to trigger another entry.
     64      const url2 = '/images/black-rectangle.png';
     65 
     66      const pathname2 = (new URL(url2, document.location)).href;
     67 
     68      const promise2 = performanceEntryPromise(pathname2);
     69 
     70      //Load image with changed src.
     71      await new Promise(resolve => {
     72        img.addEventListener('load', resolve);
     73        img.src = url2;
     74      });
     75 
     76      // Get the corresponding element entry.
     77      const entry2 = await promise2;
     78 
     79      // Check entry.
     80      checkElement(entry2, pathname2, 'my_image', 'my_id', beforeRender2, img);
     81      checkRect(entry2, [0, 100, 0, 50]);
     82      checkNaturalSize(entry2, 100, 50);
     83    }, 'Element Timing: changing src causes a new entry to be dispatched.')
     84  </script>
     85 
     86 </body>