summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/layout-instability/move-distance-clamped.html
blob: 5854fe08d156f52260fb9eeb8980d31a3ae91077 (plain)
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
<!DOCTYPE html>
<title>Layout Instability: distance fraction not more than 1.0</title>
<link rel="help" href="https://wicg.github.io/layout-instability/" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-adapter.js"></script>
<script src="resources/util.js"></script>
<style>
body { margin: 0; }
#shifter {
  position: relative;
  width: 100vw;
  height: 100vh;
  left: -2000vw;
  top: -2000vh;
  background: blue;
}
</style>
<div id="shifter"></div>
<script>

promise_test(async () => {
  const watcher = new ScoreWatcher;

  // Wait for the initial render to complete.
  await waitForAnimationFrames(2);

  // Modify the position of the div.
  document.querySelector("#shifter").style = "left: 0; top: 0";

  const docElement = document.documentElement;
  const viewWidth = docElement.clientWidth;
  const viewHeight = docElement.clientHeight;

  // An element the size of the viewport has shifted by a huge distance, but
  // the move distance is effectively the viewport width or height (whichever
  // is larger) as the distance fraction is limited to a maximum of 1.0.
  const expectedScore = computeExpectedScore(
      viewWidth * viewHeight,
      Math.max(viewWidth, viewHeight));

  // Observer fires after the frame is painted.
  cls_expect(watcher, {score: 0});
  await watcher.promise;
  cls_expect(watcher, {score: expectedScore});
}, "Distance fraction not more than 1.0.");

</script>