tor-browser

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

profile_root.py (1534B)


      1 import copy
      2 import os
      3 
      4 import pytest
      5 
      6 pytestmark = pytest.mark.asyncio
      7 
      8 
      9 async def test_profile_root(tmp_path, configuration, geckodriver, default_preferences):
     10    profile_path = os.path.join(tmp_path, "geckodriver-test")
     11    os.makedirs(profile_path)
     12 
     13    config = copy.deepcopy(configuration)
     14 
     15    # Pass all the wpt preferences from the default profile's user.js via
     16    # capabilities to allow geckodriver to create a new valid profile itself.
     17    config["capabilities"]["moz:firefoxOptions"]["prefs"] = default_preferences
     18 
     19    # Ensure we don't set a profile in command line arguments
     20    del config["capabilities"]["moz:firefoxOptions"]["args"]
     21 
     22    extra_args = ["--profile-root", profile_path]
     23 
     24    assert os.listdir(profile_path) == []
     25 
     26    driver = geckodriver(config=config, extra_args=extra_args)
     27    driver.new_session()
     28    assert len(os.listdir(profile_path)) == 1
     29    await driver.delete_session()
     30    assert os.listdir(profile_path) == []
     31 
     32 
     33 def test_profile_root_missing(tmp_path, configuration, geckodriver):
     34    profile_path = os.path.join(tmp_path, "missing-path")
     35    assert not os.path.exists(profile_path)
     36 
     37    config = copy.deepcopy(configuration)
     38    # Ensure we don't set a profile in command line arguments
     39    del config["capabilities"]["moz:firefoxOptions"]["args"]
     40 
     41    extra_args = ["--profile-root", profile_path]
     42 
     43    with pytest.raises(ChildProcessError) as exc_info:
     44        geckodriver(config=config, extra_args=extra_args)
     45    assert str(exc_info.value) == "geckodriver terminated with code 64"