summaryrefslogtreecommitdiffstats
path: root/dom/events/test/test_dnd_with_modifiers.html
blob: 8b861c9306127d1f4abc80eb98e6de993f3f3698 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
  <meta charset="utf-8">
  <title>Test dragstart, drag, dragover, drop, dragend with keyboard modifiers</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
  <div id="test"></div>
  <script>
  SimpleTest.waitForExplicitFinish();

  SimpleTest.waitForFocus(() => {
    let dragEvents = ["dragstart", "drag", "dragend"];
    let dropEvents = ["dragover", "drop"];
    let source = document.getElementById("source");
    let target = document.getElementById("target");

    dragEvents.forEach((ev, idx, array) => {
      source.addEventListener(ev, (e) => {
        ok(e.ctrlKey, e.type + ".ctrlKey should be true");
        ok(!e.shiftKey, e.type + ".shiftKey should be false");
        ok(e.altKey, e.type + ".altKey should be true");
      }, {once: true});
    });

    dropEvents.forEach((ev, idx, array) => {
      target.addEventListener(ev, (e) => {
        ok(e.ctrlKey, e.type + ".ctrlKey should be true");
        ok(!e.shiftKey, e.type + ".shiftKey should be false");
        ok(e.altKey, e.type + ".altKey should be true");
      }, {once: true});
    });

    source.addEventListener("dragstart", (e) => {
      e.preventDefault();
    }, {once: true});

    source.addEventListener("dragend", (e) => {
      SimpleTest.finish();
    });

    let selection = window.getSelection();
    selection.selectAllChildren(source);

    synthesizeMouse(source, 1, 1, {type: "mousedown", ctrlKey: true, altKey: true}, window);
    synthesizeMouse(source, 10, 10, {type: "mousemove", ctrlKey: true, altKey: true}, window);
    synthesizeMouse(source, 10, 10, {type: "mouseup", ctrlKey: true, altKey: true}, window);

    let dragEvent = {
      type: "drag",
      ctrlKey: true,
      altKey: true,
    };
    sendDragEvent(dragEvent, source, window);

    let rect = target.getBoundingClientRect();
    let dropEvent = {
      ctrlKey: true,
      altKey: true,
      clientX: rect.left + rect.width / 2,
      clientY: rect.top + rect.height / 2,
    };
    selection.selectAllChildren(source);
    synthesizeDrop(source, target, [], "copy", window, window, dropEvent);

    let dragEndEvent = {
      type: "dragend",
      ctrlKey: true,
      altKey: true,
    };
    sendDragEvent(dragEndEvent, source, window);
  });
  </script>
<body>
  <span id="source" style="font-size: 40px;">test</span>
  <div id="target" contenteditable="true" width="50" height="50"></div>
</body>
</html>