summaryrefslogtreecommitdiffstats
path: root/dom/events/test/test_bug1264380.html
blob: 76b9fb46b35fc1c816e04570254d98eda7bee825 (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
<html>
<head>
  <title>Test the dragstart event on the anchor in side shadow DOM</title>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script>

SimpleTest.waitForExplicitFinish();

SpecialPowers.pushPrefEnv({"set": [
  ["dom.webcomponents.enabled", true]
]});

function runTests()
{
  let dragService = SpecialPowers.Cc["@mozilla.org/widget/dragservice;1"].
    getService(SpecialPowers.Ci.nsIDragService);

  let shadow = document.querySelector('#outter').createShadowRoot();
  let target = document.createElement('a');
  let linkText = document.createTextNode("Drag me if you can!");
  target.appendChild(linkText);
  target.href = "http://www.mozilla.org/";
  shadow.appendChild(target);

  let dataTransfer;
  let trapDrag = function(event) {
    ok(true, "Got dragstart event");
    dataTransfer = event.dataTransfer;
    ok(dataTransfer, "DataTransfer object is available.");
    is(dataTransfer.mozItemCount, 1, "initial link item count");
    is(dataTransfer.getData("text/uri-list"), "http://www.mozilla.org/", "link text/uri-list");
    is(dataTransfer.getData("text/plain"), "http://www.mozilla.org/", "link text/plain");
  }

  ok(!dragService.getCurrentSession(), "There shouldn't be a drag session!");
  window.addEventListener("dragstart", trapDrag, true);
  synthesizeMouse(target, 2, 2, { type: "mousedown" });
  synthesizeMouse(target, 11, 11, { type: "mousemove" });
  synthesizeMouse(target, 20, 20, { type: "mousemove" });
  window.removeEventListener("dragstart", trapDrag, true);
  ok(dragService.getCurrentSession(), "Drag session is available.");
  dragService.endDragSession(false);
  ok(!dragService.getCurrentSession(), "There shouldn't be a drag session anymore!");
  SimpleTest.finish();
}

</script>

<body onload="window.setTimeout(runTests, 0);">
<div id="outter"/>
</body>
</html>