2015-03-20 00:12:58 +03: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";
|
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
2015-03-20 00:12:58 +03:00
|
|
|
.getService(Ci.mozIJSSubScriptLoader);
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Log.jsm");
|
2016-01-19 01:05:30 +03:00
|
|
|
Cu.import("resource://gre/modules/Preferences.jsm");
|
2015-03-20 00:12:58 +03:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(
|
2015-07-16 01:51:51 +03:00
|
|
|
this, "cookieManager", "@mozilla.org/cookiemanager;1", "nsICookieManager2");
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2016-11-07 20:15:08 +03:00
|
|
|
Cu.import("chrome://marionette/content/accessibility.js");
|
2016-08-26 15:38:03 +03:00
|
|
|
Cu.import("chrome://marionette/content/addon.js");
|
2016-11-01 01:12:30 +03:00
|
|
|
Cu.import("chrome://marionette/content/assert.js");
|
2016-02-03 22:00:46 +03:00
|
|
|
Cu.import("chrome://marionette/content/atom.js");
|
2016-05-10 15:29:21 +03:00
|
|
|
Cu.import("chrome://marionette/content/browser.js");
|
2016-12-05 20:37:50 +03:00
|
|
|
Cu.import("chrome://marionette/content/capture.js");
|
2016-11-06 21:03:31 +03:00
|
|
|
Cu.import("chrome://marionette/content/cert.js");
|
2016-02-03 22:14:10 +03:00
|
|
|
Cu.import("chrome://marionette/content/element.js");
|
2016-02-29 21:52:30 +03:00
|
|
|
Cu.import("chrome://marionette/content/error.js");
|
|
|
|
Cu.import("chrome://marionette/content/evaluate.js");
|
2016-02-03 21:56:02 +03:00
|
|
|
Cu.import("chrome://marionette/content/event.js");
|
2016-02-29 21:52:30 +03:00
|
|
|
Cu.import("chrome://marionette/content/interaction.js");
|
2016-11-12 00:49:58 +03:00
|
|
|
Cu.import("chrome://marionette/content/l10n.js");
|
2016-10-26 20:04:48 +03:00
|
|
|
Cu.import("chrome://marionette/content/legacyaction.js");
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
Cu.import("chrome://marionette/content/logging.js");
|
2015-03-20 18:46:46 +03:00
|
|
|
Cu.import("chrome://marionette/content/modal.js");
|
2015-04-28 16:25:37 +03:00
|
|
|
Cu.import("chrome://marionette/content/proxy.js");
|
2016-12-31 15:27:13 +03:00
|
|
|
Cu.import("chrome://marionette/content/session.js");
|
2015-03-24 00:32:03 +03:00
|
|
|
Cu.import("chrome://marionette/content/simpletest.js");
|
2016-11-22 01:43:35 +03:00
|
|
|
Cu.import("chrome://marionette/content/wait.js");
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ["GeckoDriver", "Context"];
|
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var FRAME_SCRIPT = "chrome://marionette/content/listener.js";
|
2017-03-07 21:38:51 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
const CLICK_TO_START_PREF = "marionette.debugging.clicktostart";
|
|
|
|
const CONTENT_LISTENER_PREF = "marionette.contentListener";
|
|
|
|
|
2016-12-09 23:55:25 +03:00
|
|
|
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
2016-05-20 15:28:27 +03:00
|
|
|
const SUPPORTED_STRATEGIES = new Set([
|
|
|
|
element.Strategy.ClassName,
|
|
|
|
element.Strategy.Selector,
|
|
|
|
element.Strategy.ID,
|
|
|
|
element.Strategy.TagName,
|
|
|
|
element.Strategy.XPath,
|
|
|
|
element.Strategy.Anon,
|
|
|
|
element.Strategy.AnonAttribute,
|
|
|
|
]);
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
const logger = Log.repository.getLogger("Marionette");
|
|
|
|
const globalMessageManager = Cc["@mozilla.org/globalmessagemanager;1"]
|
|
|
|
.getService(Ci.nsIMessageBroadcaster);
|
|
|
|
|
|
|
|
// This is used to prevent newSession from returning before the telephony
|
|
|
|
// API's are ready; see bug 792647. This assumes that marionette-server.js
|
|
|
|
// will be loaded before the 'system-message-listener-ready' message
|
|
|
|
// is fired. If this stops being true, this approach will have to change.
|
2015-09-15 21:19:45 +03:00
|
|
|
var systemMessageListenerReady = false;
|
2015-03-20 00:12:58 +03:00
|
|
|
Services.obs.addObserver(function() {
|
|
|
|
systemMessageListenerReady = true;
|
|
|
|
}, "system-message-listener-ready", false);
|
|
|
|
|
|
|
|
this.Context = {
|
|
|
|
CHROME: "chrome",
|
|
|
|
CONTENT: "content",
|
|
|
|
};
|
|
|
|
|
2016-12-04 14:42:52 +03:00
|
|
|
this.Context.fromString = function (s) {
|
2015-03-20 00:12:58 +03:00
|
|
|
s = s.toUpperCase();
|
2015-03-23 23:43:18 +03:00
|
|
|
if (s in this) {
|
2015-03-20 00:12:58 +03:00
|
|
|
return this[s];
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements (parts of) the W3C WebDriver protocol. GeckoDriver lives
|
2015-04-28 16:25:37 +03:00
|
|
|
* in chrome space and mediates calls to the message listener of the current
|
|
|
|
* browsing context's content frame message listener via ListenerProxy.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
|
|
|
* Throughout this prototype, functions with the argument {@code cmd}'s
|
|
|
|
* documentation refers to the contents of the {@code cmd.parameters}
|
|
|
|
* object.
|
|
|
|
*
|
|
|
|
* @param {string} appName
|
|
|
|
* Description of the product, for example "B2G" or "Firefox".
|
2016-10-17 14:19:19 +03:00
|
|
|
* @param {MarionetteServer} server
|
|
|
|
* The instance of Marionette server.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
this.GeckoDriver = function (appName, server) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.appName = appName;
|
2016-10-17 14:19:19 +03:00
|
|
|
this._server = server;
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
this.sessionId = null;
|
2016-05-23 12:21:15 +03:00
|
|
|
this.wins = new browser.Windows();
|
2015-03-20 00:12:58 +03:00
|
|
|
this.browsers = {};
|
|
|
|
// points to current browser
|
|
|
|
this.curBrowser = null;
|
|
|
|
// topmost chrome frame
|
|
|
|
this.mainFrame = null;
|
|
|
|
// chrome iframe that currently has focus
|
|
|
|
this.curFrame = null;
|
|
|
|
this.mainContentFrameId = null;
|
2016-11-25 02:18:40 +03:00
|
|
|
this.mozBrowserClose = null;
|
2016-11-01 21:00:25 +03:00
|
|
|
this.currentFrameElement = null;
|
2015-03-20 00:12:58 +03:00
|
|
|
// frame ID of the current remote frame, used for mozbrowserclose events
|
|
|
|
this.oopFrameId = null;
|
|
|
|
this.observing = null;
|
|
|
|
this._browserIds = new WeakMap();
|
|
|
|
|
2016-11-01 21:00:25 +03:00
|
|
|
// The curent context decides if commands should affect chrome- or
|
|
|
|
// content space.
|
|
|
|
this.context = Context.CONTENT;
|
|
|
|
|
|
|
|
this.importedScripts = new evaluate.ScriptStorageService(
|
|
|
|
[Context.CHROME, Context.CONTENT]);
|
|
|
|
this.sandboxes = new Sandboxes(() => this.getCurrentWindow());
|
2016-11-29 19:00:52 +03:00
|
|
|
this.legacyactions = new legacyaction.Chain();
|
2016-11-01 21:00:25 +03:00
|
|
|
|
|
|
|
this.timer = null;
|
|
|
|
this.inactivityTimer = null;
|
|
|
|
|
|
|
|
this.marionetteLog = new logging.ContentLogger();
|
|
|
|
this.testName = null;
|
|
|
|
|
2016-12-31 15:32:14 +03:00
|
|
|
this.capabilities = new session.Capabilities();
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
this.mm = globalMessageManager;
|
2015-04-28 16:25:37 +03:00
|
|
|
this.listener = proxy.toListener(() => this.mm, this.sendAsync.bind(this));
|
2015-03-20 18:46:46 +03:00
|
|
|
|
2015-09-26 19:12:01 +03:00
|
|
|
// always keep weak reference to current dialogue
|
2015-03-20 18:46:46 +03:00
|
|
|
this.dialog = null;
|
|
|
|
let handleDialog = (subject, topic) => {
|
|
|
|
let winr;
|
2015-03-23 23:43:18 +03:00
|
|
|
if (topic == modal.COMMON_DIALOG_LOADED) {
|
2015-03-20 18:46:46 +03:00
|
|
|
winr = Cu.getWeakReference(subject);
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 18:46:46 +03:00
|
|
|
this.dialog = new modal.Dialog(() => this.curBrowser, winr);
|
|
|
|
};
|
|
|
|
modal.addHandler(handleDialog);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2016-12-19 22:28:17 +03:00
|
|
|
Object.defineProperty(GeckoDriver.prototype, "a11yChecks", {
|
2016-12-31 15:27:13 +03:00
|
|
|
get: function () {
|
2016-12-31 15:32:14 +03:00
|
|
|
return this.capabilities.get("moz:accessibilityChecks");
|
2016-12-31 15:27:13 +03:00
|
|
|
}
|
2016-12-19 22:28:17 +03:00
|
|
|
});
|
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
Object.defineProperty(GeckoDriver.prototype, "proxy", {
|
|
|
|
get: function () {
|
|
|
|
return this.capabilities.get("proxy");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(GeckoDriver.prototype, "secureTLS", {
|
|
|
|
get: function () {
|
|
|
|
return !this.capabilities.get("acceptInsecureCerts");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(GeckoDriver.prototype, "timeouts", {
|
|
|
|
get: function () {
|
|
|
|
return this.capabilities.get("timeouts");
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (newTimeouts) {
|
|
|
|
this.capabilities.set("timeouts", newTimeouts);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(GeckoDriver.prototype, "windowHandles", {
|
|
|
|
get: function () {
|
|
|
|
let hs = [];
|
|
|
|
let winEn = Services.wm.getEnumerator(null);
|
|
|
|
|
|
|
|
while (winEn.hasMoreElements()) {
|
|
|
|
let win = winEn.getNext();
|
2017-01-26 18:42:35 +03:00
|
|
|
let tabBrowser = browser.getTabBrowser(win);
|
|
|
|
|
|
|
|
if (tabBrowser) {
|
|
|
|
tabBrowser.tabs.forEach(tab => {
|
|
|
|
let winId = this.getIdForBrowser(browser.getBrowserForTab(tab));
|
2017-01-10 18:36:49 +03:00
|
|
|
if (winId !== null) {
|
|
|
|
hs.push(winId);
|
|
|
|
}
|
2017-01-26 18:42:35 +03:00
|
|
|
});
|
2017-01-10 18:36:49 +03:00
|
|
|
} else {
|
2017-01-27 11:09:32 +03:00
|
|
|
// For other chrome windows beside the browser window, only add the window itself.
|
|
|
|
hs.push(getOuterWindowId(win));
|
2017-01-10 18:36:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hs;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(GeckoDriver.prototype, "chromeWindowHandles", {
|
|
|
|
get : function () {
|
|
|
|
let hs = [];
|
|
|
|
let winEn = Services.wm.getEnumerator(null);
|
|
|
|
|
|
|
|
while (winEn.hasMoreElements()) {
|
2017-01-27 11:09:32 +03:00
|
|
|
hs.push(getOuterWindowId(winEn.getNext()));
|
2017-01-10 18:36:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return hs;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
GeckoDriver.prototype.QueryInterface = XPCOMUtils.generateQI([
|
|
|
|
Ci.nsIMessageListener,
|
|
|
|
Ci.nsIObserver,
|
2016-12-30 15:43:36 +03:00
|
|
|
Ci.nsISupportsWeakReference,
|
2015-03-20 00:12:58 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.switchToGlobalMessageManager = function() {
|
|
|
|
if (this.curBrowser && this.curBrowser.frameManager.currentRemoteFrame !== null) {
|
|
|
|
this.curBrowser.frameManager.removeMessageManagerListeners(this.mm);
|
|
|
|
this.sendAsync("sleepSession");
|
|
|
|
this.curBrowser.frameManager.currentRemoteFrame = null;
|
|
|
|
}
|
|
|
|
this.mm = globalMessageManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method to send async messages to the content listener.
|
2015-03-24 00:32:03 +03:00
|
|
|
* Correct usage is to pass in the name of a function in listener.js,
|
2016-12-19 22:08:46 +03:00
|
|
|
* a serialisable object, and optionally the current command's ID
|
|
|
|
* when not using the modern dispatching technique.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
|
|
|
* @param {string} name
|
2016-12-19 22:08:46 +03:00
|
|
|
* Suffix of the targetted message listener
|
|
|
|
* ({@code Marionette:<suffix>}).
|
2015-03-20 00:12:58 +03:00
|
|
|
* @param {Object=} msg
|
2016-12-19 22:08:46 +03:00
|
|
|
* Optional JSON serialisable object to send to the listener.
|
|
|
|
* @param {number=} commandID
|
|
|
|
* Optional command ID to ensure synchronisity.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-12-19 22:08:46 +03:00
|
|
|
GeckoDriver.prototype.sendAsync = function (name, data, commandID) {
|
2015-04-28 16:34:55 +03:00
|
|
|
name = "Marionette:" + name;
|
2016-12-19 22:08:46 +03:00
|
|
|
let payload = copy(data);
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2016-01-29 15:57:46 +03:00
|
|
|
// TODO(ato): When proxy.AsyncMessageChannel
|
|
|
|
// is used for all chrome <-> content communication
|
|
|
|
// this can be removed.
|
2016-12-19 22:08:46 +03:00
|
|
|
if (commandID) {
|
|
|
|
payload.command_id = commandID;
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2016-12-19 22:08:46 +03:00
|
|
|
if (!this.curBrowser.frameManager.currentRemoteFrame) {
|
|
|
|
this.broadcastDelayedAsyncMessage_(name, payload);
|
2015-03-20 00:12:58 +03:00
|
|
|
} else {
|
2016-12-19 22:08:46 +03:00
|
|
|
this.sendTargettedAsyncMessage_(name, payload);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
GeckoDriver.prototype.broadcastDelayedAsyncMessage_ = function (name, payload) {
|
|
|
|
this.curBrowser.executeWhenReady(() => {
|
|
|
|
if (this.curBrowser.curFrameId) {
|
|
|
|
const target = name + this.curBrowser.curFrameId;
|
|
|
|
this.mm.broadcastAsyncMessage(target, payload);
|
|
|
|
} else {
|
|
|
|
throw new NoSuchWindowError(
|
|
|
|
"No such content frame; perhaps the listener was not registered?");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
GeckoDriver.prototype.sendTargettedAsyncMessage_ = function (name, payload) {
|
|
|
|
const curRemoteFrame = this.curBrowser.frameManager.currentRemoteFrame;
|
|
|
|
const target = name + curRemoteFrame.targetFrameId;
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.mm.sendAsyncMessage(target, payload);
|
|
|
|
} catch (e) {
|
|
|
|
switch (e.result) {
|
|
|
|
case Cr.NS_ERROR_FAILURE:
|
|
|
|
case Cr.NS_ERROR_NOT_INITIALIZED:
|
|
|
|
throw new NoSuchWindowError();
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new WebDriverError(e);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-03-01 14:48:59 +03:00
|
|
|
* Gets the current active window.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2017-03-01 14:48:59 +03:00
|
|
|
* @return {nsIDOMWindow}
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-03-01 14:49:21 +03:00
|
|
|
GeckoDriver.prototype.getCurrentWindow = function() {
|
|
|
|
let typ = null;
|
2017-03-01 14:48:59 +03:00
|
|
|
if (this.curFrame === null) {
|
|
|
|
if (this.curBrowser === null) {
|
2017-03-01 14:49:21 +03:00
|
|
|
if (this.context == Context.CONTENT) {
|
|
|
|
typ = "navigator:browser";
|
2017-02-03 19:49:38 +03:00
|
|
|
}
|
2017-03-01 14:49:21 +03:00
|
|
|
return Services.wm.getMostRecentWindow(typ);
|
|
|
|
} else {
|
|
|
|
return this.curBrowser.window;
|
2017-03-01 14:48:59 +03:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-01 14:49:21 +03:00
|
|
|
return this.curFrame;
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.addFrameCloseListener = function (action) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let win = this.getCurrentWindow();
|
|
|
|
this.mozBrowserClose = e => {
|
|
|
|
if (e.target.id == this.oopFrameId) {
|
|
|
|
win.removeEventListener("mozbrowserclose", this.mozBrowserClose, true);
|
|
|
|
this.switchToGlobalMessageManager();
|
2015-04-29 14:00:43 +03:00
|
|
|
throw new NoSuchWindowError("The window closed during action: " + action);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
win.addEventListener("mozbrowserclose", this.mozBrowserClose, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-05-10 15:29:21 +03:00
|
|
|
* Create a new browsing context for window and add to known browsers.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
|
|
|
* @param {nsIDOMWindow} win
|
2016-05-10 15:29:21 +03:00
|
|
|
* Window for which we will create a browsing context.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Returns the unique server-assigned ID of the window.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.addBrowser = function (win) {
|
2016-05-10 15:29:21 +03:00
|
|
|
let bc = new browser.Context(win, this);
|
2017-01-27 11:09:32 +03:00
|
|
|
let winId = getOuterWindowId(win);
|
|
|
|
|
2016-05-10 15:29:21 +03:00
|
|
|
this.browsers[winId] = bc;
|
2015-03-20 00:12:58 +03:00
|
|
|
this.curBrowser = this.browsers[winId];
|
2016-05-23 12:21:15 +03:00
|
|
|
if (!this.wins.has(winId)) {
|
2015-03-20 00:12:58 +03:00
|
|
|
// add this to seenItems so we can guarantee
|
|
|
|
// the user will get winId as this window's id
|
2016-05-23 12:21:15 +03:00
|
|
|
this.wins.set(winId, win);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a new browser, win, with Marionette.
|
|
|
|
*
|
|
|
|
* If we have not seen the browser content window before, the listener
|
|
|
|
* frame script will be loaded into it. If isNewSession is true, we will
|
|
|
|
* switch focus to the start frame when it registers.
|
|
|
|
*
|
|
|
|
* @param {nsIDOMWindow} win
|
|
|
|
* Window whose browser we need to access.
|
|
|
|
* @param {boolean=false} isNewSession
|
|
|
|
* True if this is the first time we're talking to this browser.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.startBrowser = function (win, isNewSession = false) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.mainFrame = win;
|
|
|
|
this.curFrame = null;
|
|
|
|
this.addBrowser(win);
|
|
|
|
this.curBrowser.isNewSession = isNewSession;
|
|
|
|
this.curBrowser.startSession(isNewSession, 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} isNewSession
|
|
|
|
* True if this is the first time we're talking to this browser.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.whenBrowserStarted = function (win, isNewSession) {
|
2016-07-07 01:23:35 +03:00
|
|
|
let mm = win.window.messageManager;
|
|
|
|
if (mm) {
|
2015-03-20 00:12:58 +03:00
|
|
|
if (!isNewSession) {
|
|
|
|
// Loading the frame script corresponds to a situation we need to
|
|
|
|
// return to the server. If the messageManager is a message broadcaster
|
|
|
|
// with no children, we don't have a hope of coming back from this call,
|
|
|
|
// so send the ack here. Otherwise, make a note of how many child scripts
|
|
|
|
// will be loaded so we known when it's safe to return.
|
2016-08-24 01:24:06 +03:00
|
|
|
// Child managers may not have child scripts yet (e.g. socialapi), only
|
|
|
|
// count child managers that have children, but only count the top level
|
|
|
|
// children as they are the ones that we expect a response from.
|
2015-04-24 15:55:52 +03:00
|
|
|
if (mm.childCount !== 0) {
|
2016-08-24 01:24:06 +03:00
|
|
|
this.curBrowser.frameRegsPending = 0;
|
|
|
|
for (let i = 0; i < mm.childCount; i++) {
|
2016-12-30 15:43:36 +03:00
|
|
|
if (mm.getChildAt(i).childCount !== 0) {
|
2016-08-24 01:24:06 +03:00
|
|
|
this.curBrowser.frameRegsPending += 1;
|
2016-12-30 15:43:36 +03:00
|
|
|
}
|
2016-08-24 01:24:06 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 01:05:30 +03:00
|
|
|
if (!Preferences.get(CONTENT_LISTENER_PREF) || !isNewSession) {
|
2016-07-26 15:35:01 +03:00
|
|
|
// load listener into the remote frame
|
|
|
|
// and any applicable new frames
|
|
|
|
// opened after this call
|
|
|
|
mm.loadFrameScript(FRAME_SCRIPT, true);
|
2016-01-19 01:05:30 +03:00
|
|
|
Preferences.set(CONTENT_LISTENER_PREF, true);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
2016-07-07 01:23:35 +03:00
|
|
|
} else {
|
2015-03-20 00:12:58 +03:00
|
|
|
logger.error(
|
2016-07-07 01:23:35 +03:00
|
|
|
`Could not load listener into content for page ${win.location.href}`);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively get all labeled text.
|
|
|
|
*
|
|
|
|
* @param {nsIDOMElement} el
|
|
|
|
* The parent element.
|
|
|
|
* @param {Array.<string>} lines
|
|
|
|
* Array that holds the text lines.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getVisibleText = function (el, lines) {
|
2015-03-20 00:12:58 +03:00
|
|
|
try {
|
2016-02-03 21:56:02 +03:00
|
|
|
if (atom.isElementDisplayed(el, this.getCurrentWindow())) {
|
2015-03-20 00:12:58 +03:00
|
|
|
if (el.value) {
|
|
|
|
lines.push(el.value);
|
|
|
|
}
|
|
|
|
for (let child in el.childNodes) {
|
|
|
|
this.getVisibleText(el.childNodes[child], lines);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
if (el.nodeName == "#text") {
|
|
|
|
lines.push(el.textContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles registration of new content listener browsers. Depending on
|
|
|
|
* their type they are either accepted or ignored.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.registerBrowser = function (id, be) {
|
2015-04-24 15:55:52 +03:00
|
|
|
let nullPrevious = this.curBrowser.curFrameId === null;
|
2015-03-20 00:12:58 +03:00
|
|
|
let listenerWindow = Services.wm.getOuterWindowWithId(id);
|
|
|
|
|
|
|
|
// go in here if we're already in a remote frame
|
|
|
|
if (this.curBrowser.frameManager.currentRemoteFrame !== null &&
|
|
|
|
(!listenerWindow || this.mm == this.curBrowser.frameManager
|
|
|
|
.currentRemoteFrame.messageManager.get())) {
|
|
|
|
// 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)
|
|
|
|
// if we're already in a remote frame, or it will point to some
|
|
|
|
// random window, which will hopefully cause an href mismatch.
|
|
|
|
// Currently this only happens in B2G for OOP frames registered in
|
|
|
|
// Marionette:switchToFrame, so we'll acknowledge the switchToFrame
|
|
|
|
// message here.
|
|
|
|
//
|
|
|
|
// TODO: Should have a better way of determining that this message
|
|
|
|
// is from a remote frame.
|
|
|
|
this.curBrowser.frameManager.currentRemoteFrame.targetFrameId =
|
|
|
|
this.generateFrameId(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
let reg = {};
|
|
|
|
// this will be sent to tell the content process if it is the main content
|
2015-04-24 15:55:52 +03:00
|
|
|
let mainContent = this.curBrowser.mainContentId === null;
|
2016-12-09 23:55:25 +03:00
|
|
|
// We want to ignore frames that are XUL browsers that aren't in the "main"
|
|
|
|
// tabbrowser, but accept things on Fennec (which doesn't have a
|
|
|
|
// xul:tabbrowser), and accept HTML iframes (because tests depend on it),
|
|
|
|
// as well as XUL frames. Ideally this should be cleaned up and we should
|
|
|
|
// keep track of browsers a different way.
|
|
|
|
if (this.appName != "Firefox" || be.namespaceURI != XUL_NS ||
|
|
|
|
be.nodeName != "browser" || be.getTabBrowser()) {
|
2015-03-20 00:12:58 +03:00
|
|
|
// curBrowser holds all the registered frames in knownFrames
|
|
|
|
let uid = this.generateFrameId(id);
|
|
|
|
reg.id = uid;
|
|
|
|
reg.remotenessChange = this.curBrowser.register(uid, be);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set to true if we updated mainContentId
|
2015-04-24 15:55:52 +03:00
|
|
|
mainContent = mainContent && this.curBrowser.mainContentId !== null;
|
2015-03-23 23:43:18 +03:00
|
|
|
if (mainContent) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.mainContentFrameId = this.curBrowser.curFrameId;
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2016-05-23 12:21:15 +03:00
|
|
|
this.wins.set(reg.id, listenerWindow);
|
2015-04-24 15:55:52 +03:00
|
|
|
if (nullPrevious && (this.curBrowser.curFrameId !== null)) {
|
2016-12-31 15:27:13 +03:00
|
|
|
this.sendAsync(
|
|
|
|
"newSession",
|
2016-12-31 15:32:14 +03:00
|
|
|
this.capabilities.toJSON(),
|
2016-12-31 15:27:13 +03:00
|
|
|
this.newSessionCommandId);
|
2015-03-23 23:43:18 +03:00
|
|
|
if (this.curBrowser.isNewSession) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.newSessionCommandId = null;
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
|
2016-12-31 15:32:14 +03:00
|
|
|
return [reg, mainContent, this.capabilities.toJSON()];
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-01-30 17:35:16 +03:00
|
|
|
GeckoDriver.prototype.registerPromise = function () {
|
2015-03-20 00:12:58 +03:00
|
|
|
const li = "Marionette:register";
|
|
|
|
|
2016-12-19 22:08:46 +03:00
|
|
|
return new Promise(resolve => {
|
|
|
|
let cb = msg => {
|
2015-03-20 00:12:58 +03:00
|
|
|
let wid = msg.json.value;
|
|
|
|
let be = msg.target;
|
|
|
|
let rv = this.registerBrowser(wid, be);
|
|
|
|
|
2015-03-23 23:43:18 +03:00
|
|
|
if (this.curBrowser.frameRegsPending > 0) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.curBrowser.frameRegsPending--;
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2015-04-24 15:55:52 +03:00
|
|
|
if (this.curBrowser.frameRegsPending === 0) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.mm.removeMessageListener(li, cb);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is a sync message and listeners expect the ID back
|
|
|
|
return rv;
|
2015-06-24 10:10:10 +03:00
|
|
|
};
|
|
|
|
this.mm.addMessageListener(li, cb);
|
2015-03-20 00:12:58 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-30 17:35:16 +03:00
|
|
|
GeckoDriver.prototype.listeningPromise = function () {
|
2015-03-20 00:12:58 +03:00
|
|
|
const li = "Marionette:listenersAttached";
|
2016-12-19 22:08:46 +03:00
|
|
|
return new Promise(resolve => {
|
2015-06-24 10:10:10 +03:00
|
|
|
let cb = () => {
|
|
|
|
this.mm.removeMessageListener(li, cb);
|
2015-03-20 00:12:58 +03:00
|
|
|
resolve();
|
2015-06-24 10:10:10 +03:00
|
|
|
};
|
|
|
|
this.mm.addMessageListener(li, cb);
|
2015-03-20 00:12:58 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Create a new session. */
|
2017-01-30 17:35:16 +03:00
|
|
|
GeckoDriver.prototype.newSession = function* (cmd, resp) {
|
2016-05-25 17:04:40 +03:00
|
|
|
if (this.sessionId) {
|
2016-12-30 15:43:36 +03:00
|
|
|
throw new SessionNotCreatedError("Maximum number of active sessions");
|
2016-05-25 17:04:40 +03:00
|
|
|
}
|
2016-12-30 15:43:36 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
this.sessionId = cmd.parameters.sessionId ||
|
|
|
|
cmd.parameters.session_id ||
|
2016-02-23 18:01:12 +03:00
|
|
|
element.generateUUID();
|
2015-03-20 00:12:58 +03:00
|
|
|
this.newSessionCommandId = cmd.id;
|
2016-11-06 21:03:31 +03:00
|
|
|
|
2016-12-31 15:27:13 +03:00
|
|
|
try {
|
2016-12-31 15:32:14 +03:00
|
|
|
this.capabilities = session.Capabilities.fromJSON(
|
2016-12-31 15:27:13 +03:00
|
|
|
cmd.parameters.capabilities, {merge: true});
|
|
|
|
logger.config("Matched capabilities: " +
|
2016-12-31 15:32:14 +03:00
|
|
|
JSON.stringify(this.capabilities));
|
2016-12-31 15:27:13 +03:00
|
|
|
} catch (e) {
|
|
|
|
throw new SessionNotCreatedError(e);
|
|
|
|
}
|
2016-11-06 21:03:31 +03:00
|
|
|
|
|
|
|
if (!this.secureTLS) {
|
|
|
|
logger.warn("TLS certificate errors will be ignored for this session");
|
|
|
|
let acceptAllCerts = new cert.InsecureSweepingOverride();
|
|
|
|
cert.installOverride(acceptAllCerts);
|
|
|
|
}
|
|
|
|
|
2016-12-31 15:27:13 +03:00
|
|
|
if (this.proxy.init()) {
|
|
|
|
logger.info("Proxy settings initialised: " + JSON.stringify(this.proxy));
|
|
|
|
}
|
|
|
|
|
2016-11-07 20:15:08 +03:00
|
|
|
// If we are testing accessibility with marionette, start a11y service in
|
|
|
|
// chrome first. This will ensure that we do not have any content-only
|
|
|
|
// services hanging around.
|
2016-12-19 22:28:17 +03:00
|
|
|
if (this.a11yChecks && accessibility.service) {
|
2016-11-07 20:15:08 +03:00
|
|
|
logger.info("Preemptively starting accessibility service in Chrome");
|
|
|
|
}
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let registerBrowsers = this.registerPromise();
|
|
|
|
let browserListening = this.listeningPromise();
|
|
|
|
|
2017-03-01 14:48:55 +03:00
|
|
|
let waitForWindow = function() {
|
2017-03-01 14:48:59 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2015-03-20 00:12:58 +03:00
|
|
|
if (!win) {
|
2017-03-01 14:48:55 +03:00
|
|
|
// if the window isn't even created, just poll wait for it
|
2015-03-20 00:12:58 +03:00
|
|
|
let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
checkTimer.initWithCallback(waitForWindow.bind(this), 100,
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
} else if (win.document.readyState != "complete") {
|
|
|
|
// otherwise, wait for it to be fully loaded before proceeding
|
|
|
|
let listener = ev => {
|
|
|
|
// ensure that we proceed, on the top level document load event
|
|
|
|
// (not an iframe one...)
|
2015-03-23 23:43:18 +03:00
|
|
|
if (ev.target != win.document) {
|
2015-03-20 00:12:58 +03:00
|
|
|
return;
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
win.removeEventListener("load", listener);
|
|
|
|
waitForWindow.call(this);
|
|
|
|
};
|
|
|
|
win.addEventListener("load", listener, true);
|
|
|
|
} else {
|
2016-01-19 01:05:30 +03:00
|
|
|
let clickToStart = Preferences.get(CLICK_TO_START_PREF);
|
2017-03-01 14:48:59 +03:00
|
|
|
if (clickToStart && (this.appName != "B2G")) {
|
|
|
|
let pService = Cc["@mozilla.org/embedcomp/prompt-service;1"]
|
|
|
|
.getService(Ci.nsIPromptService);
|
|
|
|
pService.alert(win, "", "Click to start execution of marionette tests");
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
this.startBrowser(win, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-07 21:38:51 +03:00
|
|
|
if (!Preferences.get(CONTENT_LISTENER_PREF)) {
|
|
|
|
waitForWindow.call(this);
|
|
|
|
} else if (this.appName != "Firefox" && this.curBrowser === null) {
|
|
|
|
// if there is a content listener, then we just wake it up
|
|
|
|
this.addBrowser(this.getCurrentWindow());
|
|
|
|
this.curBrowser.startSession(this.whenBrowserStarted.bind(this));
|
|
|
|
this.mm.broadcastAsyncMessage("Marionette:restart", {});
|
2015-03-20 00:12:58 +03:00
|
|
|
} else {
|
2017-03-07 21:38:51 +03:00
|
|
|
throw new WebDriverError("Session already running");
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
2017-03-07 21:38:51 +03:00
|
|
|
this.switchToGlobalMessageManager();
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
yield registerBrowsers;
|
|
|
|
yield browserListening;
|
|
|
|
|
2017-01-26 18:42:35 +03:00
|
|
|
if (this.curBrowser.tab) {
|
|
|
|
browser.getBrowserForTab(this.curBrowser.tab).focus();
|
|
|
|
}
|
2017-01-04 22:38:34 +03:00
|
|
|
|
2016-12-19 22:08:46 +03:00
|
|
|
return {
|
|
|
|
sessionId: this.sessionId,
|
2016-12-31 15:32:14 +03:00
|
|
|
capabilities: this.capabilities,
|
2016-12-19 22:08:46 +03:00
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the current session's capabilities to the client.
|
|
|
|
*
|
|
|
|
* Capabilities informs the client of which WebDriver features are
|
|
|
|
* supported by Firefox and Marionette. They are immutable for the
|
|
|
|
* length of the session.
|
|
|
|
*
|
|
|
|
* The return value is an immutable map of string keys
|
|
|
|
* ("capabilities") to values, which may be of types boolean,
|
|
|
|
* numerical or string.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getSessionCapabilities = function (cmd, resp) {
|
2016-12-31 15:32:14 +03:00
|
|
|
resp.body.capabilities = this.capabilities;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log message. Accepts user defined log-level.
|
|
|
|
*
|
|
|
|
* @param {string} value
|
|
|
|
* Log message.
|
|
|
|
* @param {string} level
|
|
|
|
* Arbitrary log level.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.log = function (cmd, resp) {
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
// if level is null, we want to use ContentLogger#send's default
|
|
|
|
this.marionetteLog.log(
|
|
|
|
cmd.parameters.value,
|
|
|
|
cmd.parameters.level || undefined);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Return all logged messages. */
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getLogs = function (cmd, resp) {
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
resp.body = this.marionetteLog.get();
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the context of the subsequent commands to be either "chrome" or
|
|
|
|
* "content".
|
|
|
|
*
|
|
|
|
* @param {string} value
|
|
|
|
* Name of the context to be switched to. Must be one of "chrome" or
|
|
|
|
* "content".
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.setContext = function (cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let val = cmd.parameters.value;
|
|
|
|
let ctx = Context.fromString(val);
|
2015-03-23 23:43:18 +03:00
|
|
|
if (ctx === null) {
|
2015-03-20 00:12:58 +03:00
|
|
|
throw new WebDriverError(`Invalid context: ${val}`);
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
this.context = ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Gets the context of the server, either "chrome" or "content". */
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getContext = function (cmd, resp) {
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = this.context.toString();
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* Executes a JavaScript function in the context of the current browsing
|
|
|
|
* context, if in content space, or in chrome space otherwise, and returns
|
|
|
|
* the return value of the function.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* It is important to note that if the {@code sandboxName} parameter
|
|
|
|
* is left undefined, the script will be evaluated in a mutable sandbox,
|
|
|
|
* causing any change it makes on the global state of the document to have
|
|
|
|
* lasting side-effects.
|
|
|
|
*
|
|
|
|
* @param {string} script
|
|
|
|
* Script to evaluate as a function body.
|
|
|
|
* @param {Array.<(string|boolean|number|object|WebElement)>} args
|
|
|
|
* Arguments exposed to the script in {@code arguments}. The array
|
|
|
|
* items must be serialisable to the WebDriver protocol.
|
|
|
|
* @param {number} scriptTimeout
|
|
|
|
* Duration in milliseconds of when to interrupt and abort the
|
|
|
|
* script evaluation.
|
|
|
|
* @param {string=} sandbox
|
|
|
|
* Name of the sandbox to evaluate the script in. The sandbox is
|
|
|
|
* cached for later re-use on the same Window object if
|
|
|
|
* {@code newSandbox} is false. If he parameter is undefined,
|
|
|
|
* the script is evaluated in a mutable sandbox. If the parameter
|
|
|
|
* is "system", it will be evaluted in a sandbox with elevated system
|
|
|
|
* privileges, equivalent to chrome space.
|
|
|
|
* @param {boolean=} newSandbox
|
|
|
|
* Forces the script to be evaluated in a fresh sandbox. Note that if
|
|
|
|
* it is undefined, the script will normally be evaluted in a fresh
|
|
|
|
* sandbox.
|
|
|
|
* @param {string=} filename
|
|
|
|
* Filename of the client's program where this script is evaluated.
|
|
|
|
* @param {number=} line
|
|
|
|
* Line in the client's program where this script is evaluated.
|
|
|
|
* @param {boolean=} debug_script
|
|
|
|
* Attach an {@code onerror} event handler on the Window object.
|
|
|
|
* It does not differentiate content errors from chrome errors.
|
|
|
|
* @param {boolean=} directInject
|
|
|
|
* Evaluate the script without wrapping it in a function.
|
|
|
|
*
|
|
|
|
* @return {(string|boolean|number|object|WebElement)}
|
|
|
|
* Return value from the script, or null which signifies either the
|
|
|
|
* JavaScript notion of null or undefined.
|
|
|
|
*
|
|
|
|
* @throws ScriptTimeoutError
|
|
|
|
* If the script was interrupted due to reaching the {@code
|
|
|
|
* scriptTimeout} or default timeout.
|
|
|
|
* @throws JavaScriptError
|
|
|
|
* If an Error was thrown whilst evaluating the script.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.executeScript = function*(cmd, resp) {
|
|
|
|
let {script, args, scriptTimeout} = cmd.parameters;
|
2016-12-31 15:27:13 +03:00
|
|
|
scriptTimeout = scriptTimeout || this.timeouts.script;
|
2015-03-20 00:12:58 +03:00
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
let opts = {
|
|
|
|
sandboxName: cmd.parameters.sandbox,
|
|
|
|
newSandbox: !!(typeof cmd.parameters.newSandbox == "undefined") ||
|
|
|
|
cmd.parameters.newSandbox,
|
|
|
|
filename: cmd.parameters.filename,
|
|
|
|
line: cmd.parameters.line,
|
|
|
|
debug: cmd.parameters.debug_script,
|
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
resp.body.value = yield this.execute_(script, args, scriptTimeout, opts);
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
--HG--
extra : rebase_source : 38cc7b1e374fd42afb213133fd1a5e11bf8bdd95
2016-02-26 17:36:39 +03:00
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2016-05-07 01:12:14 +03:00
|
|
|
/**
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* Executes a JavaScript function in the context of the current browsing
|
|
|
|
* context, if in content space, or in chrome space otherwise, and returns
|
|
|
|
* the object passed to the callback.
|
|
|
|
*
|
|
|
|
* The callback is always the last argument to the {@code arguments}
|
|
|
|
* list passed to the function scope of the script. It can be retrieved
|
|
|
|
* as such:
|
|
|
|
*
|
|
|
|
* let callback = arguments[arguments.length - 1];
|
|
|
|
* callback("foo");
|
|
|
|
* // "foo" is returned
|
|
|
|
*
|
|
|
|
* It is important to note that if the {@code sandboxName} parameter
|
|
|
|
* is left undefined, the script will be evaluated in a mutable sandbox,
|
|
|
|
* causing any change it makes on the global state of the document to have
|
|
|
|
* lasting side-effects.
|
2016-05-07 01:12:14 +03:00
|
|
|
*
|
|
|
|
* @param {string} script
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* Script to evaluate as a function body.
|
|
|
|
* @param {Array.<(string|boolean|number|object|WebElement)>} args
|
|
|
|
* Arguments exposed to the script in {@code arguments}. The array
|
|
|
|
* items must be serialisable to the WebDriver protocol.
|
|
|
|
* @param {number} scriptTimeout
|
|
|
|
* Duration in milliseconds of when to interrupt and abort the
|
|
|
|
* script evaluation.
|
|
|
|
* @param {string=} sandbox
|
|
|
|
* Name of the sandbox to evaluate the script in. The sandbox is
|
|
|
|
* cached for later re-use on the same Window object if
|
2017-01-26 18:42:35 +03:00
|
|
|
* {@code newSandbox} is false. If the parameter is undefined,
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* the script is evaluated in a mutable sandbox. If the parameter
|
|
|
|
* is "system", it will be evaluted in a sandbox with elevated system
|
|
|
|
* privileges, equivalent to chrome space.
|
|
|
|
* @param {boolean=} newSandbox
|
|
|
|
* Forces the script to be evaluated in a fresh sandbox. Note that if
|
|
|
|
* it is undefined, the script will normally be evaluted in a fresh
|
|
|
|
* sandbox.
|
|
|
|
* @param {string=} filename
|
|
|
|
* Filename of the client's program where this script is evaluated.
|
|
|
|
* @param {number=} line
|
|
|
|
* Line in the client's program where this script is evaluated.
|
|
|
|
* @param {boolean=} debug_script
|
|
|
|
* Attach an {@code onerror} event handler on the Window object.
|
|
|
|
* It does not differentiate content errors from chrome errors.
|
|
|
|
* @param {boolean=} directInject
|
|
|
|
* Evaluate the script without wrapping it in a function.
|
|
|
|
*
|
|
|
|
* @return {(string|boolean|number|object|WebElement)}
|
|
|
|
* Return value from the script, or null which signifies either the
|
|
|
|
* JavaScript notion of null or undefined.
|
|
|
|
*
|
|
|
|
* @throws ScriptTimeoutError
|
|
|
|
* If the script was interrupted due to reaching the {@code
|
|
|
|
* scriptTimeout} or default timeout.
|
|
|
|
* @throws JavaScriptError
|
|
|
|
* If an Error was thrown whilst evaluating the script.
|
|
|
|
*/
|
2016-12-15 10:54:46 +03:00
|
|
|
GeckoDriver.prototype.executeAsyncScript = function* (cmd, resp) {
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
let {script, args, scriptTimeout} = cmd.parameters;
|
2016-12-31 15:27:13 +03:00
|
|
|
scriptTimeout = scriptTimeout || this.timeouts.script;
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
--HG--
extra : rebase_source : 38cc7b1e374fd42afb213133fd1a5e11bf8bdd95
2016-02-26 17:36:39 +03:00
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
let opts = {
|
|
|
|
sandboxName: cmd.parameters.sandbox,
|
|
|
|
newSandbox: !!(typeof cmd.parameters.newSandbox == "undefined") ||
|
|
|
|
cmd.parameters.newSandbox,
|
|
|
|
filename: cmd.parameters.filename,
|
|
|
|
line: cmd.parameters.line,
|
|
|
|
debug: cmd.parameters.debug_script,
|
|
|
|
async: true,
|
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
resp.body.value = yield this.execute_(script, args, scriptTimeout, opts);
|
|
|
|
};
|
2016-05-07 01:12:14 +03:00
|
|
|
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.execute_ = function (script, args, timeout, opts = {}) {
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CONTENT:
|
|
|
|
// evaluate in content with lasting side-effects
|
|
|
|
if (!opts.sandboxName) {
|
|
|
|
return this.listener.execute(script, args, timeout, opts);
|
|
|
|
|
|
|
|
// evaluate in content with sandbox
|
|
|
|
} else {
|
|
|
|
return this.listener.executeInSandbox(script, args, timeout, opts);
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
--HG--
extra : rebase_source : 38cc7b1e374fd42afb213133fd1a5e11bf8bdd95
2016-02-26 17:36:39 +03:00
|
|
|
}
|
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
case Context.CHROME:
|
|
|
|
let sb = this.sandboxes.get(opts.sandboxName, opts.newSandbox);
|
|
|
|
if (opts.sandboxName) {
|
|
|
|
sb = sandbox.augment(sb, new logging.Adapter(this.marionetteLog));
|
|
|
|
sb = sandbox.augment(sb, {global: sb});
|
|
|
|
}
|
|
|
|
|
|
|
|
opts.timeout = timeout;
|
|
|
|
script = this.importedScripts.for(Context.CHROME).concat(script);
|
2016-05-20 18:49:19 +03:00
|
|
|
let wargs = element.fromJson(args, this.curBrowser.seenEls, sb.window);
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
let evaluatePromise = evaluate.sandbox(sb, script, wargs, opts);
|
2016-05-20 18:49:19 +03:00
|
|
|
return evaluatePromise.then(res => element.toJson(res, this.curBrowser.seenEls));
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* Execute pure JavaScript. Used to execute simpletest harness tests,
|
|
|
|
* which are like mochitests only injected using Marionette.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* Scripts are expected to call the {@code finish} global when done.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-12-15 10:54:46 +03:00
|
|
|
GeckoDriver.prototype.executeJSScript = function* (cmd, resp) {
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
let {script, args, scriptTimeout} = cmd.parameters;
|
2016-12-31 15:27:13 +03:00
|
|
|
scriptTimeout = scriptTimeout || this.timeouts.script;
|
2015-03-20 00:12:58 +03:00
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
let opts = {
|
|
|
|
filename: cmd.parameters.filename,
|
|
|
|
line: cmd.parameters.line,
|
|
|
|
async: cmd.parameters.async,
|
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let wargs = element.fromJson(args, this.curBrowser.seenEls, win);
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
let harness = new simpletest.Harness(
|
|
|
|
win,
|
|
|
|
Context.CHROME,
|
|
|
|
this.marionetteLog,
|
|
|
|
scriptTimeout,
|
|
|
|
function() {},
|
|
|
|
this.testName);
|
|
|
|
|
|
|
|
let sb = sandbox.createSimpleTest(win, harness);
|
|
|
|
// TODO(ato): Not sure this is needed:
|
|
|
|
sb = sandbox.augment(sb, new logging.Adapter(this.marionetteLog));
|
|
|
|
|
|
|
|
let res = yield evaluate.sandbox(sb, script, wargs, opts);
|
2016-05-20 18:49:19 +03:00
|
|
|
resp.body.value = element.toJson(res, this.curBrowser.seenEls);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
resp.body.value = yield this.listener.executeSimpleTest(script, args, scriptTimeout, opts);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-05-04 13:25:03 +03:00
|
|
|
* Navigate to given URL.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2015-05-04 13:25:03 +03:00
|
|
|
* Navigates the current browsing context to the given URL and waits for
|
|
|
|
* the document to load or the session's page timeout duration to elapse
|
|
|
|
* before returning.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2015-05-04 13:25:03 +03:00
|
|
|
* The command will return with a failure if there is an error loading
|
|
|
|
* the document or the URL is blocked. This can occur if it fails to
|
|
|
|
* reach host, the URL is malformed, or if there is a certificate issue
|
|
|
|
* to name some examples.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2015-05-04 13:25:03 +03:00
|
|
|
* The document is considered successfully loaded when the
|
|
|
|
* DOMContentLoaded event on the frame element associated with the
|
|
|
|
* current window triggers and document.readyState is "complete".
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2015-05-04 13:25:03 +03:00
|
|
|
* In chrome context it will change the current window's location to
|
|
|
|
* the supplied URL and wait until document.readyState equals "complete"
|
|
|
|
* or the page timeout duration has elapsed.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
|
|
|
* @param {string} url
|
|
|
|
* URL to navigate to.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.get = function*(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context);
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let url = cmd.parameters.url;
|
|
|
|
|
2016-12-31 15:27:13 +03:00
|
|
|
let get = this.listener.get({url: url, pageTimeout: this.timeouts.pageLoad});
|
2016-12-29 16:04:16 +03:00
|
|
|
|
|
|
|
// If a remoteness update interrupts our page load, this will never return
|
|
|
|
// We need to re-issue this request to correctly poll for readyState and
|
|
|
|
// send errors.
|
|
|
|
this.curBrowser.pendingCommands.push(() => {
|
2017-03-09 13:21:30 +03:00
|
|
|
let parameters = {
|
|
|
|
// TODO(ato): Bug 1242595
|
|
|
|
command_id: this.listener.activeMessageId,
|
|
|
|
pageTimeout: this.timeouts.pageLoad,
|
|
|
|
startTime: new Date().getTime(),
|
|
|
|
};
|
2016-12-29 16:04:16 +03:00
|
|
|
this.mm.broadcastAsyncMessage(
|
|
|
|
"Marionette:pollForReadyState" + this.curBrowser.curFrameId,
|
2017-03-09 13:21:30 +03:00
|
|
|
parameters);
|
2016-12-29 16:04:16 +03:00
|
|
|
});
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2016-12-29 16:04:16 +03:00
|
|
|
yield get;
|
2017-01-26 18:42:35 +03:00
|
|
|
browser.getBrowserForTab(this.curBrowser.tab).focus();
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a string representing the current URL.
|
|
|
|
*
|
|
|
|
* On Desktop this returns a string representation of the URL of the
|
|
|
|
* current top level browsing context. This is equivalent to
|
|
|
|
* document.location.href.
|
|
|
|
*
|
|
|
|
* When in the context of the chrome, this returns the canonical URL
|
|
|
|
* of the current resource.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getCurrentUrl = function (cmd) {
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
return this.getCurrentWindow().location.href;
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
case Context.CONTENT:
|
2017-03-01 14:49:21 +03:00
|
|
|
let isB2G = this.appName == "B2G";
|
|
|
|
return this.listener.getCurrentUrl(isB2G);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Gets the current title of the window. */
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getTitle = function* (cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = win.document.documentElement.getAttribute("title");
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = yield this.listener.getTitle();
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Gets the current type of the window. */
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getWindowType = function (cmd, resp) {
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = win.document.documentElement.getAttribute("windowtype");
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Gets the page source of the content document. */
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getPageSource = function* (cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2015-03-20 00:12:58 +03:00
|
|
|
let s = new win.XMLSerializer();
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = s.serializeToString(win.document);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = yield this.listener.getPageSource();
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Go back in history. */
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.goBack = function*(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context);
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
yield this.listener.goBack();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Go forward in history. */
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.goForward = function*(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context);
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
yield this.listener.goForward();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Refresh the page. */
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.refresh = function*(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context);
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
yield this.listener.refresh();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forces an update for the given browser's id.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.updateIdForBrowser = function (browser, newId) {
|
|
|
|
this._browserIds.set(browser.permanentKey, newId);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a listener id for the given xul browser element. In case
|
|
|
|
* the browser is not known, an attempt is made to retrieve the id from
|
|
|
|
* a CPOW, and null is returned if this fails.
|
|
|
|
*/
|
2017-01-10 18:36:49 +03:00
|
|
|
GeckoDriver.prototype.getIdForBrowser = function (browser) {
|
2015-03-20 00:12:58 +03:00
|
|
|
if (browser === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
let permKey = browser.permanentKey;
|
|
|
|
if (this._browserIds.has(permKey)) {
|
|
|
|
return this._browserIds.get(permKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
let winId = browser.outerWindowID;
|
|
|
|
if (winId) {
|
2017-01-10 18:36:49 +03:00
|
|
|
winId = winId.toString();
|
2015-03-20 00:12:58 +03:00
|
|
|
this._browserIds.set(permKey, winId);
|
|
|
|
return winId;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2017-01-10 18:36:49 +03:00
|
|
|
* Get the current window's handle. On desktop this typically corresponds
|
|
|
|
* to the currently selected tab.
|
|
|
|
*
|
|
|
|
* Return an opaque server-assigned identifier to this window that
|
|
|
|
* uniquely identifies it within this Marionette instance. This can
|
|
|
|
* be used to switch to this window at a later point.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Unique window handle.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.getWindowHandle = function (cmd, resp) {
|
|
|
|
// curFrameId always holds the current tab.
|
|
|
|
if (this.curBrowser.curFrameId) {
|
|
|
|
resp.body.value = this.curBrowser.curFrameId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i in this.browsers) {
|
|
|
|
if (this.curBrowser == this.browsers[i]) {
|
|
|
|
resp.body.value = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of top-level browsing contexts. On desktop this typically
|
|
|
|
* corresponds to the set of open tabs for browser windows, or the window itself
|
|
|
|
* for non-browser chrome windows.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
|
|
|
* Each window handle is assigned by the server and is guaranteed unique,
|
|
|
|
* however the return array does not have a specified ordering.
|
|
|
|
*
|
|
|
|
* @return {Array.<string>}
|
|
|
|
* Unique window handles.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getWindowHandles = function (cmd, resp) {
|
2017-01-10 18:36:49 +03:00
|
|
|
return this.windowHandles;
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current window's handle. This corresponds to a window that
|
|
|
|
* may itself contain tabs.
|
|
|
|
*
|
|
|
|
* Return an opaque server-assigned identifier to this window that
|
|
|
|
* uniquely identifies it within this Marionette instance. This can
|
|
|
|
* be used to switch to this window at a later point.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Unique window handle.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getChromeWindowHandle = function (cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
for (let i in this.browsers) {
|
|
|
|
if (this.curBrowser == this.browsers[i]) {
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = i;
|
2015-03-20 00:12:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns identifiers for each open chrome window for tests interested in
|
|
|
|
* managing a set of chrome windows and tabs separately.
|
|
|
|
*
|
|
|
|
* @return {Array.<string>}
|
|
|
|
* Unique window handles.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getChromeWindowHandles = function (cmd, resp) {
|
2017-01-10 18:36:49 +03:00
|
|
|
return this.chromeWindowHandles;
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current window position.
|
|
|
|
*
|
|
|
|
* @return {Object.<string, number>}
|
2016-10-06 15:11:31 +03:00
|
|
|
* Object with |x| and |y| coordinates.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getWindowPosition = function (cmd, resp) {
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-11-22 01:33:03 +03:00
|
|
|
return {
|
|
|
|
x: win.screenX,
|
|
|
|
y: win.screenY,
|
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the window position of the browser on the OS Window Manager
|
|
|
|
*
|
|
|
|
* @param {number} x
|
|
|
|
* X coordinate of the top/left of the window that it will be
|
|
|
|
* moved to.
|
|
|
|
* @param {number} y
|
|
|
|
* Y coordinate of the top/left of the window that it will be
|
|
|
|
* moved to.
|
2016-10-06 15:11:31 +03:00
|
|
|
*
|
|
|
|
* @return {Object.<string, number>}
|
|
|
|
* Object with |x| and |y| coordinates.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-11-22 01:43:35 +03:00
|
|
|
GeckoDriver.prototype.setWindowPosition = function* (cmd, resp) {
|
2017-03-01 14:49:21 +03:00
|
|
|
assert.firefox()
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2016-10-06 15:10:56 +03:00
|
|
|
let {x, y} = cmd.parameters;
|
2016-11-01 01:12:30 +03:00
|
|
|
assert.positiveInteger(x);
|
|
|
|
assert.positiveInteger(y);
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-11-22 01:43:35 +03:00
|
|
|
let orig = {screenX: win.screenX, screenY: win.screenY};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
win.moveTo(x, y);
|
2017-02-02 17:58:36 +03:00
|
|
|
yield wait.until((resolve, reject) => {
|
|
|
|
if ((x == win.screenX && y == win.screenY) ||
|
|
|
|
(win.screenX != orig.screenX || win.screenY != orig.screenY)) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
});
|
2016-10-06 15:11:31 +03:00
|
|
|
|
|
|
|
return this.curBrowser.position;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch current top-level browsing context by name or server-assigned ID.
|
|
|
|
* Searches for windows by name, then ID. Content windows take precedence.
|
|
|
|
*
|
|
|
|
* @param {string} name
|
|
|
|
* Target name or ID of the window to switch to.
|
2017-01-30 17:35:16 +03:00
|
|
|
* @param {boolean=} focus
|
|
|
|
* A boolean value which determines whether to focus
|
|
|
|
* the window. Defaults to true.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.switchToWindow = function* (cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let switchTo = cmd.parameters.name;
|
2017-01-30 17:35:16 +03:00
|
|
|
let focus = (cmd.parameters.focus !== undefined) ? cmd.parameters.focus : true;
|
2015-03-20 00:12:58 +03:00
|
|
|
let found;
|
|
|
|
|
2017-02-05 17:55:10 +03:00
|
|
|
let byNameOrId = function (name, windowId) {
|
|
|
|
return switchTo === name || switchTo === windowId;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2016-03-23 17:48:11 +03:00
|
|
|
let winEn = Services.wm.getEnumerator(null);
|
2015-03-20 00:12:58 +03:00
|
|
|
while (winEn.hasMoreElements()) {
|
|
|
|
let win = winEn.getNext();
|
|
|
|
let outerId = getOuterWindowId(win);
|
2017-02-05 17:55:10 +03:00
|
|
|
let tabBrowser = browser.getTabBrowser(win);
|
2017-01-26 18:42:35 +03:00
|
|
|
|
2017-02-05 17:55:10 +03:00
|
|
|
if (byNameOrId(win.name, outerId)) {
|
|
|
|
// In case the wanted window is a chrome window, we are done.
|
|
|
|
found = {win: win, outerId: outerId, hasTabBrowser: !!tabBrowser};
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else if (tabBrowser) {
|
|
|
|
// Otherwise check if the chrome window has a tab browser, and that it
|
|
|
|
// contains a tab with the wanted window handle.
|
|
|
|
for (let i = 0; i < tabBrowser.tabs.length; ++i) {
|
|
|
|
let contentBrowser = browser.getBrowserForTab(tabBrowser.tabs[i]);
|
2017-01-26 18:42:35 +03:00
|
|
|
let contentWindowId = this.getIdForBrowser(contentBrowser);
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-02-05 17:55:10 +03:00
|
|
|
if (byNameOrId(win.name, contentWindowId)) {
|
2015-03-20 00:12:58 +03:00
|
|
|
found = {
|
|
|
|
win: win,
|
|
|
|
outerId: outerId,
|
2017-02-05 17:55:10 +03:00
|
|
|
hasTabBrowser: true,
|
2015-03-20 00:12:58 +03:00
|
|
|
tabIndex: i,
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
if (!(found.outerId in this.browsers)) {
|
2017-02-05 17:55:10 +03:00
|
|
|
// Initialise Marionette if the current chrome window has not been seen
|
|
|
|
// before. Also register the initial tab, if one exists.
|
2015-03-20 00:12:58 +03:00
|
|
|
let registerBrowsers, browserListening;
|
2017-02-05 17:55:10 +03:00
|
|
|
|
|
|
|
if (found.hasTabBrowser) {
|
2015-03-20 00:12:58 +03:00
|
|
|
registerBrowsers = this.registerPromise();
|
|
|
|
browserListening = this.listeningPromise();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.startBrowser(found.win, false /* isNewSession */);
|
|
|
|
|
|
|
|
if (registerBrowsers && browserListening) {
|
|
|
|
yield registerBrowsers;
|
|
|
|
yield browserListening;
|
|
|
|
}
|
2017-02-05 17:55:10 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
} else {
|
2017-02-05 17:55:10 +03:00
|
|
|
// Otherwise switch to the known chrome window, and activate the tab
|
|
|
|
// if it's a content browser.
|
2015-03-20 00:12:58 +03:00
|
|
|
this.curBrowser = this.browsers[found.outerId];
|
|
|
|
|
2015-06-01 23:26:15 +03:00
|
|
|
if ("tabIndex" in found) {
|
2017-01-30 17:35:16 +03:00
|
|
|
this.curBrowser.switchToTab(found.tabIndex, found.win, focus);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new NoSuchWindowError(`Unable to locate window: ${switchTo}`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getActiveFrame = function (cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
// no frame means top-level
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = null;
|
2015-03-23 23:43:18 +03:00
|
|
|
if (this.curFrame) {
|
2016-07-13 00:56:34 +03:00
|
|
|
let elRef = this.curBrowser.seenEls
|
2016-05-20 15:28:27 +03:00
|
|
|
.add(this.curFrame.frameElement);
|
2016-07-13 00:56:34 +03:00
|
|
|
let el = element.makeWebElement(elRef);
|
|
|
|
resp.body.value = el;
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
2016-07-13 00:56:34 +03:00
|
|
|
resp.body.value = null;
|
|
|
|
if (this.currentFrameElement !== null) {
|
|
|
|
let el = element.makeWebElement(this.currentFrameElement);
|
|
|
|
resp.body.value = el;
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.switchToParentFrame = function*(cmd, resp) {
|
2015-10-19 23:39:48 +03:00
|
|
|
let res = yield this.listener.switchToParentFrame();
|
|
|
|
};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
/**
|
|
|
|
* Switch to a given frame within the current window.
|
|
|
|
*
|
|
|
|
* @param {Object} element
|
|
|
|
* A web element reference to the element to switch to.
|
|
|
|
* @param {(string|number)} id
|
|
|
|
* If element is not defined, then this holds either the id, name,
|
|
|
|
* or index of the frame to switch to.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.switchToFrame = function* (cmd, resp) {
|
2015-11-09 20:48:31 +03:00
|
|
|
let {id, element, focus} = cmd.parameters;
|
|
|
|
|
2016-11-06 21:01:23 +03:00
|
|
|
const otherErrorsExpr = /about:.+(error)|(blocked)\?/;
|
|
|
|
const checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let curWindow = this.getCurrentWindow();
|
|
|
|
|
|
|
|
let checkLoad = function() {
|
2016-11-06 21:01:23 +03:00
|
|
|
let win = this.getCurrentWindow();
|
|
|
|
if (win.document.readyState == "complete") {
|
2015-03-20 00:12:58 +03:00
|
|
|
return;
|
2016-11-06 21:01:23 +03:00
|
|
|
} else if (win.document.readyState == "interactive") {
|
|
|
|
let baseURI = win.document.baseURI;
|
|
|
|
if (baseURI.startsWith("about:certerror")) {
|
|
|
|
throw new InsecureCertificateError();
|
|
|
|
} else if (otherErrorsExpr.exec(win.document.baseURI)) {
|
|
|
|
throw new UnknownError("Error loading page");
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.context == Context.CHROME) {
|
|
|
|
let foundFrame = null;
|
2015-04-24 15:55:52 +03:00
|
|
|
|
2015-11-09 20:48:31 +03:00
|
|
|
// just focus
|
|
|
|
if (typeof id == "undefined" && typeof element == "undefined") {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.curFrame = null;
|
2015-11-09 20:48:31 +03:00
|
|
|
if (focus) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.mainFrame.focus();
|
|
|
|
}
|
|
|
|
checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-24 15:55:52 +03:00
|
|
|
|
2015-11-09 20:48:31 +03:00
|
|
|
// by element
|
2016-05-20 17:07:21 +03:00
|
|
|
if (this.curBrowser.seenEls.has(element)) {
|
|
|
|
// HTMLIFrameElement
|
2016-05-20 18:49:19 +03:00
|
|
|
let wantedFrame = this.curBrowser.seenEls.get(element, {frame: curWindow});
|
2016-05-20 17:07:21 +03:00
|
|
|
// Deal with an embedded xul:browser case
|
|
|
|
if (wantedFrame.tagName == "xul:browser" || wantedFrame.tagName == "browser") {
|
|
|
|
curWindow = wantedFrame.contentWindow;
|
|
|
|
this.curFrame = curWindow;
|
|
|
|
if (focus) {
|
|
|
|
this.curFrame.focus();
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
2016-05-20 17:07:21 +03:00
|
|
|
checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
return;
|
|
|
|
}
|
2016-01-09 00:55:55 +03:00
|
|
|
|
2016-05-20 17:07:21 +03:00
|
|
|
// Check if the frame is XBL anonymous
|
|
|
|
let parent = curWindow.document.getBindingParent(wantedFrame);
|
|
|
|
// Shadow nodes also show up in getAnonymousNodes, we should ignore them.
|
|
|
|
if (parent && !(parent.shadowRoot && parent.shadowRoot.contains(wantedFrame))) {
|
|
|
|
let anonNodes = [...curWindow.document.getAnonymousNodes(parent) || []];
|
|
|
|
if (anonNodes.length > 0) {
|
|
|
|
let el = wantedFrame;
|
|
|
|
while (el) {
|
|
|
|
if (anonNodes.indexOf(el) > -1) {
|
|
|
|
curWindow = wantedFrame.contentWindow;
|
|
|
|
this.curFrame = curWindow;
|
|
|
|
if (focus) {
|
|
|
|
this.curFrame.focus();
|
2016-01-09 00:55:55 +03:00
|
|
|
}
|
2016-05-20 17:07:21 +03:00
|
|
|
checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
return;
|
2016-01-09 00:55:55 +03:00
|
|
|
}
|
2016-05-20 17:07:21 +03:00
|
|
|
el = el.parentNode;
|
2016-01-09 00:55:55 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-20 17:07:21 +03:00
|
|
|
}
|
2016-01-09 00:55:55 +03:00
|
|
|
|
2016-05-20 17:07:21 +03:00
|
|
|
// else, assume iframe
|
|
|
|
let frames = curWindow.document.getElementsByTagName("iframe");
|
|
|
|
let numFrames = frames.length;
|
|
|
|
for (let i = 0; i < numFrames; i++) {
|
|
|
|
if (new XPCNativeWrapper(frames[i]) == new XPCNativeWrapper(wantedFrame)) {
|
|
|
|
curWindow = frames[i].contentWindow;
|
|
|
|
this.curFrame = curWindow;
|
|
|
|
if (focus) {
|
|
|
|
this.curFrame.focus();
|
2015-11-09 20:48:31 +03:00
|
|
|
}
|
2016-05-20 17:07:21 +03:00
|
|
|
checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
return;
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-09 20:48:31 +03:00
|
|
|
|
|
|
|
switch (typeof id) {
|
|
|
|
case "string" :
|
|
|
|
let foundById = null;
|
|
|
|
let frames = curWindow.document.getElementsByTagName("iframe");
|
|
|
|
let numFrames = frames.length;
|
|
|
|
for (let i = 0; i < numFrames; i++) {
|
|
|
|
//give precedence to name
|
|
|
|
let frame = frames[i];
|
|
|
|
if (frame.getAttribute("name") == id) {
|
|
|
|
foundFrame = i;
|
|
|
|
curWindow = frame.contentWindow;
|
|
|
|
break;
|
|
|
|
} else if (foundById === null && frame.id == id) {
|
|
|
|
foundById = i;
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
2015-11-09 20:48:31 +03:00
|
|
|
if (foundFrame === null && foundById !== null) {
|
|
|
|
foundFrame = foundById;
|
|
|
|
curWindow = frames[foundById].contentWindow;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "number":
|
|
|
|
if (typeof curWindow.frames[id] != "undefined") {
|
|
|
|
foundFrame = id;
|
|
|
|
curWindow = curWindow.frames[foundFrame].frameElement.contentWindow;
|
|
|
|
}
|
|
|
|
break;
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
2015-11-09 20:48:31 +03:00
|
|
|
|
2015-04-24 15:55:52 +03:00
|
|
|
if (foundFrame !== null) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.curFrame = curWindow;
|
2015-11-09 20:48:31 +03:00
|
|
|
if (focus) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.curFrame.focus();
|
|
|
|
}
|
|
|
|
checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
} else {
|
2015-11-09 20:48:31 +03:00
|
|
|
throw new NoSuchFrameError(`Unable to locate frame: ${id}`);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
2015-11-09 20:48:31 +03:00
|
|
|
|
|
|
|
} else if (this.context == Context.CONTENT) {
|
|
|
|
if (!id && !element &&
|
|
|
|
this.curBrowser.frameManager.currentRemoteFrame !== null) {
|
2015-03-20 00:12:58 +03:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
cmd.command_id = cmd.id;
|
|
|
|
|
|
|
|
let res = yield this.listener.switchToFrame(cmd.parameters);
|
|
|
|
if (res) {
|
|
|
|
let {win: winId, frame: frameId} = res;
|
|
|
|
this.mm = this.curBrowser.frameManager.getFrameMM(winId, frameId);
|
|
|
|
|
|
|
|
let registerBrowsers = this.registerPromise();
|
|
|
|
let browserListening = this.listeningPromise();
|
|
|
|
|
|
|
|
this.oopFrameId =
|
|
|
|
this.curBrowser.frameManager.switchToFrame(winId, frameId);
|
|
|
|
|
|
|
|
yield registerBrowsers;
|
|
|
|
yield browserListening;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getTimeouts = function (cmd, resp) {
|
2016-12-31 15:27:13 +03:00
|
|
|
return this.timeouts;
|
2016-11-10 21:29:55 +03:00
|
|
|
};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
/**
|
|
|
|
* Set timeout for page loading, searching, and scripts.
|
|
|
|
*
|
2016-09-14 20:10:22 +03:00
|
|
|
* @param {Object.<string, number>}
|
|
|
|
* Dictionary of timeout types and their new value, where all timeout
|
|
|
|
* types are optional.
|
|
|
|
*
|
|
|
|
* @throws {InvalidArgumentError}
|
|
|
|
* If timeout type key is unknown, or the value provided with it is
|
|
|
|
* not an integer.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.setTimeouts = function (cmd, resp) {
|
2016-09-14 20:10:22 +03:00
|
|
|
// backwards compatibility with old API
|
|
|
|
// that accepted a dictionary {type: <string>, ms: <number>}
|
2016-12-31 15:27:13 +03:00
|
|
|
let json = {};
|
2016-09-14 20:10:22 +03:00
|
|
|
if (typeof cmd.parameters == "object" &&
|
|
|
|
"type" in cmd.parameters &&
|
|
|
|
"ms" in cmd.parameters) {
|
|
|
|
logger.warn("Using deprecated data structure for setting timeouts");
|
2016-12-31 15:27:13 +03:00
|
|
|
json = {[cmd.parameters.type]: parseInt(cmd.parameters.ms)};
|
2016-09-14 20:10:22 +03:00
|
|
|
} else {
|
2016-12-31 15:27:13 +03:00
|
|
|
json = cmd.parameters;
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2016-12-31 15:27:13 +03:00
|
|
|
// merge with existing timeouts
|
|
|
|
let merged = Object.assign(this.timeouts.toJSON(), json);
|
|
|
|
this.timeouts = session.Timeouts.fromJSON(merged);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Single tap. */
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.singleTap = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let {id, x, y} = cmd.parameters;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2016-12-29 16:04:16 +03:00
|
|
|
throw new UnsupportedOperationError(
|
|
|
|
"Command 'singleTap' is not yet available in chrome context");
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
case Context.CONTENT:
|
|
|
|
this.addFrameCloseListener("tap");
|
2015-09-10 18:45:33 +03:00
|
|
|
yield this.listener.singleTap(id, x, y);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-14 02:29:48 +03:00
|
|
|
/**
|
|
|
|
* Perform a series of grouped actions at the specified points in time.
|
|
|
|
*
|
|
|
|
* @param {Array.<?>} actions
|
|
|
|
* Array of objects that each represent an action sequence.
|
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* If the command is made in chrome context.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.performActions = function(cmd, resp) {
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
throw new UnsupportedOperationError(
|
2016-12-29 16:04:16 +03:00
|
|
|
"Command 'performActions' is not yet available in chrome context");
|
|
|
|
|
2016-12-14 02:29:48 +03:00
|
|
|
case Context.CONTENT:
|
|
|
|
return this.listener.performActions({"actions": cmd.parameters.actions});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release all the keys and pointer buttons that are currently depressed.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.releaseActions = function(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
throw new UnsupportedOperationError(
|
|
|
|
"Command 'releaseActions' is not yet available in chrome context");
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
|
|
|
return this.listener.releaseActions();
|
|
|
|
}
|
2016-12-14 02:29:48 +03:00
|
|
|
};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
/**
|
|
|
|
* An action chain.
|
|
|
|
*
|
|
|
|
* @param {Object} value
|
|
|
|
* A nested array where the inner array represents each event,
|
|
|
|
* and the outer array represents a collection of events.
|
|
|
|
*
|
|
|
|
* @return {number}
|
|
|
|
* Last touch ID.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.actionChain = function*(cmd, resp) {
|
2015-03-24 18:35:58 +03:00
|
|
|
let {chain, nextId} = cmd.parameters;
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2016-12-29 16:04:16 +03:00
|
|
|
// be conservative until this has a use case and is established
|
|
|
|
// to work as expected in Fennec
|
2017-03-01 14:49:21 +03:00
|
|
|
assert.firefox()
|
2015-03-24 18:35:58 +03:00
|
|
|
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-11-29 19:00:52 +03:00
|
|
|
resp.body.value = yield this.legacyactions.dispatchActions(
|
2016-05-20 18:49:19 +03:00
|
|
|
chain, nextId, {frame: win}, this.curBrowser.seenEls);
|
2015-03-24 18:35:58 +03:00
|
|
|
break;
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
case Context.CONTENT:
|
|
|
|
this.addFrameCloseListener("action chain");
|
2015-09-02 15:36:03 +03:00
|
|
|
resp.body.value = yield this.listener.actionChain(chain, nextId);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A multi-action chain.
|
|
|
|
*
|
|
|
|
* @param {Object} value
|
|
|
|
* A nested array where the inner array represents eache vent,
|
|
|
|
* the middle array represents a collection of events for each
|
|
|
|
* finger, and the outer array represents all fingers.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.multiAction = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
2015-03-23 23:43:18 +03:00
|
|
|
case Context.CHROME:
|
2016-12-29 16:04:16 +03:00
|
|
|
throw new UnsupportedOperationError(
|
|
|
|
"Command 'multiAction' is not yet available in chrome context");
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2015-03-23 23:43:18 +03:00
|
|
|
case Context.CONTENT:
|
|
|
|
this.addFrameCloseListener("multi action chain");
|
2015-11-30 18:20:05 +03:00
|
|
|
yield this.listener.multiAction(cmd.parameters.value, cmd.parameters.max_length);
|
2015-03-23 23:43:18 +03:00
|
|
|
break;
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find an element using the indicated search strategy.
|
|
|
|
*
|
|
|
|
* @param {string} using
|
|
|
|
* Indicates which search method to use.
|
|
|
|
* @param {string} value
|
|
|
|
* Value the client is looking for.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.findElement = function*(cmd, resp) {
|
2016-05-20 15:28:27 +03:00
|
|
|
let strategy = cmd.parameters.using;
|
|
|
|
let expr = cmd.parameters.value;
|
2016-02-23 18:19:21 +03:00
|
|
|
let opts = {
|
|
|
|
startNode: cmd.parameters.element,
|
2016-12-31 15:27:13 +03:00
|
|
|
timeout: this.timeouts.implicit,
|
2016-02-23 18:19:21 +03:00
|
|
|
all: false,
|
|
|
|
};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2016-05-20 15:28:27 +03:00
|
|
|
if (!SUPPORTED_STRATEGIES.has(strategy)) {
|
|
|
|
throw new InvalidSelectorError(`Strategy not supported: ${strategy}`);
|
|
|
|
}
|
|
|
|
|
2017-03-01 14:49:21 +03:00
|
|
|
let container = {frame: this.getCurrentWindow()};
|
2016-05-20 15:28:27 +03:00
|
|
|
if (opts.startNode) {
|
2016-05-20 18:49:19 +03:00
|
|
|
opts.startNode = this.curBrowser.seenEls.get(opts.startNode, container);
|
2016-05-20 15:28:27 +03:00
|
|
|
}
|
|
|
|
let el = yield element.find(container, strategy, expr, opts);
|
2016-05-20 18:49:19 +03:00
|
|
|
let elRef = this.curBrowser.seenEls.add(el);
|
2016-05-20 15:28:27 +03:00
|
|
|
let webEl = element.makeWebElement(elRef);
|
|
|
|
|
|
|
|
resp.body.value = webEl;
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
2016-02-23 18:19:21 +03:00
|
|
|
resp.body.value = yield this.listener.findElementContent(
|
2016-05-20 15:28:27 +03:00
|
|
|
strategy,
|
|
|
|
expr,
|
2016-02-23 18:19:21 +03:00
|
|
|
opts);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find elements using the indicated search strategy.
|
|
|
|
*
|
|
|
|
* @param {string} using
|
|
|
|
* Indicates which search method to use.
|
|
|
|
* @param {string} value
|
|
|
|
* Value the client is looking for.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.findElements = function*(cmd, resp) {
|
2016-05-20 15:28:27 +03:00
|
|
|
let strategy = cmd.parameters.using;
|
|
|
|
let expr = cmd.parameters.value;
|
2016-02-23 18:19:21 +03:00
|
|
|
let opts = {
|
|
|
|
startNode: cmd.parameters.element,
|
2016-12-31 15:27:13 +03:00
|
|
|
timeout: this.timeouts.implicit,
|
2016-02-23 18:19:21 +03:00
|
|
|
all: true,
|
|
|
|
};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2016-05-20 15:28:27 +03:00
|
|
|
if (!SUPPORTED_STRATEGIES.has(strategy)) {
|
|
|
|
throw new InvalidSelectorError(`Strategy not supported: ${strategy}`);
|
|
|
|
}
|
|
|
|
|
2017-03-01 14:49:21 +03:00
|
|
|
let container = {frame: this.getCurrentWindow()};
|
2016-05-20 15:28:27 +03:00
|
|
|
if (opts.startNode) {
|
2016-05-20 18:49:19 +03:00
|
|
|
opts.startNode = this.curBrowser.seenEls.get(opts.startNode, container);
|
2016-05-20 15:28:27 +03:00
|
|
|
}
|
|
|
|
let els = yield element.find(container, strategy, expr, opts);
|
|
|
|
|
2016-05-20 18:49:19 +03:00
|
|
|
let elRefs = this.curBrowser.seenEls.addAll(els);
|
2016-05-20 15:28:27 +03:00
|
|
|
let webEls = elRefs.map(element.makeWebElement);
|
|
|
|
resp.body = webEls;
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
2016-02-23 18:19:21 +03:00
|
|
|
resp.body = yield this.listener.findElementsContent(
|
|
|
|
cmd.parameters.using,
|
|
|
|
cmd.parameters.value,
|
|
|
|
opts);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Return the active element on the page. */
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.getActiveElement = function*(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
throw new UnsupportedOperationError(
|
|
|
|
"Command 'getActiveElement' is not yet available in chrome context");
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
|
|
|
resp.body.value = yield this.listener.getActiveElement();
|
|
|
|
break;
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send click event to element.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be clicked.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.clickElement = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2016-12-19 22:28:17 +03:00
|
|
|
yield interaction.clickElement(el, this.a11yChecks);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
|
|
|
// 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
|
|
|
|
this.addFrameCloseListener("click");
|
2015-04-15 14:18:00 +03:00
|
|
|
yield this.listener.clickElement(id);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a given attribute of an element.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
2016-05-13 16:42:05 +03:00
|
|
|
* Web element reference ID to the element that will be inspected.
|
2015-03-20 00:12:58 +03:00
|
|
|
* @param {string} name
|
2016-05-13 16:42:05 +03:00
|
|
|
* Name of the attribute which value to retrieve.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Value of the attribute.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.getElementAttribute = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let {id, name} = cmd.parameters;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2016-12-15 00:26:34 +03:00
|
|
|
|
|
|
|
resp.body.value = el.getAttribute(name);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = yield this.listener.getElementAttribute(id, name);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-13 16:42:05 +03:00
|
|
|
/**
|
|
|
|
* Returns the value of a property associated with given element.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Web element reference ID to the element that will be inspected.
|
|
|
|
* @param {string} name
|
|
|
|
* Name of the property which value to retrieve.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Value of the property.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.getElementProperty = function*(cmd, resp) {
|
|
|
|
let {id, name} = cmd.parameters;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-06-01 01:08:42 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
|
|
|
resp.body.value = el[name];
|
|
|
|
break;
|
2016-05-13 16:42:05 +03:00
|
|
|
|
|
|
|
case Context.CONTENT:
|
2016-06-24 11:25:03 +03:00
|
|
|
resp.body.value = yield this.listener.getElementProperty(id, name);
|
|
|
|
break;
|
2016-05-13 16:42:05 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
/**
|
|
|
|
* Get the text of an element, if any. Includes the text of all child
|
|
|
|
* elements.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be inspected.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.getElementText = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
// for chrome, we look at text nodes, and any node with a "label" field
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2015-03-20 00:12:58 +03:00
|
|
|
let lines = [];
|
|
|
|
this.getVisibleText(el, lines);
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = lines.join("\n");
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = yield this.listener.getElementText(id);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the tag name of the element.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be inspected.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.getElementTagName = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = el.tagName.toLowerCase();
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = yield this.listener.getElementTagName(id);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if element is displayed.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be inspected.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.isElementDisplayed = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2016-03-03 16:58:13 +03:00
|
|
|
resp.body.value = yield interaction.isElementDisplayed(
|
2016-12-19 22:28:17 +03:00
|
|
|
el, this.a11yChecks);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = yield this.listener.isElementDisplayed(id);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the property of the computed style of an element.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be checked.
|
|
|
|
* @param {string} propertyName
|
|
|
|
* CSS rule that is being requested.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.getElementValueOfCssProperty = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let {id, propertyName: prop} = cmd.parameters;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2017-01-27 12:51:02 +03:00
|
|
|
let sty = win.document.defaultView.getComputedStyle(el);
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = sty.getPropertyValue(prop);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = yield this.listener.getElementValueOfCssProperty(id, prop);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if element is enabled.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be checked.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.isElementEnabled = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
// Selenium atom doesn't quite work here
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2016-03-03 16:58:13 +03:00
|
|
|
resp.body.value = yield interaction.isElementEnabled(
|
2016-12-19 22:28:17 +03:00
|
|
|
el, this.a11yChecks);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = yield this.listener.isElementEnabled(id);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if element is selected.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be checked.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.isElementSelected = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
// Selenium atom doesn't quite work here
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2016-03-03 16:58:13 +03:00
|
|
|
resp.body.value = yield interaction.isElementSelected(
|
2016-12-19 22:28:17 +03:00
|
|
|
el, this.a11yChecks);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = yield this.listener.isElementSelected(id);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.getElementRect = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2015-03-20 00:12:58 +03:00
|
|
|
let rect = el.getBoundingClientRect();
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body = {
|
2015-03-20 00:12:58 +03:00
|
|
|
x: rect.x + win.pageXOffset,
|
|
|
|
y: rect.y + win.pageYOffset,
|
|
|
|
width: rect.width,
|
|
|
|
height: rect.height
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body = yield this.listener.getElementRect(id);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send key presses to element after focusing on it.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be checked.
|
|
|
|
* @param {string} value
|
|
|
|
* Value to send to the element.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.sendKeysToElement = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let {id, value} = cmd.parameters;
|
2016-11-01 01:12:30 +03:00
|
|
|
assert.defined(value, `Expected character sequence: ${value}`);
|
2015-04-02 17:16:00 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2016-03-03 16:58:13 +03:00
|
|
|
yield interaction.sendKeysToElement(
|
2016-12-19 22:28:17 +03:00
|
|
|
el, value, true, this.a11yChecks);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
2016-08-30 14:46:01 +03:00
|
|
|
yield this.listener.sendKeysToElement(id, value);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Sets the test name. The test name is used for logging purposes. */
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.setTestName = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let val = cmd.parameters.value;
|
|
|
|
this.testName = val;
|
|
|
|
yield this.listener.setTestName({value: val});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the text of an element.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be cleared.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.clearElement = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
// the selenium atom doesn't work here
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2015-03-20 00:12:58 +03:00
|
|
|
if (el.nodeName == "textbox") {
|
|
|
|
el.value = "";
|
|
|
|
} else if (el.nodeName == "checkbox") {
|
|
|
|
el.checked = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
2015-08-21 17:37:04 +03:00
|
|
|
yield this.listener.clearElement(id);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-28 23:43:54 +03:00
|
|
|
/**
|
|
|
|
* Switch to shadow root of the given host element.
|
|
|
|
*
|
|
|
|
* @param {string} id element id.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.switchToShadowRoot = function*(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context)
|
|
|
|
|
2015-08-28 23:43:54 +03:00
|
|
|
let id;
|
|
|
|
if (cmd.parameters) { id = cmd.parameters.id; }
|
|
|
|
yield this.listener.switchToShadowRoot(id);
|
|
|
|
};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
/** Add a cookie to the document. */
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.addCookie = function*(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context)
|
|
|
|
|
2015-11-13 16:35:22 +03:00
|
|
|
let cb = msg => {
|
|
|
|
this.mm.removeMessageListener("Marionette:addCookie", cb);
|
|
|
|
let cookie = msg.json;
|
|
|
|
Services.cookies.add(
|
|
|
|
cookie.domain,
|
|
|
|
cookie.path,
|
|
|
|
cookie.name,
|
|
|
|
cookie.value,
|
|
|
|
cookie.secure,
|
|
|
|
cookie.httpOnly,
|
|
|
|
cookie.session,
|
2016-05-25 06:54:21 +03:00
|
|
|
cookie.expiry,
|
|
|
|
{}); // originAttributes
|
2015-11-13 16:35:22 +03:00
|
|
|
return true;
|
|
|
|
};
|
2016-12-29 16:04:16 +03:00
|
|
|
|
2015-11-13 16:35:22 +03:00
|
|
|
this.mm.addMessageListener("Marionette:addCookie", cb);
|
|
|
|
yield this.listener.addCookie(cmd.parameters.cookie);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the cookies for the current domain.
|
|
|
|
*
|
|
|
|
* This is the equivalent of calling {@code document.cookie} and parsing
|
|
|
|
* the result.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.getCookies = function*(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context)
|
|
|
|
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body = yield this.listener.getCookies();
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Delete all cookies that are visible to a document. */
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.deleteAllCookies = function*(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context)
|
|
|
|
|
2015-11-13 16:35:22 +03:00
|
|
|
let cb = msg => {
|
|
|
|
let cookie = msg.json;
|
|
|
|
cookieManager.remove(
|
|
|
|
cookie.host,
|
|
|
|
cookie.name,
|
|
|
|
cookie.path,
|
2016-04-10 07:46:07 +03:00
|
|
|
false,
|
|
|
|
cookie.originAttributes);
|
2015-11-13 16:35:22 +03:00
|
|
|
return true;
|
|
|
|
};
|
2016-12-29 16:04:16 +03:00
|
|
|
|
2015-11-13 16:35:22 +03:00
|
|
|
this.mm.addMessageListener("Marionette:deleteCookie", cb);
|
2015-03-20 00:12:58 +03:00
|
|
|
yield this.listener.deleteAllCookies();
|
2015-11-13 16:35:22 +03:00
|
|
|
this.mm.removeMessageListener("Marionette:deleteCookie", cb);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Delete a cookie by name. */
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.deleteCookie = function*(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context)
|
|
|
|
|
2015-11-13 16:35:22 +03:00
|
|
|
let cb = msg => {
|
|
|
|
this.mm.removeMessageListener("Marionette:deleteCookie", cb);
|
|
|
|
let cookie = msg.json;
|
|
|
|
cookieManager.remove(
|
|
|
|
cookie.host,
|
|
|
|
cookie.name,
|
|
|
|
cookie.path,
|
2016-04-10 07:46:07 +03:00
|
|
|
false,
|
|
|
|
cookie.originAttributes);
|
2015-11-13 16:35:22 +03:00
|
|
|
return true;
|
|
|
|
};
|
2016-12-29 16:04:16 +03:00
|
|
|
|
2015-11-13 16:35:22 +03:00
|
|
|
this.mm.addMessageListener("Marionette:deleteCookie", cb);
|
|
|
|
yield this.listener.deleteCookie(cmd.parameters.name);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-01-10 18:36:49 +03:00
|
|
|
* Close the currently selected tab/window.
|
|
|
|
*
|
|
|
|
* With multiple open tabs present the currently selected tab will be closed.
|
|
|
|
* Otherwise the window itself will be closed. If it is the last window
|
|
|
|
* currently open, the window will not be closed to prevent a shutdown of the
|
|
|
|
* application. Instead the returned list of window handles is empty.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2017-01-10 18:36:49 +03:00
|
|
|
* @return {Array.<string>}
|
|
|
|
* Unique window handles of remaining windows.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.close = function (cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let nwins = 0;
|
2017-02-03 19:49:38 +03:00
|
|
|
let winEn = Services.wm.getEnumerator(null);
|
2017-03-01 14:49:21 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
while (winEn.hasMoreElements()) {
|
|
|
|
let win = winEn.getNext();
|
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
// For browser windows count the tabs. Otherwise take the window itself.
|
2017-01-26 18:42:35 +03:00
|
|
|
let tabbrowser = browser.getTabBrowser(win);
|
|
|
|
if (tabbrowser) {
|
|
|
|
nwins += tabbrowser.tabs.length;
|
2015-03-23 23:43:18 +03:00
|
|
|
} else {
|
2015-03-20 00:12:58 +03:00
|
|
|
nwins++;
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
// If there is only 1 window left, do not close it. Instead return a faked
|
|
|
|
// empty array of window handles. This will instruct geckodriver to terminate
|
|
|
|
// the application.
|
2015-03-20 00:12:58 +03:00
|
|
|
if (nwins == 1) {
|
2017-01-10 18:36:49 +03:00
|
|
|
return [];
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
if (this.mm != globalMessageManager) {
|
|
|
|
this.mm.removeDelayedFrameScript(FRAME_SCRIPT);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
2017-01-10 18:36:49 +03:00
|
|
|
|
|
|
|
return this.curBrowser.closeTab().then(() => this.windowHandles);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-01-10 18:36:49 +03:00
|
|
|
* Close the currently selected chrome window.
|
|
|
|
*
|
|
|
|
* If it is the last window currently open, the chrome window will not be
|
|
|
|
* closed to prevent a shutdown of the application. Instead the returned
|
|
|
|
* list of chrome window handles is empty.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2017-01-10 18:36:49 +03:00
|
|
|
* @return {Array.<string>}
|
|
|
|
* Unique chrome window handles of remaining chrome windows.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.closeChromeWindow = function (cmd, resp) {
|
2017-01-10 18:36:49 +03:00
|
|
|
assert.firefox();
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-03-01 14:49:21 +03:00
|
|
|
// Get the total number of windows
|
2015-03-20 00:12:58 +03:00
|
|
|
let nwins = 0;
|
2017-02-03 19:49:38 +03:00
|
|
|
let winEn = Services.wm.getEnumerator(null);
|
2017-03-01 14:49:21 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
while (winEn.hasMoreElements()) {
|
|
|
|
nwins++;
|
|
|
|
winEn.getNext();
|
|
|
|
}
|
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
// If there is only 1 window left, do not close it. Instead return a faked
|
|
|
|
// empty array of window handles. This will instruct geckodriver to terminate
|
|
|
|
// the application.
|
2015-03-20 00:12:58 +03:00
|
|
|
if (nwins == 1) {
|
2017-01-10 18:36:49 +03:00
|
|
|
return [];
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
// reset frame to the top-most frame
|
|
|
|
this.curFrame = null;
|
2016-12-13 23:36:56 +03:00
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
if (this.mm != globalMessageManager) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.mm.removeDelayedFrameScript(FRAME_SCRIPT);
|
|
|
|
}
|
2017-01-10 18:36:49 +03:00
|
|
|
|
|
|
|
return this.curBrowser.closeWindow().then(() => this.chromeWindowHandles);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-02-02 19:11:08 +03:00
|
|
|
/** Delete Marionette session. */
|
|
|
|
GeckoDriver.prototype.deleteSession = function (cmd, resp) {
|
2015-04-24 15:55:52 +03:00
|
|
|
if (this.curBrowser !== null) {
|
2017-02-02 19:10:18 +03:00
|
|
|
// frame scripts can be safely reused
|
|
|
|
Preferences.set(CONTENT_LISTENER_PREF, false);
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
// delete session in each frame in each browser
|
|
|
|
for (let win in this.browsers) {
|
|
|
|
let browser = this.browsers[win];
|
|
|
|
for (let i in browser.knownFrames) {
|
|
|
|
globalMessageManager.broadcastAsyncMessage(
|
|
|
|
"Marionette:deleteSession" + browser.knownFrames[i], {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 17:48:11 +03:00
|
|
|
let winEn = Services.wm.getEnumerator(null);
|
2015-03-20 00:12:58 +03:00
|
|
|
while (winEn.hasMoreElements()) {
|
2016-07-07 01:23:35 +03:00
|
|
|
let win = winEn.getNext();
|
2017-02-02 19:10:18 +03:00
|
|
|
if (win.messageManager) {
|
2016-07-07 01:23:35 +03:00
|
|
|
win.messageManager.removeDelayedFrameScript(FRAME_SCRIPT);
|
|
|
|
} else {
|
|
|
|
logger.error(
|
|
|
|
`Could not remove listener from page ${win.location.href}`);
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.curBrowser.frameManager.removeMessageManagerListeners(
|
|
|
|
globalMessageManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.switchToGlobalMessageManager();
|
|
|
|
|
|
|
|
// reset frame to the top-most frame
|
|
|
|
this.curFrame = null;
|
2015-03-23 23:43:18 +03:00
|
|
|
if (this.mainFrame) {
|
2016-09-01 23:30:24 +03:00
|
|
|
try {
|
|
|
|
this.mainFrame.focus();
|
2017-01-04 22:38:34 +03:00
|
|
|
} catch (e) {
|
2016-09-01 23:30:24 +03:00
|
|
|
this.mainFrame = null;
|
|
|
|
}
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
if (this.observing !== null) {
|
|
|
|
for (let topic in this.observing) {
|
|
|
|
Services.obs.removeObserver(this.observing[topic], topic);
|
|
|
|
}
|
|
|
|
this.observing = null;
|
|
|
|
}
|
2016-11-06 21:03:31 +03:00
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
this.sandboxes.clear();
|
2016-11-06 21:03:31 +03:00
|
|
|
cert.uninstallOverride();
|
2016-12-31 15:28:19 +03:00
|
|
|
|
|
|
|
this.sessionId = null;
|
2016-12-31 15:32:14 +03:00
|
|
|
this.capabilities = new session.Capabilities();
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Returns the current status of the Application Cache. */
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getAppCacheStatus = function* (cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
throw new UnsupportedOperationError(
|
|
|
|
"Command 'getAppCacheStatus' is not yet available in chrome context");
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
|
|
|
resp.body.value = yield this.listener.getAppCacheStatus();
|
|
|
|
break;
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2016-02-29 21:52:30 +03:00
|
|
|
/**
|
|
|
|
* Import script to the JS evaluation runtime.
|
|
|
|
*
|
|
|
|
* Imported scripts are exposed in the contexts of all subsequent
|
|
|
|
* calls to {@code executeScript}, {@code executeAsyncScript}, and
|
|
|
|
* {@code executeJSScript} by prepending them to the evaluated script.
|
|
|
|
*
|
|
|
|
* Scripts can be cleared with the {@code clearImportedScripts} command.
|
|
|
|
*
|
|
|
|
* @param {string} script
|
|
|
|
* Script to include. If the script is byte-by-byte equal to an
|
|
|
|
* existing imported script, it is not imported.
|
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.importScript = function*(cmd, resp) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let script = cmd.parameters.script;
|
2016-02-29 21:52:30 +03:00
|
|
|
this.importedScripts.for(this.context).add(script);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2016-02-29 21:52:30 +03:00
|
|
|
/**
|
|
|
|
* Clear all scripts that are imported into the JS evaluation runtime.
|
|
|
|
*
|
|
|
|
* Scripts can be imported using the {@code importScript} command.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.clearImportedScripts = function*(cmd, resp) {
|
|
|
|
this.importedScripts.for(this.context).clear();
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a screenshot of a web element, current frame, or viewport.
|
|
|
|
*
|
|
|
|
* The screen capture is returned as a lossless PNG image encoded as
|
|
|
|
* a base 64 string.
|
|
|
|
*
|
|
|
|
* If called in the content context, the <code>id</code> argument is not null
|
|
|
|
* and refers to a present and visible web element's ID, the capture area
|
|
|
|
* will be limited to the bounding box of that element. Otherwise, the
|
|
|
|
* capture area will be the bounding box of the current frame.
|
|
|
|
*
|
|
|
|
* If called in the chrome context, the screenshot will always represent the
|
|
|
|
* entire viewport.
|
|
|
|
*
|
2016-12-20 17:30:48 +03:00
|
|
|
* @param {string=} id
|
|
|
|
* Optional web element reference to take a screenshot of.
|
|
|
|
* If undefined, a screenshot will be taken of the document element.
|
|
|
|
* @param {Array.<string>=} highlights
|
2015-03-20 00:12:58 +03:00
|
|
|
* List of web elements to highlight.
|
2016-12-07 19:38:14 +03:00
|
|
|
* @param {boolean} full
|
|
|
|
* True to take a screenshot of the entire document element. Is not
|
|
|
|
* considered if {@code id} is not defined. Defaults to true.
|
2016-12-20 17:30:48 +03:00
|
|
|
* @param {boolean=} hash
|
2016-04-18 04:37:14 +03:00
|
|
|
* True if the user requests a hash of the image data.
|
2016-12-20 17:30:48 +03:00
|
|
|
* @param {boolean=} scroll
|
|
|
|
* Scroll to element if |id| is provided. If undefined, it will
|
|
|
|
* scroll to the element.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
|
|
|
* @return {string}
|
2016-04-18 04:37:14 +03:00
|
|
|
* If {@code hash} is false, PNG image encoded as base64 encoded string. If
|
|
|
|
* 'hash' is True, hex digest of the SHA-256 hash of the base64 encoded
|
|
|
|
* string.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.takeScreenshot = function (cmd, resp) {
|
2016-12-20 17:30:48 +03:00
|
|
|
let {id, highlights, full, hash, scroll} = cmd.parameters;
|
2015-10-13 18:52:26 +03:00
|
|
|
highlights = highlights || [];
|
2016-12-20 17:30:48 +03:00
|
|
|
let format = hash ? capture.Format.Hash : capture.Format.Base64;
|
2015-10-09 14:02:42 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-03-01 14:49:21 +03:00
|
|
|
let container = {frame: this.getCurrentWindow().document.defaultView};
|
|
|
|
if (!container.frame) {
|
|
|
|
throw new NoSuchWindowError("Unable to locate window");
|
|
|
|
}
|
2016-12-07 23:47:44 +03:00
|
|
|
|
2016-12-20 17:30:48 +03:00
|
|
|
let highlightEls = highlights.map(
|
|
|
|
ref => this.curBrowser.seenEls.get(ref, container));
|
2016-12-05 23:19:46 +03:00
|
|
|
|
2016-12-07 19:38:14 +03:00
|
|
|
// viewport
|
2016-12-20 17:30:48 +03:00
|
|
|
let canvas;
|
2016-12-07 19:38:14 +03:00
|
|
|
if (!id && !full) {
|
|
|
|
canvas = capture.viewport(container.frame, highlightEls);
|
|
|
|
|
|
|
|
// element or full document element
|
|
|
|
} else {
|
|
|
|
let node;
|
|
|
|
if (id) {
|
|
|
|
node = this.curBrowser.seenEls.get(id, container);
|
|
|
|
} else {
|
|
|
|
node = container.frame.document.documentElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas = capture.element(node, highlightEls);
|
|
|
|
}
|
|
|
|
|
2016-12-20 17:30:48 +03:00
|
|
|
switch (format) {
|
|
|
|
case capture.Format.Hash:
|
|
|
|
return capture.toHash(canvas);
|
|
|
|
|
|
|
|
case capture.Format.Base64:
|
|
|
|
return capture.toBase64(canvas);
|
2016-12-06 01:06:36 +03:00
|
|
|
}
|
2016-12-20 17:30:48 +03:00
|
|
|
break;
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
case Context.CONTENT:
|
2016-12-20 17:30:48 +03:00
|
|
|
return this.listener.takeScreenshot(format, cmd.parameters);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current browser orientation.
|
|
|
|
*
|
|
|
|
* Will return one of the valid primary orientation values
|
|
|
|
* portrait-primary, landscape-primary, portrait-secondary, or
|
|
|
|
* landscape-secondary.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getScreenOrientation = function (cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.fennec();
|
|
|
|
|
2017-03-01 14:49:21 +03:00
|
|
|
resp.body.value = this.getCurrentWindow().screen.mozOrientation;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current browser orientation.
|
|
|
|
*
|
|
|
|
* The supplied orientation should be given as one of the valid
|
|
|
|
* orientation values. If the orientation is unknown, an error will
|
|
|
|
* be raised.
|
|
|
|
*
|
|
|
|
* Valid orientations are "portrait" and "landscape", which fall
|
|
|
|
* back to "portrait-primary" and "landscape-primary" respectively,
|
|
|
|
* and "portrait-secondary" as well as "landscape-secondary".
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.setScreenOrientation = function (cmd, resp) {
|
2016-11-01 01:12:30 +03:00
|
|
|
assert.fennec();
|
2016-03-17 17:54:48 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
const ors = [
|
|
|
|
"portrait", "landscape",
|
|
|
|
"portrait-primary", "landscape-primary",
|
2016-11-01 01:12:30 +03:00
|
|
|
"portrait-secondary", "landscape-secondary",
|
2015-03-20 00:12:58 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
let or = String(cmd.parameters.orientation);
|
2016-11-01 01:12:30 +03:00
|
|
|
assert.string(or);
|
2015-03-20 00:12:58 +03:00
|
|
|
let mozOr = or.toLowerCase();
|
2016-12-29 16:04:16 +03:00
|
|
|
if (!ors.includes(mozOr)) {
|
2016-05-10 16:31:04 +03:00
|
|
|
throw new InvalidArgumentError(`Unknown screen orientation: ${or}`);
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2015-03-23 23:43:18 +03:00
|
|
|
if (!win.screen.mozLockOrientation(mozOr)) {
|
2015-03-20 00:12:58 +03:00
|
|
|
throw new WebDriverError(`Unable to set screen orientation: ${or}`);
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the size of the browser window currently in focus.
|
|
|
|
*
|
|
|
|
* Will return the current browser window size in pixels. Refers to
|
|
|
|
* window outerWidth and outerHeight values, which include scroll bars,
|
|
|
|
* title bars, etc.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getWindowSize = function (cmd, resp) {
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-11-22 01:36:29 +03:00
|
|
|
return {
|
|
|
|
width: win.outerWidth,
|
|
|
|
height: win.outerHeight,
|
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the size of the browser window currently in focus.
|
|
|
|
*
|
2016-11-22 01:44:22 +03:00
|
|
|
* The supplied width and height values refer to the window outerWidth
|
|
|
|
* and outerHeight values, which include browser chrome and OS-level
|
|
|
|
* window borders.
|
|
|
|
*
|
|
|
|
* @param {number} width
|
|
|
|
* Requested window outer width.
|
|
|
|
* @param {number} height
|
|
|
|
* Requested window outer height.
|
|
|
|
*
|
|
|
|
* @return {Map.<string, number>}
|
|
|
|
* New outerWidth/outerHeight dimensions.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-11-22 01:44:22 +03:00
|
|
|
GeckoDriver.prototype.setWindowSize = function* (cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.firefox()
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2016-11-22 01:44:22 +03:00
|
|
|
const {width, height} = cmd.parameters;
|
2017-03-01 14:49:21 +03:00
|
|
|
const win = this.getCurrentWindow();
|
2016-11-22 01:44:22 +03:00
|
|
|
|
|
|
|
yield new Promise(resolve => {
|
|
|
|
// When the DOM resize event claims that it fires _after_ the document
|
|
|
|
// view has been resized, it is lying.
|
|
|
|
//
|
|
|
|
// Because resize events fire at a high rate, DOM modifications
|
|
|
|
// such as updates to outerWidth/outerHeight are not guaranteed to
|
|
|
|
// have processed. To overcome this... abomination... of the web
|
|
|
|
// platform, we throttle the event using setTimeout. If everything
|
|
|
|
// was well in this world we would use requestAnimationFrame, but
|
|
|
|
// it does not seem to like our particular flavour of XUL.
|
|
|
|
const fps15 = 66;
|
|
|
|
const synchronousResize = () => win.setTimeout(resolve, fps15);
|
|
|
|
win.addEventListener("resize", synchronousResize, {once: true});
|
|
|
|
win.resizeTo(width, height);
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
width: win.outerWidth,
|
|
|
|
height: win.outerHeight,
|
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximizes the user agent window as if the user pressed the maximise
|
|
|
|
* button.
|
|
|
|
*
|
|
|
|
* Not Supported on B2G or Fennec.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.maximizeWindow = function (cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.firefox()
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.getCurrentWindow();
|
2016-05-06 23:15:13 +03:00
|
|
|
win.maximize()
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dismisses a currently displayed tab modal, or returns no such alert if
|
|
|
|
* no modal is displayed.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.dismissDialog = function (cmd, resp) {
|
2016-05-23 13:16:04 +03:00
|
|
|
this._checkIfAlertIsPresent();
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
let {button0, button1} = this.dialog.ui;
|
|
|
|
(button1 ? button1 : button0).click();
|
|
|
|
this.dialog = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accepts a currently displayed tab modal, or returns no such alert if
|
|
|
|
* no modal is displayed.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.acceptDialog = function (cmd, resp) {
|
2016-05-23 13:16:04 +03:00
|
|
|
this._checkIfAlertIsPresent();
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
let {button0} = this.dialog.ui;
|
|
|
|
button0.click();
|
|
|
|
this.dialog = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the message shown in a currently displayed modal, or returns a no such
|
|
|
|
* alert error if no modal is currently displayed.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getTextFromDialog = function (cmd, resp) {
|
2016-05-23 13:16:04 +03:00
|
|
|
this._checkIfAlertIsPresent();
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
let {infoBody} = this.dialog.ui;
|
Bug 1153822: Adjust Marionette responses to match WebDriver protocol
Introduce protocol version levels in the Marionette server.
On establishing a connection to a local end, the remote will return a
`marionetteProtocol` field indicating which level it speaks.
The protocol level can be used by local ends to either fall into
compatibility mode or warn the user that the local end is incompatible
with the remote.
The protocol is currently also more expressive than it needs to be and
this expressiveness has previously resulted in subtle inconsistencies
in the fields returned.
This patch reduces the amount of superfluous fields, reducing the
amount of data sent. Aligning the protocol closer to the WebDriver
specification's expectations will also reduce the amount of
post-processing required in the httpd.
Previous to this patch, this is a value response:
{"from":"0","value":null,"status":0,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}"}
And this for ok responses:
{"from":"0","ok":true}
And this for errors:
{"from":"0","status":21,"sessionId":"{6b6d68d2-4ac9-4308-9f07-d2e72519c407}","error":{"message":"Error loading page, timed out (onDOMContentLoaded)","stacktrace":null,"status":21}}
This patch drops the `from` and `sessionId` fields, and the `status`
field from non-error responses. It also drops the `ok` field in non-value
responses and flattens the error response to a simple dictionary with the
`error` (previously `status`), `message`, and `stacktrace` properties,
which are now all required.
r=jgriffin
--HG--
extra : commitid : FbEkv70rxl9
extra : rebase_source : 3116110a0d197289cc95eba8748be0a33566c5a5
2015-05-21 13:26:58 +03:00
|
|
|
resp.body.value = infoBody.textContent;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends keys to the input field of a currently displayed modal, or
|
|
|
|
* returns a no such alert error if no modal is currently displayed. If
|
|
|
|
* a tab modal is currently displayed but has no means for text input,
|
|
|
|
* an element not visible error is returned.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.sendKeysToDialog = function (cmd, resp) {
|
2016-05-23 13:16:04 +03:00
|
|
|
this._checkIfAlertIsPresent();
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
// see toolkit/components/prompts/content/commonDialog.js
|
|
|
|
let {loginContainer, loginTextbox} = this.dialog.ui;
|
2015-03-23 23:43:18 +03:00
|
|
|
if (loginContainer.hidden) {
|
2015-03-20 00:12:58 +03:00
|
|
|
throw new ElementNotVisibleError("This prompt does not accept text input");
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-03-01 14:49:21 +03:00
|
|
|
let win = this.dialog.window ? this.dialog.window : this.getCurrentWindow();
|
2016-02-03 21:56:02 +03:00
|
|
|
event.sendKeysToElement(
|
2016-02-11 19:05:41 +03:00
|
|
|
cmd.parameters.value,
|
2016-02-03 21:56:02 +03:00
|
|
|
loginTextbox,
|
|
|
|
{ignoreVisibility: true},
|
2017-03-01 14:49:21 +03:00
|
|
|
win);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2016-05-23 13:16:04 +03:00
|
|
|
GeckoDriver.prototype._checkIfAlertIsPresent = function() {
|
|
|
|
if (!this.dialog || !this.dialog.ui) {
|
|
|
|
throw new NoAlertOpenError(
|
|
|
|
"No tab modal was open when attempting to get the dialog text");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-17 14:19:19 +03:00
|
|
|
/**
|
|
|
|
* Enables or disables accepting new socket connections.
|
|
|
|
*
|
|
|
|
* By calling this method with `false` the server will not accept any further
|
|
|
|
* connections, but existing connections will not be forcible closed. Use `true`
|
|
|
|
* to re-enable accepting connections.
|
|
|
|
*
|
|
|
|
* Please note that when closing the connection via the client you can end-up in
|
|
|
|
* a non-recoverable state if it hasn't been enabled before.
|
|
|
|
*
|
|
|
|
* This method is used for custom in application shutdowns via marionette.quit()
|
|
|
|
* or marionette.restart(), like File -> Quit.
|
|
|
|
*
|
|
|
|
* @param {boolean} state
|
|
|
|
* True if the server should accept new socket connections.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.acceptConnections = function (cmd, resp) {
|
2016-11-01 01:12:30 +03:00
|
|
|
assert.boolean(cmd.parameters.value);
|
2016-10-17 14:19:19 +03:00
|
|
|
this._server.acceptConnections = cmd.parameters.value;
|
|
|
|
}
|
|
|
|
|
2015-09-26 19:12:01 +03:00
|
|
|
/**
|
|
|
|
* Quits Firefox with the provided flags and tears down the current
|
|
|
|
* session.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.quitApplication = function (cmd, resp) {
|
2017-01-04 15:04:55 +03:00
|
|
|
assert.firefox("Bug 1298921 - In app initiated quit not yet available beside Firefox")
|
2015-09-26 19:12:01 +03:00
|
|
|
|
|
|
|
let flags = Ci.nsIAppStartup.eAttemptQuit;
|
2016-09-13 21:20:39 +03:00
|
|
|
for (let k of cmd.parameters.flags || []) {
|
2015-09-26 19:12:01 +03:00
|
|
|
flags |= Ci.nsIAppStartup[k];
|
|
|
|
}
|
|
|
|
|
2016-10-17 14:19:19 +03:00
|
|
|
this._server.acceptConnections = false;
|
2015-09-26 19:12:01 +03:00
|
|
|
resp.send();
|
|
|
|
|
2017-02-02 19:11:08 +03:00
|
|
|
this.deleteSession();
|
2015-09-26 19:12:01 +03:00
|
|
|
Services.startup.quit(flags);
|
|
|
|
};
|
|
|
|
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.installAddon = function (cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.firefox()
|
2016-08-26 15:38:03 +03:00
|
|
|
|
|
|
|
let path = cmd.parameters.path;
|
|
|
|
let temp = cmd.parameters.temporary || false;
|
|
|
|
if (typeof path == "undefined" || typeof path != "string" ||
|
|
|
|
typeof temp != "boolean") {
|
|
|
|
throw InvalidArgumentError();
|
|
|
|
}
|
|
|
|
|
|
|
|
return addon.install(path, temp);
|
|
|
|
};
|
|
|
|
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.uninstallAddon = function (cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.firefox()
|
2016-08-26 15:38:03 +03:00
|
|
|
|
|
|
|
let id = cmd.parameters.id;
|
|
|
|
if (typeof id == "undefined" || typeof id != "string") {
|
|
|
|
throw new InvalidArgumentError();
|
|
|
|
}
|
|
|
|
|
|
|
|
return addon.uninstall(id);
|
|
|
|
};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
/**
|
|
|
|
* Helper function to convert an outerWindowID into a UID that Marionette
|
|
|
|
* tracks.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.generateFrameId = function (id) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let uid = id + (this.appName == "B2G" ? "-b2g" : "");
|
|
|
|
return uid;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Receives all messages from content messageManager. */
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.receiveMessage = function (message) {
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (message.name) {
|
2015-10-30 09:29:14 +03:00
|
|
|
case "Marionette:ok":
|
|
|
|
case "Marionette:done":
|
|
|
|
case "Marionette:error":
|
|
|
|
// check if we need to remove the mozbrowserclose listener
|
|
|
|
if (this.mozBrowserClose !== null) {
|
|
|
|
let win = this.getCurrentWindow();
|
|
|
|
win.removeEventListener("mozbrowserclose", this.mozBrowserClose, true);
|
|
|
|
this.mozBrowserClose = null;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
case "Marionette:log":
|
|
|
|
// log server-side messages
|
|
|
|
logger.info(message.json.message);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Marionette:shareData":
|
|
|
|
// log messages from tests
|
2015-03-23 23:43:18 +03:00
|
|
|
if (message.json.log) {
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
this.marionetteLog.addAll(message.json.log);
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Marionette:switchToModalOrigin":
|
|
|
|
this.curBrowser.frameManager.switchToModalOrigin(message);
|
|
|
|
this.mm = this.curBrowser.frameManager
|
|
|
|
.currentRemoteFrame.messageManager.get();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Marionette:switchedToFrame":
|
|
|
|
if (message.json.restorePrevious) {
|
|
|
|
this.currentFrameElement = this.previousFrameElement;
|
|
|
|
} else {
|
|
|
|
// we don't arbitrarily save previousFrameElement, since
|
|
|
|
// we allow frame switching after modals appear, which would
|
|
|
|
// override this value and we'd lose our reference
|
2015-03-23 23:43:18 +03:00
|
|
|
if (message.json.storePrevious) {
|
2015-03-20 00:12:58 +03:00
|
|
|
this.previousFrameElement = this.currentFrameElement;
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
this.currentFrameElement = message.json.frameValue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Marionette:getVisibleCookies":
|
2015-11-13 16:35:22 +03:00
|
|
|
let [currentPath, host] = message.json;
|
2015-03-20 00:12:58 +03:00
|
|
|
let isForCurrentPath = path => currentPath.indexOf(path) != -1;
|
|
|
|
let results = [];
|
|
|
|
|
2016-05-25 06:54:21 +03:00
|
|
|
let en = cookieManager.getCookiesFromHost(host, {});
|
2015-03-20 00:12:58 +03:00
|
|
|
while (en.hasMoreElements()) {
|
2015-07-16 01:51:51 +03:00
|
|
|
let cookie = en.getNext().QueryInterface(Ci.nsICookie2);
|
2015-03-20 00:12:58 +03:00
|
|
|
// take the hostname and progressively shorten
|
|
|
|
let hostname = host;
|
|
|
|
do {
|
|
|
|
if ((cookie.host == "." + hostname || cookie.host == hostname) &&
|
|
|
|
isForCurrentPath(cookie.path)) {
|
|
|
|
results.push({
|
|
|
|
"name": cookie.name,
|
|
|
|
"value": cookie.value,
|
|
|
|
"path": cookie.path,
|
|
|
|
"host": cookie.host,
|
|
|
|
"secure": cookie.isSecure,
|
2015-07-16 01:51:51 +03:00
|
|
|
"expiry": cookie.expires,
|
2016-05-05 10:12:00 +03:00
|
|
|
"httpOnly": cookie.isHttpOnly,
|
|
|
|
"originAttributes": cookie.originAttributes
|
2015-03-20 00:12:58 +03:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hostname = hostname.replace(/^.*?\./, "");
|
|
|
|
} while (hostname.indexOf(".") != -1);
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
|
|
|
|
case "Marionette:emitTouchEvent":
|
|
|
|
globalMessageManager.broadcastAsyncMessage(
|
|
|
|
"MarionetteMainListener:emitTouchEvent", message.json);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Marionette:register":
|
|
|
|
let wid = message.json.value;
|
|
|
|
let be = message.target;
|
|
|
|
let rv = this.registerBrowser(wid, be);
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
case "Marionette:listenersAttached":
|
|
|
|
if (message.json.listenerId === this.curBrowser.curFrameId) {
|
|
|
|
// If remoteness gets updated we need to call newSession. In the case
|
|
|
|
// of desktop this just sets up a small amount of state that doesn't
|
|
|
|
// change over the course of a session.
|
2016-12-31 15:32:14 +03:00
|
|
|
this.sendAsync("newSession", this.capabilities);
|
2015-03-20 00:12:58 +03:00
|
|
|
this.curBrowser.flushPendingCommands();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
GeckoDriver.prototype.responseCompleted = function () {
|
|
|
|
if (this.curBrowser !== null) {
|
|
|
|
this.curBrowser.pendingCommands = [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-12 00:49:58 +03:00
|
|
|
/**
|
|
|
|
* Retrieve the localized string for the specified entity id.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* localizeEntity(["chrome://global/locale/about.dtd"], "about.version")
|
|
|
|
*
|
|
|
|
* @param {Array.<string>} urls
|
|
|
|
* Array of .dtd URLs.
|
|
|
|
* @param {string} id
|
|
|
|
* The ID of the entity to retrieve the localized string for.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* The localized string for the requested entity.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.localizeEntity = function (cmd, resp) {
|
2016-11-12 00:49:58 +03:00
|
|
|
let {urls, id} = cmd.parameters;
|
|
|
|
|
|
|
|
if (!Array.isArray(urls)) {
|
|
|
|
throw new InvalidArgumentError("Value of `urls` should be of type 'Array'");
|
|
|
|
}
|
|
|
|
if (typeof id != "string") {
|
|
|
|
throw new InvalidArgumentError("Value of `id` should be of type 'string'");
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.body.value = l10n.localizeEntity(urls, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the localized string for the specified property id.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* localizeProperty(["chrome://global/locale/findbar.properties"], "FastFind")
|
|
|
|
*
|
|
|
|
* @param {Array.<string>} urls
|
|
|
|
* Array of .properties URLs.
|
|
|
|
* @param {string} id
|
|
|
|
* The ID of the property to retrieve the localized string for.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* The localized string for the requested property.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.localizeProperty = function (cmd, resp) {
|
2016-11-12 00:49:58 +03:00
|
|
|
let {urls, id} = cmd.parameters;
|
|
|
|
|
|
|
|
if (!Array.isArray(urls)) {
|
|
|
|
throw new InvalidArgumentError("Value of `urls` should be of type 'Array'");
|
|
|
|
}
|
|
|
|
if (typeof id != "string") {
|
|
|
|
throw new InvalidArgumentError("Value of `id` should be of type 'string'");
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.body.value = l10n.localizeProperty(urls, id);
|
|
|
|
}
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
GeckoDriver.prototype.commands = {
|
|
|
|
"getMarionetteID": GeckoDriver.prototype.getMarionetteID,
|
|
|
|
"sayHello": GeckoDriver.prototype.sayHello,
|
|
|
|
"newSession": GeckoDriver.prototype.newSession,
|
|
|
|
"getSessionCapabilities": GeckoDriver.prototype.getSessionCapabilities,
|
|
|
|
"log": GeckoDriver.prototype.log,
|
|
|
|
"getLogs": GeckoDriver.prototype.getLogs,
|
|
|
|
"setContext": GeckoDriver.prototype.setContext,
|
|
|
|
"getContext": GeckoDriver.prototype.getContext,
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
"executeScript": GeckoDriver.prototype.executeScript,
|
2016-11-10 21:29:55 +03:00
|
|
|
"getTimeouts": GeckoDriver.prototype.getTimeouts,
|
|
|
|
"timeouts": GeckoDriver.prototype.setTimeouts, // deprecated until Firefox 55
|
|
|
|
"setTimeouts": GeckoDriver.prototype.setTimeouts,
|
2015-03-20 00:12:58 +03:00
|
|
|
"singleTap": GeckoDriver.prototype.singleTap,
|
2016-12-14 02:29:48 +03:00
|
|
|
"performActions": GeckoDriver.prototype.performActions,
|
|
|
|
"releaseActions": GeckoDriver.prototype.releaseActions,
|
2016-11-29 19:00:52 +03:00
|
|
|
"actionChain": GeckoDriver.prototype.actionChain, // deprecated
|
|
|
|
"multiAction": GeckoDriver.prototype.multiAction, // deprecated
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
"executeAsyncScript": GeckoDriver.prototype.executeAsyncScript,
|
2015-03-20 00:12:58 +03:00
|
|
|
"executeJSScript": GeckoDriver.prototype.executeJSScript,
|
|
|
|
"findElement": GeckoDriver.prototype.findElement,
|
|
|
|
"findElements": GeckoDriver.prototype.findElements,
|
|
|
|
"clickElement": GeckoDriver.prototype.clickElement,
|
|
|
|
"getElementAttribute": GeckoDriver.prototype.getElementAttribute,
|
2016-05-13 16:42:05 +03:00
|
|
|
"getElementProperty": GeckoDriver.prototype.getElementProperty,
|
2015-03-20 00:12:58 +03:00
|
|
|
"getElementText": GeckoDriver.prototype.getElementText,
|
|
|
|
"getElementTagName": GeckoDriver.prototype.getElementTagName,
|
|
|
|
"isElementDisplayed": GeckoDriver.prototype.isElementDisplayed,
|
|
|
|
"getElementValueOfCssProperty": GeckoDriver.prototype.getElementValueOfCssProperty,
|
|
|
|
"getElementRect": GeckoDriver.prototype.getElementRect,
|
|
|
|
"isElementEnabled": GeckoDriver.prototype.isElementEnabled,
|
|
|
|
"isElementSelected": GeckoDriver.prototype.isElementSelected,
|
|
|
|
"sendKeysToElement": GeckoDriver.prototype.sendKeysToElement,
|
|
|
|
"clearElement": GeckoDriver.prototype.clearElement,
|
|
|
|
"getTitle": GeckoDriver.prototype.getTitle,
|
|
|
|
"getWindowType": GeckoDriver.prototype.getWindowType,
|
|
|
|
"getPageSource": GeckoDriver.prototype.getPageSource,
|
|
|
|
"get": GeckoDriver.prototype.get,
|
|
|
|
"getCurrentUrl": GeckoDriver.prototype.getCurrentUrl,
|
|
|
|
"goBack": GeckoDriver.prototype.goBack,
|
|
|
|
"goForward": GeckoDriver.prototype.goForward,
|
|
|
|
"refresh": GeckoDriver.prototype.refresh,
|
|
|
|
"getWindowHandle": GeckoDriver.prototype.getWindowHandle,
|
|
|
|
"getChromeWindowHandle": GeckoDriver.prototype.getChromeWindowHandle,
|
|
|
|
"getCurrentChromeWindowHandle": GeckoDriver.prototype.getChromeWindowHandle,
|
|
|
|
"getWindowHandles": GeckoDriver.prototype.getWindowHandles,
|
|
|
|
"getChromeWindowHandles": GeckoDriver.prototype.getChromeWindowHandles,
|
|
|
|
"getWindowPosition": GeckoDriver.prototype.getWindowPosition,
|
|
|
|
"setWindowPosition": GeckoDriver.prototype.setWindowPosition,
|
|
|
|
"getActiveFrame": GeckoDriver.prototype.getActiveFrame,
|
|
|
|
"switchToFrame": GeckoDriver.prototype.switchToFrame,
|
2015-10-19 23:39:48 +03:00
|
|
|
"switchToParentFrame": GeckoDriver.prototype.switchToParentFrame,
|
2015-03-20 00:12:58 +03:00
|
|
|
"switchToWindow": GeckoDriver.prototype.switchToWindow,
|
2015-08-28 23:43:54 +03:00
|
|
|
"switchToShadowRoot": GeckoDriver.prototype.switchToShadowRoot,
|
2015-03-20 00:12:58 +03:00
|
|
|
"deleteSession": GeckoDriver.prototype.deleteSession,
|
|
|
|
"importScript": GeckoDriver.prototype.importScript,
|
|
|
|
"clearImportedScripts": GeckoDriver.prototype.clearImportedScripts,
|
|
|
|
"getAppCacheStatus": GeckoDriver.prototype.getAppCacheStatus,
|
|
|
|
"close": GeckoDriver.prototype.close,
|
|
|
|
"closeChromeWindow": GeckoDriver.prototype.closeChromeWindow,
|
|
|
|
"setTestName": GeckoDriver.prototype.setTestName,
|
|
|
|
"takeScreenshot": GeckoDriver.prototype.takeScreenshot,
|
|
|
|
"addCookie": GeckoDriver.prototype.addCookie,
|
|
|
|
"getCookies": GeckoDriver.prototype.getCookies,
|
|
|
|
"deleteAllCookies": GeckoDriver.prototype.deleteAllCookies,
|
|
|
|
"deleteCookie": GeckoDriver.prototype.deleteCookie,
|
|
|
|
"getActiveElement": GeckoDriver.prototype.getActiveElement,
|
|
|
|
"getScreenOrientation": GeckoDriver.prototype.getScreenOrientation,
|
|
|
|
"setScreenOrientation": GeckoDriver.prototype.setScreenOrientation,
|
|
|
|
"getWindowSize": GeckoDriver.prototype.getWindowSize,
|
|
|
|
"setWindowSize": GeckoDriver.prototype.setWindowSize,
|
|
|
|
"maximizeWindow": GeckoDriver.prototype.maximizeWindow,
|
|
|
|
"dismissDialog": GeckoDriver.prototype.dismissDialog,
|
|
|
|
"acceptDialog": GeckoDriver.prototype.acceptDialog,
|
|
|
|
"getTextFromDialog": GeckoDriver.prototype.getTextFromDialog,
|
2015-09-26 19:12:01 +03:00
|
|
|
"sendKeysToDialog": GeckoDriver.prototype.sendKeysToDialog,
|
2016-10-17 14:19:19 +03:00
|
|
|
"acceptConnections": GeckoDriver.prototype.acceptConnections,
|
2015-09-26 19:12:01 +03:00
|
|
|
"quitApplication": GeckoDriver.prototype.quitApplication,
|
2016-11-12 00:49:58 +03:00
|
|
|
|
|
|
|
"localization:l10n:localizeEntity": GeckoDriver.prototype.localizeEntity,
|
|
|
|
"localization:l10n:localizeProperty": GeckoDriver.prototype.localizeProperty,
|
2016-08-26 15:38:03 +03:00
|
|
|
|
|
|
|
"addon:install": GeckoDriver.prototype.installAddon,
|
|
|
|
"addon:uninstall": GeckoDriver.prototype.uninstallAddon,
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
2016-12-19 22:08:46 +03:00
|
|
|
|
|
|
|
function copy (obj) {
|
|
|
|
if (Array.isArray(obj)) {
|
|
|
|
return obj.slice();
|
|
|
|
} else if (typeof obj == "object") {
|
|
|
|
return Object.assign({}, obj);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
2017-01-27 11:09:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the outer window ID for the specified window.
|
|
|
|
*
|
|
|
|
* @param {nsIDOMWindow} win
|
|
|
|
* Window whose browser we need to access.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Returns the unique window ID.
|
|
|
|
*/
|
|
|
|
function getOuterWindowId(win) {
|
|
|
|
let id = win.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.outerWindowID;
|
|
|
|
|
|
|
|
return id.toString();
|
|
|
|
}
|