gecko-dev/dom/events/test/test_bug1264380.html
Jessica Jong 4bee56a645 Bug 1428685 - Use dom.webcomponents.shadowdom.enabled pref for Shadow DOM. r=smaug
Most of the Shadow DOM related code are behind "dom.webcomponents.enabled" and
this pref is only used by Shadow DOM right now, so we should rename it to
"dom.webcomponents.shadowdom.enabled"

MozReview-Commit-ID: er1c7AsSSW
2018-01-16 17:16:30 +01:00

65 lines
2.3 KiB
HTML

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