summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/webdriver/new_session/binary.py
blob: 2baa40572bad6a23022b84123ab5f93b076b8f12 (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
import os
import sys

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 sys.platform == "linux":
        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)