File: image-src-change.html

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (86 lines) | stat: -rw-r--r-- 2,589 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Element Timing: src change triggers new entry</title>

<body>
  <style>
    body {
      margin: 0;
    }

  </style>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="resources/element-timing-helpers.js"></script>
  <img elementtiming='my_image' id='my_id' />
  <script>
    setup({"hide_test_state": true});

    const performanceEntryPromise = (pathname) => {
      return new Promise(resolve => {
        new PerformanceObserver((entryList, observer) => {
          assert_equals(entryList.getEntries().length, 1);
          if (entryList.getEntries()[0].url == pathname) {
            observer.disconnect();
            resolve(entryList.getEntries()[0]);
          }
        }).observe({ type: 'element' });
      });
    }

    promise_test(async (t) => {
      assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");

      // Take beforeRender timestamp.
      const beforeRender1 = performance.now();

      const img = document.getElementById('my_id');

      const url1 = 'resources/square100.png';

      const pathname1 = (new URL(url1, document.location)).href

      // Register performance observer.
      const promise1 = performanceEntryPromise(pathname1);

      //Load image
      await new Promise(resolve => {
        img.addEventListener('load', resolve);
        img.src = url1;
      });

      // Get element entry.
      const entry1 = await promise1;

      // Check entry.
      checkElement(entry1, pathname1, 'my_image', 'my_id', beforeRender1, img);
      checkRect(entry1, [0, 100, 0, 100]);
      checkNaturalSize(entry1, 100, 100);

      // Take beforeRender timestamp before changing image src.
      const beforeRender2 = performance.now();

      // Set the src to trigger another entry.
      const url2 = '/images/black-rectangle.png';

      const pathname2 = (new URL(url2, document.location)).href;

      const promise2 = performanceEntryPromise(pathname2);

      //Load image with changed src.
      await new Promise(resolve => {
        img.addEventListener('load', resolve);
        img.src = url2;
      });

      // Get the corresponding element entry.
      const entry2 = await promise2;

      // Check entry.
      checkElement(entry2, pathname2, 'my_image', 'my_id', beforeRender2, img);
      checkRect(entry2, [0, 100, 0, 50]);
      checkNaturalSize(entry2, 100, 50);
    }, 'Element Timing: changing src causes a new entry to be dispatched.')
  </script>

</body>