Skip to content

Commit

Permalink
Bug 1665718 - [marionette] Throw NoSuchElementError when we get a nul…
Browse files Browse the repository at this point in the history
…l ContentDOMReference r=marionette-reviewers,whimboo

Differential Revision: https://phabricator.services.mozilla.com/D95097
  • Loading branch information
mjzffr committed Nov 12, 2020
1 parent 4491f48 commit afa2b32
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions testing/marionette/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ element.Store = class {
delete this.els[webEl.uuid];
}

if (element.isStale(el, win)) {
if (el === null || element.isStale(el, win)) {
throw new error.StaleElementReferenceError(
pprint`The element reference of ${el || webEl.uuid} is stale; ` +
"either the element is no longer attached to the DOM, " +
Expand Down Expand Up @@ -814,15 +814,17 @@ element.getElementId = function(el) {
* active document.
*/
element.resolveElement = function(id, win = undefined) {
let webEl;
if (id.webElRef) {
webEl = WebElement.fromJSON(id.webElRef);
}
const el = ContentDOMReference.resolve(id);
if (el === null) {
// the element is unknown in the current browsing context
throw new error.NoSuchElementError(
`Web element reference not seen before: ${JSON.stringify(id.webElRef)}`
);
}
if (element.isStale(el, win)) {
throw new error.StaleElementReferenceError(
pprint`The element reference of ${el || webEl?.uuid} is stale; ` +
"either the element is no longer attached to the DOM, " +
pprint`The element reference of ${el || JSON.stringify(id.webElRef)} ` +
"is stale; either the element is no longer attached to the DOM, " +
"it is not in the current frame context, " +
"or the document has been refreshed"
);
Expand Down Expand Up @@ -871,9 +873,7 @@ element.isCollection = function(seq) {
* browsing context such as an <tt>&lt;iframe&gt;</tt>.
*
* @param {Element=} el
* DOM element to check for staleness. If null, which may be
* the case if the element has been unwrapped from a weak
* reference, it is always considered stale.
* DOM element to check for staleness.
* @param {WindowProxy=} win
* Current window global, which may differ from the associated
* window global of <var>el</var>. When retrieving XUL
Expand All @@ -883,11 +883,13 @@ element.isCollection = function(seq) {
* True if <var>el</var> is stale, false otherwise.
*/
element.isStale = function(el, win = undefined) {
if (!el) {
throw new TypeError(`Expected Element got ${el}`);
}
if (typeof win == "undefined") {
win = el.ownerGlobal;
}

if (el === null || !el.ownerGlobal || el.ownerDocument !== win.document) {
if (!el.ownerGlobal || el.ownerDocument !== win.document) {
return true;
}

Expand Down

0 comments on commit afa2b32

Please sign in to comment.