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";
|
2017-06-28 21:04:14 +03:00
|
|
|
/* global XPCNativeWrapper */
|
2015-03-20 00:12:58 +03:00
|
|
|
|
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");
|
|
|
|
|
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");
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
Cu.import("chrome://marionette/content/cookie.js");
|
2016-02-03 22:14:10 +03:00
|
|
|
Cu.import("chrome://marionette/content/element.js");
|
2017-06-28 21:01:49 +03:00
|
|
|
const {
|
|
|
|
ElementNotInteractableError,
|
|
|
|
error,
|
|
|
|
InsecureCertificateError,
|
|
|
|
InvalidArgumentError,
|
|
|
|
InvalidCookieDomainError,
|
|
|
|
InvalidSelectorError,
|
|
|
|
NoAlertOpenError,
|
|
|
|
NoSuchFrameError,
|
|
|
|
NoSuchWindowError,
|
|
|
|
SessionNotCreatedError,
|
|
|
|
UnknownError,
|
|
|
|
UnsupportedOperationError,
|
|
|
|
WebDriverError,
|
|
|
|
} = Cu.import("chrome://marionette/content/error.js", {});
|
2016-02-29 21:52:30 +03:00
|
|
|
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");
|
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");
|
Bug 1363428 - Add reftest-specific endpoints to Marionette, r=ato
This adds commands to start a reftest session, run a test, and end the
session. It as assumed that after you start a reftest session you will
just run reftests until you end the session. When starting a session
the user provides a string indicating when screenshots should be
taken, and an object mapping urls to a count of the number of times
that url is expected to be used in the session, to help with
caching. Running the tests takes a url to a test, an expected status,
a timeout, and a nested list of possible references, in which each
entry at a specific level is combined by OR and nested references are
combined by AND.
The implementation is heavilly inspired by the existing reftest
harness, starting a minimal window with no tabs, and loading the urls
directly in there. In order to get a screenshot in the e10s case we
have to pass the DRAW_VIEW and USE_WIDGET_LAYERS flags when taking the
screenshot.
For performance we heavily cache canvases; for references that will be
repeated we cache the full canvas with image, and we also cache a
single canvas to use for all other screenshots to avoid the overhead
of repeatedly creating a new canvas element.
MozReview-Commit-ID: JOFvtmH7tg
2017-05-10 12:51:10 +03:00
|
|
|
Cu.import("chrome://marionette/content/reftest.js");
|
2016-12-31 15:27:13 +03:00
|
|
|
Cu.import("chrome://marionette/content/session.js");
|
2016-11-22 01:43:35 +03:00
|
|
|
Cu.import("chrome://marionette/content/wait.js");
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-06-13 16:46:59 +03:00
|
|
|
Cu.importGlobalProperties(["URL"]);
|
|
|
|
|
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);
|
|
|
|
|
2017-07-26 15:11:53 +03:00
|
|
|
/**
|
|
|
|
* The Marionette WebDriver services provides a standard conforming
|
|
|
|
* implementation of the W3C WebDriver specification.
|
|
|
|
*
|
|
|
|
* @see {@link https://w3c.github.io/webdriver/webdriver-spec.html}
|
|
|
|
* @namespace driver
|
|
|
|
*/
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
// 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;
|
2017-04-14 22:51:38 +03:00
|
|
|
}, "system-message-listener-ready");
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-07-26 15:11:53 +03:00
|
|
|
/**
|
|
|
|
* @enum
|
|
|
|
* @memberof driver
|
|
|
|
*/
|
2015-03-20 00:12:58 +03:00
|
|
|
this.Context = {
|
|
|
|
CHROME: "chrome",
|
|
|
|
CONTENT: "content",
|
|
|
|
};
|
|
|
|
|
2017-07-26 15:11:53 +03:00
|
|
|
/** @memberof driver */
|
2017-06-30 02:40:24 +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;
|
|
|
|
};
|
|
|
|
|
2017-05-09 19:49:09 +03:00
|
|
|
/**
|
2017-07-26 15:11:53 +03:00
|
|
|
* Helper function for converting a {@link nsISimpleEnumerator} to a
|
|
|
|
* JavaScript iterator.
|
|
|
|
*
|
|
|
|
* @memberof driver
|
|
|
|
*
|
|
|
|
* @param {nsISimpleEnumerator} enumerator
|
|
|
|
* Enumerator to turn into iterator.
|
|
|
|
*
|
|
|
|
* @return {Iterable}
|
|
|
|
* Iterator.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
function* enumeratorIterator(enumerator) {
|
2017-05-09 19:49:09 +03:00
|
|
|
while (enumerator.hasMoreElements()) {
|
|
|
|
yield enumerator.getNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* Throughout this prototype, functions with the argument <var>cmd</var>'s
|
|
|
|
* documentation refers to the contents of the <code>cmd.parameter</code>}
|
2015-03-20 00:12:58 +03:00
|
|
|
* object.
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @class GeckoDriver
|
|
|
|
*
|
2015-03-20 00:12:58 +03:00
|
|
|
* @param {string} appName
|
2017-05-04 12:45:08 +03:00
|
|
|
* Description of the product, for example "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
|
|
|
*/
|
2017-06-30 02:40:24 +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;
|
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.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.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;
|
2017-06-27 02:55:02 +03:00
|
|
|
this.listener = proxy.toListener(() => this.mm, this.sendAsync.bind(this),
|
2017-07-29 12:03:00 +03:00
|
|
|
() => this.curBrowser);
|
2015-03-20 18:46:46 +03:00
|
|
|
|
2017-03-28 23:47:57 +03:00
|
|
|
// points to an alert instance if a modal dialog is present
|
2015-03-20 18:46:46 +03:00
|
|
|
this.dialog = null;
|
2017-03-28 23:47:57 +03:00
|
|
|
this.dialogHandler = this.globalModalDialogHandler.bind(this);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2016-12-19 22:28:17 +03:00
|
|
|
Object.defineProperty(GeckoDriver.prototype, "a11yChecks", {
|
2017-06-30 02:40:24 +03:00
|
|
|
get() {
|
2016-12-31 15:32:14 +03:00
|
|
|
return this.capabilities.get("moz:accessibilityChecks");
|
2017-06-30 02:40:24 +03:00
|
|
|
},
|
2016-12-19 22:28:17 +03:00
|
|
|
});
|
|
|
|
|
2017-06-13 16:46:59 +03:00
|
|
|
/**
|
|
|
|
* Returns the current URL of the ChromeWindow or content browser,
|
|
|
|
* depending on context.
|
|
|
|
*
|
|
|
|
* @return {URL}
|
|
|
|
* Read-only property containing the currently loaded URL.
|
|
|
|
*/
|
2017-05-31 17:49:56 +03:00
|
|
|
Object.defineProperty(GeckoDriver.prototype, "currentURL", {
|
2017-06-30 02:40:24 +03:00
|
|
|
get() {
|
2017-05-31 17:49:56 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2017-06-13 16:46:59 +03:00
|
|
|
let chromeWin = this.getCurrentWindow();
|
|
|
|
return new URL(chromeWin.location.href);
|
2017-05-31 17:49:56 +03:00
|
|
|
|
|
|
|
case Context.CONTENT:
|
2017-06-13 16:46:59 +03:00
|
|
|
return new URL(this.curBrowser.currentURI.spec);
|
2017-06-30 02:40:24 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
throw TypeError(`Unknown context: ${this.context}`);
|
2017-05-31 17:49:56 +03:00
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
},
|
2017-05-31 17:49:56 +03:00
|
|
|
});
|
|
|
|
|
2017-07-02 14:31:18 +03:00
|
|
|
Object.defineProperty(GeckoDriver.prototype, "title", {
|
|
|
|
get() {
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
let chromeWin = this.getCurrentWindow();
|
|
|
|
return chromeWin.document.documentElement.getAttribute("title");
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
|
|
|
return this.curBrowser.currentTitle;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw TypeError(`Unknown context: ${this.context}`);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
Object.defineProperty(GeckoDriver.prototype, "proxy", {
|
2017-06-30 02:40:24 +03:00
|
|
|
get() {
|
2017-01-10 18:36:49 +03:00
|
|
|
return this.capabilities.get("proxy");
|
2017-06-30 02:40:24 +03:00
|
|
|
},
|
2017-01-10 18:36:49 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(GeckoDriver.prototype, "secureTLS", {
|
2017-06-30 02:40:24 +03:00
|
|
|
get() {
|
2017-01-10 18:36:49 +03:00
|
|
|
return !this.capabilities.get("acceptInsecureCerts");
|
2017-06-30 02:40:24 +03:00
|
|
|
},
|
2017-01-10 18:36:49 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(GeckoDriver.prototype, "timeouts", {
|
2017-06-30 02:40:24 +03:00
|
|
|
get() {
|
2017-01-10 18:36:49 +03:00
|
|
|
return this.capabilities.get("timeouts");
|
|
|
|
},
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
set(newTimeouts) {
|
2017-01-10 18:36:49 +03:00
|
|
|
this.capabilities.set("timeouts", newTimeouts);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-05-09 19:49:09 +03:00
|
|
|
Object.defineProperty(GeckoDriver.prototype, "windows", {
|
2017-06-30 02:40:24 +03:00
|
|
|
get() {
|
2017-05-09 19:49:09 +03:00
|
|
|
return enumeratorIterator(Services.wm.getEnumerator(null));
|
2017-06-30 02:40:24 +03:00
|
|
|
},
|
2017-05-09 19:49:09 +03:00
|
|
|
});
|
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
Object.defineProperty(GeckoDriver.prototype, "windowHandles", {
|
2017-06-30 02:40:24 +03:00
|
|
|
get() {
|
2017-01-10 18:36:49 +03:00
|
|
|
let hs = [];
|
|
|
|
|
2017-05-09 19:49:09 +03:00
|
|
|
for (let win of this.windows) {
|
2017-01-26 18:42:35 +03:00
|
|
|
let tabBrowser = browser.getTabBrowser(win);
|
|
|
|
|
2017-06-13 19:08:44 +03:00
|
|
|
// Only return handles for browser windows
|
2017-06-09 20:28:10 +03:00
|
|
|
if (tabBrowser && tabBrowser.tabs) {
|
2017-01-26 18:42:35 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hs;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(GeckoDriver.prototype, "chromeWindowHandles", {
|
2017-06-30 02:40:24 +03:00
|
|
|
get() {
|
2017-01-10 18:36:49 +03:00
|
|
|
let hs = [];
|
|
|
|
|
2017-05-09 19:49:09 +03:00
|
|
|
for (let win of this.windows) {
|
|
|
|
hs.push(getOuterWindowId(win));
|
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
|
|
|
]);
|
|
|
|
|
2017-03-28 23:47:57 +03:00
|
|
|
/**
|
|
|
|
* Callback used to observe the creation of new modal or tab modal dialogs
|
|
|
|
* during the session's lifetime.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.globalModalDialogHandler = function(subject, topic) {
|
2017-03-28 23:47:57 +03:00
|
|
|
let winr;
|
|
|
|
if (topic === modal.COMMON_DIALOG_LOADED) {
|
|
|
|
// Always keep a weak reference to the current dialog
|
|
|
|
winr = Cu.getWeakReference(subject);
|
|
|
|
}
|
|
|
|
this.dialog = new modal.Dialog(() => this.curBrowser, winr);
|
|
|
|
};
|
|
|
|
|
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() {
|
2017-06-30 02:40:24 +03:00
|
|
|
if (this.curBrowser &&
|
|
|
|
this.curBrowser.frameManager.currentRemoteFrame !== null) {
|
2015-03-20 00:12:58 +03:00
|
|
|
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
|
2017-07-26 15:11:53 +03:00
|
|
|
* <tt>Marionette:SUFFIX</tt>.
|
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
|
|
|
*/
|
2017-06-30 02:40:24 +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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
// eslint-disable-next-line
|
|
|
|
GeckoDriver.prototype.broadcastDelayedAsyncMessage_ = function(name, payload) {
|
2016-12-19 22:08:46 +03:00
|
|
|
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?");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.sendTargettedAsyncMessage_ = function(name, payload) {
|
2016-12-19 22:08:46 +03:00
|
|
|
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-21 00:43:32 +03:00
|
|
|
* Get the session's current top-level browsing context.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* It will return the outer {@link ChromeWindow} previously selected by
|
|
|
|
* window handle through {@link #switchToWindow}, or the first window that
|
|
|
|
* was registered.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2017-03-20 17:13:32 +03:00
|
|
|
* @param {Context=} forcedContext
|
2017-06-30 02:40:24 +03:00
|
|
|
* Optional name of the context to use for finding the window.
|
|
|
|
* It will be required if a command always needs a specific context,
|
|
|
|
* whether which context is currently set. Defaults to the current
|
|
|
|
* context.
|
2017-03-20 17:13:32 +03:00
|
|
|
*
|
2017-03-21 00:43:32 +03:00
|
|
|
* @return {ChromeWindow}
|
|
|
|
* The current top-level browsing context.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getCurrentWindow = function(forcedContext = undefined) {
|
2017-03-20 17:13:32 +03:00
|
|
|
let context = typeof forcedContext == "undefined" ? this.context : forcedContext;
|
|
|
|
let win = null;
|
|
|
|
|
2017-03-21 00:43:32 +03:00
|
|
|
switch (context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
if (this.curFrame !== null) {
|
|
|
|
win = this.curFrame;
|
|
|
|
} else if (this.curBrowser !== null) {
|
2017-03-20 17:13:32 +03:00
|
|
|
win = this.curBrowser.window;
|
2017-02-03 19:49:38 +03:00
|
|
|
}
|
2017-03-21 00:43:32 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
|
|
|
if (this.curFrame !== null) {
|
|
|
|
win = this.curFrame;
|
2017-06-13 19:08:44 +03:00
|
|
|
} else if (this.curBrowser !== null && this.curBrowser.contentBrowser) {
|
2017-05-09 21:05:49 +03:00
|
|
|
win = this.curBrowser.window;
|
2017-03-20 17:13:32 +03:00
|
|
|
}
|
2017-03-21 00:43:32 +03:00
|
|
|
break;
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
2017-03-20 17:13:32 +03:00
|
|
|
|
|
|
|
return win;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.isReftestBrowser = function(element) {
|
2017-05-09 21:05:49 +03:00
|
|
|
return this._reftest &&
|
|
|
|
element &&
|
|
|
|
element.tagName === "xul:browser" &&
|
|
|
|
element.parentElement &&
|
|
|
|
element.parentElement.id === "reftest";
|
2017-06-30 02:40:24 +03:00
|
|
|
};
|
2017-05-09 21:05:49 +03:00
|
|
|
|
2017-06-30 02:40:24 +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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +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.
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {boolean=} [false] isNewSession
|
2015-03-20 00:12:58 +03:00
|
|
|
* True if this is the first time we're talking to this browser.
|
|
|
|
*/
|
2017-06-30 02:40:24 +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;
|
2017-07-04 11:27:54 +03:00
|
|
|
this.whenBrowserStarted(win, isNewSession);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +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
|
2017-06-30 02:40:24 +03:00
|
|
|
// 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.
|
|
|
|
// 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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +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.
|
2017-05-09 11:25:26 +03:00
|
|
|
this.curBrowser.frameManager.currentRemoteFrame.targetFrameId = id;
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
|
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
|
2017-07-06 19:02:19 +03:00
|
|
|
this.curBrowser.register(id, be);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
|
2017-07-06 19:02:19 +03:00
|
|
|
this.wins.set(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
|
|
|
}
|
|
|
|
|
2017-07-06 19:02:19 +03:00
|
|
|
return [id, this.capabilities.toJSON()];
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-06-30 02:40:24 +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-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.listeningPromise = function() {
|
2015-03-20 00:12:58 +03:00
|
|
|
const li = "Marionette:listenersAttached";
|
2017-07-06 19:02:19 +03:00
|
|
|
|
2016-12-19 22:08:46 +03:00
|
|
|
return new Promise(resolve => {
|
2017-07-06 19:02:19 +03:00
|
|
|
let cb = msg => {
|
|
|
|
if (msg.json.listenerId === this.curBrowser.curFrameId) {
|
|
|
|
this.mm.removeMessageListener(li, cb);
|
|
|
|
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-21 00:43:32 +03:00
|
|
|
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
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-21 00:43:32 +03:00
|
|
|
if (clickToStart) {
|
|
|
|
Services.prompt.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
|
2017-07-04 11:27:54 +03:00
|
|
|
let win = this.getCurrentWindow();
|
|
|
|
this.addBrowser(win);
|
|
|
|
this.whenBrowserStarted(win, false);
|
2017-03-07 21:38:51 +03:00
|
|
|
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) {
|
2017-03-27 12:02:36 +03:00
|
|
|
this.curBrowser.contentBrowser.focus();
|
2017-01-26 18:42:35 +03:00
|
|
|
}
|
2017-01-04 22:38:34 +03:00
|
|
|
|
2017-03-28 23:47:57 +03:00
|
|
|
// Setup global listener for modal dialogs, and check if there is already
|
|
|
|
// one open for the currently selected browser window.
|
|
|
|
modal.addHandler(this.dialogHandler);
|
|
|
|
this.dialog = modal.findModalDialogs(this.curBrowser);
|
|
|
|
|
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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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".
|
|
|
|
*/
|
2017-06-30 02:40:24 +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". */
|
2017-06-30 02:40:24 +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
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* It is important to note that if the <var>sandboxName</var> parameter
|
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
|
|
|
* 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
|
2017-07-26 15:11:53 +03:00
|
|
|
* Arguments exposed to the script in <code>arguments</code>.
|
|
|
|
* The array items must be serialisable to the WebDriver protocol.
|
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
|
|
|
* @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-07-26 15:11:53 +03:00
|
|
|
* <var>newSandbox</var> is false. If he 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
|
2017-07-26 15:11:53 +03:00
|
|
|
* Attach an <code>onerror</code> event handler on the {@link Window}
|
|
|
|
* object. It does not differentiate content errors from chrome errors.
|
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
|
|
|
* @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.
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @throws {ScriptTimeoutError}
|
|
|
|
* If the script was interrupted due to reaching the
|
|
|
|
* <var>scriptTimeout</var> or default timeout.
|
|
|
|
* @throws {JavaScriptError}
|
|
|
|
* If an {@link Error} was thrown whilst evaluating the 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
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.executeScript = function*(cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
|
|
|
|
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 = {
|
|
|
|
sandboxName: cmd.parameters.sandbox,
|
|
|
|
newSandbox: !!(typeof cmd.parameters.newSandbox == "undefined") ||
|
|
|
|
cmd.parameters.newSandbox,
|
2017-07-26 15:11:53 +03:00
|
|
|
file: cmd.parameters.filename,
|
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
|
|
|
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.
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* The callback is always the last argument to the <var>arguments</var>
|
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
|
|
|
* list passed to the function scope of the script. It can be retrieved
|
|
|
|
* as such:
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* <pre><code>
|
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 callback = arguments[arguments.length - 1];
|
|
|
|
* callback("foo");
|
|
|
|
* // "foo" is returned
|
2017-07-26 15:11:53 +03:00
|
|
|
* </code></pre>
|
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
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* It is important to note that if the <var>sandboxName</var> parameter
|
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
|
|
|
* 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
|
2017-07-26 15:11:53 +03:00
|
|
|
* Arguments exposed to the script in <code>arguments</code>.
|
|
|
|
* The array items must be serialisable to the WebDriver protocol.
|
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
|
|
|
* @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-07-26 15:11:53 +03:00
|
|
|
* <var>newSandbox</var> 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
|
2017-07-26 15:11:53 +03:00
|
|
|
* Attach an <code>onerror</code> event handler on the {@link Window}
|
|
|
|
* object. It does not differentiate content errors from chrome errors.
|
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
|
|
|
* @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.
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @throws {ScriptTimeoutError}
|
|
|
|
* If the script was interrupted due to reaching the
|
|
|
|
* <var>scriptTimeout</var> or default timeout.
|
|
|
|
* @throws {JavaScriptError}
|
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 an Error was thrown whilst evaluating the script.
|
|
|
|
*/
|
2016-12-15 10:54:46 +03:00
|
|
|
GeckoDriver.prototype.executeAsyncScript = function* (cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
|
|
|
|
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,
|
2017-07-26 15:11:53 +03:00
|
|
|
file: cmd.parameters.filename,
|
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
|
|
|
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
|
|
|
|
2017-06-30 02:40:24 +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) {
|
2017-06-07 14:46:14 +03:00
|
|
|
return this.listener.execute(script, args, timeout, opts)
|
|
|
|
.then(evaluate.toJSON);
|
2017-06-30 02:40:24 +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
|
|
|
|
|
|
|
// evaluate in content with sandbox
|
2017-06-30 02:40:24 +03:00
|
|
|
return this.listener.executeInSandbox(script, args, timeout, opts)
|
|
|
|
.then(evaluate.toJSON);
|
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);
|
|
|
|
opts.timeout = timeout;
|
2017-05-08 19:05:20 +03:00
|
|
|
let wargs = evaluate.fromJSON(args, this.curBrowser.seenEls, sb.window);
|
2017-06-07 14:46:14 +03:00
|
|
|
return evaluate.sandbox(sb, script, wargs, opts)
|
|
|
|
.then(res => evaluate.toJSON(res, this.curBrowser.seenEls));
|
2017-06-30 02:40:24 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
throw new TypeError(`Unknown context: ${this.context}`);
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-03-28 22:41:38 +03:00
|
|
|
GeckoDriver.prototype.get = function* (cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context);
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2016-12-29 16:04:16 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let url = cmd.parameters.url;
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
let get = this.listener.get({url, pageTimeout: this.timeouts.pageLoad});
|
2016-12-29 16:04:16 +03:00
|
|
|
|
2017-07-06 19:02:19 +03:00
|
|
|
// If a reload of the frame script interrupts our page load, this will
|
|
|
|
// never return. We need to re-issue this request to correctly poll for
|
|
|
|
// readyState and send errors.
|
2016-12-29 16:04:16 +03:00
|
|
|
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(
|
2017-03-28 22:41:38 +03:00
|
|
|
"Marionette:waitForPageLoaded" + 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-03-27 12:02:36 +03:00
|
|
|
|
|
|
|
this.curBrowser.contentBrowser.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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getCurrentUrl = function(cmd) {
|
2017-05-31 17:49:56 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2017-06-13 16:46:59 +03:00
|
|
|
return this.currentURL.toString();
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
/**
|
|
|
|
* Gets the current title of the window.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Document title of the top-level browsing context.
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getTitle = function* (cmd, resp) {
|
2017-07-02 14:31:18 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2017-07-02 14:31:18 +03:00
|
|
|
return this.title;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Gets the current type of the window. */
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getWindowType = function(cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
let win = assert.window(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
|
|
|
};
|
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
/**
|
|
|
|
* Gets the page source of the content document.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* String serialisation of the DOM of the current browsing context's
|
|
|
|
* active document.
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.getPageSource = function* (cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-06 16:14:21 +03:00
|
|
|
/**
|
|
|
|
* Cause the browser to traverse one step backward in the joint history
|
|
|
|
* of the current browsing context.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2017-03-06 16:14:21 +03:00
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.goBack = function* (cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context);
|
2017-05-31 17:49:56 +03:00
|
|
|
assert.contentBrowser(this.curBrowser);
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2016-12-29 16:04:16 +03:00
|
|
|
|
2017-05-31 17:49:56 +03:00
|
|
|
// If there is no history, just return
|
2017-03-27 12:02:36 +03:00
|
|
|
if (!this.curBrowser.contentBrowser.webNavigation.canGoBack) {
|
2017-03-06 16:14:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-13 16:46:59 +03:00
|
|
|
let lastURL = this.currentURL;
|
2017-03-06 16:14:21 +03:00
|
|
|
let goBack = this.listener.goBack({pageTimeout: this.timeouts.pageLoad});
|
|
|
|
|
2017-07-06 19:02:19 +03:00
|
|
|
// If a reload of the frame script interrupts our page load, this will
|
|
|
|
// never return. We need to re-issue this request to correctly poll for
|
|
|
|
// readyState and send errors.
|
2017-03-06 16:14:21 +03:00
|
|
|
this.curBrowser.pendingCommands.push(() => {
|
|
|
|
let parameters = {
|
|
|
|
// TODO(ato): Bug 1242595
|
|
|
|
command_id: this.listener.activeMessageId,
|
2017-06-13 16:46:59 +03:00
|
|
|
lastSeenURL: lastURL.toString(),
|
2017-03-06 16:14:21 +03:00
|
|
|
pageTimeout: this.timeouts.pageLoad,
|
|
|
|
startTime: new Date().getTime(),
|
|
|
|
};
|
|
|
|
this.mm.broadcastAsyncMessage(
|
2017-03-28 22:41:38 +03:00
|
|
|
"Marionette:waitForPageLoaded" + this.curBrowser.curFrameId,
|
2017-03-06 16:14:21 +03:00
|
|
|
parameters);
|
|
|
|
});
|
|
|
|
|
|
|
|
yield goBack;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-03-06 16:14:21 +03:00
|
|
|
/**
|
|
|
|
* Cause the browser to traverse one step forward in the joint history
|
|
|
|
* of the current browsing context.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2017-03-06 16:14:21 +03:00
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.goForward = function* (cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context);
|
2017-05-31 17:49:56 +03:00
|
|
|
assert.contentBrowser(this.curBrowser);
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2016-12-29 16:04:16 +03:00
|
|
|
|
2017-05-31 17:49:56 +03:00
|
|
|
// If there is no history, just return
|
2017-03-27 12:02:36 +03:00
|
|
|
if (!this.curBrowser.contentBrowser.webNavigation.canGoForward) {
|
2017-03-06 16:14:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-13 16:46:59 +03:00
|
|
|
let lastURL = this.currentURL;
|
2017-06-30 02:40:24 +03:00
|
|
|
let goForward = this.listener.goForward(
|
|
|
|
{pageTimeout: this.timeouts.pageLoad});
|
2017-03-06 16:14:21 +03:00
|
|
|
|
2017-07-06 19:02:19 +03:00
|
|
|
// If a reload of the frame script interrupts our page load, this will
|
|
|
|
// never return. We need to re-issue this request to correctly poll for
|
|
|
|
// readyState and send errors.
|
2017-03-06 16:14:21 +03:00
|
|
|
this.curBrowser.pendingCommands.push(() => {
|
|
|
|
let parameters = {
|
|
|
|
// TODO(ato): Bug 1242595
|
|
|
|
command_id: this.listener.activeMessageId,
|
2017-06-13 16:46:59 +03:00
|
|
|
lastSeenURL: lastURL.toString(),
|
2017-03-06 16:14:21 +03:00
|
|
|
pageTimeout: this.timeouts.pageLoad,
|
|
|
|
startTime: new Date().getTime(),
|
|
|
|
};
|
|
|
|
this.mm.broadcastAsyncMessage(
|
2017-03-28 22:41:38 +03:00
|
|
|
"Marionette:waitForPageLoaded" + this.curBrowser.curFrameId,
|
2017-03-06 16:14:21 +03:00
|
|
|
parameters);
|
|
|
|
});
|
|
|
|
|
|
|
|
yield goForward;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-03-27 17:16:36 +03:00
|
|
|
/**
|
2017-04-20 20:00:46 +03:00
|
|
|
* Causes the browser to reload the page in current top-level browsing
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2017-03-27 17:16:36 +03:00
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.refresh = function* (cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.content(this.context);
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2016-12-29 16:04:16 +03:00
|
|
|
|
2017-07-06 19:02:19 +03:00
|
|
|
let refresh = this.listener.refresh(
|
2017-07-29 12:03:00 +03:00
|
|
|
{pageTimeout: this.timeouts.pageLoad});
|
2017-07-06 19:02:19 +03:00
|
|
|
|
|
|
|
// If a reload of the frame script 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(() => {
|
|
|
|
let parameters = {
|
|
|
|
// TODO(ato): Bug 1242595
|
|
|
|
command_id: this.listener.activeMessageId,
|
|
|
|
pageTimeout: this.timeouts.pageLoad,
|
|
|
|
startTime: new Date().getTime(),
|
|
|
|
};
|
|
|
|
this.mm.broadcastAsyncMessage(
|
|
|
|
"Marionette:waitForPageLoaded" + this.curBrowser.curFrameId,
|
|
|
|
parameters);
|
|
|
|
});
|
|
|
|
|
|
|
|
yield refresh;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forces an update for the given browser's id.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.updateIdForBrowser = function(browser, newId) {
|
2015-03-20 00:12:58 +03:00
|
|
|
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-06-30 02:40:24 +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) {
|
|
|
|
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.
|
2017-06-13 19:08:44 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
2017-01-10 18:36:49 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getWindowHandle = function(cmd, resp) {
|
2017-06-13 19:08:44 +03:00
|
|
|
assert.contentBrowser(this.curBrowser);
|
2017-01-10 18:36:49 +03:00
|
|
|
|
2017-06-13 19:08:44 +03:00
|
|
|
return this.curBrowser.curFrameId.toString();
|
2017-01-10 18:36:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of top-level browsing contexts. On desktop this typically
|
2017-06-30 02:40:24 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getWindowHandles = function(cmd, resp) {
|
2017-05-05 23:21:51 +03:00
|
|
|
return this.windowHandles.map(String);
|
2017-07-29 12:03:00 +03:00
|
|
|
};
|
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.
|
2017-06-13 19:08:44 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getChromeWindowHandle = function(cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow(Context.CHROME));
|
|
|
|
|
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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getChromeWindowHandles = function(cmd, resp) {
|
2017-05-05 23:21:51 +03:00
|
|
|
return this.chromeWindowHandles.map(String);
|
2017-07-29 12:03:00 +03:00
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
/**
|
2017-03-24 16:54:37 +03:00
|
|
|
* Get the current position and 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.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
|
|
|
* @return {Object.<string, number>}
|
2017-03-24 16:54:37 +03:00
|
|
|
* Object with |x| and |y| coordinates, and |width| and |height|
|
|
|
|
* of browser window.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getWindowRect = function(cmd, resp) {
|
2017-07-09 19:15:28 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
return this.curBrowser.rect;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-04-20 20:00:46 +03:00
|
|
|
* Set the window position and size of the browser on the operating
|
|
|
|
* system window manager.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2017-04-20 20:00:46 +03:00
|
|
|
* The supplied |width| and |height| values refer to the window outerWidth
|
2017-03-24 17:35:38 +03:00
|
|
|
* and outerHeight values, which include browser chrome and OS-level
|
|
|
|
* window borders.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
2015-03-20 00:12:58 +03:00
|
|
|
* @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.
|
2017-04-20 20:00:46 +03:00
|
|
|
* @param {number} width
|
|
|
|
* Width to resize the window to.
|
|
|
|
* @param {number} height
|
|
|
|
* Height to resize the window to.
|
2016-10-06 15:11:31 +03:00
|
|
|
*
|
|
|
|
* @return {Object.<string, number>}
|
2017-04-20 20:00:46 +03:00
|
|
|
* Object with |x| and |y| coordinates and |width| and |height|
|
|
|
|
* dimensions.
|
2017-03-24 17:35:38 +03:00
|
|
|
*
|
2017-04-20 20:00:46 +03:00
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not applicable to application.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.setWindowRect = async function(cmd, resp) {
|
2017-07-29 12:03:00 +03:00
|
|
|
assert.firefox();
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-04-19 23:19:36 +03:00
|
|
|
let {x, y, width, height} = cmd.parameters;
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
let origRect = this.curBrowser.rect;
|
2017-03-24 17:35:38 +03:00
|
|
|
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
// Throttle resize event by forcing the event queue to flush and delay
|
|
|
|
// until the main thread is idle.
|
2017-06-30 02:40:24 +03:00
|
|
|
function optimisedResize(resolve) {
|
2017-06-22 11:16:08 +03:00
|
|
|
return () => Services.tm.idleDispatchToMainThread(() => {
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
win.requestAnimationFrame(resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit fullscreen and wait for window to resize.
|
2017-06-30 02:40:24 +03:00
|
|
|
async function exitFullscreen() {
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
return new Promise(resolve => {
|
2017-06-12 15:52:53 +03:00
|
|
|
win.addEventListener("sizemodechange", optimisedResize(resolve), {once: true});
|
2017-05-27 00:14:14 +03:00
|
|
|
win.fullScreen = false;
|
|
|
|
});
|
2017-05-22 23:54:26 +03:00
|
|
|
}
|
|
|
|
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
// Synchronous resize to |width| and |height| dimensions.
|
2017-06-30 02:40:24 +03:00
|
|
|
async function resizeWindow(width, height) {
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
return new Promise(resolve => {
|
|
|
|
win.addEventListener("resize", optimisedResize(resolve), {once: true});
|
|
|
|
win.resizeTo(width, height);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait until window size has changed. We can't wait for the
|
|
|
|
// user-requested window size as this may not be achievable on the
|
|
|
|
// current system.
|
|
|
|
const windowResizeChange = async () => {
|
|
|
|
return wait.until((resolve, reject) => {
|
|
|
|
let curRect = this.curBrowser.rect;
|
|
|
|
if (curRect.width != origRect.width &&
|
|
|
|
curRect.height != origRect.height) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Wait for the window position to change.
|
2017-06-30 02:40:24 +03:00
|
|
|
async function windowPosition(x, y) {
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
return wait.until((resolve, reject) => {
|
|
|
|
if ((x == win.screenX && y == win.screenY) ||
|
|
|
|
(win.screenX != origRect.x || win.screenY != origRect.y)) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (win.windowState == win.STATE_FULLSCREEN) {
|
|
|
|
await exitFullscreen();
|
|
|
|
}
|
|
|
|
|
2017-03-24 17:35:38 +03:00
|
|
|
if (height != null && width != null) {
|
|
|
|
assert.positiveInteger(height);
|
|
|
|
assert.positiveInteger(width);
|
2017-04-19 23:19:36 +03:00
|
|
|
|
2017-06-12 15:52:53 +03:00
|
|
|
if (win.outerWidth != width || win.outerHeight != height) {
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
await resizeWindow(width, height);
|
|
|
|
await windowResizeChange();
|
2017-04-19 23:19:36 +03:00
|
|
|
}
|
2017-03-24 17:35:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (x != null && y != null) {
|
|
|
|
assert.integer(x);
|
|
|
|
assert.integer(y);
|
2017-04-19 23:19:36 +03:00
|
|
|
|
2017-03-24 17:35:38 +03:00
|
|
|
win.moveTo(x, y);
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
await windowPosition(x, y);
|
2017-03-24 17:35:38 +03:00
|
|
|
}
|
2016-11-22 01:43:35 +03:00
|
|
|
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
return this.curBrowser.rect;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-06-30 02:40:24 +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.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
|
|
|
* @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) {
|
2017-06-30 02:40:24 +03:00
|
|
|
let focus = true;
|
|
|
|
if (typeof cmd.parameters.focus != "undefined") {
|
|
|
|
focus = cmd.parameters.focus;
|
|
|
|
}
|
2017-05-09 11:25:26 +03:00
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
// Window IDs are internally handled as numbers, but here it could
|
|
|
|
// also be the name of the window.
|
2017-05-09 11:25:26 +03:00
|
|
|
let switchTo = parseInt(cmd.parameters.name);
|
|
|
|
if (isNaN(switchTo)) {
|
|
|
|
switchTo = cmd.parameters.name;
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
let byNameOrId = function(win, windowId) {
|
2017-05-09 20:59:09 +03:00
|
|
|
return switchTo === win.name || switchTo === windowId;
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-05-09 20:59:09 +03:00
|
|
|
let found = this.findWindow(this.windows, byNameOrId);
|
|
|
|
|
|
|
|
if (found) {
|
2017-06-30 02:40:24 +03:00
|
|
|
yield this.setWindowHandle(found, focus);
|
2017-05-09 20:59:09 +03:00
|
|
|
} else {
|
|
|
|
throw new NoSuchWindowError(`Unable to locate window: ${switchTo}`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find a specific window according to some filter function.
|
|
|
|
*
|
|
|
|
* @param {Iterable.<Window>} winIterable
|
|
|
|
* Iterable that emits Windows.
|
|
|
|
* @param {function(Window, number): boolean} filter
|
|
|
|
* A callback function taking two arguments; the window and
|
|
|
|
* the outerId of the window, and returning a boolean indicating
|
|
|
|
* whether the window is the target.
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
* A window handle object containing the window and some
|
|
|
|
* associated metadata.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.findWindow = function(winIterable, filter) {
|
2017-05-09 20:59:09 +03:00
|
|
|
for (let win of winIterable) {
|
2015-03-20 00:12:58 +03:00
|
|
|
let outerId = getOuterWindowId(win);
|
2017-02-05 17:55:10 +03:00
|
|
|
let tabBrowser = browser.getTabBrowser(win);
|
2017-06-30 02:40:24 +03:00
|
|
|
|
|
|
|
// In case the wanted window is a chrome window, we are done.
|
2017-05-09 20:59:09 +03:00
|
|
|
if (filter(win, outerId)) {
|
2017-06-30 02:40:24 +03:00
|
|
|
return {win, outerId, hasTabBrowser: !!tabBrowser};
|
|
|
|
|
|
|
|
// Otherwise check if the chrome window has a tab browser, and that it
|
|
|
|
// contains a tab with the wanted window handle.
|
2017-06-09 20:28:10 +03:00
|
|
|
} else if (tabBrowser && tabBrowser.tabs) {
|
2017-02-05 17:55:10 +03:00
|
|
|
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-05-09 20:59:09 +03:00
|
|
|
if (filter(win, contentWindowId)) {
|
|
|
|
return {
|
2017-06-30 02:40:24 +03:00
|
|
|
win,
|
|
|
|
outerId,
|
2017-02-05 17:55:10 +03:00
|
|
|
hasTabBrowser: true,
|
2015-03-20 00:12:58 +03:00
|
|
|
tabIndex: i,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
|
2017-05-09 20:59:09 +03:00
|
|
|
return null;
|
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-05-09 20:59:09 +03:00
|
|
|
/**
|
|
|
|
* Switch the marionette window to a given window. If the browser in
|
|
|
|
* the window is unregistered, registers that browser and waits for
|
|
|
|
* the registration is complete. If |focus| is true then set the focus
|
|
|
|
* on the window.
|
|
|
|
*
|
|
|
|
* @param {Object} winProperties
|
|
|
|
* Object containing window properties such as returned from
|
|
|
|
* GeckoDriver#findWindow
|
|
|
|
* @param {boolean=} focus
|
|
|
|
* A boolean value which determines whether to focus the window.
|
|
|
|
* Defaults to true.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.setWindowHandle = function* (
|
|
|
|
winProperties, focus = true) {
|
2017-05-09 20:59:09 +03:00
|
|
|
if (!(winProperties.outerId in this.browsers)) {
|
|
|
|
// Initialise Marionette if the current chrome window has not been seen
|
|
|
|
// before. Also register the initial tab, if one exists.
|
|
|
|
let registerBrowsers, browserListening;
|
|
|
|
|
|
|
|
if (winProperties.hasTabBrowser) {
|
|
|
|
registerBrowsers = this.registerPromise();
|
|
|
|
browserListening = this.listeningPromise();
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-05-09 20:59:09 +03:00
|
|
|
this.startBrowser(winProperties.win, false /* isNewSession */);
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-05-09 20:59:09 +03:00
|
|
|
if (registerBrowsers && browserListening) {
|
|
|
|
yield registerBrowsers;
|
|
|
|
yield browserListening;
|
|
|
|
}
|
2017-02-05 17:55:10 +03:00
|
|
|
|
2017-05-09 20:59:09 +03:00
|
|
|
} else {
|
|
|
|
// Otherwise switch to the known chrome window, and activate the tab
|
|
|
|
// if it's a content browser.
|
|
|
|
this.curBrowser = this.browsers[winProperties.outerId];
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-05-09 20:59:09 +03:00
|
|
|
if ("tabIndex" in winProperties) {
|
2017-06-30 02:40:24 +03:00
|
|
|
this.curBrowser.switchToTab(
|
|
|
|
winProperties.tabIndex, winProperties.win, focus);
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getActiveFrame = function(cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
/**
|
|
|
|
* Set the current browsing context for future commands to the parent
|
|
|
|
* of the current browsing context.
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.switchToParentFrame = function* (cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
yield this.listener.switchToParentFrame();
|
2015-10-19 23:39:48 +03:00
|
|
|
};
|
|
|
|
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-12-04 14:42:52 +03:00
|
|
|
GeckoDriver.prototype.switchToFrame = function* (cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
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") {
|
2017-07-07 16:36:08 +03:00
|
|
|
let documentURI = win.document.documentURI;
|
|
|
|
if (documentURI.startsWith("about:certerror")) {
|
2016-11-06 21:01:23 +03:00
|
|
|
throw new InsecureCertificateError();
|
2017-07-07 16:36:08 +03:00
|
|
|
} else if (otherErrorsExpr.exec(documentURI)) {
|
|
|
|
throw new UnknownError("Reached error page: " + documentURI);
|
2016-11-06 21:01:23 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
checkTimer.initWithCallback(
|
|
|
|
checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if (this.context == Context.CHROME) {
|
|
|
|
let foundFrame = null;
|
2015-04-24 15:55:52 +03:00
|
|
|
|
2017-06-30 02:40:24 +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();
|
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
checkTimer.initWithCallback(
|
|
|
|
checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
2015-03-20 00:12:58 +03:00
|
|
|
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
|
2017-06-30 02:40:24 +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
|
2017-06-30 02:40:24 +03:00
|
|
|
if (wantedFrame.tagName == "xul:browser" ||
|
|
|
|
wantedFrame.tagName == "browser") {
|
2016-05-20 17:07:21 +03:00
|
|
|
curWindow = wantedFrame.contentWindow;
|
|
|
|
this.curFrame = curWindow;
|
|
|
|
if (focus) {
|
|
|
|
this.curFrame.focus();
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
checkTimer.initWithCallback(
|
|
|
|
checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
2016-05-20 17:07:21 +03:00
|
|
|
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);
|
2017-06-30 02:40:24 +03:00
|
|
|
// Shadow nodes also show up in getAnonymousNodes, we should
|
|
|
|
// ignore them.
|
|
|
|
if (parent &&
|
|
|
|
!(parent.shadowRoot && parent.shadowRoot.contains(wantedFrame))) {
|
|
|
|
const doc = curWindow.document;
|
|
|
|
let anonNodes = [...doc.getAnonymousNodes(parent) || []];
|
2016-05-20 17:07:21 +03:00
|
|
|
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
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
checkTimer.initWithCallback(
|
|
|
|
checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
2016-05-20 17:07:21 +03:00
|
|
|
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++) {
|
2017-06-30 02:40:24 +03:00
|
|
|
let wrappedEl = new XPCNativeWrapper(frames[i]);
|
|
|
|
let wrappedWanted = new XPCNativeWrapper(wantedFrame);
|
|
|
|
if (wrappedEl == wrappedWanted) {
|
2016-05-20 17:07:21 +03:00
|
|
|
curWindow = frames[i].contentWindow;
|
|
|
|
this.curFrame = curWindow;
|
|
|
|
if (focus) {
|
|
|
|
this.curFrame.focus();
|
2015-11-09 20:48:31 +03:00
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
checkTimer.initWithCallback(
|
|
|
|
checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
2016-05-20 17:07:21 +03:00
|
|
|
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++) {
|
2017-06-30 02:40:24 +03:00
|
|
|
// give precedence to name
|
2015-11-09 20:48:31 +03:00
|
|
|
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;
|
2017-06-30 02:40:24 +03:00
|
|
|
let frameEl = curWindow.frames[foundFrame].frameElement;
|
|
|
|
curWindow = frameEl.contentWindow;
|
2015-11-09 20:48:31 +03:00
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
checkTimer.initWithCallback(
|
|
|
|
checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
|
2015-03-20 00:12:58 +03:00
|
|
|
} 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) {
|
2017-06-30 02:40:24 +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.
|
2015-03-20 00:12:58 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-30 02:40:24 +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
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.setTimeouts = function(cmd, resp) {
|
2016-12-31 15:27:13 +03:00
|
|
|
// merge with existing timeouts
|
2017-06-22 12:42:55 +03:00
|
|
|
let merged = Object.assign(this.timeouts.toJSON(), cmd.parameters);
|
2016-12-31 15:27:13 +03:00
|
|
|
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) {
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
|
|
|
|
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}
|
2017-04-20 20:00:46 +03:00
|
|
|
* Not yet available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2016-12-14 02:29:48 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.performActions = function* (cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.content(this.context,
|
|
|
|
"Command 'performActions' is not yet available in chrome context");
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
let actions = cmd.parameters.actions;
|
|
|
|
yield this.listener.performActions({"actions": actions});
|
2016-12-14 02:29:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release all the keys and pointer buttons that are currently depressed.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2016-12-14 02:29:48 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.releaseActions = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.content(this.context);
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
yield 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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not applicable to application.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2016-02-06 21:19:02 +03:00
|
|
|
GeckoDriver.prototype.actionChain = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
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-20 17:13:32 +03:00
|
|
|
assert.firefox();
|
2015-03-24 18:35:58 +03:00
|
|
|
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-04-20 20:00:46 +03:00
|
|
|
GeckoDriver.prototype.multiAction = function* (cmd, resp) {
|
|
|
|
assert.content(this.context);
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
let {value, max_length} = cmd.parameters;
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
this.addFrameCloseListener("multi action chain");
|
|
|
|
yield this.listener.multiAction(value, max_length);
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-04-20 20:00:46 +03:00
|
|
|
GeckoDriver.prototype.findElement = function* (cmd, resp) {
|
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
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-20 17:13:32 +03:00
|
|
|
let container = {frame: win};
|
2016-05-20 15:28:27 +03:00
|
|
|
if (opts.startNode) {
|
2017-06-30 02:40:24 +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) {
|
2017-03-20 17:13:32 +03:00
|
|
|
let win = assert.window(this.getCurrentWindow());
|
|
|
|
|
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-20 17:13:32 +03:00
|
|
|
let container = {frame: win};
|
2016-05-20 15:28:27 +03:00
|
|
|
if (opts.startNode) {
|
2017-06-30 02:40:24 +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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
/**
|
|
|
|
* Return the active element on the page.
|
|
|
|
*
|
|
|
|
* @return {WebElement}
|
|
|
|
* Active element of the current browsing context's document element.
|
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.getActiveElement = function* (cmd, resp) {
|
|
|
|
assert.content(this.context);
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
resp.body.value = yield this.listener.getActiveElement();
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-08-04 17:45:02 +03:00
|
|
|
GeckoDriver.prototype.clickElement = async function (cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
2016-05-20 18:49:19 +03:00
|
|
|
let el = this.curBrowser.seenEls.get(id, {frame: win});
|
2017-08-04 17:45:02 +03:00
|
|
|
await interaction.clickElement(el, this.a11yChecks);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
2017-06-30 02:40:24 +03:00
|
|
|
// We need to protect against the click causing an OOP frame
|
|
|
|
// to close. This fires the mozbrowserclose event when it closes
|
|
|
|
// so we need to listen for it and then just send an error back.
|
|
|
|
// The person making the call should be aware something is not right
|
|
|
|
// and handle accordingly.
|
2015-03-20 00:12:58 +03:00
|
|
|
this.addFrameCloseListener("click");
|
2017-04-20 13:12:27 +03:00
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
let click = this.listener.clickElement(
|
|
|
|
{id, pageTimeout: this.timeouts.pageLoad});
|
2017-04-20 13:12:27 +03:00
|
|
|
|
2017-07-06 19:02:19 +03:00
|
|
|
// If a reload of the frame script interrupts our page load, this will
|
|
|
|
// never return. We need to re-issue this request to correctly poll for
|
|
|
|
// readyState and send errors.
|
2017-04-20 13:12:27 +03:00
|
|
|
this.curBrowser.pendingCommands.push(() => {
|
|
|
|
let parameters = {
|
|
|
|
// TODO(ato): Bug 1242595
|
|
|
|
command_id: this.listener.activeMessageId,
|
|
|
|
pageTimeout: this.timeouts.pageLoad,
|
|
|
|
startTime: new Date().getTime(),
|
|
|
|
};
|
|
|
|
this.mm.broadcastAsyncMessage(
|
|
|
|
"Marionette:waitForPageLoaded" + this.curBrowser.curFrameId,
|
|
|
|
parameters);
|
|
|
|
});
|
|
|
|
|
2017-08-04 17:45:02 +03:00
|
|
|
await click;
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getElementAttribute = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let {id, name} = cmd.parameters;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2016-05-13 16:42:05 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getElementProperty = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2016-05-13 16:42:05 +03:00
|
|
|
let {id, name} = cmd.parameters;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Element's text "as rendered".
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getElementText = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
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
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Local tag name of element.
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getElementTagName = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
* True if displayed, false otherwise.
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.isElementDisplayed = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Value of |propertyName|.
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getElementValueOfCssProperty = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let {id, propertyName: prop} = cmd.parameters;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
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:
|
2017-06-30 02:40:24 +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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
* True if enabled, false if disabled.
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.isElementEnabled = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
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
|
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;
|
|
|
|
}
|
2017-04-20 20:00:46 +03:00
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if element is selected.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be checked.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
* True if selected, false if unselected.
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.isElementSelected = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
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
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
/**
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getElementRect = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let id = cmd.parameters.id;
|
|
|
|
|
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
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,
|
2017-06-30 02:40:24 +03:00
|
|
|
height: rect.height,
|
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 = 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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.sendKeysToElement = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
|
|
|
|
2017-03-25 00:37:43 +03:00
|
|
|
let {id, text} = cmd.parameters;
|
|
|
|
assert.string(text);
|
2015-04-02 17:16:00 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
switch (this.context) {
|
|
|
|
case Context.CHROME:
|
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(
|
2017-03-25 00:37:43 +03:00
|
|
|
el, text, true, this.a11yChecks);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Context.CONTENT:
|
2017-03-25 00:37:43 +03:00
|
|
|
yield this.listener.sendKeysToElement(id, text);
|
2015-03-20 00:12:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the text of an element.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Reference ID to the element that will be cleared.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.clearElement = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
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
|
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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.switchToShadowRoot = function*(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.content(this.context);
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2016-12-29 16:04:16 +03:00
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
let id = cmd.parameters.id;
|
2015-08-28 23:43:54 +03:00
|
|
|
yield this.listener.switchToShadowRoot(id);
|
|
|
|
};
|
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
/**
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
* Add a single cookie to the cookie store associated with the active
|
|
|
|
* document's address.
|
|
|
|
*
|
|
|
|
* @param {Map.<string, (string|number|boolean)> cookie
|
|
|
|
* Cookie object.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
* @throws {InvalidCookieDomainError}
|
2017-07-26 15:11:53 +03:00
|
|
|
* If <var>cookie</var> is for a different domain than the active
|
|
|
|
* document's host.
|
2017-04-20 20:00:46 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.addCookie = function(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.content(this.context);
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2016-12-29 16:04:16 +03:00
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
let {protocol, hostname} = this.currentURL;
|
|
|
|
|
|
|
|
const networkSchemes = ["ftp:", "http:", "https:"];
|
|
|
|
if (!networkSchemes.includes(protocol)) {
|
|
|
|
throw new InvalidCookieDomainError("Document is cookie-averse");
|
|
|
|
}
|
2016-12-29 16:04:16 +03:00
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
let newCookie = cookie.fromJSON(cmd.parameters.cookie);
|
|
|
|
if (typeof newCookie.domain == "undefined") {
|
|
|
|
newCookie.domain = hostname;
|
|
|
|
}
|
|
|
|
|
|
|
|
cookie.add(newCookie, {restrictToHost: hostname});
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the cookies for the current domain.
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* This is the equivalent of calling <code>document.cookie</code> and
|
|
|
|
* parsing the result.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getCookies = function(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.content(this.context);
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2016-12-29 16:04:16 +03:00
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
let {hostname, pathname} = this.currentURL;
|
|
|
|
resp.body = [...cookie.iter(hostname, pathname)];
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
/**
|
|
|
|
* Delete all cookies that are visible to a document.
|
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.deleteAllCookies = function(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.content(this.context);
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2016-12-29 16:04:16 +03:00
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
let {hostname, pathname} = this.currentURL;
|
|
|
|
for (let toDelete of cookie.iter(hostname, pathname)) {
|
|
|
|
cookie.remove(toDelete);
|
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
/**
|
|
|
|
* Delete a cookie by name.
|
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available in current context.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.deleteCookie = function(cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.content(this.context);
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2016-12-29 16:04:16 +03:00
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
let {hostname, pathname} = this.currentURL;
|
|
|
|
let candidateName = assert.string(cmd.parameters.name);
|
|
|
|
for (let toDelete of cookie.iter(hostname, pathname)) {
|
|
|
|
if (toDelete.name === candidateName) {
|
|
|
|
return cookie.remove(toDelete);
|
|
|
|
}
|
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
|
|
|
|
throw UnknownError("Unable to find cookie");
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-01-10 18:36:49 +03:00
|
|
|
* Close the currently selected tab/window.
|
|
|
|
*
|
2017-04-20 20:00:46 +03:00
|
|
|
* 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.
|
2017-04-20 20:00:46 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.close = function(cmd, resp) {
|
2017-06-13 19:08:44 +03:00
|
|
|
assert.contentBrowser(this.curBrowser);
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.noUserPrompt(this.dialog);
|
2017-03-20 17:13:32 +03:00
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
let nwins = 0;
|
2017-03-01 14:49:21 +03:00
|
|
|
|
2017-05-09 19:49:09 +03:00
|
|
|
for (let win of this.windows) {
|
|
|
|
// For browser windows count the tabs. Otherwise take the window itself.
|
2017-01-26 18:42:35 +03:00
|
|
|
let tabbrowser = browser.getTabBrowser(win);
|
2017-06-09 20:28:10 +03:00
|
|
|
if (tabbrowser && tabbrowser.tabs) {
|
2017-01-26 18:42:35 +03:00
|
|
|
nwins += tabbrowser.tabs.length;
|
2017-06-09 20:28:10 +03:00
|
|
|
} else {
|
|
|
|
nwins += 1;
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
}
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
// If there is only one window left, do not close it. Instead return
|
|
|
|
// a faked empty array of window handles. This will instruct geckodriver
|
|
|
|
// to terminate the application.
|
2017-06-13 19:08:44 +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
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
return this.curBrowser.closeTab()
|
|
|
|
.then(() => this.windowHandles.map(String));
|
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
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.closeChromeWindow = function(cmd, resp) {
|
2017-01-10 18:36:49 +03:00
|
|
|
assert.firefox();
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow(Context.CHROME));
|
2015-03-20 00:12:58 +03:00
|
|
|
|
|
|
|
let nwins = 0;
|
2017-03-01 14:49:21 +03:00
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
// eslint-disable-next-line
|
2017-05-09 19:49:09 +03:00
|
|
|
for (let _ of this.windows) {
|
2015-03-20 00:12:58 +03:00
|
|
|
nwins++;
|
|
|
|
}
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
// If there is only one 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
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
return this.curBrowser.closeWindow()
|
|
|
|
.then(() => this.chromeWindowHandles.map(String));
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-02-02 19:11:08 +03:00
|
|
|
/** Delete Marionette session. */
|
2017-06-30 02:40:24 +03:00
|
|
|
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], {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 19:49:09 +03:00
|
|
|
for (let win of this.windows) {
|
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
|
|
|
|
2017-03-28 23:47:57 +03:00
|
|
|
modal.removeHandler(this.dialogHandler);
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2017-06-30 02:40:24 +03:00
|
|
|
* If called in the content context, the |id| 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.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2017-06-30 02:40:24 +03:00
|
|
|
* If called in the chrome context, the screenshot will always represent
|
|
|
|
* the entire viewport.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
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
|
2017-07-26 15:11:53 +03:00
|
|
|
* considered if <var>id</var> 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}
|
2017-07-26 15:11:53 +03:00
|
|
|
* If <var>hash</var> is false, PNG image encoded as Base64 encoded
|
|
|
|
* string. If <var>hash</var> is true, hex digest of the SHA-256
|
|
|
|
* hash of the Base64 encoded string.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.takeScreenshot = function(cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
let win = assert.window(this.getCurrentWindow());
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
let {id, highlights, full, hash} = 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-20 17:13:32 +03:00
|
|
|
let container = {frame: win.document.defaultView};
|
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
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
|
|
|
|
throw new TypeError(`Unknown context: ${this.context}`);
|
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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getScreenOrientation = function(cmd, resp) {
|
2016-12-29 16:04:16 +03:00
|
|
|
assert.fennec();
|
2017-03-20 17:13:32 +03:00
|
|
|
let win = assert.window(this.getCurrentWindow());
|
2016-12-29 16:04:16 +03:00
|
|
|
|
2017-03-20 17:13:32 +03:00
|
|
|
resp.body.value = win.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".
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.setScreenOrientation = function(cmd, resp) {
|
2016-11-01 01:12:30 +03:00
|
|
|
assert.fennec();
|
2017-03-20 17:13:32 +03:00
|
|
|
let win = assert.window(this.getCurrentWindow());
|
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
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2017-07-21 12:00:41 +03:00
|
|
|
/**
|
|
|
|
* Synchronously minimizes the user agent window as if the user pressed
|
|
|
|
* the minimize button, or restores it if it is already minimized.
|
|
|
|
*
|
|
|
|
* Not supported on Fennec.
|
|
|
|
*
|
|
|
|
* @return {Object.<string, number>}
|
|
|
|
* Window rect and window state.
|
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available for current application.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.minimizeWindow = function* (cmd, resp) {
|
|
|
|
assert.firefox();
|
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
|
|
|
|
|
|
|
let state;
|
|
|
|
yield new Promise(resolve => {
|
|
|
|
win.addEventListener("sizemodechange", resolve, {once: true});
|
|
|
|
|
|
|
|
if (win.windowState == win.STATE_MINIMIZED) {
|
|
|
|
win.restore();
|
|
|
|
state = "normal";
|
|
|
|
} else {
|
|
|
|
win.minimize();
|
|
|
|
state = "minimized";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
resp.body = {
|
|
|
|
x: win.screenX,
|
|
|
|
y: win.screenY,
|
|
|
|
width: win.outerWidth,
|
|
|
|
height: win.outerHeight,
|
|
|
|
state,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
/**
|
2017-04-20 19:04:58 +03:00
|
|
|
* Synchronously maximizes the user agent window as if the user pressed
|
|
|
|
* the maximize button, or restores it if it is already maximized.
|
|
|
|
*
|
|
|
|
* Not supported on Fennec.
|
|
|
|
*
|
|
|
|
* @return {Map.<string, number>}
|
|
|
|
* Window rect.
|
2015-03-20 00:12:58 +03:00
|
|
|
*
|
2017-04-20 20:00:46 +03:00
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available for current application.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-04-20 19:04:58 +03:00
|
|
|
GeckoDriver.prototype.maximizeWindow = function* (cmd, resp) {
|
2017-04-20 20:00:46 +03:00
|
|
|
assert.firefox();
|
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-04-20 19:04:58 +03:00
|
|
|
yield new Promise(resolve => {
|
|
|
|
win.addEventListener("resize", resolve, {once: true});
|
|
|
|
|
|
|
|
if (win.windowState == win.STATE_MAXIMIZED) {
|
|
|
|
win.restore();
|
|
|
|
} else {
|
|
|
|
win.maximize();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-05-05 22:29:04 +03:00
|
|
|
resp.body = {
|
2017-04-20 19:04:58 +03:00
|
|
|
x: win.screenX,
|
|
|
|
y: win.screenY,
|
|
|
|
width: win.outerWidth,
|
|
|
|
height: win.outerHeight,
|
|
|
|
};
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-05-08 18:41:35 +03:00
|
|
|
/**
|
|
|
|
* Synchronously sets the user agent window to full screen as if the user
|
|
|
|
* had done "View > Enter Full Screen", or restores it if it is already
|
|
|
|
* in full screen.
|
|
|
|
*
|
|
|
|
* Not supported on Fennec.
|
|
|
|
*
|
|
|
|
* @return {Map.<string, number>}
|
|
|
|
* Window rect.
|
|
|
|
*
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* Not available for current application.
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* Top-level browsing context has been discarded.
|
|
|
|
* @throws {UnexpectedAlertOpenError}
|
|
|
|
* A modal dialog is open, blocking this operation.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.fullscreen = function* (cmd, resp) {
|
|
|
|
assert.firefox();
|
|
|
|
const win = assert.window(this.getCurrentWindow());
|
|
|
|
assert.noUserPrompt(this.dialog);
|
|
|
|
|
|
|
|
yield new Promise(resolve => {
|
2017-05-27 00:14:14 +03:00
|
|
|
win.addEventListener("sizemodechange", resolve, {once: true});
|
2017-05-08 18:41:35 +03:00
|
|
|
|
2017-05-27 00:14:14 +03:00
|
|
|
win.fullScreen = !win.fullScreen;
|
2017-05-08 18:41:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
resp.body = {
|
|
|
|
x: win.screenX,
|
|
|
|
y: win.screenY,
|
|
|
|
width: win.outerWidth,
|
|
|
|
height: win.outerHeight,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
/**
|
|
|
|
* Dismisses a currently displayed tab modal, or returns no such alert if
|
|
|
|
* no modal is displayed.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.dismissDialog = function(cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.acceptDialog = function(cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-06-30 02:40:24 +03:00
|
|
|
* Returns the message shown in a currently displayed modal, or returns
|
|
|
|
* a no such alert error if no modal is currently displayed.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.getTextFromDialog = function(cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
assert.window(this.getCurrentWindow());
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-04-07 01:37:04 +03:00
|
|
|
* Set the user prompt's value field.
|
|
|
|
*
|
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.
|
2017-04-07 01:37:04 +03:00
|
|
|
*
|
|
|
|
* @param {string} text
|
|
|
|
* Input to the user prompt's value field.
|
|
|
|
*
|
|
|
|
* @throws {ElementNotInteractableError}
|
|
|
|
* If the current user prompt is an alert or confirm.
|
|
|
|
* @throws {NoSuchAlertError}
|
|
|
|
* If there is no current user prompt.
|
|
|
|
* @throws {UnsupportedOperationError}
|
|
|
|
* If the current user prompt is something other than an alert,
|
|
|
|
* confirm, or a prompt.
|
2015-03-20 00:12:58 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.sendKeysToDialog = function(cmd, resp) {
|
2017-03-20 17:13:32 +03:00
|
|
|
let win = assert.window(this.getCurrentWindow());
|
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) {
|
2017-02-03 22:30:13 +03:00
|
|
|
throw new ElementNotInteractableError(
|
|
|
|
"This prompt does not accept text input");
|
2015-03-23 23:43:18 +03:00
|
|
|
}
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2016-02-03 21:56:02 +03:00
|
|
|
event.sendKeysToElement(
|
2017-04-07 01:37:04 +03:00
|
|
|
cmd.parameters.text,
|
2016-02-03 21:56:02 +03:00
|
|
|
loginTextbox,
|
|
|
|
{ignoreVisibility: true},
|
2017-03-20 17:13:32 +03:00
|
|
|
this.dialog.window ? this.dialog.window : win);
|
2015-03-20 00:12:58 +03:00
|
|
|
};
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype._checkIfAlertIsPresent = function() {
|
2016-05-23 13:16:04 +03:00
|
|
|
if (!this.dialog || !this.dialog.ui) {
|
2017-03-28 23:47:57 +03:00
|
|
|
throw new NoAlertOpenError("No modal dialog is currently open");
|
2016-05-23 13:16:04 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-17 14:19:19 +03:00
|
|
|
/**
|
|
|
|
* Enables or disables accepting new socket connections.
|
|
|
|
*
|
2017-06-30 02:40:24 +03:00
|
|
|
* 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.
|
2016-10-17 14:19:19 +03:00
|
|
|
*
|
2017-06-30 02:40:24 +03:00
|
|
|
* 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.
|
2016-10-17 14:19:19 +03:00
|
|
|
*
|
2017-06-30 02:40:24 +03:00
|
|
|
* This method is used for custom in application shutdowns via
|
|
|
|
* marionette.quit() or marionette.restart(), like File -> Quit.
|
2016-10-17 14:19:19 +03:00
|
|
|
*
|
|
|
|
* @param {boolean} state
|
|
|
|
* True if the server should accept new socket connections.
|
|
|
|
*/
|
2017-06-30 02:40:24 +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;
|
2017-07-29 12:03:00 +03:00
|
|
|
};
|
2016-10-17 14:19:19 +03:00
|
|
|
|
2015-09-26 19:12:01 +03:00
|
|
|
/**
|
2017-02-09 21:35:00 +03:00
|
|
|
* Quits the application with the provided flags.
|
|
|
|
*
|
|
|
|
* Marionette will stop accepting new connections before ending the
|
|
|
|
* current session, and finally attempting to quit the application.
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* Optional {@link nsIAppStartup} flags may be provided as
|
2017-02-09 21:35:00 +03:00
|
|
|
* an array of masks, and these will be combined by ORing
|
|
|
|
* them with a bitmask. The available masks are defined in
|
|
|
|
* https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIAppStartup.
|
|
|
|
*
|
|
|
|
* Crucially, only one of the *Quit flags can be specified. The |eRestart|
|
|
|
|
* flag may be bit-wise combined with one of the *Quit flags to cause
|
|
|
|
* the application to restart after it quits.
|
|
|
|
*
|
|
|
|
* @param {Array.<string>=} flags
|
|
|
|
* Constant name of masks to pass to |Services.startup.quit|.
|
|
|
|
* If empty or undefined, |nsIAppStartup.eAttemptQuit| is used.
|
|
|
|
*
|
2017-03-27 14:49:22 +03:00
|
|
|
* @return {string}
|
|
|
|
* Explaining the reason why the application quit. This can be
|
|
|
|
* in response to a normal shutdown or restart, yielding "shutdown"
|
|
|
|
* or "restart", respectively.
|
|
|
|
*
|
2017-02-09 21:35:00 +03:00
|
|
|
* @throws {InvalidArgumentError}
|
|
|
|
* If |flags| contains unknown or incompatible flags, for example
|
|
|
|
* multiple Quit flags.
|
2015-09-26 19:12:01 +03:00
|
|
|
*/
|
2017-03-27 14:53:27 +03:00
|
|
|
GeckoDriver.prototype.quit = function* (cmd, resp) {
|
2017-02-09 21:35:00 +03:00
|
|
|
const quits = ["eConsiderQuit", "eAttemptQuit", "eForceQuit"];
|
2015-09-26 19:12:01 +03:00
|
|
|
|
2017-02-09 21:35:00 +03:00
|
|
|
let flags = [];
|
|
|
|
if (typeof cmd.parameters.flags != "undefined") {
|
|
|
|
flags = assert.array(cmd.parameters.flags);
|
2015-09-26 19:12:01 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 21:35:00 +03:00
|
|
|
// bug 1298921
|
2017-07-29 12:03:00 +03:00
|
|
|
assert.firefox();
|
2015-09-26 19:12:01 +03:00
|
|
|
|
2017-02-09 21:35:00 +03:00
|
|
|
let quitSeen;
|
|
|
|
let mode = 0;
|
|
|
|
if (flags.length > 0) {
|
|
|
|
for (let k of flags) {
|
|
|
|
assert.in(k, Ci.nsIAppStartup);
|
|
|
|
|
|
|
|
if (quits.includes(k)) {
|
|
|
|
if (quitSeen) {
|
|
|
|
throw new InvalidArgumentError(
|
|
|
|
`${k} cannot be combined with ${quitSeen}`);
|
|
|
|
}
|
|
|
|
quitSeen = k;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode |= Ci.nsIAppStartup[k];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mode = Ci.nsIAppStartup.eAttemptQuit;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._server.acceptConnections = false;
|
2017-02-02 19:11:08 +03:00
|
|
|
this.deleteSession();
|
2017-02-09 21:35:00 +03:00
|
|
|
|
|
|
|
// delay response until the application is about to quit
|
2017-03-27 14:49:22 +03:00
|
|
|
let quitApplication = new Promise(resolve => {
|
|
|
|
Services.obs.addObserver(
|
|
|
|
(subject, topic, data) => resolve(data),
|
2017-04-14 22:51:38 +03:00
|
|
|
"quit-application");
|
2017-03-27 14:49:22 +03:00
|
|
|
});
|
2017-02-09 21:35:00 +03:00
|
|
|
|
|
|
|
Services.startup.quit(mode);
|
2017-03-27 14:49:22 +03:00
|
|
|
|
|
|
|
yield quitApplication
|
|
|
|
.then(cause => resp.body.cause = cause)
|
|
|
|
.then(() => resp.send());
|
2015-09-26 19:12:01 +03:00
|
|
|
};
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.installAddon = function(cmd, resp) {
|
2017-07-29 12:03:00 +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);
|
|
|
|
};
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.uninstallAddon = function(cmd, resp) {
|
2017-07-29 12:03:00 +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
|
|
|
/** Receives all messages from content messageManager. */
|
2017-06-30 02:40:24 +03:00
|
|
|
/* eslint-disable consistent-return */
|
|
|
|
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: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: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) {
|
2017-07-06 19:02:19 +03:00
|
|
|
// If the frame script gets reloaded 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.
|
2017-07-04 22:03:36 +03:00
|
|
|
this.sendAsync("newSession", this.capabilities.toJSON());
|
2015-03-20 00:12:58 +03:00
|
|
|
this.curBrowser.flushPendingCommands();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2017-06-30 02:40:24 +03:00
|
|
|
/* eslint-enable consistent-return */
|
2015-03-20 00:12:58 +03:00
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
GeckoDriver.prototype.responseCompleted = function() {
|
2015-03-20 00:12:58 +03:00
|
|
|
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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +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);
|
2017-07-29 12:03:00 +03:00
|
|
|
};
|
2016-11-12 00:49:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the localized string for the specified property id.
|
|
|
|
*
|
|
|
|
* Example:
|
2017-06-30 02:40:24 +03:00
|
|
|
*
|
|
|
|
* localizeProperty(
|
|
|
|
* ["chrome://global/locale/findbar.properties"], "FastFind");
|
2016-11-12 00:49:58 +03:00
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*/
|
2017-06-30 02:40:24 +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);
|
2017-07-29 12:03:00 +03:00
|
|
|
};
|
2016-11-12 00:49:58 +03:00
|
|
|
|
Bug 1363428 - Add reftest-specific endpoints to Marionette, r=ato
This adds commands to start a reftest session, run a test, and end the
session. It as assumed that after you start a reftest session you will
just run reftests until you end the session. When starting a session
the user provides a string indicating when screenshots should be
taken, and an object mapping urls to a count of the number of times
that url is expected to be used in the session, to help with
caching. Running the tests takes a url to a test, an expected status,
a timeout, and a nested list of possible references, in which each
entry at a specific level is combined by OR and nested references are
combined by AND.
The implementation is heavilly inspired by the existing reftest
harness, starting a minimal window with no tabs, and loading the urls
directly in there. In order to get a screenshot in the e10s case we
have to pass the DRAW_VIEW and USE_WIDGET_LAYERS flags when taking the
screenshot.
For performance we heavily cache canvases; for references that will be
repeated we cache the full canvas with image, and we also cache a
single canvas to use for all other screenshots to avoid the overhead
of repeatedly creating a new canvas element.
MozReview-Commit-ID: JOFvtmH7tg
2017-05-10 12:51:10 +03:00
|
|
|
/**
|
|
|
|
* Initialize the reftest mode
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.setupReftest = function* (cmd, resp) {
|
|
|
|
if (this._reftest) {
|
|
|
|
throw new UnsupportedOperationError("Called reftest:setup with a reftest session already active");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.context !== Context.CHROME) {
|
|
|
|
throw new UnsupportedOperationError("Must set chrome context before running reftests");
|
|
|
|
}
|
|
|
|
|
|
|
|
let {urlCount = {}, screenshot = "unexpected"} = cmd.parameters;
|
|
|
|
if (!["always", "fail", "unexpected"].includes(screenshot)) {
|
|
|
|
throw new InvalidArgumentError("Value of `screenshot` should be 'always', 'fail' or 'unexpected'");
|
|
|
|
}
|
|
|
|
|
|
|
|
this._reftest = new reftest.Runner(this);
|
|
|
|
|
|
|
|
yield this._reftest.setup(urlCount, screenshot);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run a reftest
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.runReftest = function* (cmd, resp) {
|
|
|
|
let {test, references, expected, timeout} = cmd.parameters;
|
|
|
|
|
|
|
|
if (!this._reftest) {
|
|
|
|
throw new UnsupportedOperationError("Called reftest:run before reftest:start");
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.string(test);
|
|
|
|
assert.string(expected);
|
|
|
|
assert.array(references);
|
|
|
|
|
|
|
|
let result = yield this._reftest.run(test, references, expected, timeout);
|
|
|
|
|
|
|
|
resp.body.value = result;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* End a reftest run
|
|
|
|
*
|
|
|
|
* Closes the reftest window (without changing the current window handle),
|
|
|
|
* and removes cached canvases.
|
|
|
|
*/
|
|
|
|
GeckoDriver.prototype.teardownReftest = function* (cmd, resp) {
|
|
|
|
if (!this._reftest) {
|
|
|
|
throw new UnsupportedOperationError("Called reftest:teardown before reftest:start");
|
|
|
|
}
|
|
|
|
|
|
|
|
this._reftest.abort();
|
|
|
|
|
|
|
|
this._reftest = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-03-20 00:12:58 +03:00
|
|
|
GeckoDriver.prototype.commands = {
|
2017-06-22 14:11:21 +03:00
|
|
|
// Marionette service
|
|
|
|
"Marionette:SetContext": GeckoDriver.prototype.setContext,
|
|
|
|
"setContext": GeckoDriver.prototype.setContext, // deprecated, remove in Firefox 60
|
|
|
|
"Marionette:GetContext": GeckoDriver.prototype.getContext,
|
|
|
|
"getContext": GeckoDriver.prototype.getContext,
|
|
|
|
"Marionette:AcceptConnections": GeckoDriver.prototype.acceptConnections,
|
|
|
|
"acceptConnections": GeckoDriver.prototype.acceptConnections, // deprecated, remove in Firefox 60
|
|
|
|
"Marionette:Quit": GeckoDriver.prototype.quit,
|
|
|
|
"quit": GeckoDriver.prototype.quit, // deprecated, remove in Firefox 60
|
2017-06-28 00:48:36 +03:00
|
|
|
"quitApplication": GeckoDriver.prototype.quit, // deprecated, remove in Firefox 60
|
2017-06-22 14:11:21 +03:00
|
|
|
|
2017-06-22 14:55:00 +03:00
|
|
|
// Addon service
|
|
|
|
"Addon:Install": GeckoDriver.prototype.installAddon,
|
|
|
|
"addon:install": GeckoDriver.prototype.installAddon, // deprecated, remove in Firefox 60
|
|
|
|
"Addon:Uninstall": GeckoDriver.prototype.uninstallAddon,
|
|
|
|
"addon:uninstall": GeckoDriver.prototype.uninstallAddon, // deprecated, remove in Firefox 60
|
|
|
|
|
2017-06-22 14:59:33 +03:00
|
|
|
// L10n service
|
|
|
|
"L10n:LocalizeEntity": GeckoDriver.prototype.localizeEntity,
|
|
|
|
"localization:l10n:localizeEntity": GeckoDriver.prototype.localizeEntity, // deprecated, remove in Firefox 60
|
|
|
|
"L10n:LocalizeProperty": GeckoDriver.prototype.localizeProperty,
|
|
|
|
"localization:l10n:localizeProperty": GeckoDriver.prototype.localizeProperty, // deprecated, remove in Firefox 60
|
|
|
|
|
Bug 1363428 - Add reftest-specific endpoints to Marionette, r=ato
This adds commands to start a reftest session, run a test, and end the
session. It as assumed that after you start a reftest session you will
just run reftests until you end the session. When starting a session
the user provides a string indicating when screenshots should be
taken, and an object mapping urls to a count of the number of times
that url is expected to be used in the session, to help with
caching. Running the tests takes a url to a test, an expected status,
a timeout, and a nested list of possible references, in which each
entry at a specific level is combined by OR and nested references are
combined by AND.
The implementation is heavilly inspired by the existing reftest
harness, starting a minimal window with no tabs, and loading the urls
directly in there. In order to get a screenshot in the e10s case we
have to pass the DRAW_VIEW and USE_WIDGET_LAYERS flags when taking the
screenshot.
For performance we heavily cache canvases; for references that will be
repeated we cache the full canvas with image, and we also cache a
single canvas to use for all other screenshots to avoid the overhead
of repeatedly creating a new canvas element.
MozReview-Commit-ID: JOFvtmH7tg
2017-05-10 12:51:10 +03:00
|
|
|
// Reftest service
|
|
|
|
"reftest:setup": GeckoDriver.prototype.setupReftest,
|
|
|
|
"reftest:run": GeckoDriver.prototype.runReftest,
|
|
|
|
"reftest:teardown": GeckoDriver.prototype.teardownReftest,
|
|
|
|
|
2017-06-22 15:07:02 +03:00
|
|
|
// WebDriver service
|
|
|
|
"WebDriver:AcceptDialog": GeckoDriver.prototype.acceptDialog,
|
|
|
|
"WebDriver:AddCookie": GeckoDriver.prototype.addCookie,
|
|
|
|
"WebDriver:Back": GeckoDriver.prototype.goBack,
|
|
|
|
"WebDriver:CloseChromeWindow": GeckoDriver.prototype.closeChromeWindow,
|
|
|
|
"WebDriver:CloseWindow": GeckoDriver.prototype.close,
|
|
|
|
"WebDriver:DeleteAllCookies": GeckoDriver.prototype.deleteAllCookies,
|
|
|
|
"WebDriver:DeleteCookie": GeckoDriver.prototype.deleteCookie,
|
|
|
|
"WebDriver:DeleteSession": GeckoDriver.prototype.deleteSession,
|
|
|
|
"WebDriver:DismissAlert": GeckoDriver.prototype.dismissDialog,
|
|
|
|
"WebDriver:ElementClear": GeckoDriver.prototype.clearElement,
|
|
|
|
"WebDriver:ElementClick": GeckoDriver.prototype.clickElement,
|
|
|
|
"WebDriver:ElementSendKeys": GeckoDriver.prototype.sendKeysToElement,
|
|
|
|
"WebDriver:ExecuteAsyncScript": GeckoDriver.prototype.executeAsyncScript,
|
|
|
|
"WebDriver:ExecuteScript": GeckoDriver.prototype.executeScript,
|
|
|
|
"WebDriver:FindElement": GeckoDriver.prototype.findElement,
|
|
|
|
"WebDriver:FindElements": GeckoDriver.prototype.findElements,
|
|
|
|
"WebDriver:Forward": GeckoDriver.prototype.goForward,
|
|
|
|
"WebDriver:FullscreenWindow": GeckoDriver.prototype.fullscreen,
|
|
|
|
"WebDriver:GetActiveElement": GeckoDriver.prototype.getActiveElement,
|
|
|
|
"WebDriver:GetActiveFrame": GeckoDriver.prototype.getActiveFrame,
|
|
|
|
"WebDriver:GetAlertText": GeckoDriver.prototype.getTextFromDialog,
|
|
|
|
"WebDriver:GetCapabilities": GeckoDriver.prototype.getSessionCapabilities,
|
|
|
|
"WebDriver:GetChromeWindowHandle": GeckoDriver.prototype.getChromeWindowHandle,
|
|
|
|
"WebDriver:GetChromeWindowHandles": GeckoDriver.prototype.getChromeWindowHandles,
|
|
|
|
"WebDriver:GetCookies": GeckoDriver.prototype.getCookies,
|
|
|
|
"WebDriver:GetCurrentChromeWindowHandle": GeckoDriver.prototype.getChromeWindowHandle,
|
|
|
|
"WebDriver:GetCurrentURL": GeckoDriver.prototype.getCurrentUrl,
|
|
|
|
"WebDriver:GetElementAttribute": GeckoDriver.prototype.getElementAttribute,
|
|
|
|
"WebDriver:GetElementCSSValue": GeckoDriver.prototype.getElementValueOfCssProperty,
|
|
|
|
"WebDriver:GetElementProperty": GeckoDriver.prototype.getElementProperty,
|
|
|
|
"WebDriver:GetElementRect": GeckoDriver.prototype.getElementRect,
|
|
|
|
"WebDriver:GetElementTagName": GeckoDriver.prototype.getElementTagName,
|
|
|
|
"WebDriver:GetElementText": GeckoDriver.prototype.getElementText,
|
|
|
|
"WebDriver:GetPageSource": GeckoDriver.prototype.getPageSource,
|
|
|
|
"WebDriver:GetScreenOrientation": GeckoDriver.prototype.getScreenOrientation,
|
|
|
|
"WebDriver:GetTimeouts": GeckoDriver.prototype.getTimeouts,
|
|
|
|
"WebDriver:GetTitle": GeckoDriver.prototype.getTitle,
|
|
|
|
"WebDriver:GetWindowHandle": GeckoDriver.prototype.getWindowHandle,
|
|
|
|
"WebDriver:GetWindowHandles": GeckoDriver.prototype.getWindowHandles,
|
|
|
|
"WebDriver:GetWindowRect": GeckoDriver.prototype.getWindowRect,
|
|
|
|
"WebDriver:GetWindowType": GeckoDriver.prototype.getWindowType,
|
|
|
|
"WebDriver:IsElementDisplayed": GeckoDriver.prototype.isElementDisplayed,
|
|
|
|
"WebDriver:IsElementEnabled": GeckoDriver.prototype.isElementEnabled,
|
|
|
|
"WebDriver:IsElementSelected": GeckoDriver.prototype.isElementSelected,
|
2017-07-21 12:00:41 +03:00
|
|
|
"WebDriver:MinimizeWindow": GeckoDriver.prototype.minimizeWindow,
|
2017-06-22 15:07:02 +03:00
|
|
|
"WebDriver:MaximizeWindow": GeckoDriver.prototype.maximizeWindow,
|
|
|
|
"WebDriver:Navigate": GeckoDriver.prototype.get,
|
|
|
|
"WebDriver:NewSession": GeckoDriver.prototype.newSession,
|
|
|
|
"WebDriver:PerformActions": GeckoDriver.prototype.performActions,
|
|
|
|
"WebDriver:Refresh": GeckoDriver.prototype.refresh,
|
|
|
|
"WebDriver:ReleaseActions": GeckoDriver.prototype.releaseActions,
|
|
|
|
"WebDriver:SendAlertText": GeckoDriver.prototype.sendKeysToDialog,
|
|
|
|
"WebDriver:SetScreenOrientation": GeckoDriver.prototype.setScreenOrientation,
|
|
|
|
"WebDriver:SetTimeouts": GeckoDriver.prototype.setTimeouts,
|
|
|
|
"WebDriver:SetWindowRect": GeckoDriver.prototype.setWindowRect,
|
|
|
|
"WebDriver:SwitchToFrame": GeckoDriver.prototype.switchToFrame,
|
|
|
|
"WebDriver:SwitchToParentFrame": GeckoDriver.prototype.switchToParentFrame,
|
|
|
|
"WebDriver:SwitchToShadowRoot": GeckoDriver.prototype.switchToShadowRoot,
|
|
|
|
"WebDriver:SwitchToWindow": GeckoDriver.prototype.switchToWindow,
|
|
|
|
"WebDriver:TakeScreenshot": GeckoDriver.prototype.takeScreenshot,
|
|
|
|
|
|
|
|
// deprecated WebDriver commands, remove in Firefox 60
|
|
|
|
"acceptDialog": GeckoDriver.prototype.acceptDialog,
|
|
|
|
"actionChain": GeckoDriver.prototype.actionChain,
|
|
|
|
"addCookie": GeckoDriver.prototype.addCookie,
|
|
|
|
"clearElement": GeckoDriver.prototype.clearElement,
|
|
|
|
"clickElement": GeckoDriver.prototype.clickElement,
|
|
|
|
"closeChromeWindow": GeckoDriver.prototype.closeChromeWindow,
|
|
|
|
"close": GeckoDriver.prototype.close,
|
|
|
|
"deleteAllCookies": GeckoDriver.prototype.deleteAllCookies,
|
|
|
|
"deleteCookie": GeckoDriver.prototype.deleteCookie,
|
|
|
|
"deleteSession": GeckoDriver.prototype.deleteSession,
|
|
|
|
"dismissDialog": GeckoDriver.prototype.dismissDialog,
|
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,
|
2017-06-22 15:07:02 +03:00
|
|
|
"executeScript": GeckoDriver.prototype.executeScript,
|
2015-03-20 00:12:58 +03:00
|
|
|
"findElement": GeckoDriver.prototype.findElement,
|
|
|
|
"findElements": GeckoDriver.prototype.findElements,
|
2017-06-22 15:07:02 +03:00
|
|
|
"fullscreen": GeckoDriver.prototype.fullscreen,
|
|
|
|
"getActiveElement": GeckoDriver.prototype.getActiveElement,
|
|
|
|
"getActiveFrame": GeckoDriver.prototype.getActiveFrame,
|
|
|
|
"getChromeWindowHandle": GeckoDriver.prototype.getChromeWindowHandle,
|
|
|
|
"getChromeWindowHandles": GeckoDriver.prototype.getChromeWindowHandles,
|
|
|
|
"getCookies": GeckoDriver.prototype.getCookies,
|
|
|
|
"getCurrentChromeWindowHandle": GeckoDriver.prototype.getChromeWindowHandle,
|
|
|
|
"getCurrentUrl": GeckoDriver.prototype.getCurrentUrl,
|
2015-03-20 00:12:58 +03:00
|
|
|
"getElementAttribute": GeckoDriver.prototype.getElementAttribute,
|
2016-05-13 16:42:05 +03:00
|
|
|
"getElementProperty": GeckoDriver.prototype.getElementProperty,
|
2017-06-22 15:07:02 +03:00
|
|
|
"getElementRect": GeckoDriver.prototype.getElementRect,
|
2015-03-20 00:12:58 +03:00
|
|
|
"getElementTagName": GeckoDriver.prototype.getElementTagName,
|
2017-06-22 15:07:02 +03:00
|
|
|
"getElementText": GeckoDriver.prototype.getElementText,
|
2015-03-20 00:12:58 +03:00
|
|
|
"getElementValueOfCssProperty": GeckoDriver.prototype.getElementValueOfCssProperty,
|
2017-06-22 15:07:02 +03:00
|
|
|
"get": GeckoDriver.prototype.get,
|
|
|
|
"getPageSource": GeckoDriver.prototype.getPageSource,
|
|
|
|
"getScreenOrientation": GeckoDriver.prototype.getScreenOrientation,
|
|
|
|
"getSessionCapabilities": GeckoDriver.prototype.getSessionCapabilities,
|
|
|
|
"getTextFromDialog": GeckoDriver.prototype.getTextFromDialog,
|
|
|
|
"getTimeouts": GeckoDriver.prototype.getTimeouts,
|
2015-03-20 00:12:58 +03:00
|
|
|
"getTitle": GeckoDriver.prototype.getTitle,
|
2017-06-22 15:07:02 +03:00
|
|
|
"getWindowHandle": GeckoDriver.prototype.getWindowHandle,
|
|
|
|
"getWindowHandles": GeckoDriver.prototype.getWindowHandles,
|
|
|
|
"getWindowPosition": GeckoDriver.prototype.getWindowRect, // redirect for compatibility
|
|
|
|
"getWindowRect": GeckoDriver.prototype.getWindowRect,
|
|
|
|
"getWindowSize": GeckoDriver.prototype.getWindowRect, // redirect for compatibility
|
2015-03-20 00:12:58 +03:00
|
|
|
"getWindowType": GeckoDriver.prototype.getWindowType,
|
|
|
|
"goBack": GeckoDriver.prototype.goBack,
|
|
|
|
"goForward": GeckoDriver.prototype.goForward,
|
2017-06-22 15:07:02 +03:00
|
|
|
"isElementDisplayed": GeckoDriver.prototype.isElementDisplayed,
|
|
|
|
"isElementEnabled": GeckoDriver.prototype.isElementEnabled,
|
|
|
|
"isElementSelected": GeckoDriver.prototype.isElementSelected,
|
|
|
|
"maximizeWindow": GeckoDriver.prototype.maximizeWindow,
|
|
|
|
"multiAction": GeckoDriver.prototype.multiAction,
|
|
|
|
"newSession": GeckoDriver.prototype.newSession,
|
|
|
|
"performActions": GeckoDriver.prototype.performActions,
|
2015-03-20 00:12:58 +03:00
|
|
|
"refresh": GeckoDriver.prototype.refresh,
|
2017-06-22 15:07:02 +03:00
|
|
|
"releaseActions": GeckoDriver.prototype.releaseActions,
|
|
|
|
"sendKeysToDialog": GeckoDriver.prototype.sendKeysToDialog,
|
|
|
|
"sendKeysToElement": GeckoDriver.prototype.sendKeysToElement,
|
|
|
|
"setScreenOrientation": GeckoDriver.prototype.setScreenOrientation,
|
|
|
|
"setTimeouts": GeckoDriver.prototype.setTimeouts,
|
|
|
|
"setWindowPosition": GeckoDriver.prototype.setWindowRect, // redirect for compatibility
|
2017-03-24 17:35:38 +03:00
|
|
|
"setWindowRect": GeckoDriver.prototype.setWindowRect,
|
2017-06-22 15:07:02 +03:00
|
|
|
"setWindowSize": GeckoDriver.prototype.setWindowRect, // redirect for compatibility
|
|
|
|
"singleTap": GeckoDriver.prototype.singleTap,
|
2015-03-20 00:12:58 +03:00
|
|
|
"switchToFrame": GeckoDriver.prototype.switchToFrame,
|
2015-10-19 23:39:48 +03:00
|
|
|
"switchToParentFrame": GeckoDriver.prototype.switchToParentFrame,
|
2015-08-28 23:43:54 +03:00
|
|
|
"switchToShadowRoot": GeckoDriver.prototype.switchToShadowRoot,
|
2017-06-22 15:07:02 +03:00
|
|
|
"switchToWindow": GeckoDriver.prototype.switchToWindow,
|
2015-03-20 00:12:58 +03:00
|
|
|
"takeScreenshot": GeckoDriver.prototype.takeScreenshot,
|
|
|
|
};
|
2016-12-19 22:08:46 +03:00
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
function copy(obj) {
|
2016-12-19 22:08:46 +03:00
|
|
|
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) {
|
2017-05-09 11:25:26 +03:00
|
|
|
return win.QueryInterface(Ci.nsIInterfaceRequestor)
|
2017-01-27 11:09:32 +03:00
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.outerWindowID;
|
|
|
|
}
|