зеркало из https://github.com/mozilla/gecko-dev.git
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 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
17142f45ab
Коммит
16b25917b7
|
@ -13,37 +13,58 @@ function runTests()
|
|||
|
||||
let iframe = document.createElement('iframe');
|
||||
document.body.appendChild(iframe);
|
||||
iframe.contentDocument.body.innerHTML = '<div id="outter"/>';
|
||||
iframe.contentDocument.body.innerHTML = '<div id="outer"/>';
|
||||
|
||||
let iframeDoc = iframe.contentDocument;
|
||||
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 linkText = iframeDoc.createTextNode("Drag me if you can!");
|
||||
|
||||
const TEXT = "Drag me if you can!";
|
||||
let linkText = iframeDoc.createTextNode(TEXT);
|
||||
target.appendChild(linkText);
|
||||
target.href = "http://www.mozilla.org/";
|
||||
|
||||
const URL = "http://www.mozilla.org/";
|
||||
target.href = URL;
|
||||
shadow.appendChild(target);
|
||||
|
||||
let dataTransfer;
|
||||
let trapDrag = function(event) {
|
||||
ok(true, "Got dragstart event");
|
||||
dataTransfer = event.dataTransfer;
|
||||
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");
|
||||
// Some of the drag data we don't actually care about for this test,
|
||||
// so we'll use this comparator function to ignore them.
|
||||
function ignoreFunc(actualData, expectedData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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!");
|
||||
const EXPECTED_DRAG_DATA = [[{
|
||||
type: "text/x-moz-url",
|
||||
data: "",
|
||||
eqTest: ignoreFunc,
|
||||
}, {
|
||||
type: "text/x-moz-url-data",
|
||||
data: "",
|
||||
eqTest: ignoreFunc,
|
||||
}, {
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ skip-if = os=='win'
|
|||
[test_image_selection.html]
|
||||
[test_image_selection_2.html]
|
||||
[test_invalidate_during_plugin_paint.html]
|
||||
skip-if = toolkit == 'android'
|
||||
skip-if = toolkit == 'android' || headless # Headless:Bug 1405871
|
||||
[test_intrinsic_size_on_loading.html]
|
||||
[test_movement_by_characters.html]
|
||||
[test_movement_by_words.html]
|
||||
|
|
|
@ -26,6 +26,11 @@ function doShiftDrag(){
|
|||
// Drag canvas element starts with a mouse down event, combine with shift
|
||||
// key, follows by two mouse move events.
|
||||
|
||||
window.addEventListener("dragstart", e => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}, { once: true });
|
||||
|
||||
// Press on left-top corner of the canvas element.
|
||||
wu.sendMouseEvent('mousedown', canvasRect.left, canvasRect.top, 0, 1, 4);
|
||||
// Move to the center of this cavas element.
|
||||
|
|
|
@ -205,6 +205,23 @@ nsBaseDragService::InvokeDragSession(
|
|||
nsContentPolicyType aContentPolicyType = nsIContentPolicy::TYPE_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(mSuppressLevel == 0, NS_ERROR_FAILURE);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче