mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 23:05:42 +00:00
Bug 1721327 - [remote] Share Marionette's assertion module with WebDriver BiDi. r=webdriver-reviewers,jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D120303
This commit is contained in:
parent
ae3fd8d195
commit
10c712a65e
@ -21,6 +21,7 @@ remote.jar:
|
||||
content/shared/WindowManager.jsm (shared/WindowManager.jsm)
|
||||
|
||||
# shared modules (WebDriver HTTP / BiDi only)
|
||||
content/shared/webdriver/Assert.jsm (shared/webdriver/Assert.jsm)
|
||||
content/shared/webdriver/Capabilities.jsm (shared/webdriver/Capabilities.jsm)
|
||||
content/shared/webdriver/Errors.jsm (shared/webdriver/Errors.jsm)
|
||||
content/shared/webdriver/Session.jsm (shared/webdriver/Session.jsm)
|
||||
|
@ -15,7 +15,7 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
AppInfo: "chrome://remote/content/marionette/appinfo.js",
|
||||
assert: "chrome://remote/content/marionette/assert.js",
|
||||
assert: "chrome://remote/content/shared/webdriver/Assert.jsm",
|
||||
element: "chrome://remote/content/marionette/element.js",
|
||||
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
|
||||
event: "chrome://remote/content/marionette/event.js",
|
||||
|
@ -12,7 +12,7 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
assert: "chrome://remote/content/marionette/assert.js",
|
||||
assert: "chrome://remote/content/shared/webdriver/Assert.jsm",
|
||||
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
|
||||
pprint: "chrome://remote/content/marionette/format.js",
|
||||
});
|
||||
|
@ -1,4 +0,0 @@
|
||||
assert module
|
||||
=============
|
||||
.. js:autoclass:: assert
|
||||
:members:
|
@ -16,7 +16,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
|
||||
Addon: "chrome://remote/content/marionette/addon.js",
|
||||
AppInfo: "chrome://remote/content/marionette/appinfo.js",
|
||||
assert: "chrome://remote/content/marionette/assert.js",
|
||||
assert: "chrome://remote/content/shared/webdriver/Assert.jsm",
|
||||
atom: "chrome://remote/content/marionette/atom.js",
|
||||
browser: "chrome://remote/content/marionette/browser.js",
|
||||
capture: "chrome://remote/content/marionette/capture.js",
|
||||
|
@ -20,7 +20,7 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
ContentDOMReference: "resource://gre/modules/ContentDOMReference.jsm",
|
||||
|
||||
assert: "chrome://remote/content/marionette/assert.js",
|
||||
assert: "chrome://remote/content/shared/webdriver/Assert.jsm",
|
||||
atom: "chrome://remote/content/marionette/atom.js",
|
||||
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
|
||||
PollPromise: "chrome://remote/content/marionette/sync.js",
|
||||
|
@ -14,7 +14,6 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
assert: "chrome://remote/content/marionette/assert.js",
|
||||
element: "chrome://remote/content/marionette/element.js",
|
||||
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
|
||||
Log: "chrome://remote/content/shared/Log.jsm",
|
||||
@ -34,6 +33,26 @@ const FINISH = "finish";
|
||||
/** @namespace */
|
||||
this.evaluate = {};
|
||||
|
||||
/**
|
||||
* Asserts that an arbitrary object is not cyclic.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* Object to test. This assertion is only meaningful if passed
|
||||
* an actual object or array.
|
||||
* @param {String=} msg
|
||||
* Custom message to use for `error` if assertion fails.
|
||||
* @param {Error=} [error=JavaScriptError] error
|
||||
* Error to throw if assertion fails.
|
||||
*
|
||||
* @throws {JavaScriptError}
|
||||
* If the object is cyclic.
|
||||
*/
|
||||
evaluate.assertAcyclic = function(obj, msg = "", err = error.JavaScriptError) {
|
||||
if (evaluate.isCyclic(obj)) {
|
||||
throw new err(msg || "Cyclic object value");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Evaluate a script in given sandbox.
|
||||
*
|
||||
@ -300,7 +319,7 @@ evaluate.toJSON = function(obj, seenEls) {
|
||||
|
||||
// Array, NodeList, HTMLCollection, et al.
|
||||
} else if (element.isCollection(obj)) {
|
||||
assert.acyclic(obj);
|
||||
evaluate.assertAcyclic(obj);
|
||||
return [...obj].map(el => evaluate.toJSON(el, seenEls));
|
||||
|
||||
// WebElement
|
||||
@ -336,7 +355,7 @@ evaluate.toJSON = function(obj, seenEls) {
|
||||
// arbitrary objects + files
|
||||
let rv = {};
|
||||
for (let prop in obj) {
|
||||
assert.acyclic(obj[prop]);
|
||||
evaluate.assertAcyclic(obj[prop]);
|
||||
|
||||
try {
|
||||
rv[prop] = evaluate.toJSON(obj[prop], seenEls);
|
||||
|
@ -14,7 +14,6 @@ remote.jar:
|
||||
content/marionette/actors/MarionetteReftestParent.jsm (actors/MarionetteReftestParent.jsm)
|
||||
content/marionette/addon.js (addon.js)
|
||||
content/marionette/appinfo.js (appinfo.js)
|
||||
content/marionette/assert.js (assert.js)
|
||||
content/marionette/atom.js (atom.js)
|
||||
content/marionette/browser.js (browser.js)
|
||||
content/marionette/capture.js (capture.js)
|
||||
|
@ -11,7 +11,7 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
assert: "chrome://remote/content/marionette/assert.js",
|
||||
assert: "chrome://remote/content/shared/webdriver/Assert.jsm",
|
||||
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
|
||||
truncate: "chrome://remote/content/marionette/format.js",
|
||||
});
|
||||
|
@ -16,7 +16,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
OS: "resource://gre/modules/osfile.jsm",
|
||||
|
||||
AppInfo: "chrome://remote/content/marionette/appinfo.js",
|
||||
assert: "chrome://remote/content/marionette/assert.js",
|
||||
assert: "chrome://remote/content/shared/webdriver/Assert.jsm",
|
||||
capture: "chrome://remote/content/marionette/capture.js",
|
||||
Log: "chrome://remote/content/shared/Log.jsm",
|
||||
navigate: "chrome://remote/content/marionette/navigate.js",
|
||||
|
@ -11,7 +11,7 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
assert: "chrome://remote/content/marionette/assert.js",
|
||||
assert: "chrome://remote/content/shared/webdriver/Assert.jsm",
|
||||
Command: "chrome://remote/content/marionette/message.js",
|
||||
DebuggerTransport: "chrome://remote/content/marionette/transport.js",
|
||||
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
|
||||
|
@ -67,6 +67,34 @@ const xulElId = { id: 3, browsingContextId: 6, webElRef: xulWebEl.toJSON() };
|
||||
|
||||
const elementIdCache = new element.ReferenceStore();
|
||||
|
||||
add_test(function test_acyclic() {
|
||||
evaluate.assertAcyclic({});
|
||||
|
||||
Assert.throws(() => {
|
||||
let obj = {};
|
||||
obj.reference = obj;
|
||||
evaluate.assertAcyclic(obj);
|
||||
}, /JavaScriptError/);
|
||||
|
||||
// custom message
|
||||
let cyclic = {};
|
||||
cyclic.reference = cyclic;
|
||||
Assert.throws(
|
||||
() => evaluate.assertAcyclic(cyclic, "", RangeError),
|
||||
RangeError
|
||||
);
|
||||
Assert.throws(
|
||||
() => evaluate.assertAcyclic(cyclic, "foo"),
|
||||
/JavaScriptError: foo/
|
||||
);
|
||||
Assert.throws(
|
||||
() => evaluate.assertAcyclic(cyclic, "bar", RangeError),
|
||||
/RangeError: bar/
|
||||
);
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_toJSON_types() {
|
||||
// null
|
||||
equal(null, evaluate.toJSON(undefined));
|
||||
|
@ -8,7 +8,6 @@ skip-if = appname == "thunderbird"
|
||||
[test_action.js]
|
||||
[test_actors.js]
|
||||
[test_appinfo.js]
|
||||
[test_assert.js]
|
||||
[test_browser.js]
|
||||
[test_cookie.js]
|
||||
[test_dom.js]
|
||||
|
@ -13,39 +13,18 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
AppInfo: "chrome://remote/content/marionette/appinfo.js",
|
||||
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
|
||||
evaluate: "chrome://remote/content/marionette/evaluate.js",
|
||||
pprint: "chrome://remote/content/marionette/format.js",
|
||||
});
|
||||
|
||||
/**
|
||||
* Shorthands for common assertions made in Marionette.
|
||||
* Shorthands for common assertions made in WebDriver.
|
||||
*
|
||||
* @namespace
|
||||
*/
|
||||
this.assert = {};
|
||||
|
||||
/**
|
||||
* Asserts that an arbitrary object is not acyclic.
|
||||
*
|
||||
* @param {*} obj
|
||||
* Object to test. This assertion is only meaningful if passed
|
||||
* an actual object or array.
|
||||
* @param {Error=} [error=JavaScriptError] error
|
||||
* Error to throw if assertion fails.
|
||||
* @param {string=} message
|
||||
* Custom message to use for `error` if assertion fails.
|
||||
*
|
||||
* @throws {JavaScriptError}
|
||||
* If the object is cyclic.
|
||||
*/
|
||||
assert.acyclic = function(obj, msg = "", err = error.JavaScriptError) {
|
||||
if (evaluate.isCyclic(obj)) {
|
||||
throw new err(msg || "Cyclic object value");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Asserts that Marionette has an active session.
|
||||
* Asserts that WebDriver has an active session.
|
||||
*
|
||||
* @param {WebDriverSession} session
|
||||
* WebDriver session instance.
|
@ -21,7 +21,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
|
||||
AppInfo: "chrome://remote/content/marionette/appinfo.js",
|
||||
assert: "chrome://remote/content/marionette/assert.js",
|
||||
assert: "chrome://remote/content/shared/webdriver/Assert.jsm",
|
||||
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
|
||||
pprint: "chrome://remote/content/marionette/format.js",
|
||||
RemoteAgent: "chrome://remote/content/components/RemoteAgent.jsm",
|
||||
|
@ -6,34 +6,12 @@
|
||||
/* eslint-disable no-array-constructor, no-new-object */
|
||||
|
||||
const { assert } = ChromeUtils.import(
|
||||
"chrome://remote/content/marionette/assert.js"
|
||||
"chrome://remote/content/shared/webdriver/Assert.jsm"
|
||||
);
|
||||
const { error } = ChromeUtils.import(
|
||||
"chrome://remote/content/shared/webdriver/Errors.jsm"
|
||||
);
|
||||
|
||||
add_test(function test_acyclic() {
|
||||
assert.acyclic({});
|
||||
|
||||
Assert.throws(() => {
|
||||
let obj = {};
|
||||
obj.reference = obj;
|
||||
assert.acyclic(obj);
|
||||
}, /JavaScriptError/);
|
||||
|
||||
// custom message
|
||||
let cyclic = {};
|
||||
cyclic.reference = cyclic;
|
||||
Assert.throws(() => assert.acyclic(cyclic, "", RangeError), RangeError);
|
||||
Assert.throws(() => assert.acyclic(cyclic, "foo"), /JavaScriptError: foo/);
|
||||
Assert.throws(
|
||||
() => assert.acyclic(cyclic, "bar", RangeError),
|
||||
/RangeError: bar/
|
||||
);
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_session() {
|
||||
assert.session({ id: "foo" });
|
||||
|
@ -2,6 +2,7 @@
|
||||
# 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/.
|
||||
|
||||
[test_Assert.js]
|
||||
[test_Capabilities.js]
|
||||
[test_Errors.js]
|
||||
[test_Session.js]
|
||||
|
Loading…
Reference in New Issue
Block a user