summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/layout-instability/mousemove-becomes-drag.html
blob: df4a416c81cd0ebaccfe2b0a041ca88ef34dc4e4 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<title>Layout Instability: no shift in mouse moves with a button pressed</title>
<link rel="help" href="https://wicg.github.io/layout-instability/" />
<style>

body { margin: 0; height: 2000px; }
#draggable {
  top:50px;
  left:50px;
  width:50px;
  height:50px;
  background-color:blue;
  position:absolute
}

</style>
<div id="draggable" ></div>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/util.js"></script>
<script>

const draggable = document.getElementById("draggable");
draggable.addEventListener('mousemove', function(event) {
  // Move the element when the mouse moves.
  draggable.style.top = event.pageY - 25 + 'px';
  event.preventDefault();
}, false);

generateMouseMoveSequence = () => new test_driver.Actions()
    .pointerMove(0, 0, {origin: draggable})
    .pointerDown()
    .pointerMove(0, 15, {origin: draggable})
    .pause(100)
    .pointerMove(0, 30, {origin: draggable})
    .pause(100)
    .pointerMove(0, 45, {origin: draggable})
    .pause(100)
    .pointerUp()
    .pause(100);

promise_test(async () => {

  const watcher = new ScoreWatcher;

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

  // Send pointer events for a sequence of mouse actions, mouse down, mouse moves and mouse up.
  await generateMouseMoveSequence().send();

  // Mouse moves which drag the objects should be counted as the excluding inputs
  // for the layout shift.
  assert_greater_than(watcher.score, 0);
  assert_equals(watcher.scoreWithInputExclusion, 0);

}, "No layout shift when mouse moves with a button pressed.");

</script>