mirror of
https://github.com/servo/servo.git
synced 2025-07-10 08:53:41 +01:00
37 lines
1.4 KiB
HTML
37 lines
1.4 KiB
HTML
<!DOCTYPE HTML>
|
|
<meta charset=utf-8>
|
|
<title>Layout Jank: observe jank fraction via PerformanceObserver</title>
|
|
<body>
|
|
<style>
|
|
#myDiv { position: relative; width: 300px; height: 100px; }
|
|
</style>
|
|
<div id='myDiv'></div>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script>
|
|
async_test(function (t) {
|
|
const startTime = performance.now();
|
|
const observer = new PerformanceObserver(
|
|
t.step_func_done(function(entryList) {
|
|
const endTime = performance.now();
|
|
assert_equals(entryList.getEntries().length, 1);
|
|
const entry = entryList.getEntries()[0];
|
|
assert_equals(entry.entryType, "layoutJank");
|
|
assert_equals(entry.name, "");
|
|
assert_greater_than_equal(entry.startTime, startTime)
|
|
assert_less_than_equal(entry.startTime, endTime)
|
|
assert_equals(entry.duration, 0.0);
|
|
// The layout jank fraction should be: 300 * (100 + 60) / viewport size.
|
|
assert_equals(entry.fraction, 300 * (100 + 60) /
|
|
(document.documentElement.clientWidth * document.documentElement.clientHeight));
|
|
})
|
|
);
|
|
observer.observe({entryTypes: ['layoutJank']});
|
|
window.onload = () => {
|
|
// Modify the position of the div.
|
|
document.getElementById('myDiv').style = "top: 60px";
|
|
};
|
|
}, 'LayoutJank is observable via PerformanceObserver.');
|
|
</script>
|
|
|
|
</body>
|