From 279179c7986d79b4913767cd70fb425a946bae4c Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Fri, 19 Jun 2015 09:13:11 -0700 Subject: [PATCH] Bug 1176281 - Part 2: Simplify clickTheLink using BrowserTestUtils.synthesizeMouseAtCenter. r=Gijs --- browser/base/content/test/referrer/head.js | 48 +--------------------- 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/browser/base/content/test/referrer/head.js b/browser/base/content/test/referrer/head.js index f2b744479416..45a559deb934 100644 --- a/browser/base/content/test/referrer/head.js +++ b/browser/base/content/test/referrer/head.js @@ -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); } /**