summaryrefslogtreecommitdiffstats
path: root/dom/events/test/test_drag_coords.html
blob: 2db65a66f94123a538f0c03368a6d31e208b8f14 (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
<!doctype html>
<title>Test for drag event coordinates</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<style>
  #draggable {
    display: inline-block;
    border: 1px solid;
  }
</style>
<div draggable="true" id="draggable">Drag me</div>
<script>
add_task(async function test_drag_coords() {
  await SpecialPowers.contentTransformsReceived(window);

  let target = document.getElementById("draggable");
  let coords = {};
  let promises = [];
  for (let type of ["dragstart", "dragend"]) {
    promises.push(new Promise(function(resolve) {
      target.addEventListener(type, function(e) {
        info("Got " + e.type);
        coords[e.type] = {
          screen: {
            x: e.screenX,
            y: e.screenY,
          },
          client: {
            x: e.clientX,
            y: e.clientY,
          },
        };
        resolve();
      });
    }));
  }
  synthesizePlainDragAndDrop({
    srcElement: target,
    srcX: 2,
    srcY: 2,
    stepX: 10,
    stepY: 10,
  });
  await Promise.all(promises);
  info(JSON.stringify(coords));
  for (let coordType of ["screen", "client"]) {
    is(coords.dragend[coordType].x, coords.dragstart[coordType].x + 12, `x ${coordType} is correct`);
    is(coords.dragend[coordType].y, coords.dragstart[coordType].y + 12, `y ${coordType} is correct`);
  }
});
</script>