2015-03-19 18:41:19 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
this.EXPORTED_SYMBOLS = ["ActionChain"];
|
|
|
|
|
2015-03-19 18:41:19 -07:00
|
|
|
/**
|
|
|
|
* Functionality for (single finger) action chains.
|
|
|
|
*/
|
2015-03-24 08:35:58 -07:00
|
|
|
this.ActionChain = function(utils, checkForInterrupted) {
|
|
|
|
// for assigning unique ids to all touches
|
2015-03-19 18:41:19 -07:00
|
|
|
this.nextTouchId = 1000;
|
2015-03-24 08:35:58 -07:00
|
|
|
// keep track of active Touches
|
2015-03-19 18:41:19 -07:00
|
|
|
this.touchIds = {};
|
|
|
|
// last touch for each fingerId
|
|
|
|
this.lastCoordinates = null;
|
|
|
|
this.isTap = false;
|
|
|
|
this.scrolling = false;
|
|
|
|
// whether to send mouse event
|
|
|
|
this.mouseEventsOnly = false;
|
|
|
|
this.checkTimer = Components.classes["@mozilla.org/timer;1"]
|
2015-03-24 08:35:58 -07:00
|
|
|
.createInstance(Components.interfaces.nsITimer);
|
2015-03-19 18:41:19 -07:00
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
// callbacks for command completion
|
2015-03-19 18:41:19 -07:00
|
|
|
this.onSuccess = null;
|
|
|
|
this.onError = null;
|
|
|
|
if (typeof checkForInterrupted == "function") {
|
|
|
|
this.checkForInterrupted = checkForInterrupted;
|
|
|
|
} else {
|
|
|
|
this.checkForInterrupted = () => {};
|
|
|
|
}
|
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
// determines if we create touch events
|
2015-03-19 18:41:19 -07:00
|
|
|
this.inputSource = null;
|
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
// test utilities providing some event synthesis code
|
2015-03-19 18:41:19 -07:00
|
|
|
this.utils = utils;
|
2015-03-24 08:35:58 -07:00
|
|
|
};
|
2015-03-19 18:41:19 -07:00
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
ActionChain.prototype.dispatchActions = function(
|
|
|
|
args,
|
|
|
|
touchId,
|
2015-08-28 13:43:54 -07:00
|
|
|
container,
|
2015-03-24 08:35:58 -07:00
|
|
|
elementManager,
|
|
|
|
callbacks,
|
|
|
|
touchProvider) {
|
|
|
|
// Some touch events code in the listener needs to do ipc, so we can't
|
|
|
|
// share this code across chrome/content.
|
|
|
|
if (touchProvider) {
|
|
|
|
this.touchProvider = touchProvider;
|
|
|
|
}
|
2015-03-19 18:41:19 -07:00
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
this.elementManager = elementManager;
|
2015-08-28 13:43:54 -07:00
|
|
|
let commandArray = elementManager.convertWrappedArguments(args, container);
|
2015-03-24 08:35:58 -07:00
|
|
|
this.onSuccess = callbacks.onSuccess;
|
|
|
|
this.onError = callbacks.onError;
|
2015-08-28 13:43:54 -07:00
|
|
|
this.container = container;
|
2015-03-19 18:41:19 -07:00
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
if (touchId == null) {
|
|
|
|
touchId = this.nextTouchId++;
|
|
|
|
}
|
2015-03-19 18:41:19 -07:00
|
|
|
|
2015-08-28 13:43:54 -07:00
|
|
|
if (!container.frame.document.createTouch) {
|
2015-03-24 08:35:58 -07:00
|
|
|
this.mouseEventsOnly = true;
|
|
|
|
}
|
2015-03-19 18:41:19 -07:00
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
let keyModifiers = {
|
|
|
|
shiftKey: false,
|
|
|
|
ctrlKey: false,
|
|
|
|
altKey: false,
|
|
|
|
metaKey: false
|
|
|
|
};
|
2015-03-19 18:41:19 -07:00
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
try {
|
|
|
|
this.actions(commandArray, touchId, 0, keyModifiers);
|
|
|
|
} catch (e) {
|
|
|
|
this.onError(e);
|
|
|
|
this.resetValues();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function emit mouse event.
|
|
|
|
*
|
|
|
|
* @param {Document} doc
|
|
|
|
* Current document.
|
|
|
|
* @param {string} type
|
|
|
|
* Type of event to dispatch.
|
|
|
|
* @param {number} clickCount
|
|
|
|
* Number of clicks, button notes the mouse button.
|
|
|
|
* @param {number} elClientX
|
|
|
|
* X coordinate of the mouse relative to the viewport.
|
|
|
|
* @param {number} elClientY
|
|
|
|
* Y coordinate of the mouse relative to the viewport.
|
|
|
|
* @param {Object} modifiers
|
|
|
|
* An object of modifier keys present.
|
|
|
|
*/
|
|
|
|
ActionChain.prototype.emitMouseEvent = function(
|
|
|
|
doc,
|
|
|
|
type,
|
|
|
|
elClientX,
|
|
|
|
elClientY,
|
|
|
|
button,
|
|
|
|
clickCount,
|
|
|
|
modifiers) {
|
|
|
|
if (!this.checkForInterrupted()) {
|
|
|
|
let loggingInfo = "emitting Mouse event of type " + type +
|
|
|
|
" at coordinates (" + elClientX + ", " + elClientY +
|
|
|
|
") relative to the viewport\n" +
|
|
|
|
" button: " + button + "\n" +
|
|
|
|
" clickCount: " + clickCount + "\n";
|
|
|
|
dump(Date.now() + " Marionette: " + loggingInfo);
|
|
|
|
|
|
|
|
let win = doc.defaultView;
|
|
|
|
let domUtils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
2015-03-19 18:41:19 -07:00
|
|
|
.getInterface(Components.interfaces.nsIDOMWindowUtils);
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
let mods;
|
|
|
|
if (typeof modifiers != "undefined") {
|
|
|
|
mods = this.utils._parseModifiers(modifiers);
|
|
|
|
} else {
|
|
|
|
mods = 0;
|
2015-03-19 18:41:19 -07:00
|
|
|
}
|
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
domUtils.sendMouseEvent(
|
|
|
|
type,
|
|
|
|
elClientX,
|
|
|
|
elClientY,
|
2015-08-28 13:43:54 -07:00
|
|
|
button || 0,
|
2015-03-24 08:35:58 -07:00
|
|
|
clickCount || 1,
|
|
|
|
mods,
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
this.inputSource);
|
|
|
|
}
|
|
|
|
};
|
2015-03-19 18:41:19 -07:00
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
/**
|
|
|
|
* Reset any persisted values after a command completes.
|
|
|
|
*/
|
|
|
|
ActionChain.prototype.resetValues = function() {
|
|
|
|
this.onSuccess = null;
|
|
|
|
this.onError = null;
|
2015-08-28 13:43:54 -07:00
|
|
|
this.container = null;
|
2015-03-24 08:35:58 -07:00
|
|
|
this.elementManager = null;
|
|
|
|
this.touchProvider = null;
|
|
|
|
this.mouseEventsOnly = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to emit touch events for each finger. e.g.
|
|
|
|
* finger=[['press', id], ['wait', 5], ['release']] touchId represents
|
|
|
|
* the finger id, i keeps track of the current action of the chain
|
|
|
|
* keyModifiers is an object keeping track keyDown/keyUp pairs through
|
|
|
|
* an action chain.
|
|
|
|
*/
|
|
|
|
ActionChain.prototype.actions = function(chain, touchId, i, keyModifiers) {
|
|
|
|
if (i == chain.length) {
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
2015-05-21 03:26:58 -07:00
|
|
|
this.onSuccess({value: touchId || null});
|
2015-03-24 08:35:58 -07:00
|
|
|
this.resetValues();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let pack = chain[i];
|
|
|
|
let command = pack[0];
|
|
|
|
let el;
|
|
|
|
let c;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (["press", "wait", "keyDown", "keyUp", "click"].indexOf(command) == -1) {
|
|
|
|
// if mouseEventsOnly, then touchIds isn't used
|
|
|
|
if (!(touchId in this.touchIds) && !this.mouseEventsOnly) {
|
|
|
|
this.resetValues();
|
|
|
|
throw new WebDriverError("Element has not been pressed");
|
2015-03-19 18:41:19 -07:00
|
|
|
}
|
2015-03-24 08:35:58 -07:00
|
|
|
}
|
2015-03-19 18:41:19 -07:00
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
switch(command) {
|
|
|
|
case "keyDown":
|
2015-08-28 13:43:54 -07:00
|
|
|
this.utils.sendKeyDown(pack[1], keyModifiers, this.container.frame);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.actions(chain, touchId, i, keyModifiers);
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "keyUp":
|
2015-08-28 13:43:54 -07:00
|
|
|
this.utils.sendKeyUp(pack[1], keyModifiers, this.container.frame);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.actions(chain, touchId, i, keyModifiers);
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "click":
|
2015-08-28 13:43:54 -07:00
|
|
|
el = this.elementManager.getKnownElement(pack[1], this.container);
|
2015-03-19 18:41:19 -07:00
|
|
|
let button = pack[2];
|
|
|
|
let clickCount = pack[3];
|
|
|
|
c = this.coordinates(el, null, null);
|
2015-03-24 08:35:58 -07:00
|
|
|
this.mouseTap(el.ownerDocument, c.x, c.y, button, clickCount, keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
if (button == 2) {
|
2015-03-24 08:35:58 -07:00
|
|
|
this.emitMouseEvent(el.ownerDocument, "contextmenu", c.x, c.y,
|
|
|
|
button, clickCount, keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
}
|
|
|
|
this.actions(chain, touchId, i, keyModifiers);
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "press":
|
2015-03-19 18:41:19 -07:00
|
|
|
if (this.lastCoordinates) {
|
2015-03-24 08:35:58 -07:00
|
|
|
this.generateEvents(
|
|
|
|
"cancel",
|
|
|
|
this.lastCoordinates[0],
|
|
|
|
this.lastCoordinates[1],
|
|
|
|
touchId,
|
|
|
|
null,
|
|
|
|
keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.resetValues();
|
2015-03-24 08:35:58 -07:00
|
|
|
throw new WebDriverError(
|
|
|
|
"Invalid Command: press cannot follow an active touch event");
|
2015-03-19 18:41:19 -07:00
|
|
|
}
|
2015-03-24 08:35:58 -07:00
|
|
|
|
2015-03-19 18:41:19 -07:00
|
|
|
// look ahead to check if we're scrolling. Needed for APZ touch dispatching.
|
|
|
|
if ((i != chain.length) && (chain[i][0].indexOf('move') !== -1)) {
|
|
|
|
this.scrolling = true;
|
|
|
|
}
|
2015-08-28 13:43:54 -07:00
|
|
|
el = this.elementManager.getKnownElement(pack[1], this.container);
|
2015-03-19 18:41:19 -07:00
|
|
|
c = this.coordinates(el, pack[2], pack[3]);
|
2015-03-24 08:35:58 -07:00
|
|
|
touchId = this.generateEvents("press", c.x, c.y, null, el, keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.actions(chain, touchId, i, keyModifiers);
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "release":
|
|
|
|
this.generateEvents(
|
|
|
|
"release",
|
|
|
|
this.lastCoordinates[0],
|
|
|
|
this.lastCoordinates[1],
|
|
|
|
touchId,
|
|
|
|
null,
|
|
|
|
keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.actions(chain, null, i, keyModifiers);
|
|
|
|
this.scrolling = false;
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "move":
|
2015-08-28 13:43:54 -07:00
|
|
|
el = this.elementManager.getKnownElement(pack[1], this.container);
|
2015-03-19 18:41:19 -07:00
|
|
|
c = this.coordinates(el);
|
2015-03-24 08:35:58 -07:00
|
|
|
this.generateEvents("move", c.x, c.y, touchId, null, keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.actions(chain, touchId, i, keyModifiers);
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "moveByOffset":
|
|
|
|
this.generateEvents(
|
|
|
|
"move",
|
|
|
|
this.lastCoordinates[0] + pack[1],
|
|
|
|
this.lastCoordinates[1] + pack[2],
|
|
|
|
touchId,
|
|
|
|
null,
|
|
|
|
keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.actions(chain, touchId, i, keyModifiers);
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "wait":
|
|
|
|
if (pack[1] != null) {
|
|
|
|
let time = pack[1] * 1000;
|
|
|
|
|
2015-03-19 18:41:19 -07:00
|
|
|
// standard waiting time to fire contextmenu
|
|
|
|
let standard = 750;
|
|
|
|
try {
|
|
|
|
standard = Services.prefs.getIntPref("ui.click_hold_context_menus.delay");
|
2015-03-24 08:35:58 -07:00
|
|
|
} catch (e) {}
|
|
|
|
|
2015-03-19 18:41:19 -07:00
|
|
|
if (time >= standard && this.isTap) {
|
2015-03-24 08:35:58 -07:00
|
|
|
chain.splice(i, 0, ["longPress"], ["wait", (time - standard) / 1000]);
|
2015-03-19 18:41:19 -07:00
|
|
|
time = standard;
|
|
|
|
}
|
2015-03-24 08:35:58 -07:00
|
|
|
this.checkTimer.initWithCallback(
|
|
|
|
() => this.actions(chain, touchId, i, keyModifiers),
|
|
|
|
time, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
} else {
|
2015-03-19 18:41:19 -07:00
|
|
|
this.actions(chain, touchId, i, keyModifiers);
|
|
|
|
}
|
|
|
|
break;
|
2015-08-28 13:43:54 -07:00
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
case "cancel":
|
|
|
|
this.generateEvents(
|
|
|
|
"cancel",
|
|
|
|
this.lastCoordinates[0],
|
|
|
|
this.lastCoordinates[1],
|
|
|
|
touchId,
|
|
|
|
null,
|
|
|
|
keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.actions(chain, touchId, i, keyModifiers);
|
|
|
|
this.scrolling = false;
|
|
|
|
break;
|
2015-08-28 13:43:54 -07:00
|
|
|
|
2015-03-24 08:35:58 -07:00
|
|
|
case "longPress":
|
|
|
|
this.generateEvents(
|
|
|
|
"contextmenu",
|
|
|
|
this.lastCoordinates[0],
|
|
|
|
this.lastCoordinates[1],
|
|
|
|
touchId,
|
|
|
|
null,
|
|
|
|
keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.actions(chain, touchId, i, keyModifiers);
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function generates a pair of coordinates relative to the viewport given a
|
|
|
|
* target element and coordinates relative to that element's top-left corner.
|
|
|
|
*
|
|
|
|
* @param {DOMElement} target
|
|
|
|
* The target to calculate coordinates of.
|
|
|
|
* @param {number} x
|
|
|
|
* X coordinate relative to target. If unspecified, the centre of
|
|
|
|
* the target is used.
|
|
|
|
* @param {number} y
|
|
|
|
* Y coordinate relative to target. If unspecified, the centre of
|
|
|
|
* the target is used.
|
|
|
|
*/
|
|
|
|
ActionChain.prototype.coordinates = function(target, x, y) {
|
|
|
|
let box = target.getBoundingClientRect();
|
|
|
|
if (x == null) {
|
|
|
|
x = box.width / 2;
|
|
|
|
}
|
|
|
|
if (y == null) {
|
|
|
|
y = box.height / 2;
|
|
|
|
}
|
|
|
|
let coords = {};
|
|
|
|
coords.x = box.left + x;
|
|
|
|
coords.y = box.top + y;
|
|
|
|
return coords;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given an element and a pair of coordinates, returns an array of the
|
|
|
|
* form [clientX, clientY, pageX, pageY, screenX, screenY].
|
|
|
|
*/
|
|
|
|
ActionChain.prototype.getCoordinateInfo = function(el, corx, cory) {
|
|
|
|
let win = el.ownerDocument.defaultView;
|
|
|
|
return [
|
|
|
|
corx, // clientX
|
|
|
|
cory, // clientY
|
|
|
|
corx + win.pageXOffset, // pageX
|
|
|
|
cory + win.pageYOffset, // pageY
|
|
|
|
corx + win.mozInnerScreenX, // screenX
|
|
|
|
cory + win.mozInnerScreenY // screenY
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} x
|
|
|
|
* X coordinate of the location to generate the event that is relative
|
|
|
|
* to the viewport.
|
|
|
|
* @param {number} y
|
|
|
|
* Y coordinate of the location to generate the event that is relative
|
|
|
|
* to the viewport.
|
|
|
|
*/
|
|
|
|
ActionChain.prototype.generateEvents = function(
|
|
|
|
type, x, y, touchId, target, keyModifiers) {
|
|
|
|
this.lastCoordinates = [x, y];
|
2015-08-28 13:43:54 -07:00
|
|
|
let doc = this.container.frame.document;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case "tap":
|
2015-03-19 18:41:19 -07:00
|
|
|
if (this.mouseEventsOnly) {
|
2015-03-24 08:35:58 -07:00
|
|
|
this.mouseTap(
|
|
|
|
touch.target.ownerDocument,
|
|
|
|
touch.clientX,
|
|
|
|
touch.clientY,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
} else {
|
|
|
|
touchId = this.nextTouchId++;
|
|
|
|
let touch = this.touchProvider.createATouch(target, x, y, touchId);
|
2015-03-24 08:35:58 -07:00
|
|
|
this.touchProvider.emitTouchEvent("touchstart", touch);
|
|
|
|
this.touchProvider.emitTouchEvent("touchend", touch);
|
|
|
|
this.mouseTap(
|
|
|
|
touch.target.ownerDocument,
|
|
|
|
touch.clientX,
|
|
|
|
touch.clientY,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
}
|
|
|
|
this.lastCoordinates = null;
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "press":
|
2015-03-19 18:41:19 -07:00
|
|
|
this.isTap = true;
|
|
|
|
if (this.mouseEventsOnly) {
|
2015-03-24 08:35:58 -07:00
|
|
|
this.emitMouseEvent(doc, "mousemove", x, y, null, null, keyModifiers);
|
|
|
|
this.emitMouseEvent(doc, "mousedown", x, y, null, null, keyModifiers);
|
|
|
|
} else {
|
2015-03-19 18:41:19 -07:00
|
|
|
touchId = this.nextTouchId++;
|
|
|
|
let touch = this.touchProvider.createATouch(target, x, y, touchId);
|
2015-03-24 08:35:58 -07:00
|
|
|
this.touchProvider.emitTouchEvent("touchstart", touch);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.touchIds[touchId] = touch;
|
|
|
|
return touchId;
|
|
|
|
}
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "release":
|
2015-03-19 18:41:19 -07:00
|
|
|
if (this.mouseEventsOnly) {
|
|
|
|
let [x, y] = this.lastCoordinates;
|
2015-03-24 08:35:58 -07:00
|
|
|
this.emitMouseEvent(doc, "mouseup", x, y, null, null, keyModifiers);
|
|
|
|
} else {
|
2015-03-19 18:41:19 -07:00
|
|
|
let touch = this.touchIds[touchId];
|
|
|
|
let [x, y] = this.lastCoordinates;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
2015-03-19 18:41:19 -07:00
|
|
|
touch = this.touchProvider.createATouch(touch.target, x, y, touchId);
|
2015-03-24 08:35:58 -07:00
|
|
|
this.touchProvider.emitTouchEvent("touchend", touch);
|
|
|
|
|
2015-03-19 18:41:19 -07:00
|
|
|
if (this.isTap) {
|
2015-03-24 08:35:58 -07:00
|
|
|
this.mouseTap(
|
|
|
|
touch.target.ownerDocument,
|
|
|
|
touch.clientX,
|
|
|
|
touch.clientY,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
keyModifiers);
|
2015-03-19 18:41:19 -07:00
|
|
|
}
|
|
|
|
delete this.touchIds[touchId];
|
|
|
|
}
|
2015-03-24 08:35:58 -07:00
|
|
|
|
2015-03-19 18:41:19 -07:00
|
|
|
this.isTap = false;
|
|
|
|
this.lastCoordinates = null;
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "cancel":
|
2015-03-19 18:41:19 -07:00
|
|
|
this.isTap = false;
|
|
|
|
if (this.mouseEventsOnly) {
|
|
|
|
let [x, y] = this.lastCoordinates;
|
2015-03-24 08:35:58 -07:00
|
|
|
this.emitMouseEvent(doc, "mouseup", x, y, null, null, keyModifiers);
|
|
|
|
} else {
|
|
|
|
this.touchProvider.emitTouchEvent("touchcancel", this.touchIds[touchId]);
|
2015-03-19 18:41:19 -07:00
|
|
|
delete this.touchIds[touchId];
|
|
|
|
}
|
|
|
|
this.lastCoordinates = null;
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "move":
|
2015-03-19 18:41:19 -07:00
|
|
|
this.isTap = false;
|
|
|
|
if (this.mouseEventsOnly) {
|
2015-03-24 08:35:58 -07:00
|
|
|
this.emitMouseEvent(doc, "mousemove", x, y, null, null, keyModifiers);
|
|
|
|
} else {
|
|
|
|
let touch = this.touchProvider.createATouch(
|
|
|
|
this.touchIds[touchId].target, x, y, touchId);
|
2015-03-19 18:41:19 -07:00
|
|
|
this.touchIds[touchId] = touch;
|
2015-03-24 08:35:58 -07:00
|
|
|
this.touchProvider.emitTouchEvent("touchmove", touch);
|
2015-03-19 18:41:19 -07:00
|
|
|
}
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
case "contextmenu":
|
2015-03-19 18:41:19 -07:00
|
|
|
this.isTap = false;
|
2015-08-28 13:43:54 -07:00
|
|
|
let event = this.container.frame.document.createEvent("MouseEvents");
|
2015-03-19 18:41:19 -07:00
|
|
|
if (this.mouseEventsOnly) {
|
|
|
|
target = doc.elementFromPoint(this.lastCoordinates[0], this.lastCoordinates[1]);
|
2015-03-24 08:35:58 -07:00
|
|
|
} else {
|
2015-03-19 18:41:19 -07:00
|
|
|
target = this.touchIds[touchId].target;
|
|
|
|
}
|
2015-03-24 08:35:58 -07:00
|
|
|
|
|
|
|
let [clientX, clientY, pageX, pageY, screenX, screenY] =
|
|
|
|
this.getCoordinateInfo(target, x, y);
|
|
|
|
|
|
|
|
event.initMouseEvent(
|
|
|
|
"contextmenu",
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
target.ownerDocument.defaultView,
|
|
|
|
1,
|
|
|
|
screenX,
|
|
|
|
screenY,
|
|
|
|
clientX,
|
|
|
|
clientY,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
null);
|
2015-03-19 18:41:19 -07:00
|
|
|
target.dispatchEvent(event);
|
|
|
|
break;
|
2015-03-24 08:35:58 -07:00
|
|
|
|
2015-03-19 18:41:19 -07:00
|
|
|
default:
|
2015-03-24 08:35:58 -07:00
|
|
|
throw new WebDriverError("Unknown event type: " + type);
|
|
|
|
}
|
|
|
|
this.checkForInterrupted();
|
|
|
|
};
|
|
|
|
|
|
|
|
ActionChain.prototype.mouseTap = function(doc, x, y, button, count, mod) {
|
|
|
|
this.emitMouseEvent(doc, "mousemove", x, y, button, count, mod);
|
|
|
|
this.emitMouseEvent(doc, "mousedown", x, y, button, count, mod);
|
|
|
|
this.emitMouseEvent(doc, "mouseup", x, y, button, count, mod);
|
|
|
|
};
|