Bug 891882 - DOMWindowUtils.sendMouseEvent dispatch events with isSynthesized chrome attribute set to true. r=smaug

This commit is contained in:
Alexandre Poirot 2014-01-15 09:28:04 -05:00
parent 04f3a9020f
commit e1bfc229ce
9 changed files with 121 additions and 11 deletions

View File

@ -179,6 +179,11 @@ public:
return mEvent->mFlags.mIsTrusted;
}
bool IsSynthesized() const
{
return mEvent->mFlags.mIsSynthesizedForTests;
}
uint64_t TimeStamp() const
{
return mEvent->time;

View File

@ -604,11 +604,14 @@ nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
bool aIsSynthesized,
uint8_t aOptionalArgCount,
bool *aPreventDefault)
{
return SendMouseEventCommon(aType, aX, aY, aButton, aClickCount, aModifiers,
aIgnoreRootScrollFrame, aPressure,
aInputSourceArg, false, aPreventDefault);
aInputSourceArg, false, aPreventDefault,
aOptionalArgCount >= 4 ? aIsSynthesized : true);
}
NS_IMETHODIMP
@ -620,12 +623,15 @@ nsDOMWindowUtils::SendMouseEventToWindow(const nsAString& aType,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg)
unsigned short aInputSourceArg,
bool aIsSynthesized,
uint8_t aOptionalArgCount)
{
PROFILER_LABEL("nsDOMWindowUtils", "SendMouseEventToWindow");
return SendMouseEventCommon(aType, aX, aY, aButton, aClickCount, aModifiers,
aIgnoreRootScrollFrame, aPressure,
aInputSourceArg, true, nullptr);
aInputSourceArg, true, nullptr,
aOptionalArgCount >= 4 ? aIsSynthesized : true);
}
static LayoutDeviceIntPoint
@ -668,7 +674,8 @@ nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
float aPressure,
unsigned short aInputSourceArg,
bool aToWindow,
bool *aPreventDefault)
bool *aPreventDefault,
bool aIsSynthesized)
{
if (!nsContentUtils::IsCallerChrome()) {
return NS_ERROR_DOM_SECURITY_ERR;
@ -715,7 +722,7 @@ nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
event.inputSource = aInputSourceArg;
event.clickCount = aClickCount;
event.time = PR_IntervalNow();
event.mFlags.mIsSynthesizedForTests = true;
event.mFlags.mIsSynthesizedForTests = aIsSynthesized;
nsPresContext* presContext = GetPresContext();
if (!presContext)

View File

@ -46,7 +46,8 @@ protected:
float aPressure,
unsigned short aInputSourceArg,
bool aToWindow,
bool *aPreventDefault);
bool *aPreventDefault,
bool aIsSynthesized);
NS_IMETHOD SendTouchEventCommon(const nsAString& aType,
uint32_t* aIdentifiers,

View File

@ -49,3 +49,4 @@ support-files =
[test_window_extensible.html]
[test_window_indexing.html]
[test_writable-replaceable.html]
[test_domwindowutils.html]

View File

@ -0,0 +1,84 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test for DOMWindowUtils</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div id="content" style="display: none"></div>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
var utils = SpecialPowers.getDOMWindowUtils(window);
function test_sendMouseEventDefaults() {
var x = 1, y = 2, button = 1, clickCount = 2,
modifiers = SpecialPowers.Ci.nsIDOMNSEvent.SHIFT_MASK;
window.addEventListener("mousedown", function listener(evt) {
window.removeEventListener("mousedown", listener);
// Mandatory args
is(evt.clientX, x, "check x");
is(evt.clientY, y, "check y");
is(evt.button, button, "check button");
is(evt.detail, clickCount, "check click count");
is(evt.getModifierState("Shift"), true, "check modifiers");
// Default value for optionals
is(evt.mozPressure, 0, "check pressure");
is(evt.mozInputSource, SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_MOUSE, "check input source");
is(evt.isSynthesized, undefined, "check isSynthesized is undefined in content");
is(SpecialPowers.wrap(evt).isSynthesized, true, "check isSynthesized is true from chrome");
next();
});
// Only pass mandatory arguments and check default values
utils.sendMouseEvent("mousedown", x, y, button, clickCount, modifiers);
}
function test_sendMouseEventOptionals() {
var x = 1, y = 2, button = 1, clickCount = 3,
modifiers = SpecialPowers.Ci.nsIDOMNSEvent.SHIFT_MASK,
pressure = 0.5,
source = SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_KEYBOARD;
window.addEventListener("mouseup", function listener(evt) {
window.removeEventListener("mouseup", listener);
is(evt.mozInputSource, source, "explicit input source is valid");
is(SpecialPowers.wrap(evt).isSynthesized, false, "we can dispatch event that don't look synthesized");
next();
});
// Check explicit value for optional args
utils.sendMouseEvent("mouseup", x, y, button, clickCount, modifiers,
false, pressure, source, false);
}
var tests = [
test_sendMouseEventDefaults,
test_sendMouseEventOptionals
];
function next() {
if (!tests.length) {
SimpleTest.finish();
return;
}
var test = tests.shift();
test();
}
function start() {
SimpleTest.waitForExplicitFinish();
SimpleTest.executeSoon(next);
}
window.addEventListener("load", start);
</script>
</pre>
</body>
</html>

View File

@ -43,7 +43,7 @@ interface nsIDOMEventTarget;
interface nsIRunnable;
interface nsICompositionStringSynthesizer;
[scriptable, uuid(c6efd629-7282-4f0d-9db8-0fa59c191dd5)]
[scriptable, uuid(fa0fe174-7c07-11e3-a5ba-000c290c393e)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -249,9 +249,13 @@ interface nsIDOMWindowUtils : nsISupports {
* @param aPressure touch input pressure: 0.0 -> 1.0
* @param aInputSourceArg input source, see nsIDOMMouseEvent for values,
* defaults to mouse input.
* @param aIsSynthesized controls nsIDOMEvent.isSynthesized value
* that helps identifying test related events,
* defaults to true
*
* returns true if the page called prevent default on this event
*/
[optional_argc]
boolean sendMouseEvent(in AString aType,
in float aX,
in float aY,
@ -260,7 +264,8 @@ interface nsIDOMWindowUtils : nsISupports {
in long aModifiers,
[optional] in boolean aIgnoreRootScrollFrame,
[optional] in float aPressure,
[optional] in unsigned short aInputSourceArg);
[optional] in unsigned short aInputSourceArg,
[optional] in boolean aIsSynthesized);
/** Synthesize a touch event. The event types supported are:
* touchstart, touchend, touchmove, and touchcancel
@ -303,6 +308,7 @@ interface nsIDOMWindowUtils : nsISupports {
/** The same as sendMouseEvent but ensures that the event is dispatched to
* this DOM window or one of its children.
*/
[optional_argc]
void sendMouseEventToWindow(in AString aType,
in float aX,
in float aY,
@ -311,7 +317,8 @@ interface nsIDOMWindowUtils : nsISupports {
in long aModifiers,
[optional] in boolean aIgnoreRootScrollFrame,
[optional] in float aPressure,
[optional] in unsigned short aInputSourceArg);
[optional] in unsigned short aInputSourceArg,
[optional] in boolean aIsSynthesized);
/** The same as sendTouchEvent but ensures that the event is dispatched to
* this DOM window or one of its children.

View File

@ -2387,7 +2387,7 @@ TabChild::DispatchMouseEvent(const nsString& aType,
bool defaultPrevented = false;
utils->SendMouseEvent(aType, aPoint.x, aPoint.y, aButton, aClickCount, aModifiers,
aIgnoreRootScrollFrame, 0, aInputSourceArg, &defaultPrevented);
aIgnoreRootScrollFrame, 0, aInputSourceArg, false, 4, &defaultPrevented);
return defaultPrevented;
}

View File

@ -56,6 +56,7 @@ partial interface Event {
readonly attribute EventTarget? originalTarget;
readonly attribute EventTarget? explicitOriginalTarget;
[ChromeOnly] readonly attribute boolean multipleActionsPrevented;
[ChromeOnly] readonly attribute boolean isSynthesized;
boolean getPreventDefault();
};

View File

@ -249,9 +249,13 @@ function synthesizeMouseAtPoint(left, top, aEvent, aWindow)
var modifiers = _parseModifiers(aEvent);
var pressure = ("pressure" in aEvent) ? aEvent.pressure : 0;
var inputSource = ("inputSource" in aEvent) ? aEvent.inputSource : 0;
var synthesized = ("isSynthesized" in aEvent) ? aEvent.isSynthesized : true;
if (("type" in aEvent) && aEvent.type) {
defaultPrevented = utils.sendMouseEvent(aEvent.type, left, top, button, clickCount, modifiers, false, pressure, inputSource);
defaultPrevented = utils.sendMouseEvent(aEvent.type, left, top, button,
clickCount, modifiers, false,
pressure, inputSource,
synthesized);
}
else {
utils.sendMouseEvent("mousedown", left, top, button, clickCount, modifiers, false, pressure, inputSource);