summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/element-timing/multiple-background-images.html
blob: 380e5e825e187d970bf156e143c77317ca5fc758 (plain)
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
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Element Timing: observe element with multiple background images</title>
<body>
<style>
body {
  margin: 0;
}
#target {
  width: 200px;
  height: 200px;
  background-image: url('resources/circle.svg'), url('resources/square100.png');
}
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/element-timing-helpers.js"></script>
<script>
  let beforeRender = performance.now();
  async_test(function (t) {
    assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");
    let numObservedElements = 0;
    let observedCircle = false;
    let observedSquare = false;
    const pathPrefix = window.location.origin + '/element-timing/resources/';
    let div = document.getElementById('target');
    const observer = new PerformanceObserver(
      t.step_func(entryList => {
        entryList.getEntries().forEach(entry => {
          numObservedElements++;
          if (entry.url.endsWith('square100.png')) {
            observedSquare = true;
            checkElement(entry, pathPrefix + 'square100.png', 'multi', 'target', beforeRender, div);
            checkRect(entry, [0, 200, 0, 200]);
            checkNaturalSize(entry, 100, 100);
          }
          else if (entry.url.endsWith('circle.svg')) {
            observedCircle = true;
            checkElement(entry, pathPrefix + 'circle.svg', 'multi', 'target', beforeRender, div);
            checkRect(entry, [0, 200, 0, 200]);
            checkNaturalSize(entry, 200, 200);
          }
          else {
            assert_unreached("Should not have observed an entry with different url!");
          }
          if (numObservedElements === 2) {
            assert_true(observedCircle);
            assert_true(observedSquare);
            t.done();
          }
        });
      })
    );
    observer.observe({entryTypes: ['element']});
  }, 'Element with two background images receives both.');
</script>
<div id='target' elementtiming='multi'></div>
</body>