tor-browser

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

rectangular-image.html (1657B)


      1 <!DOCTYPE HTML>
      2 <meta charset=utf-8>
      3 <title>Element Timing: observe a rectangular image</title>
      4 <body>
      5 <style>
      6 body {
      7  margin: 20px;
      8 }
      9 </style>
     10 <script src="/resources/testharness.js"></script>
     11 <script src="/resources/testharnessreport.js"></script>
     12 <script src="resources/element-timing-helpers.js"></script>
     13 <script>
     14  let beforeRender;
     15  let img;
     16  async_test(function (t) {
     17    assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");
     18    const observer = new PerformanceObserver(
     19      t.step_func_done(function(entryList) {
     20        assert_equals(entryList.getEntries().length, 1);
     21        const entry = entryList.getEntries()[0];
     22        const pathname = window.location.origin + '/images/black-rectangle.png';
     23        checkElement(entry, pathname, 'my_image', 'rectangle', beforeRender, img);
     24        // Assume viewport has size at least 100, so the element is fully visible.
     25        checkRect(entry, [20, 120, 20, 70]);
     26        checkNaturalSize(entry, 100, 50);
     27      })
     28    );
     29    observer.observe({entryTypes: ['element']});
     30    // We add the image during onload to be sure that the observer is registered
     31    // in time for it to observe the element timing.
     32    window.onload = () => {
     33      // Add image of width equal to 100 and height equal to 50.
     34      img = document.createElement('img');
     35      img.src = '/images/black-rectangle.png';
     36      img.id = 'rectangle';
     37      img.setAttribute('elementtiming', 'my_image');
     38      document.body.appendChild(img);
     39      beforeRender = performance.now();
     40    };
     41  }, 'Element with rectangular image has correct rect and instrinsic size.');
     42 </script>
     43 </body>