зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1722090 - [remote] Move useful browser chrome tests for Remote Agent to wdspec. r=webdriver-reviewers,jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D144213
This commit is contained in:
Родитель
da2397f3eb
Коммит
9e73783530
|
@ -10,5 +10,3 @@ support-files =
|
|||
# It should be the only tests in this suite to avoid side-effects with
|
||||
# regular tests which reuse a shared RemoteAgent instance.
|
||||
[browser_agent.js]
|
||||
[browser_agent_webdriver_bidi.js]
|
||||
skip-if = release_or_beta # Bug 1712902
|
||||
|
|
|
@ -41,30 +41,6 @@ add_agent_task(async function remoteListeningNotification() {
|
|||
is(active, null, "remote-listening observer notified disabled state");
|
||||
});
|
||||
|
||||
add_agent_task(async function remoteDevToolsActivePortFile() {
|
||||
const portFile = PathUtils.join(PathUtils.profileDir, "DevToolsActivePort");
|
||||
|
||||
const port = getNonAtomicFreePort();
|
||||
|
||||
await RemoteAgent.listen("http://localhost:" + port);
|
||||
|
||||
if (await IOUtils.exists(portFile)) {
|
||||
const buffer = await IOUtils.read(portFile);
|
||||
const lines = new TextDecoder().decode(buffer).split("\n");
|
||||
is(lines.length, 2, "DevToolsActivePort file contains two lines");
|
||||
is(parseInt(lines[0]), port, "DevToolsActivePort file contains port");
|
||||
ok(
|
||||
RemoteAgent.cdp.mainTargetPath.includes(lines[1]),
|
||||
"DevToolsActivePort file contains main target path"
|
||||
);
|
||||
} else {
|
||||
ok(false, "DevToolsActivePort file written");
|
||||
}
|
||||
|
||||
await RemoteAgent.close();
|
||||
ok(!(await IOUtils.exists(portFile)), "DevToolsActivePort file removed");
|
||||
});
|
||||
|
||||
// TODO(ato): https://bugzil.la/1590829
|
||||
add_agent_task(async function listenTakesString() {
|
||||
await RemoteAgent.listen("http://localhost:0");
|
||||
|
@ -83,7 +59,7 @@ add_agent_task(async function listenNonURL() {
|
|||
|
||||
add_agent_task(async function listenRestrictedToLoopbackDevice() {
|
||||
try {
|
||||
await RemoteAgent.listen("http://0.0.0.0:0");
|
||||
await RemoteAgent.listen("http://0.0.0.0:9222");
|
||||
fail("listen() did not reject non-loopback device");
|
||||
} catch (e) {
|
||||
is(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
add_agent_task(async function remoteWebDriverBiDiActivePortFile() {
|
||||
const portFile = PathUtils.join(
|
||||
PathUtils.profileDir,
|
||||
"WebDriverBiDiActivePort"
|
||||
);
|
||||
|
||||
const port = getNonAtomicFreePort();
|
||||
|
||||
await RemoteAgent.listen("http://localhost:" + port);
|
||||
|
||||
if (await IOUtils.exists(portFile)) {
|
||||
const buffer = await IOUtils.read(portFile);
|
||||
const lines = new TextDecoder().decode(buffer).split("\n");
|
||||
is(lines.length, 1, "WebDriverBiDiActivePort file contains two lines");
|
||||
is(parseInt(lines[0]), port, "WebDriverBiDiActivePort file contains port");
|
||||
} else {
|
||||
ok(false, "WebDriverBiDiActivePort file written");
|
||||
}
|
||||
|
||||
await RemoteAgent.close();
|
||||
ok(!(await IOUtils.exists(portFile)), "WebDriverBiDiActivePort file removed");
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
[port_file.py]
|
||||
disabled:
|
||||
if os == "android": https://bugzilla.mozilla.org/show_bug.cgi?id=1762164
|
|
@ -52,7 +52,7 @@ from support.network import websocket_request, get_host
|
|||
)
|
||||
def test_host_header(browser, hostname, port_type, status):
|
||||
# Request a default browser
|
||||
current_browser = browser(enable_bidi=True)
|
||||
current_browser = browser(use_bidi=True)
|
||||
server_port = current_browser.remote_agent_port
|
||||
test_host = get_host(port_type, hostname, server_port)
|
||||
|
||||
|
@ -102,7 +102,7 @@ def test_host_header(browser, hostname, port_type, status):
|
|||
def test_allowed_hosts(browser, hostname, port_type, status):
|
||||
# Request a browser with custom allowed hosts.
|
||||
current_browser = browser(
|
||||
enable_bidi=True,
|
||||
use_bidi=True,
|
||||
extra_args=["--remote-allow-hosts", "testhost"],
|
||||
)
|
||||
server_port = current_browser.remote_agent_port
|
||||
|
@ -123,7 +123,7 @@ def test_allowed_hosts(browser, hostname, port_type, status):
|
|||
)
|
||||
def test_origin_header(browser, origin, status):
|
||||
# Request a default browser.
|
||||
current_browser = browser(enable_bidi=True)
|
||||
current_browser = browser(use_bidi=True)
|
||||
server_port = current_browser.remote_agent_port
|
||||
response = websocket_request(server_port, origin=origin)
|
||||
assert response.status == status
|
||||
|
@ -142,7 +142,7 @@ def test_origin_header(browser, origin, status):
|
|||
def test_allowed_origins(browser, origin, status):
|
||||
# Request a browser with custom allowed origins.
|
||||
current_browser = browser(
|
||||
enable_bidi=True,
|
||||
use_bidi=True,
|
||||
extra_args=["--remote-allow-origins", "http://localhost:1234"],
|
||||
)
|
||||
server_port = current_browser.remote_agent_port
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import os
|
||||
|
||||
from support.network import websocket_request
|
||||
|
||||
|
||||
def test_devtools_active_port_file(browser):
|
||||
current_browser = browser(use_cdp=True)
|
||||
|
||||
assert current_browser.remote_agent_port == "9222"
|
||||
assert current_browser.debugger_address.startswith("/devtools/browser/")
|
||||
|
||||
port_file = os.path.join(current_browser.profile.profile, "DevToolsActivePort")
|
||||
assert os.path.exists(port_file)
|
||||
|
||||
current_browser.quit(clean_profile=False)
|
||||
assert not os.path.exists(port_file)
|
||||
|
||||
|
||||
def test_connect(browser):
|
||||
current_browser = browser(use_cdp=True)
|
||||
|
||||
response = websocket_request(
|
||||
current_browser.remote_agent_port, path=current_browser.debugger_address
|
||||
)
|
||||
assert response.status == 101
|
|
@ -21,11 +21,11 @@ def browser(full_configuration):
|
|||
|
||||
Starting Firefox without geckodriver allows to set those command line arguments
|
||||
as needed. The fixture method returns the browser instance that should be used
|
||||
to connect to WebDriverBiDi.
|
||||
to connect to a RemoteAgent supported protocol (CDP, WebDriver BiDi).
|
||||
"""
|
||||
current_browser = None
|
||||
|
||||
def _browser(enable_bidi=False, extra_args=None, extra_prefs=None):
|
||||
def _browser(use_bidi=False, use_cdp=False, extra_args=None, extra_prefs=None):
|
||||
nonlocal current_browser
|
||||
|
||||
# If the requested preferences and arguments match the ones for the
|
||||
|
@ -33,9 +33,11 @@ def browser(full_configuration):
|
|||
# return the instance immediately.
|
||||
if current_browser:
|
||||
if (
|
||||
current_browser.enable_bidi == enable_bidi
|
||||
current_browser.use_bidi == use_bidi
|
||||
and current_browser.use_cdp == use_cdp
|
||||
and current_browser.extra_args == extra_args
|
||||
and current_browser.extra_prefs == extra_prefs
|
||||
and current_browser.is_running
|
||||
):
|
||||
return current_browser
|
||||
|
||||
|
@ -46,7 +48,8 @@ def browser(full_configuration):
|
|||
firefox_options = full_configuration["capabilities"]["moz:firefoxOptions"]
|
||||
current_browser = Browser(
|
||||
firefox_options,
|
||||
enable_bidi=enable_bidi,
|
||||
use_bidi=use_bidi,
|
||||
use_cdp=use_cdp,
|
||||
extra_args=extra_args,
|
||||
extra_prefs=extra_prefs,
|
||||
)
|
||||
|
@ -85,13 +88,17 @@ class Browser:
|
|||
def __init__(
|
||||
self,
|
||||
firefox_options,
|
||||
enable_bidi=False,
|
||||
use_bidi=False,
|
||||
use_cdp=False,
|
||||
extra_args=None,
|
||||
extra_prefs=None,
|
||||
):
|
||||
self.enable_bidi = enable_bidi
|
||||
self.use_bidi = use_bidi
|
||||
self.use_cdp = use_cdp
|
||||
self.extra_args = extra_args
|
||||
self.extra_prefs = extra_prefs
|
||||
|
||||
self.debugger_address = None
|
||||
self.remote_agent_port = None
|
||||
|
||||
# Prepare temporary profile
|
||||
|
@ -104,7 +111,7 @@ class Browser:
|
|||
binary = firefox_options["binary"]
|
||||
|
||||
cmdargs = ["-no-remote"]
|
||||
if self.enable_bidi:
|
||||
if self.use_bidi or self.use_cdp:
|
||||
cmdargs.append("--remote-debugging-port")
|
||||
if self.extra_args is not None:
|
||||
cmdargs.extend(self.extra_args)
|
||||
|
@ -112,22 +119,44 @@ class Browser:
|
|||
binary=binary, profile=self.profile, cmdargs=cmdargs
|
||||
)
|
||||
|
||||
@property
|
||||
def is_running(self):
|
||||
return self.runner.is_running()
|
||||
|
||||
def start(self):
|
||||
# Start Firefox.
|
||||
self.runner.start()
|
||||
|
||||
# Wait until the WebDriverBiDiActivePort file is ready
|
||||
port_file = os.path.join(self.profile.profile, "WebDriverBiDiActivePort")
|
||||
while not os.path.exists(port_file):
|
||||
time.sleep(0.1)
|
||||
if self.use_bidi:
|
||||
# Wait until the WebDriverBiDiActivePort file is ready
|
||||
port_file = os.path.join(self.profile.profile, "WebDriverBiDiActivePort")
|
||||
while not os.path.exists(port_file):
|
||||
time.sleep(0.1)
|
||||
|
||||
# Read the port from the WebDriverBiDiActivePort file
|
||||
self.remote_agent_port = open(port_file).read()
|
||||
# Read the port from the WebDriverBiDiActivePort file
|
||||
self.remote_agent_port = open(port_file).read()
|
||||
|
||||
def quit(self):
|
||||
if self.runner:
|
||||
if self.use_cdp:
|
||||
# Wait until the DevToolsActivePort file is ready
|
||||
port_file = os.path.join(self.profile.profile, "DevToolsActivePort")
|
||||
while not os.path.exists(port_file):
|
||||
time.sleep(0.1)
|
||||
|
||||
# Read the port if needed and the debugger address from the
|
||||
# DevToolsActivePort file
|
||||
lines = open(port_file).readlines()
|
||||
assert len(lines) == 2
|
||||
|
||||
if self.remote_agent_port is None:
|
||||
self.remote_agent_port = lines[0].strip()
|
||||
self.debugger_address = lines[1].strip()
|
||||
|
||||
def quit(self, clean_profile=True):
|
||||
if self.is_running:
|
||||
self.runner.stop()
|
||||
self.runner.cleanup()
|
||||
|
||||
if clean_profile:
|
||||
self.profile.cleanup()
|
||||
|
||||
|
||||
|
@ -174,7 +203,7 @@ class Geckodriver:
|
|||
end_time = time.time() + 10
|
||||
while time.time() < end_time:
|
||||
if self.proc.poll() is not None:
|
||||
raise (f"geckodriver terminated with code {self.proc.poll()}")
|
||||
raise Exception(f"geckodriver terminated with code {self.proc.poll()}")
|
||||
with socket.socket() as sock:
|
||||
if sock.connect_ex((self.hostname, self.port)) == 0:
|
||||
break
|
||||
|
|
|
@ -2,9 +2,9 @@ import socket
|
|||
from http.client import HTTPConnection
|
||||
|
||||
|
||||
def websocket_request(remote_agent_port, host=None, origin=None):
|
||||
def websocket_request(remote_agent_port, host=None, origin=None, path="/session"):
|
||||
real_host = f"localhost:{remote_agent_port}"
|
||||
url = f"http://{real_host}/session"
|
||||
url = f"http://{real_host}{path}"
|
||||
|
||||
conn = HTTPConnection(real_host)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче