tor-browser

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

test_install.py (2914B)


      1 import subprocess
      2 
      3 import mozinfo
      4 import mozinstall
      5 import mozunit
      6 import pytest
      7 
      8 
      9 @pytest.mark.skipif(
     10    mozinfo.isWin,
     11    reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
     12 )
     13 def test_is_installer(request, get_installer):
     14    """Test that we can identify a correct installer."""
     15    assert mozinstall.is_installer(get_installer("tar.xz"))
     16    assert mozinstall.is_installer(get_installer("zip"))
     17 
     18    if mozinfo.isWin:
     19        assert mozinstall.is_installer(get_installer("msix"))
     20 
     21        # test exe installer
     22        assert mozinstall.is_installer(get_installer("exe"))
     23 
     24        try:
     25            # test stub browser file
     26            # without pefile on the system this test will fail
     27            import pefile  # noqa
     28 
     29            stub_exe = (
     30                request.node.fspath.dirpath("build_stub").join("firefox.exe").strpath
     31            )
     32            assert not mozinstall.is_installer(stub_exe)
     33        except ImportError:
     34            pass
     35 
     36    if mozinfo.isMac or mozinfo.isLinux:
     37        assert mozinstall.is_installer(get_installer("dmg"))
     38 
     39 
     40 def test_invalid_source_error(get_installer):
     41    """Test that InvalidSource error is raised with an incorrect installer."""
     42    if mozinfo.isWin:
     43        with pytest.raises(mozinstall.InvalidSource):
     44            mozinstall.install(get_installer("dmg"), "firefox")
     45 
     46    elif mozinfo.isLinux:
     47        with pytest.raises(mozinstall.InvalidSource):
     48            mozinstall.install(get_installer("msix"), "firefox")
     49 
     50    elif mozinfo.isMac:
     51        with pytest.raises(mozinstall.InvalidSource):
     52            mozinstall.install(get_installer("exe"), "firefox")
     53 
     54    # Test an invalid url handler
     55    with pytest.raises(mozinstall.InvalidSource):
     56        mozinstall.install("file://foo.bar", "firefox")
     57 
     58 
     59 @pytest.mark.skipif(
     60    mozinfo.isWin,
     61    reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
     62 )
     63 def test_install(tmpdir, get_installer):
     64    """Test to install an installer."""
     65    installdir_zip = mozinstall.install(
     66        get_installer("zip"), tmpdir.join("zip").strpath
     67    )
     68    assert installdir_zip == tmpdir.join("zip", "firefox").strpath
     69 
     70    if mozinfo.isLinux:
     71        installdir = mozinstall.install(get_installer("tar.xz"), tmpdir.strpath)
     72        assert installdir == tmpdir.join("firefox").strpath
     73 
     74    elif mozinfo.isWin:
     75        installdir_exe = mozinstall.install(
     76            get_installer("exe"), tmpdir.join("exe").strpath
     77        )
     78        assert installdir_exe == tmpdir.join("exe", "firefox").strpath
     79 
     80    elif mozinfo.isMac:
     81        installdir = mozinstall.install(get_installer("dmg"), tmpdir.strpath)
     82        assert installdir == tmpdir.realpath().join("Firefox Stub.app").strpath
     83 
     84        mounted_images = subprocess.check_output(["hdiutil", "info"]).decode("ascii")
     85        assert get_installer("dmg") not in mounted_images
     86 
     87 
     88 if __name__ == "__main__":
     89    mozunit.main()