Steve Kobes | 1a09247 | 2019-11-25 15:54:13 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <title>Layout Instability: shift while scrolled</title> |
| 3 | <link rel="help" href="https://wicg.github.io/layout-instability/" /> |
| 4 | <style> |
| 5 | |
| 6 | body { height: 2000px; margin: 0; } |
Xianzhu Wang | 48e5e3c | 2021-03-13 00:30:33 | [diff] [blame] | 7 | #shift { position: relative; width: 300px; height: 200px; background: blue; } |
Steve Kobes | 1a09247 | 2019-11-25 15:54:13 | [diff] [blame] | 8 | |
| 9 | </style> |
| 10 | <div id="shift"></div> |
| 11 | <script src="/resources/testharness.js"></script> |
| 12 | <script src="/resources/testharnessreport.js"></script> |
| 13 | <script src="resources/util.js"></script> |
| 14 | <script> |
| 15 | |
| 16 | promise_test(async () => { |
| 17 | const watcher = new ScoreWatcher; |
| 18 | |
| 19 | // Wait for the initial render to complete. |
| 20 | await waitForAnimationFrames(2); |
| 21 | |
| 22 | // Scroll down by 100px. |
| 23 | document.scrollingElement.scrollTop = 100; |
| 24 | assert_equals(watcher.score, 0); |
| 25 | |
| 26 | // Generate a layout shift. |
| 27 | document.querySelector("#shift").style = "top: 60px"; |
| 28 | |
Xianzhu Wang | 482859c | 2021-03-12 02:43:58 | [diff] [blame] | 29 | // Impact region: width * (height - scrollTop + moveDistance) |
| 30 | const expectedScore = computeExpectedScore( |
| 31 | 300 * (200 - 100 + 60), 60); |
Steve Kobes | 1a09247 | 2019-11-25 15:54:13 | [diff] [blame] | 32 | |
| 33 | await watcher.promise; |
| 34 | assert_equals(watcher.score, expectedScore); |
| 35 | }, 'Layout shift with non-zero scroll offset.'); |
| 36 | |
| 37 | </script> |