mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 16:55:40 +00:00
Bug 1176281 - Part 2: Simplify clickTheLink using BrowserTestUtils.synthesizeMouseAtCenter. r=Gijs
This commit is contained in:
parent
b8e2245f08
commit
279179c798
@ -94,52 +94,8 @@ function getReferrerTestDescription(aTestNumber) {
|
||||
* @param aOptions The options for synthesizeMouseAtCenter.
|
||||
*/
|
||||
function clickTheLink(aWindow, aLinkId, aOptions) {
|
||||
ContentTask.spawn(aWindow.gBrowser.selectedBrowser,
|
||||
{id: aLinkId, options: aOptions},
|
||||
function(data) {
|
||||
let element = content.document.getElementById(data.id);
|
||||
let options = data.options;
|
||||
|
||||
// EventUtils.synthesizeMouseAtCenter(element, options, content);
|
||||
// Alas, EventUtils doesn't work in the content task environment.
|
||||
function doClick() {
|
||||
var domWindowUtils =
|
||||
content.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||
var rect = element.getBoundingClientRect();
|
||||
var left = rect.left + rect.width / 2;
|
||||
var top = rect.top + rect.height / 2;
|
||||
var button = options.button || 0;
|
||||
function sendMouseEvent(type) {
|
||||
domWindowUtils.sendMouseEvent(type, left, top, button,
|
||||
1, 0, false, 0, 0, true);
|
||||
}
|
||||
if ("type" in options) {
|
||||
sendMouseEvent(options.type); // e.g., "contextmenu"
|
||||
} else {
|
||||
sendMouseEvent("mousedown");
|
||||
sendMouseEvent("mouseup");
|
||||
}
|
||||
}
|
||||
|
||||
// waitForFocus(doClick, content);
|
||||
let focusManager = Components.classes["@mozilla.org/focus-manager;1"].
|
||||
getService(Components.interfaces.nsIFocusManager);
|
||||
let desiredWindow = {};
|
||||
focusManager.getFocusedElementForWindow(content, true, desiredWindow);
|
||||
desiredWindow = desiredWindow.value;
|
||||
if (desiredWindow == focusManager.focusedWindow) {
|
||||
// The window is already focused - click away.
|
||||
doClick();
|
||||
} else {
|
||||
// Focus the window first, then click.
|
||||
desiredWindow.addEventListener("focus", function onFocus() {
|
||||
desiredWindow.removeEventListener("focus", onFocus, true);
|
||||
setTimeout(doClick, 0);
|
||||
}, true);
|
||||
desiredWindow.focus();
|
||||
}
|
||||
});
|
||||
return BrowserTestUtils.synthesizeMouseAtCenter(
|
||||
"#" + aLinkId, aOptions, aWindow.gBrowser.selectedBrowser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user