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
87
88
|
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Element Timing: background image affecting multiple elements</title>
<body>
<style>
body {
margin: 0;
}
.my_div {
background-image: url('resources/square100.png');
}
#div1 {
width: 100px;
height: 100px;
}
#div2 {
width: 200px;
height: 100px;
}
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/element-timing-helpers.js"></script>
<script>
async_test(function (t) {
assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");
let beforeRender = performance.now();
let numObservedElements = 0;
let observedDiv1 = false;
let observedDiv2Img = false;
let observedDiv2Txt = false;
const pathname = window.location.origin + '/element-timing/resources/square100.png';
const observer = new PerformanceObserver(
t.step_func(function(entryList) {
entryList.getEntries().forEach(entry => {
numObservedElements++;
if (entry.id == 'div1') {
observedDiv1 = true;
checkElement(entry, pathname, 'et1', 'div1', beforeRender,
document.getElementById('div1'));
// Div is in the top left corner.
checkRect(entry, [0, 100, 0, 100]);
checkNaturalSize(entry, 100, 100);
}
else if (entry.id == 'div2') {
// Check image entry.
if (entry.name !== 'text-paint') {
observedDiv2Img = true;
checkElement(entry, pathname, 'et2', 'div2', beforeRender,
document.getElementById('div2'));
// Div is below div1, on the left.
checkRect(entry, [0, 200, 100, 200]);
checkNaturalSize(entry, 100, 100);
}
// Check the text entry.
else {
observedDiv2Txt = true;
checkTextElement(entry, 'et2', 'div2', beforeRender,
document.getElementById('div2'));
assert_greater_than_equal(entry.intersectionRect.right - entry.intersectionRect.left, 50);
assert_greater_than_equal(entry.intersectionRect.bottom - entry.intersectionRect.top, 10);
}
}
else {
assert_unreached("Should not observe other elements!");
}
if (numObservedElements === 3) {
assert_true(observedDiv1);
assert_true(observedDiv2Img);
assert_true(observedDiv2Txt);
t.done();
}
});
})
);
observer.observe({entryTypes: ['element']});
}, 'Background image affecting various elements is observed.');
</script>
<div id="div1" class="my_div" elementtiming="et1">
<img width=50 height=50 src='resources/circle.svg'/>
</div>
<div width=200 height=100 id="div2" class="my_div" elementtiming="et2">
Sample text inside div.
</div>
<div id="div3"/>
I am a div that should not be observed!
</div>
</body>
|