siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
99 lines (98 loc) • 4.3 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Delay_js_1 = require("../../../generic/util/helper/Delay.js");
var RemoteClient_js_1 = require("../RemoteClient.js");
var RemoteSimulatorClientRobotJs = /** @class */ (function (_super) {
__extends(RemoteSimulatorClientRobotJs, _super);
function RemoteSimulatorClientRobotJs() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.calibratedAtPosition = null;
return _this;
}
RemoteSimulatorClientRobotJs.prototype.setup = function () {
var _this = this;
return _super.prototype.setup.call(this).then(function () { return _this.calibrate(); });
};
RemoteSimulatorClientRobotJs.prototype.calibrate = function () {
var _this = this;
var me = this;
return new Promise(function (resolve, reject) {
var body = document.body;
var mask = document.createElement('div');
mask.setAttribute('style', "position:absolute; height:100%; width:100%; z-index: 10000");
var prevBodyPosition = body.style.position;
body.style.position = 'relative';
body.appendChild(mask);
var removeMask = function () {
if (mask) {
body.removeChild(mask);
body.style.position = prevBodyPosition;
mask = null;
}
};
var cancelCalibrationTimeout = Delay_js_1.timeout(_this.commandTimeout, function () {
removeMask();
reject("timeout");
});
var mouseMoveEvent;
var continuation;
var mouseMoveHandler = function (event) {
document.removeEventListener('mousemove', mouseMoveHandler, true);
removeMask();
if (continuation)
continuation(event);
else
mouseMoveEvent = event;
};
document.addEventListener('mousemove', mouseMoveHandler, true);
var calibrationResult;
_this.calibratedAtPosition = { x: window.screenX, y: window.screenY };
_this.sendRpcCall({
type: 'calibrate',
left: window.screenX,
top: window.screenY,
width: window.outerWidth,
height: window.outerHeight
}, _this.commandTimeout).then(function (result) {
calibrationResult = result;
return new Promise(function (resolve) {
if (mouseMoveEvent)
resolve(mouseMoveEvent);
else
continuation = resolve;
});
}).then(function (event) {
cancelCalibrationTimeout();
me.screenDeltaX = calibrationResult.x - event.clientX;
me.screenDeltaY = calibrationResult.y - event.clientY;
resolve();
}, function (reason) {
cancelCalibrationTimeout();
reject(reason);
});
});
};
RemoteSimulatorClientRobotJs.prototype.recalibrateIfNeeded = function () {
var calibratedAtPosition = this.calibratedAtPosition;
if (!calibratedAtPosition || calibratedAtPosition.x != window.screenX || calibratedAtPosition.y != window.screenY) {
return this.calibrate();
}
else
return Promise.resolve();
};
return RemoteSimulatorClientRobotJs;
}(RemoteClient_js_1.RemoteSimulatorClient));
exports.RemoteSimulatorClientRobotJs = RemoteSimulatorClientRobotJs;
;