summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/webdriver/cdp/debugger_address.py
blob: 434edae4b5f916280ced08bedda5e860bf66301e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import json

import pytest
from support.context import using_context
from tests.support.http_request import HTTPRequest


def test_debugger_address_not_set(session):
    debugger_address = session.capabilities.get("moz:debuggerAddress")
    assert debugger_address is None


@pytest.mark.capabilities({"moz:debuggerAddress": False})
def test_debugger_address_false(session):
    debugger_address = session.capabilities.get("moz:debuggerAddress")
    assert debugger_address is None


@pytest.mark.capabilities({"moz:debuggerAddress": True})
def test_debugger_address_true_fission_disabled(session):
    debugger_address = session.capabilities.get("moz:debuggerAddress")
    assert debugger_address is not None

    host, port = debugger_address.split(":")
    assert host == "127.0.0.1"
    assert port.isnumeric()

    # Fetch the browser version via the debugger address, `localhost` has
    # to work as well.
    for target_host in [host, "localhost"]:
        print(f"Connecting to WebSocket via host {target_host}")
        http = HTTPRequest(target_host, int(port))
        with http.get("/json/version") as response:
            data = json.loads(response.read())
            assert session.capabilities["browserVersion"] in data["Browser"]

    # Force disabling Fission until Remote Agent is compatible
    with using_context(session, "chrome"):
        assert (
            session.execute_script("""return Services.appinfo.fissionAutostart""")
            is False
        )


@pytest.mark.capabilities(
    {
        "moz:debuggerAddress": True,
        "moz:firefoxOptions": {
            "prefs": {
                "fission.autostart": True,
            }
        },
    }
)
def test_debugger_address_true_fission_override(session):
    debugger_address = session.capabilities.get("moz:debuggerAddress")
    assert debugger_address is not None

    host, port = debugger_address.split(":")
    assert host == "127.0.0.1"
    assert port.isnumeric()

    # Fetch the browser version via the debugger address, `localhost` has
    # to work as well.
    for target_host in [host, "localhost"]:
        print(f"Connecting to WebSocket via host {target_host}")
        http = HTTPRequest(target_host, int(port))
        with http.get("/json/version") as response:
            data = json.loads(response.read())
            assert session.capabilities["browserVersion"] in data["Browser"]

    # Allow Fission to be enabled when setting the preference
    with using_context(session, "chrome"):
        assert (
            session.execute_script("""return Services.appinfo.fissionAutostart""")
            is True
        )