2012-03-22 08:19:57 -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/. */
|
|
|
|
|
|
|
|
"use strict";
|
2012-05-11 13:06:53 -07:00
|
|
|
|
2012-09-28 16:16:22 -07:00
|
|
|
const FRAME_SCRIPT = "chrome://marionette/content/marionette-listener.js";
|
|
|
|
|
2013-05-14 13:54:07 -07:00
|
|
|
// import logger
|
|
|
|
Cu.import("resource://gre/modules/services-common/log4moz.js");
|
|
|
|
let logger = Log4Moz.repository.getLogger("Marionette");
|
|
|
|
logger.info('marionette-server.js loaded');
|
2012-03-22 08:19:57 -07:00
|
|
|
|
|
|
|
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
2012-05-11 13:06:53 -07:00
|
|
|
.getService(Ci.mozIJSSubScriptLoader);
|
2012-03-22 08:19:57 -07:00
|
|
|
loader.loadSubScript("chrome://marionette/content/marionette-simpletest.js");
|
|
|
|
loader.loadSubScript("chrome://marionette/content/marionette-log-obj.js");
|
|
|
|
Cu.import("chrome://marionette/content/marionette-elements.js");
|
2012-04-10 17:28:08 -07:00
|
|
|
let utils = {};
|
|
|
|
loader.loadSubScript("chrome://marionette/content/EventUtils.js", utils);
|
|
|
|
loader.loadSubScript("chrome://marionette/content/ChromeUtils.js", utils);
|
2012-05-11 13:06:53 -07:00
|
|
|
loader.loadSubScript("chrome://marionette/content/atoms.js", utils);
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2012-05-18 13:30:13 -07:00
|
|
|
let specialpowers = {};
|
|
|
|
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js",
|
|
|
|
specialpowers);
|
|
|
|
specialpowers.specialPowersObserver = new specialpowers.SpecialPowersObserver();
|
|
|
|
specialpowers.specialPowersObserver.init();
|
|
|
|
|
2012-05-11 13:06:53 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-06-04 10:50:06 -07:00
|
|
|
Cu.import("resource://gre/modules/FileUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2012-05-11 13:06:53 -07:00
|
|
|
Services.prefs.setBoolPref("marionette.contentListener", false);
|
|
|
|
let appName = Services.appinfo.name;
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2013-05-14 13:54:07 -07:00
|
|
|
// dumpn needed/used by dbg-transport.js
|
|
|
|
this.dumpn = function dumpn(str) {
|
|
|
|
logger.trace(str);
|
|
|
|
}
|
|
|
|
loader.loadSubScript("resource://gre/modules/devtools/DevToolsUtils.js");
|
|
|
|
loader.loadSubScript("resource://gre/modules/devtools/server/transport.js");
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2013-04-05 13:04:32 -07:00
|
|
|
let bypassOffline = false;
|
2013-06-19 17:35:20 -07:00
|
|
|
let qemu = "0";
|
|
|
|
let device = null;
|
2013-04-05 13:04:32 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "libcutils", function () {
|
|
|
|
Cu.import("resource://gre/modules/systemlibs.js");
|
|
|
|
return libcutils;
|
|
|
|
});
|
|
|
|
if (libcutils) {
|
2013-06-19 17:35:20 -07:00
|
|
|
qemu = libcutils.property_get("ro.kernel.qemu");
|
2013-05-13 19:26:32 -07:00
|
|
|
logger.info("B2G emulator: " + (qemu == "1" ? "yes" : "no"));
|
2013-06-19 17:35:20 -07:00
|
|
|
device = libcutils.property_get("ro.product.device");
|
|
|
|
logger.info("Device detected is " + device);
|
|
|
|
bypassOffline = (qemu == "1" || device == "panda");
|
2013-04-05 13:04:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(e) {}
|
|
|
|
|
|
|
|
if (bypassOffline) {
|
|
|
|
logger.info("Bypassing offline status.");
|
|
|
|
Services.prefs.setBoolPref("network.gonk.manage-offline-status", false);
|
|
|
|
Services.io.manageOfflineStatus = false;
|
|
|
|
Services.io.offline = false;
|
|
|
|
}
|
|
|
|
|
2012-10-16 16:33:55 -07:00
|
|
|
// This is used to prevent newSession from returning before the telephony
|
2013-05-14 13:54:07 -07:00
|
|
|
// API's are ready; see bug 792647. This assumes that marionette-server.js
|
2012-10-16 16:33:55 -07:00
|
|
|
// will be loaded before the 'system-message-listener-ready' message
|
|
|
|
// is fired. If this stops being true, this approach will have to change.
|
|
|
|
let systemMessageListenerReady = false;
|
|
|
|
Services.obs.addObserver(function() {
|
|
|
|
systemMessageListenerReady = true;
|
|
|
|
}, "system-message-listener-ready", false);
|
|
|
|
|
2012-09-28 16:16:22 -07:00
|
|
|
/**
|
|
|
|
* An object representing a frame that Marionette has loaded a
|
|
|
|
* frame script in.
|
|
|
|
*/
|
|
|
|
function MarionetteRemoteFrame(windowId, frameId) {
|
|
|
|
this.windowId = windowId;
|
|
|
|
this.frameId = frameId;
|
|
|
|
this.targetFrameId = null;
|
|
|
|
this.messageManager = null;
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = null;
|
2012-09-28 16:16:22 -07:00
|
|
|
}
|
|
|
|
// persistent list of remote frames that Marionette has loaded a frame script in
|
|
|
|
let remoteFrames = [];
|
|
|
|
|
2013-04-08 14:12:32 -07:00
|
|
|
/*
|
|
|
|
* Custom exceptions
|
|
|
|
*/
|
|
|
|
function FrameSendNotInitializedError(frame) {
|
|
|
|
this.code = 54;
|
|
|
|
this.frame = frame;
|
|
|
|
this.message = "Error sending message to frame (NS_ERROR_NOT_INITIALIZED)";
|
|
|
|
this.toString = function() {
|
|
|
|
return this.message + " " + this.frame + "; frame has closed.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function FrameSendFailureError(frame) {
|
|
|
|
this.code = 55;
|
|
|
|
this.frame = frame;
|
|
|
|
this.message = "Error sending message to frame (NS_ERROR_FAILURE)";
|
|
|
|
this.toString = function() {
|
|
|
|
return this.message + " " + this.frame + "; frame not responding.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
2013-05-14 13:54:07 -07:00
|
|
|
* The server connection is responsible for all marionette API calls. It gets created
|
2012-09-28 16:16:22 -07:00
|
|
|
* for each connection and manages all chrome and browser based calls. It
|
2012-03-22 08:19:57 -07:00
|
|
|
* mediates content calls by issuing appropriate messages to the content process.
|
|
|
|
*/
|
2013-05-14 13:54:07 -07:00
|
|
|
function MarionetteServerConnection(aPrefix, aTransport, aServer)
|
2012-03-22 08:19:57 -07:00
|
|
|
{
|
|
|
|
this.uuidGen = Cc["@mozilla.org/uuid-generator;1"]
|
2012-05-11 13:06:53 -07:00
|
|
|
.getService(Ci.nsIUUIDGenerator);
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2013-05-14 13:54:07 -07:00
|
|
|
this.prefix = aPrefix;
|
|
|
|
this.server = aServer;
|
|
|
|
this.conn = aTransport;
|
|
|
|
this.conn.hooks = this;
|
|
|
|
|
|
|
|
// marionette uses a protocol based on the debugger server, which requires
|
|
|
|
// passing back "actor ids" with responses. unlike the debugger server,
|
|
|
|
// we don't have multiple actors, so just use a dummy value of "0" here
|
|
|
|
this.actorID = "0";
|
|
|
|
|
2012-09-28 16:16:22 -07:00
|
|
|
this.globalMessageManager = Cc["@mozilla.org/globalmessagemanager;1"]
|
|
|
|
.getService(Ci.nsIMessageBroadcaster);
|
|
|
|
this.messageManager = this.globalMessageManager;
|
2012-03-22 08:19:57 -07:00
|
|
|
this.browsers = {}; //holds list of BrowserObjs
|
|
|
|
this.curBrowser = null; // points to current browser
|
|
|
|
this.context = "content";
|
|
|
|
this.scriptTimeout = null;
|
2013-05-01 10:16:49 -07:00
|
|
|
this.searchTimeout = null;
|
2013-01-11 11:33:58 -08:00
|
|
|
this.pageTimeout = null;
|
2012-03-22 08:19:57 -07:00
|
|
|
this.timer = null;
|
|
|
|
this.marionetteLog = new MarionetteLogObj();
|
|
|
|
this.command_id = null;
|
2012-05-02 07:21:05 -07:00
|
|
|
this.mainFrame = null; //topmost chrome frame
|
|
|
|
this.curFrame = null; //subframe that currently has focus
|
2012-06-04 10:50:06 -07:00
|
|
|
this.importedScripts = FileUtils.getFile('TmpD', ['marionettescriptchrome']);
|
2012-09-28 16:16:22 -07:00
|
|
|
this.currentRemoteFrame = null; // a member of remoteFrames
|
2012-10-31 15:36:57 -07:00
|
|
|
this.testName = null;
|
2013-01-16 07:00:00 -08:00
|
|
|
this.mozBrowserClose = null;
|
2012-09-28 16:16:22 -07:00
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
//register all message listeners
|
2012-09-28 16:16:22 -07:00
|
|
|
this.addMessageManagerListeners(this.messageManager);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
|
2013-05-14 13:54:07 -07:00
|
|
|
MarionetteServerConnection.prototype = {
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2013-05-14 13:54:07 -07:00
|
|
|
/**
|
|
|
|
* Debugger transport callbacks:
|
|
|
|
*/
|
|
|
|
onPacket: function MSC_onPacket(aPacket) {
|
|
|
|
// Dispatch the request
|
|
|
|
if (this.requestTypes && this.requestTypes[aPacket.type]) {
|
|
|
|
try {
|
|
|
|
this.requestTypes[aPacket.type].bind(this)(aPacket);
|
|
|
|
} catch(e) {
|
|
|
|
this.conn.send({ error: ("error occurred while processing '" +
|
|
|
|
aPacket.type),
|
|
|
|
message: e });
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.conn.send({ error: "unrecognizedPacketType",
|
|
|
|
message: ('Marionette does not ' +
|
|
|
|
'recognize the packet type "' +
|
|
|
|
aPacket.type + '"') });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onClosed: function MSC_onClosed(aStatus) {
|
|
|
|
this.server._connectionClosed(this);
|
|
|
|
this.deleteSession();
|
|
|
|
},
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2012-09-28 16:16:22 -07:00
|
|
|
/**
|
|
|
|
* Helper methods:
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switches to the global ChromeMessageBroadcaster, potentially replacing a frame-specific
|
|
|
|
* ChromeMessageSender. Has no effect if the global ChromeMessageBroadcaster is already
|
|
|
|
* in use. If this replaces a frame-specific ChromeMessageSender, it removes the message
|
|
|
|
* listeners from that sender, and then puts the corresponding frame script "to sleep",
|
|
|
|
* which removes most of the message listeners from it as well.
|
|
|
|
*/
|
|
|
|
switchToGlobalMessageManager: function MDA_switchToGlobalMM() {
|
|
|
|
if (this.currentRemoteFrame !== null) {
|
|
|
|
this.removeMessageManagerListeners(this.messageManager);
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("sleepSession", null, null, true);
|
2012-09-28 16:16:22 -07:00
|
|
|
}
|
|
|
|
this.messageManager = this.globalMessageManager;
|
|
|
|
this.currentRemoteFrame = null;
|
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Helper method to send async messages to the content listener
|
|
|
|
*
|
|
|
|
* @param string name
|
|
|
|
* Suffix of the targetted message listener (Marionette:<suffix>)
|
|
|
|
* @param object values
|
|
|
|
* Object to send to the listener
|
|
|
|
*/
|
2013-04-08 14:12:32 -07:00
|
|
|
sendAsync: function MDA_sendAsync(name, values, commandId, ignoreFailure) {
|
|
|
|
let success = true;
|
|
|
|
if (values instanceof Object && commandId) {
|
|
|
|
values.command_id = commandId;
|
|
|
|
}
|
2012-09-28 16:16:22 -07:00
|
|
|
if (this.currentRemoteFrame !== null) {
|
2013-04-08 14:12:32 -07:00
|
|
|
try {
|
|
|
|
this.messageManager.sendAsyncMessage(
|
|
|
|
"Marionette:" + name + this.currentRemoteFrame.targetFrameId, values);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
if (!ignoreFailure) {
|
|
|
|
success = false;
|
|
|
|
let error = e;
|
|
|
|
switch(e.result) {
|
|
|
|
case Components.results.NS_ERROR_FAILURE:
|
|
|
|
error = new FrameSendFailureError(this.currentRemoteFrame);
|
|
|
|
break;
|
|
|
|
case Components.results.NS_ERROR_NOT_INITIALIZED:
|
|
|
|
error = new FrameSendNotInitializedError(this.currentRemoteFrame);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-04-18 03:04:13 -07:00
|
|
|
let code = error.hasOwnProperty('code') ? e.code : 500;
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendError(error.toString(), code, error.stack, commandId);
|
|
|
|
}
|
|
|
|
}
|
2012-09-28 16:16:22 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.messageManager.broadcastAsyncMessage(
|
|
|
|
"Marionette:" + name + this.curBrowser.curFrameId, values);
|
|
|
|
}
|
2013-04-08 14:12:32 -07:00
|
|
|
return success;
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-09-28 16:16:22 -07:00
|
|
|
* Adds listeners for messages from content frame scripts.
|
|
|
|
*
|
|
|
|
* @param object messageManager
|
|
|
|
* The messageManager object (ChromeMessageBroadcaster or ChromeMessageSender)
|
|
|
|
* to which the listeners should be added.
|
2012-03-22 08:19:57 -07:00
|
|
|
*/
|
2012-09-28 16:16:22 -07:00
|
|
|
addMessageManagerListeners: function MDA_addMessageManagerListeners(messageManager) {
|
|
|
|
messageManager.addMessageListener("Marionette:ok", this);
|
|
|
|
messageManager.addMessageListener("Marionette:done", this);
|
|
|
|
messageManager.addMessageListener("Marionette:error", this);
|
|
|
|
messageManager.addMessageListener("Marionette:log", this);
|
|
|
|
messageManager.addMessageListener("Marionette:shareData", this);
|
|
|
|
messageManager.addMessageListener("Marionette:register", this);
|
|
|
|
messageManager.addMessageListener("Marionette:runEmulatorCmd", this);
|
|
|
|
messageManager.addMessageListener("Marionette:switchToFrame", this);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes listeners for messages from content frame scripts.
|
|
|
|
*
|
|
|
|
* @param object messageManager
|
|
|
|
* The messageManager object (ChromeMessageBroadcaster or ChromeMessageSender)
|
|
|
|
* from which the listeners should be removed.
|
|
|
|
*/
|
|
|
|
removeMessageManagerListeners: function MDA_removeMessageManagerListeners(messageManager) {
|
|
|
|
messageManager.removeMessageListener("Marionette:ok", this);
|
|
|
|
messageManager.removeMessageListener("Marionette:done", this);
|
|
|
|
messageManager.removeMessageListener("Marionette:error", this);
|
|
|
|
messageManager.removeMessageListener("Marionette:log", this);
|
|
|
|
messageManager.removeMessageListener("Marionette:shareData", this);
|
|
|
|
messageManager.removeMessageListener("Marionette:register", this);
|
|
|
|
messageManager.removeMessageListener("Marionette:runEmulatorCmd", this);
|
|
|
|
messageManager.removeMessageListener("Marionette:switchToFrame", this);
|
|
|
|
},
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2012-11-26 18:19:04 -08:00
|
|
|
logRequest: function MDA_logRequest(type, data) {
|
|
|
|
logger.debug("Got request: " + type + ", data: " + JSON.stringify(data) + ", id: " + this.command_id);
|
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Generic method to pass a response to the client
|
2012-09-28 16:16:22 -07:00
|
|
|
*
|
2012-03-22 08:19:57 -07:00
|
|
|
* @param object msg
|
|
|
|
* Response to send back to client
|
|
|
|
* @param string command_id
|
|
|
|
* Unique identifier assigned to the client's request.
|
|
|
|
* Used to distinguish the asynchronous responses.
|
|
|
|
*/
|
|
|
|
sendToClient: function MDA_sendToClient(msg, command_id) {
|
2013-02-12 10:10:03 -08:00
|
|
|
logger.info("sendToClient: " + JSON.stringify(msg) + ", " + command_id +
|
|
|
|
", " + this.command_id);
|
2012-11-26 18:19:04 -08:00
|
|
|
if (!command_id) {
|
|
|
|
logger.warn("got a response with no command_id");
|
2013-02-12 10:10:03 -08:00
|
|
|
return;
|
2012-11-26 18:19:04 -08:00
|
|
|
}
|
2013-03-06 09:48:30 -08:00
|
|
|
else if (command_id != -1) {
|
|
|
|
// A command_id of -1 is used for emulator callbacks, and those
|
|
|
|
// don't use this.command_id.
|
|
|
|
if (!this.command_id) {
|
|
|
|
// A null value for this.command_id means we've already processed
|
|
|
|
// a message for the previous value, and so the current message is a
|
|
|
|
// duplicate.
|
|
|
|
logger.warn("ignoring duplicate response for command_id " + command_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (this.command_id != command_id) {
|
|
|
|
logger.warn("ignoring out-of-sync response");
|
|
|
|
return;
|
|
|
|
}
|
2012-05-18 13:30:43 -07:00
|
|
|
}
|
|
|
|
this.conn.send(msg);
|
2013-02-12 10:10:03 -08:00
|
|
|
if (command_id != -1) {
|
|
|
|
// Don't unset this.command_id if this message is to process an
|
|
|
|
// emulator callback, since another response for this command_id is
|
|
|
|
// expected, after the containing call to execute_async_script finishes.
|
2012-03-22 08:19:57 -07:00
|
|
|
this.command_id = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a value to client
|
|
|
|
*
|
|
|
|
* @param object value
|
|
|
|
* Value to send back to client
|
|
|
|
* @param string command_id
|
|
|
|
* Unique identifier assigned to the client's request.
|
|
|
|
* Used to distinguish the asynchronous responses.
|
|
|
|
*/
|
|
|
|
sendResponse: function MDA_sendResponse(value, command_id) {
|
|
|
|
if (typeof(value) == 'undefined')
|
|
|
|
value = null;
|
|
|
|
this.sendToClient({from:this.actorID, value: value}, command_id);
|
|
|
|
},
|
|
|
|
|
2013-05-14 13:54:07 -07:00
|
|
|
sayHello: function MDA_sayHello() {
|
|
|
|
this.conn.send({ from: "root",
|
|
|
|
applicationType: "gecko",
|
|
|
|
traits: [] });
|
|
|
|
},
|
|
|
|
|
|
|
|
getMarionetteID: function MDA_getMarionette() {
|
|
|
|
this.conn.send({ "from": "root", "id": this.actorID });
|
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Send ack to client
|
|
|
|
*
|
|
|
|
* @param string command_id
|
|
|
|
* Unique identifier assigned to the client's request.
|
|
|
|
* Used to distinguish the asynchronous responses.
|
|
|
|
*/
|
|
|
|
sendOk: function MDA_sendOk(command_id) {
|
|
|
|
this.sendToClient({from:this.actorID, ok: true}, command_id);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send error message to client
|
|
|
|
*
|
|
|
|
* @param string message
|
|
|
|
* Error message
|
|
|
|
* @param number status
|
|
|
|
* Status number
|
|
|
|
* @param string trace
|
|
|
|
* Stack trace
|
|
|
|
* @param string command_id
|
|
|
|
* Unique identifier assigned to the client's request.
|
|
|
|
* Used to distinguish the asynchronous responses.
|
|
|
|
*/
|
|
|
|
sendError: function MDA_sendError(message, status, trace, command_id) {
|
|
|
|
let error_msg = {message: message, status: status, stacktrace: trace};
|
|
|
|
this.sendToClient({from:this.actorID, error: error_msg}, command_id);
|
|
|
|
},
|
|
|
|
|
2013-06-21 17:13:35 -07:00
|
|
|
/**
|
|
|
|
* Creates an error message for a JavaScript exception thrown during
|
|
|
|
* execute_(async_)script.
|
|
|
|
*
|
|
|
|
* This will generate a [msg, trace] pair like:
|
|
|
|
*
|
|
|
|
* ['ReferenceError: foo is not defined',
|
|
|
|
* 'execute_script @test_foo.py, line 10
|
|
|
|
* inline javascript, line 2
|
|
|
|
* src: "return foo;"']
|
|
|
|
*
|
|
|
|
* @param error An Error object passed to a catch() clause.
|
|
|
|
fnName The name of the function to use in the stack trace message
|
|
|
|
(e.g., 'execute_script').
|
|
|
|
pythonFile The filename of the test file containing the Marionette
|
|
|
|
command that caused this exception to occur.
|
|
|
|
pythonLine The line number of the above test file.
|
|
|
|
script The JS script being executed in text form.
|
|
|
|
*/
|
|
|
|
createStackMessage: function MDA_createStackMessage(error, fnName, pythonFile,
|
|
|
|
pythonLine, script) {
|
|
|
|
let python_stack = fnName + " @" + pythonFile + ", line " + pythonLine;
|
|
|
|
let stack = error.stack.split("\n");
|
|
|
|
let line = stack[0].substr(stack[0].lastIndexOf(':') + 1);
|
|
|
|
let msg = error.name + ": " + error.message;
|
|
|
|
let trace = python_stack +
|
|
|
|
"\ninline javascript, line " + line +
|
|
|
|
"\nsrc: \"" + script.split("\n")[line] + "\"";
|
|
|
|
return [msg, trace];
|
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Gets the current active window
|
|
|
|
*
|
|
|
|
* @return nsIDOMWindow
|
|
|
|
*/
|
|
|
|
getCurrentWindow: function MDA_getCurrentWindow() {
|
|
|
|
let type = null;
|
2012-05-02 07:21:05 -07:00
|
|
|
if (this.curFrame == null) {
|
2012-08-28 11:14:30 -07:00
|
|
|
if (this.curBrowser == null) {
|
2013-01-15 17:41:36 -08:00
|
|
|
if (this.context == "content") {
|
2012-08-28 11:14:30 -07:00
|
|
|
type = 'navigator:browser';
|
|
|
|
}
|
|
|
|
return Services.wm.getMostRecentWindow(type);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this.curBrowser.window;
|
2012-05-02 07:21:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this.curFrame;
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the the window enumerator
|
|
|
|
*
|
|
|
|
* @return nsISimpleEnumerator
|
|
|
|
*/
|
|
|
|
getWinEnumerator: function MDA_getWinEnumerator() {
|
|
|
|
let type = null;
|
2012-04-10 17:28:08 -07:00
|
|
|
if (appName != "B2G" && this.context == "content") {
|
2012-03-22 08:19:57 -07:00
|
|
|
type = 'navigator:browser';
|
|
|
|
}
|
2012-05-11 13:06:53 -07:00
|
|
|
return Services.wm.getEnumerator(type);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new BrowserObj for window and add to known browsers
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow win
|
|
|
|
* Window for which we will create a BrowserObj
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* Returns the unique server-assigned ID of the window
|
|
|
|
*/
|
|
|
|
addBrowser: function MDA_addBrowser(win) {
|
|
|
|
let browser = new BrowserObj(win);
|
|
|
|
let winId = win.QueryInterface(Ci.nsIInterfaceRequestor).
|
|
|
|
getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
|
|
|
|
winId = winId + ((appName == "B2G") ? '-b2g' : '');
|
2012-04-03 11:08:49 -07:00
|
|
|
this.browsers[winId] = browser;
|
|
|
|
this.curBrowser = this.browsers[winId];
|
|
|
|
if (this.curBrowser.elementManager.seenItems[winId] == undefined) {
|
2012-03-22 08:19:57 -07:00
|
|
|
//add this to seenItems so we can guarantee the user will get winId as this window's id
|
2013-04-09 10:05:43 -07:00
|
|
|
this.curBrowser.elementManager.seenItems[winId] = Cu.getWeakReference(win);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start a new session in a new browser.
|
|
|
|
*
|
|
|
|
* If newSession is true, we will switch focus to the start frame
|
|
|
|
* when it registers. Also, if it is in desktop, then a new tab
|
|
|
|
* with the start page uri (about:blank) will be opened.
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow win
|
|
|
|
* Window whose browser we need to access
|
|
|
|
* @param boolean newSession
|
|
|
|
* True if this is the first time we're talking to this browser
|
|
|
|
*/
|
|
|
|
startBrowser: function MDA_startBrowser(win, newSession) {
|
2012-05-02 07:21:05 -07:00
|
|
|
this.mainFrame = win;
|
|
|
|
this.curFrame = null;
|
2012-04-03 11:08:49 -07:00
|
|
|
this.addBrowser(win);
|
|
|
|
this.curBrowser.newSession = newSession;
|
2012-08-21 14:00:44 -07:00
|
|
|
this.curBrowser.startSession(newSession, win, this.whenBrowserStarted.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked after a new session has been started in a browser.
|
|
|
|
* Loads the Marionette frame script into the browser if needed.
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow win
|
|
|
|
* Window whose browser we need to access
|
|
|
|
* @param boolean newSession
|
|
|
|
* True if this is the first time we're talking to this browser
|
|
|
|
*/
|
|
|
|
whenBrowserStarted: function MDA_whenBrowserStarted(win, newSession) {
|
2012-04-10 17:28:08 -07:00
|
|
|
try {
|
2012-05-17 11:53:55 -07:00
|
|
|
if (!Services.prefs.getBoolPref("marionette.contentListener") || !newSession) {
|
2012-09-28 16:16:22 -07:00
|
|
|
this.curBrowser.loadFrameScript(FRAME_SCRIPT, win);
|
2012-05-17 11:53:55 -07:00
|
|
|
}
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
//there may not always be a content process
|
|
|
|
logger.info("could not load listener into content for page: " + win.location.href);
|
|
|
|
}
|
|
|
|
utils.window = win;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively get all labeled text
|
|
|
|
*
|
|
|
|
* @param nsIDOMElement el
|
|
|
|
* The parent element
|
|
|
|
* @param array lines
|
|
|
|
* Array that holds the text lines
|
|
|
|
*/
|
|
|
|
getVisibleText: function MDA_getVisibleText(el, lines) {
|
|
|
|
let nodeName = el.nodeName;
|
|
|
|
try {
|
|
|
|
if (utils.isElementDisplayed(el)) {
|
|
|
|
if (el.value) {
|
|
|
|
lines.push(el.value);
|
|
|
|
}
|
|
|
|
for (var child in el.childNodes) {
|
|
|
|
this.getVisibleText(el.childNodes[child], lines);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
if (nodeName == "#text") {
|
|
|
|
lines.push(el.textContent);
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
2012-11-26 18:19:04 -08:00
|
|
|
getCommandId: function MDA_getCommandId() {
|
|
|
|
return this.uuidGen.generateUUID().toString();
|
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Marionette API:
|
2012-11-26 18:19:04 -08:00
|
|
|
*
|
|
|
|
* All methods implementing a command from the client should create a
|
|
|
|
* command_id, and then use this command_id in all messages exchanged with
|
|
|
|
* the frame scripts and with responses sent to the client. This prevents
|
|
|
|
* commands and responses from getting out-of-sync, which can happen in
|
|
|
|
* the case of execute_async calls that timeout and then later send a
|
|
|
|
* response, and other situations. See bug 779011. See setScriptTimeout()
|
|
|
|
* for a basic example.
|
2012-03-22 08:19:57 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new session. This creates a BrowserObj.
|
|
|
|
*
|
|
|
|
* In a desktop environment, this opens a new 'about:blank' tab for
|
|
|
|
* the client to test in.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
newSession: function MDA_newSession() {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2013-02-12 10:10:03 -08:00
|
|
|
this.newSessionCommandId = this.command_id;
|
2012-11-26 18:19:04 -08:00
|
|
|
|
2012-11-28 13:31:23 -08:00
|
|
|
this.scriptTimeout = 10000;
|
2012-05-10 11:42:54 -07:00
|
|
|
|
|
|
|
function waitForWindow() {
|
2012-05-11 13:06:53 -07:00
|
|
|
let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
2012-05-10 11:42:54 -07:00
|
|
|
let win = this.getCurrentWindow();
|
2012-10-16 16:33:55 -07:00
|
|
|
if (!win ||
|
|
|
|
(appName == "Firefox" && !win.gBrowser) ||
|
2012-10-17 15:14:51 -07:00
|
|
|
(appName == "Fennec" && !win.BrowserApp)) {
|
2012-05-10 11:42:54 -07:00
|
|
|
checkTimer.initWithCallback(waitForWindow.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.startBrowser(win, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-28 16:16:22 -07:00
|
|
|
this.switchToGlobalMessageManager();
|
|
|
|
|
2012-05-11 13:06:53 -07:00
|
|
|
if (!Services.prefs.getBoolPref("marionette.contentListener")) {
|
2012-05-10 11:42:54 -07:00
|
|
|
waitForWindow.call(this);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
2012-09-18 01:08:55 -07:00
|
|
|
else if ((appName != "Firefox") && (this.curBrowser == null)) {
|
2012-03-22 08:19:57 -07:00
|
|
|
//if there is a content listener, then we just wake it up
|
2012-04-03 11:08:49 -07:00
|
|
|
this.addBrowser(this.getCurrentWindow());
|
2012-08-21 14:00:44 -07:00
|
|
|
this.curBrowser.startSession(false, this.getCurrentWindow(), this.whenBrowserStarted);
|
2012-08-27 07:13:02 -07:00
|
|
|
this.messageManager.broadcastAsyncMessage("Marionette:restart", {});
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError("Session already running", 500, null, this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-08-10 11:51:35 -07:00
|
|
|
getSessionCapabilities: function MDA_getSessionCapabilities(){
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
|
|
|
|
2012-08-10 11:51:35 -07:00
|
|
|
let rotatable = appName == "B2G" ? true : false;
|
|
|
|
|
|
|
|
let value = {
|
|
|
|
'appBuildId' : Services.appinfo.appBuildID,
|
|
|
|
'XULappId' : Services.appinfo.ID,
|
|
|
|
'cssSelectorsEnabled': true,
|
|
|
|
'browserName': appName,
|
|
|
|
'handlesAlerts': false,
|
|
|
|
'javascriptEnabled': true,
|
|
|
|
'nativeEvents': false,
|
|
|
|
'platform': Services.appinfo.OS,
|
2013-06-19 17:35:20 -07:00
|
|
|
'device': qemu == "1" ? "qemu" : (!device ? "desktop" : device),
|
2012-08-10 11:51:35 -07:00
|
|
|
'rotatable': rotatable,
|
|
|
|
'takesScreenshot': false,
|
|
|
|
'version': Services.appinfo.version
|
|
|
|
};
|
|
|
|
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(value, this.command_id);
|
2012-08-10 11:51:35 -07:00
|
|
|
},
|
|
|
|
|
2012-10-15 16:51:27 -07:00
|
|
|
getStatus: function MDA_getStatus(){
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
|
|
|
|
2012-10-15 16:51:27 -07:00
|
|
|
let arch;
|
|
|
|
try {
|
|
|
|
arch = (Services.appinfo.XPCOMABI || 'unknown').split('-')[0]
|
|
|
|
}
|
|
|
|
catch (ignored) {
|
|
|
|
arch = 'unknown'
|
|
|
|
};
|
|
|
|
|
|
|
|
let value = {
|
|
|
|
'os': {
|
|
|
|
'arch': arch,
|
|
|
|
'name': Services.appinfo.OS,
|
|
|
|
'version': 'unknown'
|
|
|
|
},
|
|
|
|
'build': {
|
|
|
|
'revision': 'unknown',
|
|
|
|
'time': Services.appinfo.platformBuildID,
|
|
|
|
'version': Services.appinfo.version
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(value, this.command_id);
|
2012-10-15 16:51:27 -07:00
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Log message. Accepts user defined log-level.
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'value' member holds log message
|
|
|
|
* 'level' member hold log level
|
|
|
|
*/
|
|
|
|
log: function MDA_log(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2012-03-22 08:19:57 -07:00
|
|
|
this.marionetteLog.log(aRequest.value, aRequest.level);
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all logged messages.
|
|
|
|
*/
|
|
|
|
getLogs: function MDA_getLogs() {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
|
|
|
this.sendResponse(this.marionetteLog.getLogs(), this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Sets the context of the subsequent commands to be either 'chrome' or 'content'
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'value' member holds the name of the context to be switched to
|
|
|
|
*/
|
|
|
|
setContext: function MDA_setContext(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
|
|
|
this.logRequest("setContext", aRequest);
|
2012-03-22 08:19:57 -07:00
|
|
|
let context = aRequest.value;
|
|
|
|
if (context != "content" && context != "chrome") {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError("invalid context", 500, null, this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.context = context;
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a chrome sandbox that can be used by the execute_foo functions.
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow aWindow
|
|
|
|
* Window in which we will execute code
|
|
|
|
* @param Marionette marionette
|
|
|
|
* Marionette test instance
|
|
|
|
* @param object args
|
|
|
|
* Client given args
|
|
|
|
* @return Sandbox
|
|
|
|
* Returns the sandbox
|
|
|
|
*/
|
2013-02-12 10:10:03 -08:00
|
|
|
createExecuteSandbox: function MDA_createExecuteSandbox(aWindow, marionette, args, specialPowers, command_id) {
|
2012-03-22 08:19:57 -07:00
|
|
|
try {
|
2012-04-03 11:08:49 -07:00
|
|
|
args = this.curBrowser.elementManager.convertWrappedArguments(args, aWindow);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
catch(e) {
|
2013-02-12 10:10:03 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let _chromeSandbox = new Cu.Sandbox(aWindow,
|
|
|
|
{ sandboxPrototype: aWindow, wantXrays: false, sandboxName: ''});
|
2012-04-03 11:08:49 -07:00
|
|
|
_chromeSandbox.__namedArgs = this.curBrowser.elementManager.applyNamedArgs(args);
|
2012-03-22 08:19:57 -07:00
|
|
|
_chromeSandbox.__marionetteParams = args;
|
2012-04-10 17:28:08 -07:00
|
|
|
_chromeSandbox.testUtils = utils;
|
2012-03-22 08:19:57 -07:00
|
|
|
|
|
|
|
marionette.exports.forEach(function(fn) {
|
2012-09-14 14:34:38 -07:00
|
|
|
try {
|
|
|
|
_chromeSandbox[fn] = marionette[fn].bind(marionette);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
_chromeSandbox[fn] = marionette[fn];
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
});
|
|
|
|
|
2012-10-17 15:14:51 -07:00
|
|
|
_chromeSandbox.isSystemMessageListenerReady =
|
|
|
|
function() { return systemMessageListenerReady; }
|
|
|
|
|
2012-06-25 12:08:38 -07:00
|
|
|
if (specialPowers == true) {
|
|
|
|
loader.loadSubScript("chrome://specialpowers/content/specialpowersAPI.js",
|
|
|
|
_chromeSandbox);
|
|
|
|
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserverAPI.js",
|
|
|
|
_chromeSandbox);
|
|
|
|
loader.loadSubScript("chrome://specialpowers/content/ChromePowers.js",
|
|
|
|
_chromeSandbox);
|
|
|
|
}
|
2012-05-18 13:30:04 -07:00
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
return _chromeSandbox;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes a script in the given sandbox.
|
|
|
|
*
|
|
|
|
* @param Sandbox sandbox
|
|
|
|
* Sandbox in which the script will run
|
|
|
|
* @param string script
|
|
|
|
* The script to run
|
|
|
|
* @param boolean directInject
|
|
|
|
* If true, then the script will be run as is,
|
|
|
|
* and not as a function body (as you would
|
|
|
|
* do using the WebDriver spec)
|
|
|
|
* @param boolean async
|
|
|
|
* True if the script is asynchronous
|
|
|
|
*/
|
|
|
|
executeScriptInSandbox: function MDA_executeScriptInSandbox(sandbox, script,
|
2013-01-29 09:45:59 -08:00
|
|
|
directInject, async, command_id, timeout) {
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2012-08-31 13:59:48 -07:00
|
|
|
if (directInject && async &&
|
2013-01-29 09:45:59 -08:00
|
|
|
(timeout == null || timeout == 0)) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError("Please set a timeout", 21, null, command_id);
|
2012-08-31 13:59:48 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-06-04 10:50:06 -07:00
|
|
|
|
2012-08-31 13:59:48 -07:00
|
|
|
if (this.importedScripts.exists()) {
|
|
|
|
let stream = Cc["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIFileInputStream);
|
|
|
|
stream.init(this.importedScripts, -1, 0, 0);
|
|
|
|
let data = NetUtil.readInputStreamToString(stream, stream.available());
|
|
|
|
script = data + script;
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2013-06-21 17:13:35 -07:00
|
|
|
let res = Cu.evalInSandbox(script, sandbox, "1.8", "dummy file", 0);
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2012-08-31 13:59:48 -07:00
|
|
|
if (directInject && !async &&
|
|
|
|
(res == undefined || res.passed == undefined)) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError("finish() not called", 500, null, command_id);
|
2012-08-31 13:59:48 -07:00
|
|
|
return;
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
2012-08-31 13:59:48 -07:00
|
|
|
|
|
|
|
if (!async) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(this.curBrowser.elementManager.wrapValue(res),
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the given script either as a function body (executeScript)
|
|
|
|
* or directly (for 'mochitest' like JS Marionette tests)
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'value' member is the script to run
|
|
|
|
* 'args' member holds the arguments to the script
|
|
|
|
* @param boolean directInject
|
|
|
|
* if true, it will be run directly and not as a
|
|
|
|
* function body
|
|
|
|
*/
|
|
|
|
execute: function MDA_execute(aRequest, directInject) {
|
2013-01-29 09:45:59 -08:00
|
|
|
let timeout = aRequest.scriptTimeout ? aRequest.scriptTimeout : this.scriptTimeout;
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2013-06-21 17:13:35 -07:00
|
|
|
let script;
|
2012-11-26 18:19:04 -08:00
|
|
|
this.logRequest("execute", aRequest);
|
2012-05-09 12:05:39 -07:00
|
|
|
if (aRequest.newSandbox == undefined) {
|
|
|
|
//if client does not send a value in newSandbox,
|
|
|
|
//then they expect the same behaviour as webdriver
|
|
|
|
aRequest.newSandbox = true;
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
if (this.context == "content") {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("executeScript",
|
|
|
|
{
|
|
|
|
value: aRequest.value,
|
|
|
|
args: aRequest.args,
|
|
|
|
newSandbox: aRequest.newSandbox,
|
|
|
|
timeout: timeout,
|
2013-06-21 17:13:35 -07:00
|
|
|
specialPowers: aRequest.specialPowers,
|
|
|
|
filename: aRequest.filename,
|
|
|
|
line: aRequest.line
|
2013-04-08 14:12:32 -07:00
|
|
|
},
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let curWindow = this.getCurrentWindow();
|
2012-10-31 23:51:30 -07:00
|
|
|
let marionette = new Marionette(this, curWindow, "chrome",
|
2013-04-29 09:38:54 -07:00
|
|
|
this.marionetteLog,
|
2013-01-29 09:45:59 -08:00
|
|
|
timeout, this.testName);
|
2012-11-26 18:19:04 -08:00
|
|
|
let _chromeSandbox = this.createExecuteSandbox(curWindow,
|
|
|
|
marionette,
|
|
|
|
aRequest.args,
|
2013-02-12 10:10:03 -08:00
|
|
|
aRequest.specialPowers,
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
if (!_chromeSandbox)
|
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
_chromeSandbox.finish = function chromeSandbox_finish() {
|
|
|
|
return marionette.generate_results();
|
|
|
|
};
|
|
|
|
|
|
|
|
if (directInject) {
|
|
|
|
script = aRequest.value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
script = "let func = function() {" +
|
|
|
|
aRequest.value +
|
|
|
|
"};" +
|
|
|
|
"func.apply(null, __marionetteParams);";
|
|
|
|
}
|
2012-11-26 18:19:04 -08:00
|
|
|
this.executeScriptInSandbox(_chromeSandbox, script, directInject,
|
2013-01-29 09:45:59 -08:00
|
|
|
false, command_id, timeout);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2013-06-21 17:13:35 -07:00
|
|
|
let error = this.createStackMessage(e,
|
|
|
|
"execute_script",
|
|
|
|
aRequest.filename,
|
|
|
|
aRequest.line,
|
|
|
|
script);
|
|
|
|
this.sendError(error[0], 17, error[1], command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the timeout for asynchronous script execution
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'value' member is time in milliseconds to set timeout
|
|
|
|
*/
|
|
|
|
setScriptTimeout: function MDA_setScriptTimeout(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2012-03-22 08:19:57 -07:00
|
|
|
let timeout = parseInt(aRequest.value);
|
|
|
|
if(isNaN(timeout)){
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError("Not a Number", 500, null, this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.scriptTimeout = timeout;
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* execute pure JS script. Used to execute 'mochitest'-style Marionette tests.
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'value' member holds the script to execute
|
|
|
|
* 'args' member holds the arguments to the script
|
|
|
|
* 'timeout' member will be used as the script timeout if it is given
|
|
|
|
*/
|
|
|
|
executeJSScript: function MDA_executeJSScript(aRequest) {
|
2013-01-29 09:45:59 -08:00
|
|
|
let timeout = aRequest.scriptTimeout ? aRequest.scriptTimeout : this.scriptTimeout;
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-03-22 08:19:57 -07:00
|
|
|
//all pure JS scripts will need to call Marionette.finish() to complete the test.
|
2012-05-09 12:05:39 -07:00
|
|
|
if (aRequest.newSandbox == undefined) {
|
|
|
|
//if client does not send a value in newSandbox,
|
|
|
|
//then they expect the same behaviour as webdriver
|
|
|
|
aRequest.newSandbox = true;
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
if (this.context == "chrome") {
|
2012-11-30 07:42:43 -08:00
|
|
|
if (aRequest.async) {
|
|
|
|
this.executeWithCallback(aRequest, aRequest.async);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.execute(aRequest, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("executeJSScript",
|
|
|
|
{
|
|
|
|
value: aRequest.value,
|
|
|
|
args: aRequest.args,
|
|
|
|
newSandbox: aRequest.newSandbox,
|
|
|
|
async: aRequest.async,
|
|
|
|
timeout: timeout,
|
|
|
|
specialPowers: aRequest.specialPowers
|
|
|
|
},
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used by executeAsync and executeJSScript to execute a script
|
|
|
|
* in a sandbox.
|
|
|
|
*
|
|
|
|
* For executeJSScript, it will return a message only when the finish() method is called.
|
|
|
|
* For executeAsync, it will return a response when marionetteScriptFinished/arguments[arguments.length-1]
|
|
|
|
* method is called, or if it times out.
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'value' member holds the script to execute
|
|
|
|
* 'args' member holds the arguments for the script
|
|
|
|
* @param boolean directInject
|
|
|
|
* if true, it will be run directly and not as a
|
|
|
|
* function body
|
|
|
|
*/
|
|
|
|
executeWithCallback: function MDA_executeWithCallback(aRequest, directInject) {
|
2013-01-29 09:45:59 -08:00
|
|
|
let timeout = aRequest.scriptTimeout ? aRequest.scriptTimeout : this.scriptTimeout;
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2013-06-21 17:13:35 -07:00
|
|
|
let script;
|
2013-02-12 10:10:03 -08:00
|
|
|
this.logRequest("executeWithCallback", aRequest);
|
2012-05-09 12:05:39 -07:00
|
|
|
if (aRequest.newSandbox == undefined) {
|
|
|
|
//if client does not send a value in newSandbox,
|
|
|
|
//then they expect the same behaviour as webdriver
|
|
|
|
aRequest.newSandbox = true;
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
|
|
|
|
if (this.context == "content") {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("executeAsyncScript",
|
|
|
|
{
|
|
|
|
value: aRequest.value,
|
|
|
|
args: aRequest.args,
|
|
|
|
id: this.command_id,
|
|
|
|
newSandbox: aRequest.newSandbox,
|
|
|
|
timeout: timeout,
|
2013-06-21 17:13:35 -07:00
|
|
|
specialPowers: aRequest.specialPowers,
|
|
|
|
filename: aRequest.filename,
|
|
|
|
line: aRequest.line
|
2013-04-08 14:12:32 -07:00
|
|
|
},
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let curWindow = this.getCurrentWindow();
|
|
|
|
let original_onerror = curWindow.onerror;
|
|
|
|
let that = this;
|
2013-01-29 09:45:59 -08:00
|
|
|
that.timeout = timeout;
|
2012-08-31 13:59:48 -07:00
|
|
|
let marionette = new Marionette(this, curWindow, "chrome",
|
2013-04-29 09:38:54 -07:00
|
|
|
this.marionetteLog,
|
2013-01-29 09:45:59 -08:00
|
|
|
timeout, this.testName);
|
2012-03-22 08:19:57 -07:00
|
|
|
marionette.command_id = this.command_id;
|
|
|
|
|
2013-06-21 17:13:35 -07:00
|
|
|
function chromeAsyncReturnFunc(value, status, stacktrace) {
|
2012-05-23 17:23:36 -07:00
|
|
|
if (that._emu_cbs && Object.keys(that._emu_cbs).length) {
|
|
|
|
value = "Emulator callback still pending when finish() called";
|
|
|
|
status = 500;
|
|
|
|
that._emu_cbs = null;
|
|
|
|
}
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
if (value == undefined)
|
|
|
|
value = null;
|
|
|
|
if (that.command_id == marionette.command_id) {
|
|
|
|
if (that.timer != null) {
|
|
|
|
that.timer.cancel();
|
|
|
|
that.timer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
curWindow.onerror = original_onerror;
|
|
|
|
|
|
|
|
if (status == 0 || status == undefined) {
|
2012-04-03 11:08:49 -07:00
|
|
|
that.sendToClient({from: that.actorID, value: that.curBrowser.elementManager.wrapValue(value), status: status},
|
2012-03-22 08:19:57 -07:00
|
|
|
marionette.command_id);
|
|
|
|
}
|
|
|
|
else {
|
2013-06-21 17:13:35 -07:00
|
|
|
let error_msg = {message: value, status: status, stacktrace: stacktrace};
|
2012-03-22 08:19:57 -07:00
|
|
|
that.sendToClient({from: that.actorID, error: error_msg},
|
|
|
|
marionette.command_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
curWindow.onerror = function (errorMsg, url, lineNumber) {
|
|
|
|
chromeAsyncReturnFunc(errorMsg + " at: " + url + " line: " + lineNumber, 17);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
function chromeAsyncFinish() {
|
|
|
|
chromeAsyncReturnFunc(marionette.generate_results(), 0);
|
|
|
|
}
|
|
|
|
|
2013-02-12 10:10:03 -08:00
|
|
|
let _chromeSandbox = this.createExecuteSandbox(curWindow,
|
|
|
|
marionette,
|
|
|
|
aRequest.args,
|
|
|
|
aRequest.specialPowers,
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
if (!_chromeSandbox)
|
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
if (this.timer != null) {
|
|
|
|
this.timer.initWithCallback(function() {
|
|
|
|
chromeAsyncReturnFunc("timed out", 28);
|
2013-01-29 09:45:59 -08:00
|
|
|
}, that.timeout, Ci.nsITimer.TYPE_ONESHOT);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_chromeSandbox.returnFunc = chromeAsyncReturnFunc;
|
|
|
|
_chromeSandbox.finish = chromeAsyncFinish;
|
|
|
|
|
|
|
|
if (directInject) {
|
|
|
|
script = aRequest.value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
script = '__marionetteParams.push(returnFunc);'
|
|
|
|
+ 'let marionetteScriptFinished = returnFunc;'
|
|
|
|
+ 'let __marionetteFunc = function() {' + aRequest.value + '};'
|
|
|
|
+ '__marionetteFunc.apply(null, __marionetteParams);';
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:19:04 -08:00
|
|
|
this.executeScriptInSandbox(_chromeSandbox, script, directInject,
|
2013-01-29 09:45:59 -08:00
|
|
|
true, command_id, timeout);
|
2012-03-22 08:19:57 -07:00
|
|
|
} catch (e) {
|
2013-06-21 17:13:35 -07:00
|
|
|
let error = this.createStackMessage(e,
|
|
|
|
"execute_async_script",
|
|
|
|
aRequest.filename,
|
|
|
|
aRequest.line,
|
|
|
|
script);
|
|
|
|
chromeAsyncReturnFunc(error[0], 17, error[1]);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Navigates to given url
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'value' member holds the url to navigate to
|
|
|
|
*/
|
|
|
|
goUrl: function MDA_goUrl(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-05-11 13:06:53 -07:00
|
|
|
if (this.context != "chrome") {
|
2012-11-26 18:19:04 -08:00
|
|
|
aRequest.command_id = command_id;
|
2013-01-11 11:33:58 -08:00
|
|
|
aRequest.pageTimeout = this.pageTimeout;
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("goUrl", aRequest, command_id);
|
2012-05-11 13:06:53 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getCurrentWindow().location.href = aRequest.value;
|
|
|
|
let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
2013-01-11 11:33:58 -08:00
|
|
|
let start = new Date().getTime();
|
|
|
|
let end = null;
|
2012-05-11 13:06:53 -07:00
|
|
|
function checkLoad() {
|
2013-01-11 11:33:58 -08:00
|
|
|
end = new Date().getTime();
|
|
|
|
let elapse = end - start;
|
|
|
|
if (this.pageTimeout == null || elapse <= this.pageTimeout){
|
|
|
|
if (curWindow.document.readyState == "complete") {
|
|
|
|
sendOk(command_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
checkTimer.initWithCallback(checkLoad, 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
sendError("Error loading page", 13, null, command_id);
|
2012-05-11 13:06:53 -07:00
|
|
|
return;
|
2013-01-11 11:33:58 -08:00
|
|
|
}
|
|
|
|
}//end
|
2012-05-11 13:06:53 -07:00
|
|
|
checkTimer.initWithCallback(checkLoad, 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets current url
|
|
|
|
*/
|
|
|
|
getUrl: function MDA_getUrl() {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2012-03-22 08:19:57 -07:00
|
|
|
if (this.context == "chrome") {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(this.getCurrentWindow().location.href, this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("getUrl", {}, this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-07-10 13:30:21 -07:00
|
|
|
/**
|
|
|
|
* Gets the current title of the window
|
|
|
|
*/
|
|
|
|
getTitle: function MDA_getTitle() {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2013-05-24 13:14:29 -07:00
|
|
|
if (this.context == "chrome"){
|
|
|
|
var curWindow = this.getCurrentWindow();
|
|
|
|
var title = curWindow.document.documentElement.getAttribute('title');
|
|
|
|
this.sendResponse(title, this.command_id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.sendAsync("getTitle", {}, this.command_id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current type of the window
|
|
|
|
*/
|
|
|
|
getWindowType: function MDA_getWindowType() {
|
|
|
|
this.command_id = this.getCommandId();
|
|
|
|
var curWindow = this.getCurrentWindow();
|
|
|
|
var type = curWindow.document.documentElement.getAttribute('windowtype');
|
|
|
|
this.sendResponse(type, this.command_id);
|
2012-07-10 13:30:21 -07:00
|
|
|
},
|
|
|
|
|
2012-08-09 12:31:12 -07:00
|
|
|
/**
|
|
|
|
* Gets the page source of the content document
|
|
|
|
*/
|
|
|
|
getPageSource: function MDA_getPageSource(){
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2012-08-09 12:31:12 -07:00
|
|
|
if (this.context == "chrome"){
|
2013-05-17 11:43:52 -07:00
|
|
|
let curWindow = this.getCurrentWindow();
|
|
|
|
let XMLSerializer = curWindow.XMLSerializer;
|
|
|
|
let pageSource = new XMLSerializer().serializeToString(curWindow.document);
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(pageSource, this.command_id);
|
2012-08-09 12:31:12 -07:00
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("getPageSource", {}, this.command_id);
|
2012-08-09 12:31:12 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Go back in history
|
|
|
|
*/
|
|
|
|
goBack: function MDA_goBack() {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("goBack", {}, this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go forward in history
|
|
|
|
*/
|
|
|
|
goForward: function MDA_goForward() {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("goForward", {}, this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh the page
|
|
|
|
*/
|
|
|
|
refresh: function MDA_refresh() {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("refresh", {}, this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current window's server-assigned ID
|
|
|
|
*/
|
|
|
|
getWindow: function MDA_getWindow() {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2012-04-03 11:08:49 -07:00
|
|
|
for (let i in this.browsers) {
|
|
|
|
if (this.curBrowser == this.browsers[i]) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(i, this.command_id);
|
2012-04-03 11:08:49 -07:00
|
|
|
}
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the server-assigned IDs of all available windows
|
|
|
|
*/
|
|
|
|
getWindows: function MDA_getWindows() {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2012-03-22 08:19:57 -07:00
|
|
|
let res = [];
|
|
|
|
let winEn = this.getWinEnumerator();
|
|
|
|
while(winEn.hasMoreElements()) {
|
|
|
|
let foundWin = winEn.getNext();
|
2012-06-04 10:50:06 -07:00
|
|
|
let winId = foundWin.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
|
2012-03-22 08:19:57 -07:00
|
|
|
winId = winId + ((appName == "B2G") ? '-b2g' : '');
|
|
|
|
res.push(winId)
|
|
|
|
}
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(res, this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch to a window based on name or server-assigned id.
|
|
|
|
* Searches based on name, then id.
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
2012-05-02 07:21:05 -07:00
|
|
|
* 'value' member holds the name or id of the window to switch to
|
2012-03-22 08:19:57 -07:00
|
|
|
*/
|
|
|
|
switchToWindow: function MDA_switchToWindow(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-03-22 08:19:57 -07:00
|
|
|
let winEn = this.getWinEnumerator();
|
|
|
|
while(winEn.hasMoreElements()) {
|
|
|
|
let foundWin = winEn.getNext();
|
2012-08-28 11:14:30 -07:00
|
|
|
let winId = foundWin.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.outerWindowID;
|
2012-03-22 08:19:57 -07:00
|
|
|
winId = winId + ((appName == "B2G") ? '-b2g' : '');
|
|
|
|
if (aRequest.value == foundWin.name || aRequest.value == winId) {
|
|
|
|
if (this.browsers[winId] == undefined) {
|
|
|
|
//enable Marionette in that browser window
|
|
|
|
this.startBrowser(foundWin, false);
|
|
|
|
}
|
2012-06-25 12:08:38 -07:00
|
|
|
else {
|
|
|
|
utils.window = foundWin;
|
|
|
|
this.curBrowser = this.browsers[winId];
|
|
|
|
}
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError("Unable to locate window " + aRequest.value, 23, null,
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
2012-04-03 11:08:49 -07:00
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Switch to a given frame within the current window
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
2012-05-02 07:21:05 -07:00
|
|
|
* 'element' is the element to switch to
|
|
|
|
* 'value' if element is not set, then this
|
|
|
|
* holds either the id, name or index
|
|
|
|
* of the frame to switch to
|
2012-03-22 08:19:57 -07:00
|
|
|
*/
|
|
|
|
switchToFrame: function MDA_switchToFrame(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
|
|
|
this.logRequest("switchToFrame", aRequest);
|
2012-11-15 07:07:24 -08:00
|
|
|
let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
2013-05-17 11:43:52 -07:00
|
|
|
let curWindow = this.getCurrentWindow();
|
2012-11-15 07:07:24 -08:00
|
|
|
let checkLoad = function() {
|
|
|
|
let errorRegex = /about:.+(error)|(blocked)\?/;
|
|
|
|
if (curWindow.document.readyState == "complete") {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(command_id);
|
2012-11-15 07:07:24 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (curWindow.document.readyState == "interactive" && errorRegex.exec(curWindow.document.baseURI)) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError("Error loading page", 13, null, command_id);
|
2012-11-15 07:07:24 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
}
|
2012-05-02 07:21:05 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
let foundFrame = null;
|
|
|
|
if ((aRequest.value == null) && (aRequest.element == null)) {
|
|
|
|
this.curFrame = null;
|
2012-12-17 01:45:28 -08:00
|
|
|
if (aRequest.focus) {
|
|
|
|
this.mainFrame.focus();
|
|
|
|
}
|
2012-11-15 07:07:24 -08:00
|
|
|
checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
2012-05-02 07:21:05 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aRequest.element != undefined) {
|
|
|
|
if (this.curBrowser.elementManager.seenItems[aRequest.element] != undefined) {
|
|
|
|
let wantedFrame = this.curBrowser.elementManager.getKnownElement(aRequest.element, curWindow); //HTMLIFrameElement
|
|
|
|
let numFrames = curWindow.frames.length;
|
|
|
|
for (let i = 0; i < numFrames; i++) {
|
|
|
|
if (curWindow.frames[i].frameElement == wantedFrame) {
|
|
|
|
curWindow = curWindow.frames[i];
|
|
|
|
this.curFrame = curWindow;
|
2012-12-17 01:45:28 -08:00
|
|
|
if (aRequest.focus) {
|
|
|
|
this.curFrame.focus();
|
|
|
|
}
|
2012-11-15 07:07:24 -08:00
|
|
|
checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
2012-05-02 07:21:05 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch(typeof(aRequest.value)) {
|
|
|
|
case "string" :
|
|
|
|
let foundById = null;
|
|
|
|
let numFrames = curWindow.frames.length;
|
|
|
|
for (let i = 0; i < numFrames; i++) {
|
|
|
|
//give precedence to name
|
|
|
|
let frame = curWindow.frames[i];
|
|
|
|
let frameElement = frame.frameElement;
|
|
|
|
if (frame.name == aRequest.value) {
|
|
|
|
foundFrame = i;
|
|
|
|
break;
|
|
|
|
} else if ((foundById == null) && (frameElement.id == aRequest.value)) {
|
|
|
|
foundById = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((foundFrame == null) && (foundById != null)) {
|
|
|
|
foundFrame = foundById;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "number":
|
|
|
|
if (curWindow.frames[aRequest.value] != undefined) {
|
|
|
|
foundFrame = aRequest.value;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (foundFrame != null) {
|
|
|
|
curWindow = curWindow.frames[foundFrame];
|
|
|
|
this.curFrame = curWindow;
|
2012-12-17 01:45:28 -08:00
|
|
|
if (aRequest.focus) {
|
|
|
|
this.curFrame.focus();
|
|
|
|
}
|
2012-11-15 07:07:24 -08:00
|
|
|
checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
2012-05-02 07:21:05 -07:00
|
|
|
} else {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError("Unable to locate frame: " + aRequest.value, 8, null,
|
|
|
|
command_id);
|
2012-05-02 07:21:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-02-25 13:24:19 -08:00
|
|
|
if ((!aRequest.value) && (!aRequest.element) &&
|
2012-09-28 16:16:22 -07:00
|
|
|
(this.currentRemoteFrame !== null)) {
|
|
|
|
// We're currently using a ChromeMessageSender for a remote frame, so this
|
|
|
|
// request indicates we need to switch back to the top-level (parent) frame.
|
|
|
|
// We'll first switch to the parent's (global) ChromeMessageBroadcaster, so
|
|
|
|
// we send the message to the right listener.
|
|
|
|
this.switchToGlobalMessageManager();
|
|
|
|
}
|
2012-11-26 18:19:04 -08:00
|
|
|
aRequest.command_id = command_id;
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("switchToFrame", aRequest, command_id);
|
2012-05-02 07:21:05 -07:00
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set timeout for searching for elements
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'value' holds the search timeout in milliseconds
|
|
|
|
*/
|
|
|
|
setSearchTimeout: function MDA_setSearchTimeout(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2013-05-01 10:16:49 -07:00
|
|
|
let timeout = parseInt(aRequest.value);
|
|
|
|
if (isNaN(timeout)) {
|
|
|
|
this.sendError("Not a Number", 500, null, this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
else {
|
2013-05-01 10:16:49 -07:00
|
|
|
this.searchTimeout = timeout;
|
|
|
|
this.sendOk(this.command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-02-06 11:58:14 -08:00
|
|
|
/**
|
2013-01-11 11:33:58 -08:00
|
|
|
* Set timeout for page loading, searching and scripts
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'type' hold the type of timeout
|
|
|
|
* 'ms' holds the timeout in milliseconds
|
|
|
|
*/
|
|
|
|
timeouts: function MDA_timeouts(aRequest){
|
|
|
|
/*setTimeout*/
|
|
|
|
this.command_id = this.getCommandId();
|
|
|
|
let timeout_type = aRequest.timeoutType;
|
|
|
|
let timeout = parseInt(aRequest.ms);
|
|
|
|
if (isNaN(timeout)) {
|
|
|
|
this.sendError("Not a Number", 500, null, this.command_id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (timeout_type == "implicit") {
|
|
|
|
aRequest.value = aRequest.ms;
|
|
|
|
this.setSearchTimeout(aRequest);
|
|
|
|
}
|
|
|
|
else if (timeout_type == "script") {
|
|
|
|
aRequest.value = aRequest.ms;
|
|
|
|
this.setScriptTimeout(aRequest);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.pageTimeout = timeout;
|
|
|
|
this.sendOk(this.command_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-01-22 11:27:44 -08:00
|
|
|
/**
|
|
|
|
* Single Tap
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
'element' represents the ID of the element to single tap on
|
|
|
|
*/
|
|
|
|
singleTap: function MDA_singleTap(aRequest) {
|
|
|
|
this.command_id = this.getCommandId();
|
|
|
|
let serId = aRequest.element;
|
2013-02-01 13:29:10 -08:00
|
|
|
let x = aRequest.x;
|
|
|
|
let y = aRequest.y;
|
2013-01-22 11:27:44 -08:00
|
|
|
if (this.context == "chrome") {
|
2013-05-27 10:12:13 -07:00
|
|
|
this.sendError("Command 'singleTap' is not available in chrome context", 500, null, this.command_id);
|
2013-01-22 11:27:44 -08:00
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("singleTap",
|
|
|
|
{
|
|
|
|
value: serId,
|
|
|
|
corx: x,
|
|
|
|
cory: y
|
|
|
|
},
|
|
|
|
this.command_id);
|
2013-01-22 11:27:44 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-03-04 17:09:58 -08:00
|
|
|
/**
|
|
|
|
* actionChain
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'value' represents a nested array: inner array represents each event; outer array represents collection of events
|
|
|
|
*/
|
|
|
|
actionChain: function MDA_actionChain(aRequest) {
|
|
|
|
this.command_id = this.getCommandId();
|
|
|
|
if (this.context == "chrome") {
|
2013-05-27 10:12:13 -07:00
|
|
|
this.sendError("Command 'actionChain' is not available in chrome context", 500, null, this.command_id);
|
2013-03-04 17:09:58 -08:00
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("actionChain",
|
|
|
|
{
|
|
|
|
chain: aRequest.chain,
|
|
|
|
nextId: aRequest.nextId
|
|
|
|
},
|
|
|
|
this.command_id);
|
2013-03-04 17:09:58 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-03-18 13:42:46 -07:00
|
|
|
/**
|
|
|
|
* multiAction
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'value' represents a nested array: inner array represents each event;
|
|
|
|
* middle array represents collection of events for each finger
|
|
|
|
* outer array represents all the fingers
|
|
|
|
*/
|
|
|
|
|
|
|
|
multiAction: function MDA_multiAction(aRequest) {
|
|
|
|
this.command_id = this.getCommandId();
|
|
|
|
if (this.context == "chrome") {
|
2013-05-27 10:12:13 -07:00
|
|
|
this.sendError("Command 'multiAction' is not available in chrome context", 500, null, this.command_id);
|
2013-03-18 13:42:46 -07:00
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("multiAction",
|
|
|
|
{
|
|
|
|
value: aRequest.value,
|
|
|
|
maxlen: aRequest.max_length
|
|
|
|
},
|
|
|
|
this.command_id);
|
2013-03-18 13:42:46 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Find an element using the indicated search strategy.
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'using' member indicates which search method to use
|
|
|
|
* 'value' member is the value the client is looking for
|
|
|
|
*/
|
|
|
|
findElement: function MDA_findElement(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-03-22 08:19:57 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
let id;
|
|
|
|
try {
|
2012-08-27 13:50:34 -07:00
|
|
|
let on_success = this.sendResponse.bind(this);
|
|
|
|
let on_error = this.sendError.bind(this);
|
2012-11-26 18:19:04 -08:00
|
|
|
id = this.curBrowser.elementManager.find(
|
|
|
|
this.getCurrentWindow(),
|
|
|
|
aRequest,
|
2013-05-01 10:16:49 -07:00
|
|
|
this.searchTimeout,
|
2012-11-26 18:19:04 -08:00
|
|
|
on_success,
|
|
|
|
on_error,
|
|
|
|
false,
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("findElementContent",
|
|
|
|
{
|
|
|
|
value: aRequest.value,
|
|
|
|
using: aRequest.using,
|
2013-05-01 10:16:49 -07:00
|
|
|
element: aRequest.element,
|
|
|
|
searchTimeout: this.searchTimeout
|
2013-04-08 14:12:32 -07:00
|
|
|
},
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find elements using the indicated search strategy.
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'using' member indicates which search method to use
|
|
|
|
* 'value' member is the value the client is looking for
|
|
|
|
*/
|
|
|
|
findElements: function MDA_findElements(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-03-22 08:19:57 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
let id;
|
|
|
|
try {
|
2012-08-27 13:50:34 -07:00
|
|
|
let on_success = this.sendResponse.bind(this);
|
|
|
|
let on_error = this.sendError.bind(this);
|
2012-11-26 18:19:04 -08:00
|
|
|
id = this.curBrowser.elementManager.find(this.getCurrentWindow(),
|
|
|
|
aRequest,
|
2013-05-01 10:16:49 -07:00
|
|
|
this.searchTimeout,
|
2012-11-26 18:19:04 -08:00
|
|
|
on_success,
|
|
|
|
on_error,
|
|
|
|
true,
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("findElementsContent",
|
|
|
|
{
|
|
|
|
value: aRequest.value,
|
|
|
|
using: aRequest.using,
|
2013-05-01 10:16:49 -07:00
|
|
|
element: aRequest.element,
|
|
|
|
searchTimeout: this.searchTimeout
|
2013-04-08 14:12:32 -07:00
|
|
|
},
|
|
|
|
command_id);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-01-14 06:57:54 -08:00
|
|
|
/**
|
|
|
|
* Return the active element on the page
|
|
|
|
*/
|
|
|
|
getActiveElement: function MDA_getActiveElement(){
|
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("getActiveElement", {}, command_id);
|
2013-01-14 06:57:54 -08:00
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Send click event to element
|
2013-01-14 06:57:54 -08:00
|
|
|
*
|
2012-03-22 08:19:57 -07:00
|
|
|
* @param object aRequest
|
|
|
|
* 'element' member holds the reference id to
|
|
|
|
* the element that will be clicked
|
|
|
|
*/
|
|
|
|
clickElement: function MDA_clickElement(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-04-10 17:28:08 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
try {
|
|
|
|
//NOTE: click atom fails, fall back to click() action
|
2012-11-26 18:19:04 -08:00
|
|
|
let el = this.curBrowser.elementManager.getKnownElement(
|
|
|
|
aRequest.element, this.getCurrentWindow());
|
2012-04-10 17:28:08 -07:00
|
|
|
el.click();
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-01-16 07:00:00 -08:00
|
|
|
// We need to protect against the click causing an OOP frame to close.
|
|
|
|
// This fires the mozbrowserclose event when it closes so we need to
|
|
|
|
// listen for it and then just send an error back. The person making the
|
|
|
|
// call should be aware something isnt right and handle accordingly
|
|
|
|
let curWindow = this.getCurrentWindow();
|
|
|
|
let self = this;
|
|
|
|
this.mozBrowserClose = function() {
|
|
|
|
curWindow.removeEventListener('mozbrowserclose', self.mozBrowserClose, true);
|
|
|
|
self.switchToGlobalMessageManager();
|
|
|
|
self.sendError("The frame closed during the click, recovering to allow further communications", 500, null, command_id);
|
|
|
|
};
|
|
|
|
curWindow.addEventListener('mozbrowserclose', this.mozBrowserClose, true);
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("clickElement",
|
|
|
|
{ element: aRequest.element },
|
|
|
|
command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a given attribute of an element
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'element' member holds the reference id to
|
|
|
|
* the element that will be inspected
|
|
|
|
* 'name' member holds the name of the attribute to retrieve
|
|
|
|
*/
|
2012-05-01 12:37:34 -07:00
|
|
|
getElementAttribute: function MDA_getElementAttribute(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-04-10 17:28:08 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
try {
|
2012-11-26 18:19:04 -08:00
|
|
|
let el = this.curBrowser.elementManager.getKnownElement(
|
|
|
|
aRequest.element, this.getCurrentWindow());
|
|
|
|
this.sendResponse(utils.getElementAttribute(el, aRequest.name),
|
|
|
|
command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("getElementAttribute",
|
|
|
|
{
|
|
|
|
element: aRequest.element,
|
|
|
|
name: aRequest.name
|
|
|
|
},
|
|
|
|
command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the text of an element, if any. Includes the text of all child elements.
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'element' member holds the reference id to
|
|
|
|
* the element that will be inspected
|
|
|
|
*/
|
|
|
|
getElementText: function MDA_getElementText(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-04-10 17:28:08 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
//Note: for chrome, we look at text nodes, and any node with a "label" field
|
|
|
|
try {
|
2012-11-26 18:19:04 -08:00
|
|
|
let el = this.curBrowser.elementManager.getKnownElement(
|
|
|
|
aRequest.element, this.getCurrentWindow());
|
2012-04-10 17:28:08 -07:00
|
|
|
let lines = [];
|
|
|
|
this.getVisibleText(el, lines);
|
|
|
|
lines = lines.join("\n");
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(lines, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("getElementText",
|
|
|
|
{ element: aRequest.element },
|
|
|
|
command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-08-08 13:21:50 -07:00
|
|
|
/**
|
|
|
|
* Get the tag name of the element.
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'element' member holds the reference id to
|
|
|
|
* the element that will be inspected
|
|
|
|
*/
|
|
|
|
getElementTagName: function MDA_getElementTagName(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-08-08 13:21:50 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
try {
|
2012-11-26 18:19:04 -08:00
|
|
|
let el = this.curBrowser.elementManager.getKnownElement(
|
|
|
|
aRequest.element, this.getCurrentWindow());
|
|
|
|
this.sendResponse(el.tagName.toLowerCase(), command_id);
|
2012-08-08 13:21:50 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-08-08 13:21:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("getElementTagName",
|
|
|
|
{ element: aRequest.element },
|
|
|
|
command_id);
|
2012-08-08 13:21:50 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-10 17:28:08 -07:00
|
|
|
/**
|
|
|
|
* Check if element is displayed
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'element' member holds the reference id to
|
|
|
|
* the element that will be checked
|
|
|
|
*/
|
|
|
|
isElementDisplayed: function MDA_isElementDisplayed(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-04-10 17:28:08 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
try {
|
2012-11-26 18:19:04 -08:00
|
|
|
let el = this.curBrowser.elementManager.getKnownElement(
|
|
|
|
aRequest.element, this.getCurrentWindow());
|
|
|
|
this.sendResponse(utils.isElementDisplayed(el), command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("isElementDisplayed",
|
|
|
|
{ element:aRequest.element },
|
|
|
|
command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-05-07 14:38:21 -07:00
|
|
|
/**
|
|
|
|
* Return the property of the computed style of an element
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'element' member holds the reference id to
|
|
|
|
* the element that will be checked
|
|
|
|
* 'propertyName' is the CSS rule that is being requested
|
|
|
|
*/
|
|
|
|
getElementValueOfCssProperty: function MDA_getElementValueOfCssProperty(aRequest){
|
|
|
|
let command_id = this.command_id = this.getCommandId();
|
|
|
|
this.sendAsync("getElementValueOfCssProperty",
|
|
|
|
{element: aRequest.element, propertyName: aRequest.propertyName},
|
|
|
|
command_id);
|
|
|
|
},
|
|
|
|
|
2012-04-10 17:28:08 -07:00
|
|
|
/**
|
|
|
|
* Check if element is enabled
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'element' member holds the reference id to
|
|
|
|
* the element that will be checked
|
|
|
|
*/
|
|
|
|
isElementEnabled: function MDA_isElementEnabled(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-04-10 17:28:08 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
try {
|
|
|
|
//Selenium atom doesn't quite work here
|
2012-11-26 18:19:04 -08:00
|
|
|
let el = this.curBrowser.elementManager.getKnownElement(
|
|
|
|
aRequest.element, this.getCurrentWindow());
|
2012-04-10 17:28:08 -07:00
|
|
|
if (el.disabled != undefined) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(!!!el.disabled, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(true, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("isElementEnabled",
|
|
|
|
{ element:aRequest.element },
|
|
|
|
command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if element is selected
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'element' member holds the reference id to
|
|
|
|
* the element that will be checked
|
|
|
|
*/
|
|
|
|
isElementSelected: function MDA_isElementSelected(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-04-10 17:28:08 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
try {
|
|
|
|
//Selenium atom doesn't quite work here
|
2012-11-26 18:19:04 -08:00
|
|
|
let el = this.curBrowser.elementManager.getKnownElement(
|
|
|
|
aRequest.element, this.getCurrentWindow());
|
2012-04-10 17:28:08 -07:00
|
|
|
if (el.checked != undefined) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(!!el.checked, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
else if (el.selected != undefined) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(!!el.selected, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse(true, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("isElementSelected",
|
|
|
|
{ element:aRequest.element },
|
|
|
|
command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-19 13:59:15 -07:00
|
|
|
getElementSize: function MDA_getElementSize(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-10-19 13:59:15 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
try {
|
2012-11-26 18:19:04 -08:00
|
|
|
let el = this.curBrowser.elementManager.getKnownElement(
|
|
|
|
aRequest.element, this.getCurrentWindow());
|
2012-10-19 13:59:15 -07:00
|
|
|
let clientRect = el.getBoundingClientRect();
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendResponse({width: clientRect.width, height: clientRect.height},
|
|
|
|
command_id);
|
2012-10-19 13:59:15 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-10-19 13:59:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("getElementSize",
|
|
|
|
{ element:aRequest.element },
|
|
|
|
command_id);
|
2012-10-19 13:59:15 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-10 17:28:08 -07:00
|
|
|
/**
|
|
|
|
* Send key presses to element after focusing on it
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'element' member holds the reference id to
|
|
|
|
* the element that will be checked
|
|
|
|
* 'value' member holds the value to send to the element
|
|
|
|
*/
|
|
|
|
sendKeysToElement: function MDA_sendKeysToElement(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-04-10 17:28:08 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
try {
|
2012-11-26 18:19:04 -08:00
|
|
|
let el = this.curBrowser.elementManager.getKnownElement(
|
|
|
|
aRequest.element, this.getCurrentWindow());
|
2012-04-10 17:28:08 -07:00
|
|
|
el.focus();
|
2012-08-05 12:49:42 -07:00
|
|
|
utils.sendString(aRequest.value.join(""), utils.window);
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("sendKeysToElement",
|
|
|
|
{
|
|
|
|
element:aRequest.element,
|
|
|
|
value: aRequest.value
|
|
|
|
},
|
|
|
|
command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-31 15:36:57 -07:00
|
|
|
/**
|
|
|
|
* Sets the test name
|
|
|
|
*
|
|
|
|
* The test name is used in logging messages.
|
|
|
|
*/
|
|
|
|
setTestName: function MDA_setTestName(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
|
|
|
this.logRequest("setTestName", aRequest);
|
2012-10-31 15:36:57 -07:00
|
|
|
this.testName = aRequest.value;
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("setTestName",
|
|
|
|
{ value: aRequest.value },
|
|
|
|
this.command_id);
|
2012-10-31 15:36:57 -07:00
|
|
|
},
|
|
|
|
|
2012-04-10 17:28:08 -07:00
|
|
|
/**
|
|
|
|
* Clear the text of an element
|
|
|
|
*
|
|
|
|
* @param object aRequest
|
|
|
|
* 'element' member holds the reference id to
|
|
|
|
* the element that will be cleared
|
|
|
|
*/
|
|
|
|
clearElement: function MDA_clearElement(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-04-10 17:28:08 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
//the selenium atom doesn't work here
|
|
|
|
try {
|
2012-11-26 18:19:04 -08:00
|
|
|
let el = this.curBrowser.elementManager.getKnownElement(
|
|
|
|
aRequest.element, this.getCurrentWindow());
|
2012-04-10 17:28:08 -07:00
|
|
|
if (el.nodeName == "textbox") {
|
|
|
|
el.value = "";
|
|
|
|
}
|
|
|
|
else if (el.nodeName == "checkbox") {
|
|
|
|
el.checked = false;
|
|
|
|
}
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("clearElement",
|
|
|
|
{ element:aRequest.element },
|
|
|
|
command_id);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
2012-10-19 13:35:30 -07:00
|
|
|
getElementPosition: function MDA_getElementPosition(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("getElementPosition",
|
|
|
|
{ element:aRequest.element },
|
|
|
|
this.command_id);
|
2012-10-19 13:35:30 -07:00
|
|
|
},
|
|
|
|
|
2012-11-22 07:53:44 -08:00
|
|
|
/**
|
|
|
|
* Add a cookie to the document.
|
|
|
|
*/
|
|
|
|
addCookie: function MDA_addCookie(aRequest) {
|
|
|
|
this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("addCookie",
|
|
|
|
{ cookie:aRequest.cookie },
|
|
|
|
this.command_id);
|
2012-11-22 07:53:44 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all visible cookies for a document
|
|
|
|
*/
|
|
|
|
getAllCookies: function MDA_getAllCookies() {
|
|
|
|
this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("getAllCookies", {}, this.command_id);
|
2012-11-22 07:53:44 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete all cookies that are visible to a document
|
|
|
|
*/
|
|
|
|
deleteAllCookies: function MDA_deleteAllCookies() {
|
|
|
|
this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("deleteAllCookies", {}, this.command_id);
|
2012-11-22 07:53:44 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a cookie by name
|
|
|
|
*/
|
|
|
|
deleteCookie: function MDA_deleteCookie(aRequest) {
|
|
|
|
this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("deleteCookie",
|
|
|
|
{ name:aRequest.name },
|
|
|
|
this.command_id);
|
2012-11-22 07:53:44 -08:00
|
|
|
},
|
|
|
|
|
2012-07-16 16:06:04 -07:00
|
|
|
/**
|
|
|
|
* Closes the Browser Window.
|
|
|
|
*
|
|
|
|
* If it is B2G it returns straight away and does not do anything
|
|
|
|
*
|
|
|
|
* If is desktop it calculates how many windows are open and if there is only
|
|
|
|
* 1 then it deletes the session otherwise it closes the window
|
|
|
|
*/
|
|
|
|
closeWindow: function MDA_closeWindow() {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-07-16 16:06:04 -07:00
|
|
|
if (appName == "B2G") {
|
|
|
|
// We can't close windows so just return
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(command_id);
|
2012-07-16 16:06:04 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Get the total number of windows
|
|
|
|
let numOpenWindows = 0;
|
|
|
|
let winEnum = this.getWinEnumerator();
|
|
|
|
while (winEnum.hasMoreElements()) {
|
|
|
|
numOpenWindows += 1;
|
|
|
|
winEnum.getNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is only 1 window left, delete the session
|
|
|
|
if (numOpenWindows === 1){
|
|
|
|
this.deleteSession();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try{
|
2012-09-28 16:16:22 -07:00
|
|
|
this.messageManager.removeDelayedFrameScript(FRAME_SCRIPT);
|
2012-07-16 16:06:04 -07:00
|
|
|
this.getCurrentWindow().close();
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(command_id);
|
2012-07-16 16:06:04 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendError("Could not close window: " + e.message, 13, e.stack,
|
|
|
|
command_id);
|
2012-07-16 16:06:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Deletes the session.
|
|
|
|
*
|
|
|
|
* If it is a desktop environment, it will close the session's tab and close all listeners
|
|
|
|
*
|
|
|
|
* If it is a B2G environment, it will make the main content listener sleep, and close
|
|
|
|
* all other listeners. The main content listener persists after disconnect (it's the homescreen),
|
|
|
|
* and can safely be reused.
|
|
|
|
*/
|
|
|
|
deleteSession: function MDA_deleteSession() {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-04-03 11:08:49 -07:00
|
|
|
if (this.curBrowser != null) {
|
2012-03-22 08:19:57 -07:00
|
|
|
if (appName == "B2G") {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.globalMessageManager.broadcastAsyncMessage(
|
|
|
|
"Marionette:sleepSession" + this.curBrowser.mainContentId, {});
|
|
|
|
this.curBrowser.knownFrames.splice(
|
|
|
|
this.curBrowser.knownFrames.indexOf(this.curBrowser.mainContentId), 1);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
//don't set this pref for B2G since the framescript can be safely reused
|
2012-05-11 13:06:53 -07:00
|
|
|
Services.prefs.setBoolPref("marionette.contentListener", false);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
2012-04-03 11:08:49 -07:00
|
|
|
this.curBrowser.closeTab();
|
2012-03-22 08:19:57 -07:00
|
|
|
//delete session in each frame in each browser
|
|
|
|
for (let win in this.browsers) {
|
|
|
|
for (let i in this.browsers[win].knownFrames) {
|
2012-09-28 16:16:22 -07:00
|
|
|
this.globalMessageManager.broadcastAsyncMessage("Marionette:deleteSession" + this.browsers[win].knownFrames[i], {});
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let winEnum = this.getWinEnumerator();
|
|
|
|
while (winEnum.hasMoreElements()) {
|
2012-09-28 16:16:22 -07:00
|
|
|
winEnum.getNext().messageManager.removeDelayedFrameScript(FRAME_SCRIPT);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
}
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(command_id);
|
2012-09-28 16:16:22 -07:00
|
|
|
this.removeMessageManagerListeners(this.globalMessageManager);
|
|
|
|
this.switchToGlobalMessageManager();
|
2012-11-13 13:51:58 -08:00
|
|
|
// reset frame to the top-most frame
|
|
|
|
this.curFrame = null;
|
|
|
|
if (this.mainFrame) {
|
|
|
|
this.mainFrame.focus();
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
this.curBrowser = null;
|
2012-06-04 10:50:06 -07:00
|
|
|
try {
|
|
|
|
this.importedScripts.remove(false);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
2012-08-23 15:07:16 -07:00
|
|
|
/**
|
|
|
|
* Returns the current status of the Application Cache
|
|
|
|
*/
|
|
|
|
getAppCacheStatus: function MDA_getAppCacheStatus(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("getAppCacheStatus", {}, this.command_id);
|
2012-08-23 15:07:16 -07:00
|
|
|
},
|
|
|
|
|
2012-05-18 13:30:43 -07:00
|
|
|
_emu_cb_id: 0,
|
|
|
|
_emu_cbs: null,
|
|
|
|
runEmulatorCmd: function runEmulatorCmd(cmd, callback) {
|
2012-05-25 10:37:21 -07:00
|
|
|
if (callback) {
|
|
|
|
if (!this._emu_cbs) {
|
|
|
|
this._emu_cbs = {};
|
|
|
|
}
|
|
|
|
this._emu_cbs[this._emu_cb_id] = callback;
|
2012-05-18 13:30:43 -07:00
|
|
|
}
|
2013-02-12 10:10:03 -08:00
|
|
|
this.sendToClient({emulator_cmd: cmd, id: this._emu_cb_id}, -1);
|
2012-05-18 13:30:43 -07:00
|
|
|
this._emu_cb_id += 1;
|
|
|
|
},
|
|
|
|
|
|
|
|
emulatorCmdResult: function emulatorCmdResult(message) {
|
|
|
|
if (this.context != "chrome") {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("emulatorCmdResult", message, -1);
|
2012-05-18 13:30:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-25 10:37:21 -07:00
|
|
|
if (!this._emu_cbs) {
|
2012-05-23 17:23:36 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-18 13:30:43 -07:00
|
|
|
let cb = this._emu_cbs[message.id];
|
|
|
|
delete this._emu_cbs[message.id];
|
2012-05-25 10:37:21 -07:00
|
|
|
if (!cb) {
|
|
|
|
return;
|
|
|
|
}
|
2012-05-18 13:30:43 -07:00
|
|
|
try {
|
|
|
|
cb(message.result);
|
|
|
|
}
|
|
|
|
catch(e) {
|
2013-02-12 10:10:03 -08:00
|
|
|
this.sendError(e.message, e.code, e.stack, -1);
|
2012-05-18 13:30:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
2012-06-04 10:50:06 -07:00
|
|
|
|
|
|
|
importScript: function MDA_importScript(aRequest) {
|
2012-11-26 18:19:04 -08:00
|
|
|
let command_id = this.command_id = this.getCommandId();
|
2012-06-04 10:50:06 -07:00
|
|
|
if (this.context == "chrome") {
|
|
|
|
let file;
|
|
|
|
if (this.importedScripts.exists()) {
|
2012-11-26 18:19:04 -08:00
|
|
|
file = FileUtils.openFileOutputStream(this.importedScripts,
|
|
|
|
FileUtils.MODE_APPEND | FileUtils.MODE_WRONLY);
|
2012-06-04 10:50:06 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-10-24 08:36:43 -07:00
|
|
|
//Note: The permission bits here don't actually get set (bug 804563)
|
2012-11-26 18:19:04 -08:00
|
|
|
this.importedScripts.createUnique(
|
|
|
|
Components.interfaces.nsIFile.NORMAL_FILE_TYPE, parseInt("0666", 8));
|
|
|
|
file = FileUtils.openFileOutputStream(this.importedScripts,
|
|
|
|
FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE);
|
2012-10-24 08:36:43 -07:00
|
|
|
this.importedScripts.permissions = parseInt("0666", 8); //actually set permissions
|
2012-06-04 10:50:06 -07:00
|
|
|
}
|
|
|
|
file.write(aRequest.script, aRequest.script.length);
|
|
|
|
file.close();
|
2012-11-26 18:19:04 -08:00
|
|
|
this.sendOk(command_id);
|
2012-06-04 10:50:06 -07:00
|
|
|
}
|
|
|
|
else {
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("importScript",
|
|
|
|
{ script: aRequest.script },
|
|
|
|
command_id);
|
2012-06-04 10:50:06 -07:00
|
|
|
}
|
|
|
|
},
|
2012-05-18 13:30:43 -07:00
|
|
|
|
2012-11-30 15:25:26 -08:00
|
|
|
/**
|
|
|
|
* Takes a screenshot of a DOM node. If there is no node given a screenshot
|
|
|
|
* of the window will be taken.
|
|
|
|
*/
|
|
|
|
screenShot: function MDA_saveScreenshot(aRequest) {
|
2013-03-06 09:48:30 -08:00
|
|
|
this.command_id = this.getCommandId();
|
2013-04-08 14:12:32 -07:00
|
|
|
this.sendAsync("screenShot",
|
|
|
|
{
|
|
|
|
element: aRequest.element,
|
|
|
|
highlights: aRequest.highlights
|
|
|
|
},
|
|
|
|
this.command_id);
|
2012-11-30 15:25:26 -08:00
|
|
|
},
|
|
|
|
|
2012-09-28 16:16:22 -07:00
|
|
|
/**
|
|
|
|
* Helper function to convert an outerWindowID into a UID that Marionette
|
|
|
|
* tracks.
|
|
|
|
*/
|
|
|
|
generateFrameId: function MDA_generateFrameId(id) {
|
|
|
|
let uid = id + (appName == "B2G" ? "-b2g" : "");
|
|
|
|
return uid;
|
|
|
|
},
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Receives all messages from content messageManager
|
|
|
|
*/
|
|
|
|
receiveMessage: function MDA_receiveMessage(message) {
|
2013-01-16 07:00:00 -08:00
|
|
|
// We need to just check if we need to remove the mozbrowserclose listener
|
|
|
|
if (this.mozBrowserClose !== null){
|
|
|
|
let curWindow = this.getCurrentWindow();
|
|
|
|
curWindow.removeEventListener('mozbrowserclose', this.mozBrowserClose, true);
|
|
|
|
this.mozBrowserClose = null;
|
|
|
|
}
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
switch (message.name) {
|
|
|
|
case "Marionette:done":
|
|
|
|
this.sendResponse(message.json.value, message.json.command_id);
|
|
|
|
break;
|
|
|
|
case "Marionette:ok":
|
|
|
|
this.sendOk(message.json.command_id);
|
|
|
|
break;
|
|
|
|
case "Marionette:error":
|
|
|
|
this.sendError(message.json.message, message.json.status, message.json.stacktrace, message.json.command_id);
|
|
|
|
break;
|
|
|
|
case "Marionette:log":
|
|
|
|
//log server-side messages
|
|
|
|
logger.info(message.json.message);
|
|
|
|
break;
|
2012-06-10 16:44:50 -07:00
|
|
|
case "Marionette:shareData":
|
2012-03-22 08:19:57 -07:00
|
|
|
//log messages from tests
|
2012-06-10 16:44:50 -07:00
|
|
|
if (message.json.log) {
|
|
|
|
this.marionetteLog.addLogs(message.json.log);
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
break;
|
2012-05-18 13:30:43 -07:00
|
|
|
case "Marionette:runEmulatorCmd":
|
2013-02-12 10:10:03 -08:00
|
|
|
this.sendToClient(message.json, -1);
|
2012-05-18 13:30:43 -07:00
|
|
|
break;
|
2012-09-28 16:16:22 -07:00
|
|
|
case "Marionette:switchToFrame":
|
|
|
|
// Switch to a remote frame.
|
2013-05-07 09:34:21 -07:00
|
|
|
let frameWindow = Services.wm.getOuterWindowWithId(message.json.win);
|
2012-10-02 10:37:47 -07:00
|
|
|
let thisFrame = frameWindow.document.getElementsByTagName("iframe")[message.json.frame];
|
2012-11-06 10:54:09 -08:00
|
|
|
let mm = thisFrame.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
|
2012-09-28 16:16:22 -07:00
|
|
|
|
2012-10-02 10:37:47 -07:00
|
|
|
// See if this frame already has our frame script loaded in it; if so,
|
|
|
|
// just wake it up.
|
2012-09-28 16:16:22 -07:00
|
|
|
for (let i = 0; i < remoteFrames.length; i++) {
|
|
|
|
let frame = remoteFrames[i];
|
2012-10-02 10:37:47 -07:00
|
|
|
if ((frame.messageManager == mm)) {
|
2012-09-28 16:16:22 -07:00
|
|
|
this.currentRemoteFrame = frame;
|
2012-11-26 18:19:04 -08:00
|
|
|
this.currentRemoteFrame.command_id = message.json.command_id;
|
2012-09-28 16:16:22 -07:00
|
|
|
this.messageManager = frame.messageManager;
|
|
|
|
this.addMessageManagerListeners(this.messageManager);
|
|
|
|
this.messageManager.sendAsyncMessage("Marionette:restart", {});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the frame script in this frame, and set the frame's ChromeMessageSender
|
|
|
|
// as the active message manager.
|
|
|
|
this.addMessageManagerListeners(mm);
|
|
|
|
mm.loadFrameScript(FRAME_SCRIPT, true);
|
|
|
|
this.messageManager = mm;
|
|
|
|
let aFrame = new MarionetteRemoteFrame(message.json.win, message.json.frame);
|
|
|
|
aFrame.messageManager = this.messageManager;
|
2012-11-26 18:19:04 -08:00
|
|
|
aFrame.command_id = message.json.command_id;
|
2012-09-28 16:16:22 -07:00
|
|
|
remoteFrames.push(aFrame);
|
|
|
|
this.currentRemoteFrame = aFrame;
|
|
|
|
break;
|
2012-03-22 08:19:57 -07:00
|
|
|
case "Marionette:register":
|
|
|
|
// This code processes the content listener's registration information
|
|
|
|
// and either accepts the listener, or ignores it
|
2012-04-03 11:08:49 -07:00
|
|
|
let nullPrevious = (this.curBrowser.curFrameId == null);
|
2013-05-07 09:34:21 -07:00
|
|
|
let listenerWindow =
|
|
|
|
Services.wm.getOuterWindowWithId(message.json.value);
|
2012-09-28 16:16:22 -07:00
|
|
|
|
2012-11-12 16:17:54 -08:00
|
|
|
if (!listenerWindow || (listenerWindow.location.href != message.json.href) &&
|
2012-10-02 10:37:47 -07:00
|
|
|
(this.currentRemoteFrame !== null)) {
|
2012-11-12 16:17:54 -08:00
|
|
|
// The outerWindowID from an OOP frame will not be meaningful to
|
|
|
|
// the parent process here, since each process maintains its own
|
|
|
|
// independent window list. So, it will either be null (!listenerWindow)
|
|
|
|
// or it will point to some random window, which will hopefully
|
|
|
|
// cause an href mistmach. Currently this only happens
|
2012-09-28 16:16:22 -07:00
|
|
|
// in B2G for OOP frames registered in Marionette:switchToFrame, so
|
2012-11-12 16:17:54 -08:00
|
|
|
// we'll acknowledge the switchToFrame message here.
|
2012-09-28 16:16:22 -07:00
|
|
|
// XXX: Should have a better way of determining that this message
|
|
|
|
// is from a remote frame.
|
|
|
|
this.currentRemoteFrame.targetFrameId = this.generateFrameId(message.json.value);
|
2013-05-01 10:16:49 -07:00
|
|
|
this.sendOk(this.currentRemoteFrame.command_id);
|
2012-09-28 16:16:22 -07:00
|
|
|
}
|
|
|
|
|
2012-07-26 12:36:15 -07:00
|
|
|
let browserType;
|
|
|
|
try {
|
|
|
|
browserType = message.target.getAttribute("type");
|
|
|
|
} catch (ex) {
|
|
|
|
// browserType remains undefined.
|
|
|
|
}
|
2012-12-14 08:11:02 -08:00
|
|
|
let reg = {};
|
2012-07-26 12:36:15 -07:00
|
|
|
if (!browserType || browserType != "content") {
|
2012-12-14 08:11:02 -08:00
|
|
|
reg.id = this.curBrowser.register(this.generateFrameId(message.json.value),
|
2013-05-17 11:43:52 -07:00
|
|
|
listenerWindow);
|
2012-07-26 12:36:15 -07:00
|
|
|
}
|
2013-05-17 11:43:52 -07:00
|
|
|
this.curBrowser.elementManager.seenItems[reg.id] = Cu.getWeakReference(listenerWindow);
|
2012-12-14 08:11:02 -08:00
|
|
|
reg.importedScripts = this.importedScripts.path;
|
2012-07-26 12:36:15 -07:00
|
|
|
if (nullPrevious && (this.curBrowser.curFrameId != null)) {
|
2013-04-08 14:12:32 -07:00
|
|
|
if (!this.sendAsync("newSession",
|
|
|
|
{ B2G: (appName == "B2G") },
|
|
|
|
this.newSessionCommandId)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-26 12:36:15 -07:00
|
|
|
if (this.curBrowser.newSession) {
|
2013-02-12 10:10:03 -08:00
|
|
|
this.sendResponse(reg.id, this.newSessionCommandId);
|
|
|
|
this.newSessionCommandId = null;
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return reg;
|
|
|
|
}
|
2013-02-12 10:10:03 -08:00
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
};
|
|
|
|
|
2013-05-14 13:54:07 -07:00
|
|
|
MarionetteServerConnection.prototype.requestTypes = {
|
|
|
|
"getMarionetteID": MarionetteServerConnection.prototype.getMarionetteID,
|
|
|
|
"sayHello": MarionetteServerConnection.prototype.sayHello,
|
|
|
|
"newSession": MarionetteServerConnection.prototype.newSession,
|
|
|
|
"getSessionCapabilities": MarionetteServerConnection.prototype.getSessionCapabilities,
|
|
|
|
"getStatus": MarionetteServerConnection.prototype.getStatus,
|
|
|
|
"log": MarionetteServerConnection.prototype.log,
|
|
|
|
"getLogs": MarionetteServerConnection.prototype.getLogs,
|
|
|
|
"setContext": MarionetteServerConnection.prototype.setContext,
|
|
|
|
"executeScript": MarionetteServerConnection.prototype.execute,
|
|
|
|
"setScriptTimeout": MarionetteServerConnection.prototype.setScriptTimeout,
|
|
|
|
"timeouts": MarionetteServerConnection.prototype.timeouts,
|
|
|
|
"singleTap": MarionetteServerConnection.prototype.singleTap,
|
|
|
|
"actionChain": MarionetteServerConnection.prototype.actionChain,
|
|
|
|
"multiAction": MarionetteServerConnection.prototype.multiAction,
|
|
|
|
"executeAsyncScript": MarionetteServerConnection.prototype.executeWithCallback,
|
|
|
|
"executeJSScript": MarionetteServerConnection.prototype.executeJSScript,
|
|
|
|
"setSearchTimeout": MarionetteServerConnection.prototype.setSearchTimeout,
|
|
|
|
"findElement": MarionetteServerConnection.prototype.findElement,
|
|
|
|
"findElements": MarionetteServerConnection.prototype.findElements,
|
|
|
|
"clickElement": MarionetteServerConnection.prototype.clickElement,
|
|
|
|
"getElementAttribute": MarionetteServerConnection.prototype.getElementAttribute,
|
|
|
|
"getElementText": MarionetteServerConnection.prototype.getElementText,
|
|
|
|
"getElementTagName": MarionetteServerConnection.prototype.getElementTagName,
|
|
|
|
"isElementDisplayed": MarionetteServerConnection.prototype.isElementDisplayed,
|
|
|
|
"getElementValueOfCssProperty": MarionetteServerConnection.prototype.getElementValueOfCssProperty,
|
|
|
|
"getElementSize": MarionetteServerConnection.prototype.getElementSize,
|
|
|
|
"isElementEnabled": MarionetteServerConnection.prototype.isElementEnabled,
|
|
|
|
"isElementSelected": MarionetteServerConnection.prototype.isElementSelected,
|
|
|
|
"sendKeysToElement": MarionetteServerConnection.prototype.sendKeysToElement,
|
|
|
|
"getElementPosition": MarionetteServerConnection.prototype.getElementPosition,
|
|
|
|
"clearElement": MarionetteServerConnection.prototype.clearElement,
|
|
|
|
"getTitle": MarionetteServerConnection.prototype.getTitle,
|
|
|
|
"getWindowType": MarionetteServerConnection.prototype.getWindowType,
|
|
|
|
"getPageSource": MarionetteServerConnection.prototype.getPageSource,
|
|
|
|
"goUrl": MarionetteServerConnection.prototype.goUrl,
|
|
|
|
"getUrl": MarionetteServerConnection.prototype.getUrl,
|
|
|
|
"goBack": MarionetteServerConnection.prototype.goBack,
|
|
|
|
"goForward": MarionetteServerConnection.prototype.goForward,
|
|
|
|
"refresh": MarionetteServerConnection.prototype.refresh,
|
|
|
|
"getWindow": MarionetteServerConnection.prototype.getWindow,
|
|
|
|
"getWindows": MarionetteServerConnection.prototype.getWindows,
|
|
|
|
"switchToFrame": MarionetteServerConnection.prototype.switchToFrame,
|
|
|
|
"switchToWindow": MarionetteServerConnection.prototype.switchToWindow,
|
|
|
|
"deleteSession": MarionetteServerConnection.prototype.deleteSession,
|
|
|
|
"emulatorCmdResult": MarionetteServerConnection.prototype.emulatorCmdResult,
|
|
|
|
"importScript": MarionetteServerConnection.prototype.importScript,
|
|
|
|
"getAppCacheStatus": MarionetteServerConnection.prototype.getAppCacheStatus,
|
|
|
|
"closeWindow": MarionetteServerConnection.prototype.closeWindow,
|
|
|
|
"setTestName": MarionetteServerConnection.prototype.setTestName,
|
|
|
|
"screenShot": MarionetteServerConnection.prototype.screenShot,
|
|
|
|
"addCookie": MarionetteServerConnection.prototype.addCookie,
|
|
|
|
"getAllCookies": MarionetteServerConnection.prototype.getAllCookies,
|
|
|
|
"deleteAllCookies": MarionetteServerConnection.prototype.deleteAllCookies,
|
|
|
|
"deleteCookie": MarionetteServerConnection.prototype.deleteCookie,
|
|
|
|
"getActiveElement": MarionetteServerConnection.prototype.getActiveElement
|
2012-03-22 08:19:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a BrowserObj. BrowserObjs handle interactions with the
|
|
|
|
* browser, according to the current environment (desktop, b2g, etc.)
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow win
|
|
|
|
* The window whose browser needs to be accessed
|
|
|
|
*/
|
|
|
|
|
|
|
|
function BrowserObj(win) {
|
|
|
|
this.DESKTOP = "desktop";
|
|
|
|
this.B2G = "B2G";
|
|
|
|
this.browser;
|
|
|
|
this.tab = null;
|
2012-08-28 11:14:30 -07:00
|
|
|
this.window = win;
|
2012-03-22 08:19:57 -07:00
|
|
|
this.knownFrames = [];
|
|
|
|
this.curFrameId = null;
|
|
|
|
this.startPage = "about:blank";
|
|
|
|
this.mainContentId = null; // used in B2G to identify the homescreen content page
|
|
|
|
this.newSession = true; //used to set curFrameId upon new session
|
2012-04-03 11:08:49 -07:00
|
|
|
this.elementManager = new ElementManager([SELECTOR, NAME, LINK_TEXT, PARTIAL_LINK_TEXT]);
|
2012-03-22 08:19:57 -07:00
|
|
|
this.setBrowser(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserObj.prototype = {
|
|
|
|
/**
|
|
|
|
* Set the browser if the application is not B2G
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow win
|
|
|
|
* current window reference
|
|
|
|
*/
|
|
|
|
setBrowser: function BO_setBrowser(win) {
|
2012-09-18 01:08:55 -07:00
|
|
|
switch (appName) {
|
|
|
|
case "Firefox":
|
|
|
|
this.browser = win.gBrowser;
|
|
|
|
break;
|
|
|
|
case "Fennec":
|
|
|
|
this.browser = win.BrowserApp;
|
|
|
|
break;
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Called when we start a session with this browser.
|
|
|
|
*
|
|
|
|
* In a desktop environment, if newTab is true, it will start
|
|
|
|
* a new 'about:blank' tab and change focus to this tab.
|
|
|
|
*
|
|
|
|
* This will also set the active messagemanager for this object
|
|
|
|
*
|
|
|
|
* @param boolean newTab
|
|
|
|
* If true, create new tab
|
|
|
|
*/
|
2012-08-21 14:00:44 -07:00
|
|
|
startSession: function BO_startSession(newTab, win, callback) {
|
2012-09-18 01:08:55 -07:00
|
|
|
if (appName != "Firefox") {
|
2012-08-21 14:00:44 -07:00
|
|
|
callback(win, newTab);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
2012-08-21 14:00:44 -07:00
|
|
|
else if (newTab) {
|
2013-05-17 11:43:52 -07:00
|
|
|
this.tab = this.addTab(this.startPage);
|
2012-08-21 14:00:44 -07:00
|
|
|
//if we have a new tab, make it the selected tab
|
2012-03-22 08:19:57 -07:00
|
|
|
this.browser.selectedTab = this.tab;
|
|
|
|
let newTabBrowser = this.browser.getBrowserForTab(this.tab);
|
2012-08-21 14:00:44 -07:00
|
|
|
// wait for tab to be loaded
|
|
|
|
newTabBrowser.addEventListener("load", function onLoad() {
|
|
|
|
newTabBrowser.removeEventListener("load", onLoad, true);
|
|
|
|
callback(win, newTab);
|
|
|
|
}, true);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
//set this.tab to the currently focused tab
|
2012-04-10 17:28:08 -07:00
|
|
|
if (this.browser != undefined && this.browser.selectedTab != undefined) {
|
|
|
|
this.tab = this.browser.selectedTab;
|
|
|
|
}
|
2012-08-21 14:00:44 -07:00
|
|
|
callback(win, newTab);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes current tab
|
|
|
|
*/
|
|
|
|
closeTab: function BO_closeTab() {
|
|
|
|
if (this.tab != null && (appName != "B2G")) {
|
|
|
|
this.browser.removeTab(this.tab);
|
|
|
|
this.tab = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a tab with given uri
|
|
|
|
*
|
|
|
|
* @param string uri
|
|
|
|
* URI to open
|
|
|
|
*/
|
|
|
|
addTab: function BO_addTab(uri) {
|
2013-05-17 11:43:52 -07:00
|
|
|
return this.browser.addTab(uri, true);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads content listeners if we don't already have them
|
|
|
|
*
|
|
|
|
* @param string script
|
|
|
|
* path of script to load
|
|
|
|
* @param nsIDOMWindow frame
|
|
|
|
* frame to load the script in
|
|
|
|
*/
|
|
|
|
loadFrameScript: function BO_loadFrameScript(script, frame) {
|
2012-05-17 11:53:55 -07:00
|
|
|
frame.window.messageManager.loadFrameScript(script, true);
|
|
|
|
Services.prefs.setBoolPref("marionette.contentListener", true);
|
2012-03-22 08:19:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a new frame, and sets its current frame id to this frame
|
|
|
|
* if it is not already assigned, and if a) we already have a session
|
|
|
|
* or b) we're starting a new session and it is the right start frame.
|
|
|
|
*
|
2012-09-28 16:16:22 -07:00
|
|
|
* @param string uid
|
|
|
|
* frame uid
|
2013-05-17 11:43:52 -07:00
|
|
|
* @param object frameWindow
|
|
|
|
* the DOMWindow object of the frame that's being registered
|
2012-03-22 08:19:57 -07:00
|
|
|
*/
|
2013-05-17 11:43:52 -07:00
|
|
|
register: function BO_register(uid, frameWindow) {
|
2012-03-22 08:19:57 -07:00
|
|
|
if (this.curFrameId == null) {
|
2013-05-17 11:43:52 -07:00
|
|
|
// If we're setting up a new session on Firefox, we only process the
|
|
|
|
// registration for this frame if it belongs to the tab we've just
|
|
|
|
// created.
|
|
|
|
if ((!this.newSession) ||
|
|
|
|
(this.newSession &&
|
|
|
|
((appName != "Firefox") ||
|
|
|
|
frameWindow == this.browser.getBrowserForTab(this.tab).contentWindow))) {
|
2012-03-22 08:19:57 -07:00
|
|
|
this.curFrameId = uid;
|
|
|
|
this.mainContentId = uid;
|
|
|
|
}
|
|
|
|
}
|
2012-09-28 16:16:22 -07:00
|
|
|
this.knownFrames.push(uid); //used to delete sessions
|
2012-03-22 08:19:57 -07:00
|
|
|
return uid;
|
|
|
|
},
|
|
|
|
}
|
2013-05-14 13:54:07 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Marionette server -- this class holds a reference to a socket and creates
|
|
|
|
* MarionetteServerConnection objects as needed.
|
|
|
|
*/
|
|
|
|
this.MarionetteServer = function MarionetteServer(port, forceLocal) {
|
|
|
|
let flags = Ci.nsIServerSocket.KeepWhenOffline;
|
|
|
|
if (forceLocal) {
|
|
|
|
flags |= Ci.nsIServerSocket.LoopbackOnly;
|
|
|
|
}
|
|
|
|
let socket = new ServerSocket(port, flags, 4);
|
|
|
|
logger.info("Listening on port " + socket.port + "\n");
|
|
|
|
socket.asyncListen(this);
|
|
|
|
this.listener = socket;
|
|
|
|
this.nextConnId = 0;
|
|
|
|
this.connections = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
MarionetteServer.prototype = {
|
|
|
|
onSocketAccepted: function(serverSocket, clientSocket)
|
|
|
|
{
|
|
|
|
logger.debug("accepted connection on " + clientSocket.host + ":" + clientSocket.port);
|
|
|
|
|
|
|
|
let input = clientSocket.openInputStream(0, 0, 0);
|
|
|
|
let output = clientSocket.openOutputStream(0, 0, 0);
|
|
|
|
let aTransport = new DebuggerTransport(input, output);
|
|
|
|
let connID = "conn" + this.nextConnID++ + '.';
|
|
|
|
let conn = new MarionetteServerConnection(connID, aTransport, this);
|
|
|
|
this.connections[connID] = conn;
|
|
|
|
|
|
|
|
// Create a root actor for the connection and send the hello packet.
|
|
|
|
conn.sayHello();
|
|
|
|
aTransport.ready();
|
|
|
|
},
|
|
|
|
|
|
|
|
closeListener: function() {
|
|
|
|
this.listener.close();
|
|
|
|
this.listener = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_connectionClosed: function DS_connectionClosed(aConnection) {
|
|
|
|
delete this.connections[aConnection.prefix];
|
|
|
|
}
|
|
|
|
};
|