зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1410891 - Use a command helper function. r=maja_zf
Instead of making repeated calls to session.transport.send we can use a helper function like most of the other tests do. This makes the test more succinct and easier on the eye. MozReview-Commit-ID: 689rticvu2d --HG-- extra : rebase_source : 60196056a9276d331afcdc60e9e43081746546f2
This commit is contained in:
Родитель
88ff8e0fe8
Коммит
7db958ab04
|
@ -3,6 +3,10 @@ from tests.support.fixtures import create_dialog
|
|||
from tests.support.inline import inline
|
||||
|
||||
|
||||
def get_active_element(session):
|
||||
return session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
|
||||
def assert_is_active_element(session, response):
|
||||
"""Ensure that the provided object is a successful WebDriver
|
||||
response describing an element reference and that the referenced
|
||||
|
@ -27,11 +31,10 @@ def test_closed_context(session, create_window):
|
|||
session.window_handle = new_window
|
||||
session.close()
|
||||
|
||||
response = session.transport.send("GET",
|
||||
"session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_error(response, "no such window")
|
||||
|
||||
|
||||
# [...]
|
||||
# 2. Handle any user prompts and return its value if it is an error.
|
||||
# [...]
|
||||
|
@ -51,28 +54,26 @@ def test_handle_prompt_dismiss(new_session):
|
|||
|
||||
create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
assert_dialog_handled(session, "dismiss #1")
|
||||
assert session.execute_script("return dismiss1") is None
|
||||
|
||||
create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
assert_dialog_handled(session, "dismiss #2")
|
||||
assert read_global(session, "dismiss2") is None
|
||||
|
||||
create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
assert_dialog_handled(session, "dismiss #3")
|
||||
assert read_global(session, "dismiss3") is None
|
||||
|
||||
|
||||
# [...]
|
||||
# 2. Handle any user prompts and return its value if it is an error.
|
||||
# [...]
|
||||
|
@ -91,28 +92,26 @@ def test_handle_prompt_accept(new_session):
|
|||
session.url = inline("<body><p>Hello, World!</p></body>")
|
||||
create_dialog(session)("alert", text="accept #1", result_var="accept1")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
assert_dialog_handled(session, "accept #1")
|
||||
assert read_global(session, "accept1") is None
|
||||
|
||||
create_dialog(session)("confirm", text="accept #2", result_var="accept2")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
assert_dialog_handled(session, "accept #2")
|
||||
assert read_global(session, "accept2") is True
|
||||
|
||||
create_dialog(session)("prompt", text="accept #3", result_var="accept3")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
assert_dialog_handled(session, "accept #3")
|
||||
assert read_global(session, "accept3") == ""
|
||||
|
||||
|
||||
# [...]
|
||||
# 2. Handle any user prompts and return its value if it is an error.
|
||||
# [...]
|
||||
|
@ -130,28 +129,26 @@ def test_handle_prompt_missing_value(session, create_dialog):
|
|||
|
||||
create_dialog("alert", text="dismiss #1", result_var="dismiss1")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
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
|
||||
|
||||
create_dialog("confirm", text="dismiss #2", result_var="dismiss2")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_error(response, "unexpected alert open")
|
||||
assert_dialog_handled(session, "dismiss #2")
|
||||
assert session.execute_script("return dismiss2") is False
|
||||
|
||||
create_dialog("prompt", text="dismiss #3", result_var="dismiss3")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_error(response, "unexpected alert open")
|
||||
assert_dialog_handled(session, "dismiss #3")
|
||||
assert session.execute_script("return dismiss3") is None
|
||||
|
||||
|
||||
# > [...]
|
||||
# > 3. Let active element be the active element of the current browsing
|
||||
# > context's document element.
|
||||
|
@ -163,37 +160,37 @@ def test_success_document(session):
|
|||
<h1>Heading</h1>
|
||||
<input />
|
||||
<input />
|
||||
<input style="opacity: 0;" />
|
||||
<input style="opacity: 0" />
|
||||
<p>Another element</p>
|
||||
</body>""")
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
|
||||
|
||||
def test_sucess_input(session):
|
||||
session.url = inline("""
|
||||
<body>
|
||||
<h1>Heading</h1>
|
||||
<input autofocus />
|
||||
<input style="opacity: 0;" />
|
||||
<input style="opacity: 0" />
|
||||
<p>Another element</p>
|
||||
</body>""")
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
|
||||
|
||||
def test_sucess_input_non_interactable(session):
|
||||
session.url = inline("""
|
||||
<body>
|
||||
<h1>Heading</h1>
|
||||
<input />
|
||||
<input style="opacity: 0;" autofocus />
|
||||
<input style="opacity: 0" autofocus />
|
||||
<p>Another element</p>
|
||||
</body>""")
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
|
||||
|
||||
def test_success_explicit_focus(session):
|
||||
session.url = inline("""
|
||||
<body>
|
||||
|
@ -202,44 +199,45 @@ def test_success_explicit_focus(session):
|
|||
<iframe></iframe>
|
||||
</body>""")
|
||||
|
||||
session.execute_script("document.body.getElementsByTagName('h1')[0].focus();")
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
session.execute_script("document.body.getElementsByTagName('h1')[0].focus()")
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
|
||||
session.execute_script("document.body.getElementsByTagName('input')[0].focus();")
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
session.execute_script("document.body.getElementsByTagName('input')[0].focus()")
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
|
||||
session.execute_script("document.body.getElementsByTagName('iframe')[0].focus();")
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
session.execute_script("document.body.getElementsByTagName('iframe')[0].focus()")
|
||||
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();")
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
session.execute_script("document.body.getElementsByTagName('iframe')[0].focus()")
|
||||
session.execute_script("document.body.getElementsByTagName('iframe')[0].remove()")
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
|
||||
session.execute_script("document.body.appendChild(document.createElement('textarea'));")
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
session.execute_script("document.body.appendChild(document.createElement('textarea'))")
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
|
||||
|
||||
def test_success_iframe_content(session):
|
||||
session.url = inline("<body></body>")
|
||||
session.execute_script("""
|
||||
var iframe = document.createElement('iframe');
|
||||
let iframe = document.createElement('iframe');
|
||||
document.body.appendChild(iframe);
|
||||
var input = iframe.contentDocument.createElement('input');
|
||||
let input = iframe.contentDocument.createElement('input');
|
||||
iframe.contentDocument.body.appendChild(input);
|
||||
input.focus();""")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active" % session.session_id)
|
||||
input.focus();
|
||||
""")
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
|
||||
|
||||
def test_sucess_without_body(session):
|
||||
session.url = inline("<body></body>")
|
||||
session.execute_script("document.body.remove();")
|
||||
|
||||
response = session.transport.send("GET", "session/%s/element/active"% session.session_id)
|
||||
session.execute_script("document.body.remove()")
|
||||
|
||||
response = get_active_element(session)
|
||||
assert_is_active_element(session, response)
|
||||
|
|
Загрузка…
Ссылка в новой задаче