Bug 1540150 - Make it impossible to enter the native drag-drop loop in test automation. r=NeilDeakin
Differential Revision: https://phabricator.services.mozilla.com/D25428
This commit is contained in:
@@ -13,37 +13,58 @@ function runTests()
|
|||||||
|
|
||||||
let iframe = document.createElement('iframe');
|
let iframe = document.createElement('iframe');
|
||||||
document.body.appendChild(iframe);
|
document.body.appendChild(iframe);
|
||||||
iframe.contentDocument.body.innerHTML = '<div id="outter"/>';
|
iframe.contentDocument.body.innerHTML = '<div id="outer"/>';
|
||||||
|
|
||||||
let iframeDoc = iframe.contentDocument;
|
let iframeDoc = iframe.contentDocument;
|
||||||
let iframeWin = iframe.contentWindow;
|
let iframeWin = iframe.contentWindow;
|
||||||
|
|
||||||
let shadow = iframeDoc.querySelector('#outter').attachShadow({mode: 'open'});
|
let shadow = iframeDoc.querySelector('#outer').attachShadow({mode: 'open'});
|
||||||
let target = iframeDoc.createElement('a');
|
let target = iframeDoc.createElement('a');
|
||||||
let linkText = iframeDoc.createTextNode("Drag me if you can!");
|
|
||||||
|
const TEXT = "Drag me if you can!";
|
||||||
|
let linkText = iframeDoc.createTextNode(TEXT);
|
||||||
target.appendChild(linkText);
|
target.appendChild(linkText);
|
||||||
target.href = "http://www.mozilla.org/";
|
|
||||||
|
const URL = "http://www.mozilla.org/";
|
||||||
|
target.href = URL;
|
||||||
shadow.appendChild(target);
|
shadow.appendChild(target);
|
||||||
|
|
||||||
let dataTransfer;
|
// Some of the drag data we don't actually care about for this test,
|
||||||
let trapDrag = function(event) {
|
// so we'll use this comparator function to ignore them.
|
||||||
ok(true, "Got dragstart event");
|
function ignoreFunc(actualData, expectedData) {
|
||||||
dataTransfer = event.dataTransfer;
|
return true;
|
||||||
ok(dataTransfer, "DataTransfer object is available.");
|
|
||||||
is(SpecialPowers.wrap(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!");
|
const EXPECTED_DRAG_DATA = [[{
|
||||||
iframeWin.addEventListener("dragstart", trapDrag, true);
|
type: "text/x-moz-url",
|
||||||
synthesizeMouse(target, 2, 2, { type: "mousedown" }, iframeWin);
|
data: "",
|
||||||
synthesizeMouse(target, 11, 11, { type: "mousemove" }, iframeWin);
|
eqTest: ignoreFunc,
|
||||||
synthesizeMouse(target, 20, 20, { type: "mousemove" }, iframeWin);
|
}, {
|
||||||
iframeWin.removeEventListener("dragstart", trapDrag, true);
|
type: "text/x-moz-url-data",
|
||||||
ok(dragService.getCurrentSession(), "Drag session is available.");
|
data: "",
|
||||||
dragService.endDragSession(false);
|
eqTest: ignoreFunc,
|
||||||
ok(!dragService.getCurrentSession(), "There shouldn't be a drag session anymore!");
|
}, {
|
||||||
|
type: "text/x-moz-url-desc",
|
||||||
|
data: "",
|
||||||
|
eqTest: ignoreFunc,
|
||||||
|
}, {
|
||||||
|
type: "text/uri-list",
|
||||||
|
data: URL,
|
||||||
|
}, {
|
||||||
|
type: "text/_moz_htmlinfo",
|
||||||
|
data: "",
|
||||||
|
eqTest: ignoreFunc,
|
||||||
|
}, {
|
||||||
|
type: "text/html",
|
||||||
|
data: "",
|
||||||
|
eqTest: ignoreFunc,
|
||||||
|
}, {
|
||||||
|
type: "text/plain",
|
||||||
|
data: URL,
|
||||||
|
}]];
|
||||||
|
|
||||||
|
let result = synthesizeDragStart(target, EXPECTED_DRAG_DATA, iframeWin);
|
||||||
|
is(result, null, "Should have gotten the expected drag data.");
|
||||||
SimpleTest.finish();
|
SimpleTest.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ function doShiftDrag(){
|
|||||||
// Drag canvas element starts with a mouse down event, combine with shift
|
// Drag canvas element starts with a mouse down event, combine with shift
|
||||||
// key, follows by two mouse move events.
|
// key, follows by two mouse move events.
|
||||||
|
|
||||||
|
window.addEventListener("dragstart", e => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
});
|
||||||
|
|
||||||
// Press on left-top corner of the canvas element.
|
// Press on left-top corner of the canvas element.
|
||||||
wu.sendMouseEvent('mousedown', canvasRect.left, canvasRect.top, 0, 1, 4);
|
wu.sendMouseEvent('mousedown', canvasRect.left, canvasRect.top, 0, 1, 4);
|
||||||
// Move to the center of this cavas element.
|
// Move to the center of this cavas element.
|
||||||
|
|||||||
@@ -205,6 +205,23 @@ nsBaseDragService::InvokeDragSession(
|
|||||||
nsContentPolicyType aContentPolicyType = nsIContentPolicy::TYPE_OTHER) {
|
nsContentPolicyType aContentPolicyType = nsIContentPolicy::TYPE_OTHER) {
|
||||||
AUTO_PROFILER_LABEL("nsBaseDragService::InvokeDragSession", OTHER);
|
AUTO_PROFILER_LABEL("nsBaseDragService::InvokeDragSession", OTHER);
|
||||||
|
|
||||||
|
// If you're hitting this, a test is causing the browser to attempt to enter
|
||||||
|
// the drag-drop native nested event loop, which will put the browser in a
|
||||||
|
// state that won't run tests properly until there's manual intervention
|
||||||
|
// to exit the drag-drop loop (either by moving the mouse or hitting escape),
|
||||||
|
// which can't be done from script since we're in the nested loop.
|
||||||
|
//
|
||||||
|
// The best way to avoid this is to catch the dragstart event on the item
|
||||||
|
// being dragged, and then to call preventDefault() and stopPropagating() on
|
||||||
|
// it. Alternatively, use EventUtils.synthesizeDragStart, which will do this
|
||||||
|
// for you.
|
||||||
|
if (XRE_IsParentProcess()) {
|
||||||
|
MOZ_ASSERT(
|
||||||
|
!xpc::IsInAutomation(),
|
||||||
|
"About to start drag-drop native loop on which will prevent later "
|
||||||
|
"tests from running properly.");
|
||||||
|
}
|
||||||
|
|
||||||
NS_ENSURE_TRUE(aDOMNode, NS_ERROR_INVALID_ARG);
|
NS_ENSURE_TRUE(aDOMNode, NS_ERROR_INVALID_ARG);
|
||||||
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
|
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user