blob: a4fa0d8b0d92a83984034926de30958b840c1028 [file] [log] [blame]
Nicolás Peña Morenoa3f46a82019-12-27 22:37:051<!DOCTYPE HTML>
2<meta charset=utf-8>
3<title>Layout Instability: observe after user input</title>
4<body>
5<style>
6#myDiv { position: relative; width: 300px; height: 100px; }
7
8/* Disable the button's focus ring, which otherwise expands its visual rect by
9 * 1px on all sides, triggering a layout shift event.
10 */
11#button { outline: none; }
12</style>
13<div id='myDiv'></div>
14<button id='button'>Generate a 'click' event</button>
15<script src=/resources/testharness.js></script>
16<script src=/resources/testharnessreport.js></script>
17<script src=/resources/testdriver.js></script>
18<script src=/resources/testdriver-vendor.js></script>
19<script src=resources/util.js></script>
20<script src=/event-timing/resources/event-timing-test-utils.js></script>
21<script>
22let timeAfterClick;
23
24async_test(async function(t) {
25 assert_precondition(window.LayoutShift, 'LayoutShift entries are not supported');
26 // Wait for the initial render to complete.
27 await waitForAnimationFrames(2);
28
29 const startTime = performance.now();
30 const observer = new PerformanceObserver(
31 t.step_func_done(function(entryList) {
32 const endTime = performance.now();
33 assert_equals(entryList.getEntries().length, 1);
34 const entry = entryList.getEntries()[0];
35 assert_equals(entry.entryType, "layout-shift");
36 assert_equals(entry.name, "");
37 assert_greater_than_equal(entry.startTime, startTime);
38 assert_less_than_equal(entry.startTime, endTime);
39 assert_equals(entry.duration, 0.0);
40 // The layout shift value should be:
41 // 300 * (100 + 60) * (60 / maxDimension) / viewport size.
42 assert_equals(entry.value, computeExpectedScore(300 * (100 + 60), 60));
43 // We should see that there was a click input entry.
44 assert_equals(entry.hadRecentInput, true);
45 assert_greater_than_equal(timeAfterClick, entry.lastInputTime);
46 })
47 );
48 observer.observe({entryTypes: ['layout-shift']});
49 // User input event
50 clickAndBlockMain('button').then(() => {
51 timeAfterClick = performance.now();
52 // Modify the position of the div.
53 document.getElementById('myDiv').style = "top: 60px";
54 });
55}, 'Layout shift right after user input is observable via PerformanceObserver.');
56</script>
57
58</body>