DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (1aeaa33a64f9)

VCS Links

Line Code
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
<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>

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

  let iframe = document.createElement('iframe');
  document.body.appendChild(iframe);
  iframe.contentDocument.body.innerHTML = '<div id="outter"/>';

  let iframeDoc = iframe.contentDocument;
  let iframeWin = iframe.contentWindow;

  let shadow = iframeDoc.querySelector('#outter').attachShadow({mode: 'open'});
  let target = iframeDoc.createElement('a');
  let linkText = iframeDoc.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!");
  iframeWin.addEventListener("dragstart", trapDrag, true);
  synthesizeMouse(target, 2, 2, { type: "mousedown" }, iframeWin);
  synthesizeMouse(target, 11, 11, { type: "mousemove" }, iframeWin);
  synthesizeMouse(target, 20, 20, { type: "mousemove" }, iframeWin);
  iframeWin.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();
}


SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(() => {
  SpecialPowers.pushPrefEnv({
    set: [
      ["dom.webcomponents.shadowdom.enabled", true]
    ]
  }, runTests);
});

</script>

<body>
</body>
</html>