<!DOCTYPE html>
<html>
<body>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div
id="dragtarget"
style="background-color: blue; width: 100px; height: 100px">
Drag here
</div>
<div>
<input type="password" id="password_input" value="abcdef" />
<input type="text" id="text_input" value="abcdef" />
</div>
<script>
// Drag and drop doesn't work well with pointerActionSequence. We need to
// use eventSender to simulate this. (crbug.com/41316374)
function moveMouseToCenterOfElement(element) {
const centerX = element.offsetLeft + element.offsetWidth / 2;
const centerY = element.offsetTop + element.offsetHeight / 2;
eventSender.mouseMoveTo(centerX, centerY);
}
let isDropped = false;
const dragTarget = document.getElementById("dragtarget");
dragTarget.addEventListener(
"dragover",
function () {
event.dataTransfer.dropEffect = "copy";
event.preventDefault();
},
false
);
dragTarget.addEventListener(
"drop",
function () {
isDropped = true;
event.preventDefault();
},
false
);
function dragDropInputText(inputElement) {
inputElement.focus();
inputElement.setSelectionRange(0, 3);
// Drag the selected text and drop into the '#dragTarget' element.
x = inputElement.offsetLeft + 10;
y = inputElement.offsetTop + inputElement.offsetHeight / 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.leapForward(400);
moveMouseToCenterOfElement(dragTarget);
eventSender.mouseUp();
}
test(function () {
const passwordInput = document.getElementById("password_input");
isDropped = false;
dragDropInputText(passwordInput);
assert_false(isDropped);
}, "Text in a password input should not be dropped");
test(function () {
const textInput = document.getElementById("text_input");
isDropped = false;
dragDropInputText(textInput);
assert_true(isDropped);
}, "Text in a non-password input should be dropped");
</script>
</body>
</html>