tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

marionette_port.py (1313B)


      1 import os
      2 from copy import deepcopy
      3 
      4 import pytest
      5 
      6 pytestmark = pytest.mark.asyncio
      7 
      8 
      9 @pytest.mark.parametrize("port", ["0", "2828"], ids=["system allocated", "fixed"])
     10 async def test_marionette_port(geckodriver, port):
     11    extra_args = ["--marionette-port", port]
     12 
     13    driver = geckodriver(extra_args=extra_args)
     14    driver.new_session()
     15    await driver.delete_session()
     16 
     17 
     18 async def test_marionette_port_outdated_active_port_file(
     19    configuration, create_custom_profile, geckodriver
     20 ):
     21    config = deepcopy(configuration)
     22    custom_profile = create_custom_profile()
     23    extra_args = ["--marionette-port", "0"]
     24 
     25    # Prepare a Marionette active port file that contains a port which will
     26    # never be used when requesting a system allocated port.
     27    active_port_file = os.path.join(custom_profile.profile, "MarionetteActivePort")
     28    with open(active_port_file, "wb") as f:
     29        f.write(b"53")
     30 
     31    config["capabilities"]["moz:firefoxOptions"]["args"] = [
     32        "--profile",
     33        custom_profile.profile,
     34    ]
     35 
     36    driver = geckodriver(config=config, extra_args=extra_args)
     37 
     38    driver.new_session()
     39    with open(active_port_file, "rb") as f:
     40        assert f.readline() != b"53"
     41 
     42    await driver.delete_session()
     43    with pytest.raises(FileNotFoundError):
     44        open(active_port_file, "rb")