Skip to content

Commit

Permalink
Bug 1421482 Part2: Replace test utility synthesizePointer with synthe…
Browse files Browse the repository at this point in the history
…sizeMouse. r=smaug.

We should follow the real use cases to synthesize mouse or touch events to generate pointer events so that the related logic is covered by these test cases.

MozReview-Commit-ID: 9xSgjSL0Azt
  • Loading branch information
mingchou committed Nov 23, 2017
1 parent fd4bca0 commit 841f50b
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 372 deletions.
150 changes: 0 additions & 150 deletions dom/base/nsDOMWindowUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,156 +774,6 @@ nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
aIsDOMEventSynthesized, aIsWidgetEventSynthesized);
}

NS_IMETHODIMP
nsDOMWindowUtils::SendPointerEventCommon(const nsAString& aType,
float aX,
float aY,
int32_t aButton,
int32_t aClickCount,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
int32_t aPointerId,
int32_t aWidth,
int32_t aHeight,
int32_t aTiltX,
int32_t aTiltY,
bool aIsPrimary,
bool aIsSynthesized,
uint8_t aOptionalArgCount,
bool aToWindow,
bool* aPreventDefault)
{
// get the widget to send the event to
nsPoint offset;
nsCOMPtr<nsIWidget> widget = GetWidget(&offset);
if (!widget) {
return NS_ERROR_FAILURE;
}

EventMessage msg;
if (aType.EqualsLiteral("pointerdown")) {
msg = ePointerDown;
} else if (aType.EqualsLiteral("pointerup")) {
msg = ePointerUp;
} else if (aType.EqualsLiteral("pointermove")) {
msg = ePointerMove;
} else if (aType.EqualsLiteral("pointerover")) {
msg = ePointerOver;
} else if (aType.EqualsLiteral("pointerout")) {
msg = ePointerOut;
} else {
return NS_ERROR_FAILURE;
}

if (aInputSourceArg == nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN) {
aInputSourceArg = nsIDOMMouseEvent::MOZ_SOURCE_MOUSE;
}

WidgetPointerEvent event(true, msg, widget);
event.mModifiers = nsContentUtils::GetWidgetModifiers(aModifiers);
event.button = aButton;
event.buttons = nsContentUtils::GetButtonsFlagForButton(aButton);
event.pressure = aPressure;
event.inputSource = aInputSourceArg;
event.pointerId = aPointerId;
event.mWidth = aWidth;
event.mHeight = aHeight;
event.tiltX = aTiltX;
event.tiltY = aTiltY;
event.mIsPrimary =
(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE == aInputSourceArg) ? true : aIsPrimary;
event.mClickCount = aClickCount;
event.mTime = PR_IntervalNow();
event.mFlags.mIsSynthesizedForTests = aOptionalArgCount >= 10 ? aIsSynthesized : true;

nsPresContext* presContext = GetPresContext();
if (!presContext) {
return NS_ERROR_FAILURE;
}

event.mRefPoint =
nsContentUtils::ToWidgetPoint(CSSPoint(aX, aY), offset, presContext);
event.mIgnoreRootScrollFrame = aIgnoreRootScrollFrame;

nsEventStatus status;
if (aToWindow) {
nsCOMPtr<nsIPresShell> presShell;
nsView* view = nsContentUtils::GetViewToDispatchEvent(presContext, getter_AddRefs(presShell));
if (!presShell || !view) {
return NS_ERROR_FAILURE;
}
status = nsEventStatus_eIgnore;
return presShell->HandleEvent(view->GetFrame(), &event, false, &status);
}
nsresult rv = widget->DispatchEvent(&event, status);
if (aPreventDefault) {
*aPreventDefault = (status == nsEventStatus_eConsumeNoDefault);
}

return rv;
}

NS_IMETHODIMP
nsDOMWindowUtils::SendPointerEvent(const nsAString& aType,
float aX,
float aY,
int32_t aButton,
int32_t aClickCount,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
int32_t aPointerId,
int32_t aWidth,
int32_t aHeight,
int32_t aTiltX,
int32_t aTiltY,
bool aIsPrimary,
bool aIsSynthesized,
uint8_t aOptionalArgCount,
bool* aPreventDefault)
{
AUTO_PROFILER_LABEL("nsDOMWindowUtils::SendPointerEvent", EVENTS);

return SendPointerEventCommon(aType, aX, aY, aButton, aClickCount,
aModifiers, aIgnoreRootScrollFrame,
aPressure, aInputSourceArg, aPointerId,
aWidth, aHeight, aTiltX, aTiltY,
aIsPrimary, aIsSynthesized,
aOptionalArgCount, false, aPreventDefault);
}

NS_IMETHODIMP
nsDOMWindowUtils::SendPointerEventToWindow(const nsAString& aType,
float aX,
float aY,
int32_t aButton,
int32_t aClickCount,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
int32_t aPointerId,
int32_t aWidth,
int32_t aHeight,
int32_t aTiltX,
int32_t aTiltY,
bool aIsPrimary,
bool aIsSynthesized,
uint8_t aOptionalArgCount)
{
AUTO_PROFILER_LABEL("nsDOMWindowUtils::SendPointerEventToWindow", EVENTS);

return SendPointerEventCommon(aType, aX, aY, aButton, aClickCount,
aModifiers, aIgnoreRootScrollFrame,
aPressure, aInputSourceArg, aPointerId,
aWidth, aHeight, aTiltX, aTiltY,
aIsPrimary, aIsSynthesized,
aOptionalArgCount, true, nullptr);
}

NS_IMETHODIMP
nsDOMWindowUtils::SendWheelEvent(float aX,
float aY,
Expand Down
20 changes: 0 additions & 20 deletions dom/base/nsDOMWindowUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,6 @@ class nsDOMWindowUtils final : public nsIDOMWindowUtils,
bool aIsWidgetEventSynthesized,
int32_t aButtons);

NS_IMETHOD SendPointerEventCommon(const nsAString& aType,
float aX,
float aY,
int32_t aButton,
int32_t aClickCount,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
int32_t aPointerId,
int32_t aWidth,
int32_t aHeight,
int32_t aTiltX,
int32_t aTiltY,
bool aIsPrimary,
bool aIsSynthesized,
uint8_t aOptionalArgCount,
bool aToWindow,
bool* aPreventDefault);

NS_IMETHOD SendTouchEventCommon(const nsAString& aType,
uint32_t* aIdentifiers,
int32_t* aXs,
Expand Down
42 changes: 21 additions & 21 deletions dom/events/test/test_bug967796.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
var pointerovercount = 0;
var pointeroutcount = 0;

function sendPointerEvent(t, elem) {
function sendMouseEventToElement(t, elem) {
var r = elem.getBoundingClientRect();
synthesizePointer(elem, r.width / 2, r.height / 2, {type: t});
synthesizeMouse(elem, r.width / 2, r.height / 2, {type: t});
}

var expectedPointerEnterTargets = [];
Expand All @@ -68,7 +68,7 @@
iframe.addEventListener("pointerover", pover);

// Make sure ESM thinks pointer is outside the test elements.
sendPointerEvent("pointermove", outside);
sendMouseEventToElement("mousemove", outside);

pointerentercount = 0;
pointerleavecount = 0;
Expand All @@ -78,15 +78,15 @@
expectedRelatedEnter = outside;
expectedRelatedLeave = inner;
expectedPointerEnterTargets = ["outertest", "middletest", "innertest"];
sendPointerEvent("pointermove", inner);
sendMouseEventToElement("mousemove", inner);
is(pointerentercount, 3, "Unexpected pointerenter event count!");
is(pointerovercount, 1, "Unexpected pointerover event count!");
is(pointeroutcount, 0, "Unexpected pointerout event count!");
is(pointerleavecount, 0, "Unexpected pointerleave event count!");
expectedRelatedEnter = inner;
expectedRelatedLeave = outside;
expectedPointerLeaveTargets = ["innertest", "middletest", "outertest"];
sendPointerEvent("pointermove", outside);
sendMouseEventToElement("mousemove", outside);
is(pointerentercount, 3, "Unexpected pointerenter event count!");
is(pointerovercount, 1, "Unexpected pointerover event count!");
is(pointeroutcount, 1, "Unexpected pointerout event count!");
Expand All @@ -96,22 +96,22 @@
var r = file.getBoundingClientRect();
expectedRelatedEnter = outside;
expectedRelatedLeave = file;
synthesizePointer(file, r.width / 6, r.height / 2, {type: "pointermove"});
synthesizeMouse(file, r.width / 6, r.height / 2, {type: "mousemove"});
is(pointerentercount, 4, "Unexpected pointerenter event count!");
is(pointerovercount, 2, "Unexpected pointerover event count!");
is(pointeroutcount, 1, "Unexpected pointerout event count!");
is(pointerleavecount, 3, "Unexpected pointerleave event count!");

// Moving pointer over type="file" shouldn't cause pointerover/out/enter/leave events
synthesizePointer(file, r.width - (r.width / 6), r.height / 2, {type: "pointermove"});
synthesizeMouse(file, r.width - (r.width / 6), r.height / 2, {type: "mousemove"});
is(pointerentercount, 4, "Unexpected pointerenter event count!");
is(pointerovercount, 2, "Unexpected pointerover event count!");
is(pointeroutcount, 1, "Unexpected pointerout event count!");
is(pointerleavecount, 3, "Unexpected pointerleave event count!");

expectedRelatedEnter = file;
expectedRelatedLeave = outside;
sendPointerEvent("pointermove", outside);
sendMouseEventToElement("mousemove", outside);
is(pointerentercount, 4, "Unexpected pointerenter event count!");
is(pointerovercount, 2, "Unexpected pointerover event count!");
is(pointeroutcount, 2, "Unexpected pointerout event count!");
Expand All @@ -135,37 +135,37 @@
expectedRelatedEnter = outside;
expectedRelatedLeave = iframe;
// Move pointer inside the iframe.
synthesizePointer(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "pointermove"},
iframe.contentWindow);
synthesizeMouse(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "mousemove"},
iframe.contentWindow);
is(pointerentercount, 6, "Unexpected pointerenter event count!");
is(pointerleavecount, 4, "Unexpected pointerleave event count!");
synthesizePointer(iframe.contentDocument.body, r.width / 2, r.height - (r.height / 4), {type: "pointermove"},
iframe.contentWindow);
synthesizeMouse(iframe.contentDocument.body, r.width / 2, r.height - (r.height / 4), {type: "mousemove"},
iframe.contentWindow);
is(pointerentercount, 7, "Unexpected pointerenter event count!");
is(pointerleavecount, 5, "Unexpected pointerleave event count!");
expectedRelatedEnter = iframe;
expectedRelatedLeave = outside;
sendPointerEvent("pointermove", outside);
sendMouseEventToElement("mousemove", outside);
is(pointerentercount, 7, "Unexpected pointerenter event count!");
is(pointerleavecount, 7, "Unexpected pointerleave event count!");

// pointerdown must produce pointerenter event
expectedRelatedEnter = outside;
expectedRelatedLeave = iframe;
// Move pointer inside the iframe.
synthesizePointer(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "pointerdown"},
iframe.contentWindow);
synthesizePointer(iframe.contentDocument.body, r.width / 2, r.height - (r.height / 4), {type: "pointerdown"},
iframe.contentWindow);
synthesizeMouse(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "mousedown"},
iframe.contentWindow);
synthesizeMouse(iframe.contentDocument.body, r.width / 2, r.height - (r.height / 4), {type: "mousedown"},
iframe.contentWindow);
is(pointerentercount, 10, "Unexpected pointerenter event count!");

// pointerdown + pointermove must produce single pointerenter event
expectedRelatedEnter = outside;
expectedRelatedLeave = iframe;
synthesizePointer(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "pointerdown"},
iframe.contentWindow);
synthesizePointer(iframe.contentDocument.body, r.width / 2 + 1, r.height / 4 + 1, {type: "pointermove"},
iframe.contentWindow);
synthesizeMouse(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "mousedown"},
iframe.contentWindow);
synthesizeMouse(iframe.contentDocument.body, r.width / 2 + 1, r.height / 4 + 1, {type: "mousemove"},
iframe.contentWindow);
is(pointerentercount, 11, "Unexpected pointerenter event count!");

Array.from(document.querySelectorAll('*'))
Expand Down
Loading

0 comments on commit 841f50b

Please sign in to comment.