Bug 1370403 - Synthesize contextmenu MouseEvent when performing webdriver actions; r=maja_zf

MozReview-Commit-ID: 85nQTsTRttF
This commit is contained in:
muthuraj90ec 2017-08-09 07:51:18 -04:00
Родитель 65c8f5216a
Коммит 0d332730e8
4 изменённых файлов: 48 добавлений и 0 удалений

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

@ -1213,6 +1213,15 @@ function dispatchPointerDown(a, inputState, win) {
inputState.y,
mouseEvent,
win);
if (event.MouseButton.isSecondary(a.button)) {
let contextMenuEvent = Object.assign({},
mouseEvent, {type: "contextmenu"});
event.synthesizeMouseAtPoint(
inputState.x,
inputState.y,
contextMenuEvent,
win);
}
break;
case action.PointerType.Pen:

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

@ -57,6 +57,18 @@ event.Modifiers = {
metaKey: 3,
};
event.MouseButton = {
isPrimary(button) {
return button === 0;
},
isAuxiliary(button) {
return button === 1;
},
isSecondary(button) {
return button === 2;
},
};
/**
* Sends a mouse event to given target.
*

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

@ -50,6 +50,30 @@ def test_click_at_coordinates(session, test_actions_page, mouse_chain):
assert expected == filtered_events[1:]
def test_context_menu_at_coordinates(session, test_actions_page, mouse_chain):
div_point = {
"x": 82,
"y": 187,
}
mouse_chain \
.pointer_move(div_point["x"], div_point["y"]) \
.pointer_down(button=2) \
.pointer_up(button=2) \
.perform()
events = get_events(session)
expected = [
{"type": "mousedown", "button": 2},
{"type": "contextmenu", "button": 2},
]
assert len(events) == 4
filtered_events = [filter_dict(e, expected[0]) for e in events]
mousedown_contextmenu_events = [
x for x in filtered_events
if x["type"] in ["mousedown", "contextmenu"]
]
assert expected == mousedown_contextmenu_events
def test_click_element_center(session, test_actions_page, mouse_chain):
outer = session.find.css("#outer", all=False)
center = get_center(outer.rect)

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

@ -64,6 +64,9 @@
}
function recordPointerEvent(event) {
if (event.type === "contextmenu") {
event.preventDefault();
}
allEvents.events.push({
"type": event.type,
"button": event.button,