File: debugger_address.py

package info (click to toggle)
mozjs140 140.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,216,752 kB
  • sloc: javascript: 2,267,210; cpp: 1,423,664; python: 966,252; ansic: 632,297; xml: 115,965; sh: 15,392; asm: 13,399; makefile: 10,455; yacc: 4,504; perl: 2,223; lex: 1,414; ruby: 1,064; exp: 756; java: 185; sql: 66; sed: 18
file content (82 lines) | stat: -rw-r--r-- 2,365 bytes parent folder | download | duplicates (10)
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
78
79
80
81
82
# META: timeout=long

import json

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


@pytest.fixture(autouse=True)
def clear_protocol_pref(session):
    yield
    clear_pref(session, "remote.active-protocols")


@pytest.mark.allow_system_access
@pytest.mark.capabilities(
    {
        "moz:firefoxOptions": {
            "prefs": {
                "remote.active-protocols": 2,
            },
        },
    }
)
def test_debugger_address_not_set(session, capabilities):
    debugger_address = session.capabilities.get("moz:debuggerAddress")
    assert debugger_address is None


@pytest.mark.allow_system_access
@pytest.mark.capabilities(
    {
        "moz:debuggerAddress": False,
        "moz:firefoxOptions": {
            "prefs": {
                "remote.active-protocols": 2,
            },
        },
    }
)
def test_debugger_address_false(session):
    debugger_address = session.capabilities.get("moz:debuggerAddress")
    assert debugger_address is None


@pytest.mark.allow_system_access
@pytest.mark.capabilities(
    {
        "moz:debuggerAddress": True,
        "moz:firefoxOptions": {
            "prefs": {
                "remote.active-protocols": 2,
            },
        },
    }
)
@pytest.mark.parametrize("fission_enabled", [True, False], ids=["enabled", "disabled"])
def test_debugger_address_true_with_fission(session, capabilities, fission_enabled):
    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"]

    # Ensure Fission is not disabled (bug 1813981)
    with using_context(session, "chrome"):
        assert (
            session.execute_script("""return Services.appinfo.fissionAutostart""")
            is fission_enabled
        )