From 44ce91548167d909e201ca0bc235a2ad02d94d6e Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Fri, 24 Nov 2017 16:23:02 +0000 Subject: [PATCH] Bug 1420431 - Return no such element error when on no active element. r=maja_zf document.activeElement will return null if there is no document element. This may happen if, for example, in an HTML document the element is removed. The WPT test test_sucess_without_body in get_active_element.py is wrong. It expects Get Active Element to return null if there is no document element, but following a recent specification change we want it to return a no such element error. Specification change: https://github.com/w3c/webdriver/pull/1157 MozReview-Commit-ID: LQJ3slV9aty --- testing/marionette/driver.js | 8 ++++++-- testing/marionette/listener.js | 15 ++++++++++++++- testing/web-platform/meta/MANIFEST.json | 2 +- .../element_retrieval/get_active_element.py.ini | 5 +---- .../tests/element_retrieval/get_active_element.py | 6 ++++-- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/testing/marionette/driver.js b/testing/marionette/driver.js index 8a044210de03..1ce4e7e34dd1 100644 --- a/testing/marionette/driver.js +++ b/testing/marionette/driver.js @@ -2159,10 +2159,11 @@ GeckoDriver.prototype.findElements = async function(cmd, resp) { }; /** - * Return the active element on the page. + * Return the active element in the document. * * @return {WebElement} - * Active element of the current browsing context's document element. + * Active element of the current browsing context's document + * element, if the document element is non-null. * * @throws {UnsupportedOperationError} * Not available in current context. @@ -2170,6 +2171,9 @@ GeckoDriver.prototype.findElements = async function(cmd, resp) { * Top-level browsing context has been discarded. * @throws {UnexpectedAlertOpenError} * A modal dialog is open, blocking this operation. + * @throws {NoSuchElementError} + * If the document does not have an active element, i.e. if + * its document element has been deleted. */ GeckoDriver.prototype.getActiveElement = async function() { assert.content(this.context); diff --git a/testing/marionette/listener.js b/testing/marionette/listener.js index bb062e1709b2..f89320702111 100644 --- a/testing/marionette/listener.js +++ b/testing/marionette/listener.js @@ -1274,9 +1274,22 @@ async function findElementsContent(strategy, selector, opts = {}) { return webEls; } -/** Find and return the active element on the page. */ +/** + * Return the active element in the document. + * + * @return {WebElement} + * Active element of the current browsing context's document + * element, if the document element is non-null. + * + * @throws {NoSuchElementError} + * If the document does not have an active element, i.e. if + * its document element has been deleted. + */ function getActiveElement() { let el = curContainer.frame.document.activeElement; + if (!el) { + throw new NoSuchElementError(); + } return evaluate.toJSON(el, seenEls); } diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 610b431dbc21..1ddada085d67 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -575993,7 +575993,7 @@ "wdspec" ], "webdriver/tests/element_retrieval/get_active_element.py": [ - "74bb0beec41ab857f6814d47191f29065a536802", + "918c6e48047f31a088ec44e9b0d070b0ae3d6077", "wdspec" ], "webdriver/tests/fullscreen_window.py": [ diff --git a/testing/web-platform/meta/webdriver/tests/element_retrieval/get_active_element.py.ini b/testing/web-platform/meta/webdriver/tests/element_retrieval/get_active_element.py.ini index 32f84d5db5d4..23ed8a29b618 100644 --- a/testing/web-platform/meta/webdriver/tests/element_retrieval/get_active_element.py.ini +++ b/testing/web-platform/meta/webdriver/tests/element_retrieval/get_active_element.py.ini @@ -1,11 +1,8 @@ [get_active_element.py] type: wdspec + [get_active_element.py::test_handle_prompt_dismiss] expected: FAIL [get_active_element.py::test_handle_prompt_accept] expected: FAIL - - [get_active_element.py::test_sucess_without_body] - expected: FAIL - diff --git a/testing/web-platform/tests/webdriver/tests/element_retrieval/get_active_element.py b/testing/web-platform/tests/webdriver/tests/element_retrieval/get_active_element.py index 9bc6f732768f..5c2b52a55a03 100644 --- a/testing/web-platform/tests/webdriver/tests/element_retrieval/get_active_element.py +++ b/testing/web-platform/tests/webdriver/tests/element_retrieval/get_active_element.py @@ -2,9 +2,11 @@ from tests.support.fixtures import create_dialog from tests.support.inline import inline + def read_global(session, name): return session.execute_script("return %s;" % name) + def get_active_element(session): return session.transport.send("GET", "session/%s/element/active" % session.session_id) @@ -244,7 +246,7 @@ def test_success_iframe_content(session): assert_is_active_element(session, response) -def test_sucess_without_body(session): +def test_missing_document_element(session): session.url = inline("") session.execute_script(""" if (document.body.remove) { @@ -254,4 +256,4 @@ def test_sucess_without_body(session): }""") response = get_active_element(session) - assert_is_active_element(session, response) + assert_error(response, "no such element")