Bug 411521 - EventUtils.synthesize* doesn't allow you to specify a window. r=Enn

This commit is contained in:
sdwilsh%shawnwilsher.com 2008-01-28 17:12:17 +00:00
Родитель f23afb923b
Коммит 1a1837ad42
3 изменённых файлов: 28 добавлений и 46 удалений

Просмотреть файл

@ -191,13 +191,18 @@ function _parseModifiers(aEvent)
*
* If the type is specified, an mouse event of that type is fired. Otherwise,
* a mousedown followed by a mouse up is performed.
*
* aWindow is optional, and defaults to the current window object.
*/
function synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent)
function synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
if (!aWindow)
aWindow = window;
var utils = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
if (utils) {
var button = aEvent.button || 0;
var clickCount = aEvent.clickCount || 1;
@ -228,13 +233,18 @@ function synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent)
*
* If the type is specified, a key event of that type is fired. Otherwise,
* a keydown, a keypress and then a keyup event are fired in sequence.
*
* aWindow is optional, and defaults to the current window object.
*/
function synthesizeKey(aKey, aEvent)
function synthesizeKey(aKey, aEvent, aWindow)
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
if (!aWindow)
aWindow = window;
var utils = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
if (utils) {
var keyCode = 0, charCode = 0;
if (aKey.indexOf("VK_") == 0)
@ -312,12 +322,15 @@ function _checkExpectedEvent(aExpectedTarget, aExpectedEvent, aEventHandler, aTe
* To test that an event is not fired, use an expected type preceded by an
* exclamation mark, such as '!select'. This might be used to test that a
* click on a disabled element doesn't fire certain events for instance.
*
* aWindow is optional, and defaults to the current window object.
*/
function synthesizeMouseExpectEvent(aTarget, aOffsetX, aOffsetY, aEvent,
aExpectedTarget, aExpectedEvent, aTestName)
aExpectedTarget, aExpectedEvent, aTestName,
aWindow)
{
var eventHandler = _expectEvent(aExpectedTarget, aExpectedEvent, aTestName);
synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent);
synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent, aWindow);
_checkExpectedEvent(aExpectedTarget, aExpectedEvent, eventHandler, aTestName);
}
@ -331,10 +344,13 @@ function synthesizeMouseExpectEvent(aTarget, aOffsetX, aOffsetY, aEvent,
*
* To test that an event is not fired, use an expected type preceded by an
* exclamation mark, such as '!select'.
*
* aWindow is optional, and defaults to the current window object.
*/
function synthesizeKeyExpectEvent(key, aEvent, aExpectedTarget, aExpectedEvent, aTestName)
function synthesizeKeyExpectEvent(key, aEvent, aExpectedTarget, aExpectedEvent,
aTestName, aWindow)
{
var eventHandler = _expectEvent(aExpectedTarget, aExpectedEvent, aTestName);
synthesizeKey(key, aEvent);
synthesizeKey(key, aEvent, aWindow);
_checkExpectedEvent(aExpectedTarget, aExpectedEvent, eventHandler, aTestName);
}

Просмотреть файл

@ -80,23 +80,6 @@ const DownloadData = [
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
];
// XXX remove me when Bug 411521 is fixed
function synthesizeKey(aKey, aWin)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = aWin.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
if (utils) {
var charCode = 0;
var keyCode = Ci.nsIDOMKeyEvent[aKey];
var modifiers = 0;
utils.sendKeyEvent("keydown", keyCode, charCode, modifiers);
utils.sendKeyEvent("keypress", keyCode, charCode, modifiers);
utils.sendKeyEvent("keyup", keyCode, charCode, modifiers);
}
}
function test_deleteKeyRemoves(aWin)
{
// This also tests the ordering of the display
@ -114,7 +97,7 @@ function test_deleteKeyRemoves(aWin)
var len = DownloadData.length;
for (var i = 0; i < len; i++) {
synthesizeKey("DOM_VK_DELETE", aWin);
EventUtils.synthesizeKey("VK_DELETE", {}, aWin);
stmt.executeStep();
is(stmt.getInt32(0), len - (i + 1),

Просмотреть файл

@ -80,23 +80,6 @@ const DownloadData = [
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
];
// XXX remove me when Bug 411521 is fixed
function synthesizeKey(aKey, aWin)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = aWin.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
if (utils) {
var charCode = 0;
var keyCode = Ci.nsIDOMKeyEvent[aKey];
var modifiers = 0;
utils.sendKeyEvent("keydown", keyCode, charCode, modifiers);
utils.sendKeyEvent("keypress", keyCode, charCode, modifiers);
utils.sendKeyEvent("keyup", keyCode, charCode, modifiers);
}
}
function test_backspaceKeyRemoves(aWin)
{
// This also tests the ordering of the display
@ -114,7 +97,7 @@ function test_backspaceKeyRemoves(aWin)
var len = DownloadData.length;
for (var i = 0; i < len; i++) {
synthesizeKey("DOM_VK_BACK_SPACE", aWin);
EventUtils.synthesizeKey("VK_BACK_SPACE", {}, aWin);
stmt.executeStep();
is(stmt.getInt32(0), len - (i + 1),