зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 6e89ab9da437 (bug 1648964) for WebDriver Failures in new_session_binary.py. CLOSED TREE
This commit is contained in:
Родитель
47ab533983
Коммит
3955f2d04b
|
@ -1,67 +1,8 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from webdriver.transport import HTTPWireProtocol
|
||||
|
||||
base = os.path.dirname(__file__)
|
||||
webdriver_path = os.path.abspath(os.path.join(base, "..", "..", "..", "tests", "webdriver"))
|
||||
sys.path.insert(0, os.path.join(webdriver_path))
|
||||
|
||||
pytest_plugins = ["tests.support.fixtures"]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configuration(configuration):
|
||||
"""Remove "acceptInsecureCerts" from capabilities if it exists.
|
||||
|
||||
Some browser configurations add acceptInsecureCerts capability by default.
|
||||
Remove it during new_session tests to avoid interference.
|
||||
"""
|
||||
|
||||
if "acceptInsecureCerts" in configuration["capabilities"]:
|
||||
configuration = dict(configuration)
|
||||
del configuration["capabilities"]["acceptInsecureCerts"]
|
||||
return configuration
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def new_session(request, configuration, current_session):
|
||||
"""Start a new session for tests which themselves test creating new sessions.
|
||||
|
||||
:param body: The content of the body for the new session POST request.
|
||||
|
||||
:param delete_existing_session: Allows the fixture to delete an already
|
||||
created custom session before the new session is getting created. This
|
||||
is useful for tests which call this fixture multiple times within the
|
||||
same test.
|
||||
"""
|
||||
custom_session = {}
|
||||
|
||||
transport = HTTPWireProtocol(
|
||||
configuration["host"], configuration["port"], url_prefix="/",
|
||||
)
|
||||
|
||||
def _delete_session(session_id):
|
||||
transport.send("DELETE", "session/{}".format(session_id))
|
||||
|
||||
def new_session(body, delete_existing_session=False, headers=None):
|
||||
# If there is an active session from the global session fixture,
|
||||
# delete that one first
|
||||
if current_session is not None:
|
||||
current_session.end()
|
||||
|
||||
if delete_existing_session:
|
||||
_delete_session(custom_session["session"]["sessionId"])
|
||||
|
||||
response = transport.send("POST", "session", body, headers=headers)
|
||||
if response.status == 200:
|
||||
custom_session["session"] = response.body["value"]
|
||||
return response, custom_session.get("session", None)
|
||||
|
||||
yield new_session
|
||||
|
||||
if custom_session.get("session") is not None:
|
||||
_delete_session(custom_session["session"]["sessionId"])
|
||||
custom_session = None
|
||||
pytest_plugins = "tests.support.fixtures"
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.support.asserts import assert_success
|
||||
|
||||
|
||||
@pytest.mark.parametrize("headers", [{"origin": "http://localhost"},
|
||||
{"content-type": "application/json"}])
|
||||
def test_valid(new_session, configuration, headers):
|
||||
response, _ = new_session({"capabilities": {"alwaysMatch": dict(configuration["capabilities"])}},
|
||||
headers=headers)
|
||||
assert_success(response)
|
|
@ -1,32 +0,0 @@
|
|||
import os
|
||||
|
||||
from tests.support.asserts import assert_error, assert_success
|
||||
|
||||
|
||||
def test_bad_binary(new_session):
|
||||
# skipif annotations are forbidden in wpt
|
||||
if os.path.exists("/bin/echo"):
|
||||
response, _ = new_session({"capabilities":
|
||||
{"alwaysMatch": {"moz:firefoxOptions": {"binary": "/bin/echo"}}
|
||||
}})
|
||||
assert_error(response, "invalid argument")
|
||||
|
||||
|
||||
def test_shell_script_binary(new_session, configuration):
|
||||
# skipif annotations are forbidden in wpt
|
||||
if os.path.exists("/bin/bash"):
|
||||
capabilities = configuration["capabilities"].copy()
|
||||
script = """#!/bin/bash
|
||||
|
||||
%s $@""" % capabilities["moz:firefoxOptions"]["binary"]
|
||||
path = os.path.abspath("firefox.sh")
|
||||
assert not os.path.exists(path)
|
||||
try:
|
||||
with open("firefox.sh", "w") as f:
|
||||
f.write(script)
|
||||
os.chmod(path, 0o744)
|
||||
capabilities["moz:firefoxOptions"]["binary"] = path
|
||||
response, _ = new_session({"capabilities": capabilities})
|
||||
assert_success(response)
|
||||
finally:
|
||||
os.unlink(path)
|
|
@ -1,23 +0,0 @@
|
|||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.support.asserts import assert_error
|
||||
|
||||
|
||||
@pytest.mark.parametrize("headers", [{"origin": "http://example.org"},
|
||||
{"origin": "null"},
|
||||
{"ORIGIN": "https://example.org"},
|
||||
{"content-type": "application/x-www-form-urlencoded"},
|
||||
{"content-type": "multipart/form-data"},
|
||||
{"content-type": "text/plain"},
|
||||
{"Content-TYPE": "APPLICATION/x-www-form-urlencoded"},
|
||||
{"content-type": "MULTIPART/FORM-DATA"},
|
||||
{"CONTENT-TYPE": "TEXT/PLAIN"},
|
||||
{"content-type": "text/plain ; charset=utf-8"},
|
||||
{"content-type": "text/plain;foo"},
|
||||
{"content-type": "text/PLAIN ; foo;charset=utf8"}])
|
||||
def test_invalid(new_session, configuration, headers):
|
||||
response, _ = new_session({"capabilities": {"alwaysMatch": dict(configuration["capabilities"])}},
|
||||
headers=headers)
|
||||
assert_error(response, "unknown error")
|
Загрузка…
Ссылка в новой задаче