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