Skip to content

Commit

Permalink
Bug 1420431 - Return no such element error when on no active element.…
Browse files Browse the repository at this point in the history
… 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
<body> 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: w3c/webdriver#1157

MozReview-Commit-ID: LQJ3slV9aty

UltraBlame original commit: a0fdf492fb37e46ca46478de194d0998072282b6
  • Loading branch information
marco-c committed Oct 2, 2019
1 parent 2b48d59 commit 875d882
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
4 changes: 4 additions & 0 deletions testing/marionette/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,10 @@ GeckoDriver.prototype.findElements = async function(cmd, resp) {







GeckoDriver.prototype.getActiveElement = async function() {
assert.content(this.context);
assert.window(this.getCurrentWindow());
Expand Down
13 changes: 13 additions & 0 deletions testing/marionette/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -1275,8 +1275,21 @@ async function findElementsContent(strategy, selector, opts = {}) {
}












function getActiveElement() {
let el = curContainer.frame.document.activeElement;
if (!el) {
throw new NoSuchElementError();
}
return evaluate.toJSON(el, seenEls);
}

Expand Down
2 changes: 1 addition & 1 deletion testing/web-platform/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -575993,7 +575993,7 @@
"wdspec"
],
"webdriver/tests/element_retrieval/get_active_element.py": [
"74bb0beec41ab857f6814d47191f29065a536802",
"918c6e48047f31a088ec44e9b0d070b0ae3d6077",
"wdspec"
],
"webdriver/tests/fullscreen_window.py": [
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
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)

Expand Down Expand Up @@ -49,8 +53,8 @@ def test_closed_context(session, create_window):



def test_handle_prompt_dismiss(new_session):
_, session = new_session({"alwaysMatch": {"unhandledPromptBehavior": "dismiss"}})
def test_handle_prompt_dismiss(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss"})}})
session.url = inline("<body><p>Hello, World!</p></body>")

create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
Expand Down Expand Up @@ -88,8 +92,8 @@ def test_handle_prompt_dismiss(new_session):



def test_handle_prompt_accept(new_session):
_, session = new_session({"alwaysMatch": {"unhandledPromptBehavior": "accept"}})
def test_handle_prompt_accept(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
session.url = inline("<body><p>Hello, World!</p></body>")
create_dialog(session)("alert", text="accept #1", result_var="accept1")

Expand All @@ -110,7 +114,7 @@ def test_handle_prompt_accept(new_session):
response = get_active_element(session)
assert_is_active_element(session, response)
assert_dialog_handled(session, "accept #3")
assert read_global(session, "accept3") == ""
assert read_global(session, "accept3") == "" or read_global(session, "accept3") == "undefined"



Expand All @@ -133,7 +137,7 @@ def test_handle_prompt_missing_value(session, create_dialog):
response = get_active_element(session)
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, "dismiss #1")
assert session.execute_script("return accept1") is None
assert session.execute_script("return dismiss1") is None

create_dialog("confirm", text="dismiss #2", result_var="dismiss2")

Expand Down Expand Up @@ -212,8 +216,14 @@ def test_success_explicit_focus(session):
response = get_active_element(session)
assert_is_active_element(session, response)

session.execute_script("document.body.getElementsByTagName('iframe')[0].focus()")
session.execute_script("document.body.getElementsByTagName('iframe')[0].remove()")
session.execute_script("document.body.getElementsByTagName('iframe')[0].focus();")
session.execute_script("""
var iframe = document.body.getElementsByTagName('iframe')[0];
if (iframe.remove) {
iframe.remove();
} else {
iframe.removeNode(true);
}""")
response = get_active_element(session)
assert_is_active_element(session, response)

Expand All @@ -236,9 +246,14 @@ 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("<body></body>")
session.execute_script("document.body.remove()")
session.execute_script("""
if (document.body.remove) {
document.body.remove();
} else {
document.body.removeNode(true);
}""")

response = get_active_element(session)
assert_is_active_element(session, response)
assert_error(response, "no such element")

0 comments on commit 875d882

Please sign in to comment.