summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozinstall/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--testing/mozbase/mozinstall/tests/conftest.py14
-rw-r--r--testing/mozbase/mozinstall/tests/installer_stubs/firefox.dmgbin0 -> 27309 bytes
-rw-r--r--testing/mozbase/mozinstall/tests/installer_stubs/firefox.tar.bz2bin0 -> 2882 bytes
-rw-r--r--testing/mozbase/mozinstall/tests/installer_stubs/firefox.zipbin0 -> 8707 bytes
-rw-r--r--testing/mozbase/mozinstall/tests/manifest.ini8
-rw-r--r--testing/mozbase/mozinstall/tests/test_binary.py50
-rw-r--r--testing/mozbase/mozinstall/tests/test_install.py90
-rw-r--r--testing/mozbase/mozinstall/tests/test_is_installer.py40
-rw-r--r--testing/mozbase/mozinstall/tests/test_uninstall.py39
9 files changed, 241 insertions, 0 deletions
diff --git a/testing/mozbase/mozinstall/tests/conftest.py b/testing/mozbase/mozinstall/tests/conftest.py
new file mode 100644
index 0000000000..132547a96b
--- /dev/null
+++ b/testing/mozbase/mozinstall/tests/conftest.py
@@ -0,0 +1,14 @@
+import pytest
+
+
+@pytest.fixture
+def get_installer(request):
+ def _get_installer(extension):
+ """Get path to the installer for the specified extension."""
+ stub_dir = request.node.fspath.dirpath("installer_stubs")
+
+ # We had to remove firefox.exe since it is not valid for mozinstall 1.12 and higher
+ # Bug 1157352 - We should grab a firefox.exe from the build process or download it
+ return stub_dir.join("firefox.{}".format(extension)).strpath
+
+ return _get_installer
diff --git a/testing/mozbase/mozinstall/tests/installer_stubs/firefox.dmg b/testing/mozbase/mozinstall/tests/installer_stubs/firefox.dmg
new file mode 100644
index 0000000000..dd9c779dfa
--- /dev/null
+++ b/testing/mozbase/mozinstall/tests/installer_stubs/firefox.dmg
Binary files differ
diff --git a/testing/mozbase/mozinstall/tests/installer_stubs/firefox.tar.bz2 b/testing/mozbase/mozinstall/tests/installer_stubs/firefox.tar.bz2
new file mode 100644
index 0000000000..cb046a0e7f
--- /dev/null
+++ b/testing/mozbase/mozinstall/tests/installer_stubs/firefox.tar.bz2
Binary files differ
diff --git a/testing/mozbase/mozinstall/tests/installer_stubs/firefox.zip b/testing/mozbase/mozinstall/tests/installer_stubs/firefox.zip
new file mode 100644
index 0000000000..7c3f61a5e9
--- /dev/null
+++ b/testing/mozbase/mozinstall/tests/installer_stubs/firefox.zip
Binary files differ
diff --git a/testing/mozbase/mozinstall/tests/manifest.ini b/testing/mozbase/mozinstall/tests/manifest.ini
new file mode 100644
index 0000000000..d5e0d06976
--- /dev/null
+++ b/testing/mozbase/mozinstall/tests/manifest.ini
@@ -0,0 +1,8 @@
+[DEFAULT]
+subsuite = mozbase
+[test_binary.py]
+skip-if = os == 'mac'
+[test_install.py]
+skip-if = os == 'mac' # intermittent
+[test_is_installer.py]
+[test_uninstall.py]
diff --git a/testing/mozbase/mozinstall/tests/test_binary.py b/testing/mozbase/mozinstall/tests/test_binary.py
new file mode 100644
index 0000000000..6454c78ef5
--- /dev/null
+++ b/testing/mozbase/mozinstall/tests/test_binary.py
@@ -0,0 +1,50 @@
+import os
+
+import mozinfo
+import mozinstall
+import mozunit
+import pytest
+
+
+@pytest.mark.skipif(
+ mozinfo.isWin,
+ reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
+)
+def test_get_binary(tmpdir, get_installer):
+ """Test to retrieve binary from install path."""
+ if mozinfo.isLinux:
+ installdir = mozinstall.install(get_installer("tar.bz2"), tmpdir.strpath)
+ binary = os.path.join(installdir, "firefox")
+
+ assert mozinstall.get_binary(installdir, "firefox") == binary
+
+ elif mozinfo.isWin:
+ installdir_exe = mozinstall.install(
+ get_installer("exe"), tmpdir.join("exe").strpath
+ )
+ binary_exe = os.path.join(installdir_exe, "core", "firefox.exe")
+
+ assert mozinstall.get_binary(installdir_exe, "firefox") == binary_exe
+
+ installdir_zip = mozinstall.install(
+ get_installer("zip"), tmpdir.join("zip").strpath
+ )
+ binary_zip = os.path.join(installdir_zip, "firefox.exe")
+
+ assert mozinstall.get_binary(installdir_zip, "firefox") == binary_zip
+
+ elif mozinfo.isMac:
+ installdir = mozinstall.install(get_installer("dmg"), tmpdir.strpath)
+ binary = os.path.join(installdir, "Contents", "MacOS", "firefox")
+
+ assert mozinstall.get_binary(installdir, "firefox") == binary
+
+
+def test_get_binary_error(tmpdir):
+ """Test that an InvalidBinary error is raised."""
+ with pytest.raises(mozinstall.InvalidBinary):
+ mozinstall.get_binary(tmpdir.strpath, "firefox")
+
+
+if __name__ == "__main__":
+ mozunit.main()
diff --git a/testing/mozbase/mozinstall/tests/test_install.py b/testing/mozbase/mozinstall/tests/test_install.py
new file mode 100644
index 0000000000..2dceb2cc78
--- /dev/null
+++ b/testing/mozbase/mozinstall/tests/test_install.py
@@ -0,0 +1,90 @@
+import subprocess
+
+import mozinfo
+import mozinstall
+import mozunit
+import pytest
+
+
+@pytest.mark.skipif(
+ mozinfo.isWin,
+ reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
+)
+def test_is_installer(request, get_installer):
+ """Test that we can identify a correct installer."""
+ if mozinfo.isLinux:
+ assert mozinstall.is_installer(get_installer("tar.bz2"))
+
+ if mozinfo.isWin:
+ # test zip installer
+ assert mozinstall.is_installer(get_installer("zip"))
+
+ # test exe installer
+ assert mozinstall.is_installer(get_installer("exe"))
+
+ try:
+ # test stub browser file
+ # without pefile on the system this test will fail
+ import pefile # noqa
+
+ stub_exe = (
+ request.node.fspath.dirpath("build_stub").join("firefox.exe").strpath
+ )
+ assert not mozinstall.is_installer(stub_exe)
+ except ImportError:
+ pass
+
+ if mozinfo.isMac:
+ assert mozinstall.is_installer(get_installer("dmg"))
+
+
+def test_invalid_source_error(get_installer):
+ """Test that InvalidSource error is raised with an incorrect installer."""
+ if mozinfo.isLinux:
+ with pytest.raises(mozinstall.InvalidSource):
+ mozinstall.install(get_installer("dmg"), "firefox")
+
+ elif mozinfo.isWin:
+ with pytest.raises(mozinstall.InvalidSource):
+ mozinstall.install(get_installer("tar.bz2"), "firefox")
+
+ elif mozinfo.isMac:
+ with pytest.raises(mozinstall.InvalidSource):
+ mozinstall.install(get_installer("tar.bz2"), "firefox")
+
+ # Test an invalid url handler
+ with pytest.raises(mozinstall.InvalidSource):
+ mozinstall.install("file://foo.bar", "firefox")
+
+
+@pytest.mark.skipif(
+ mozinfo.isWin,
+ reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
+)
+def test_install(tmpdir, get_installer):
+ """Test to install an installer."""
+ if mozinfo.isLinux:
+ installdir = mozinstall.install(get_installer("tar.bz2"), tmpdir.strpath)
+ assert installdir == tmpdir.join("firefox").strpath
+
+ elif mozinfo.isWin:
+ installdir_exe = mozinstall.install(
+ get_installer("exe"), tmpdir.join("exe").strpath
+ )
+ assert installdir_exe == tmpdir.join("exe", "firefox").strpath
+
+ installdir_zip = mozinstall.install(
+ get_installer("zip"), tmpdir.join("zip").strpath
+ )
+ assert installdir_zip == tmpdir.join("zip", "firefox").strpath
+
+ elif mozinfo.isMac:
+ installdir = mozinstall.install(get_installer("dmg"), tmpdir.strpath)
+ assert installdir == tmpdir.realpath().join("Firefox Stub.app").strpath
+
+ mounted_images = subprocess.check_output(["hdiutil", "info"]).decode("ascii")
+ assert get_installer("dmg") not in mounted_images
+
+
+if __name__ == "__main__":
+ mozunit.main()
diff --git a/testing/mozbase/mozinstall/tests/test_is_installer.py b/testing/mozbase/mozinstall/tests/test_is_installer.py
new file mode 100644
index 0000000000..057c29f968
--- /dev/null
+++ b/testing/mozbase/mozinstall/tests/test_is_installer.py
@@ -0,0 +1,40 @@
+import mozinfo
+import mozinstall
+import mozunit
+import pytest
+
+
+@pytest.mark.skipif(
+ mozinfo.isWin,
+ reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
+)
+def test_is_installer(request, get_installer):
+ """Test that we can identify a correct installer."""
+ if mozinfo.isLinux:
+ assert mozinstall.is_installer(get_installer("tar.bz2"))
+
+ if mozinfo.isWin:
+ # test zip installer
+ assert mozinstall.is_installer(get_installer("zip"))
+
+ # test exe installer
+ assert mozinstall.is_installer(get_installer("exe"))
+
+ try:
+ # test stub browser file
+ # without pefile on the system this test will fail
+ import pefile # noqa
+
+ stub_exe = (
+ request.node.fspath.dirpath("build_stub").join("firefox.exe").strpath
+ )
+ assert not mozinstall.is_installer(stub_exe)
+ except ImportError:
+ pass
+
+ if mozinfo.isMac:
+ assert mozinstall.is_installer(get_installer("dmg"))
+
+
+if __name__ == "__main__":
+ mozunit.main()
diff --git a/testing/mozbase/mozinstall/tests/test_uninstall.py b/testing/mozbase/mozinstall/tests/test_uninstall.py
new file mode 100644
index 0000000000..45298a834d
--- /dev/null
+++ b/testing/mozbase/mozinstall/tests/test_uninstall.py
@@ -0,0 +1,39 @@
+import mozinfo
+import mozinstall
+import mozunit
+import py
+import pytest
+
+
+@pytest.mark.skipif(
+ mozinfo.isWin,
+ reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
+)
+def test_uninstall(tmpdir, get_installer):
+ """Test to uninstall an installed binary."""
+ if mozinfo.isLinux:
+ installdir = mozinstall.install(get_installer("tar.bz2"), tmpdir.strpath)
+ mozinstall.uninstall(installdir)
+ assert not py.path.local(installdir).check()
+
+ elif mozinfo.isWin:
+ installdir_exe = mozinstall.install(
+ get_installer("exe"), tmpdir.join("exe").strpath
+ )
+ mozinstall.uninstall(installdir_exe)
+ assert not py.path.local(installdir).check()
+
+ installdir_zip = mozinstall.install(
+ get_installer("zip"), tmpdir.join("zip").strpath
+ )
+ mozinstall.uninstall(installdir_zip)
+ assert not py.path.local(installdir).check()
+
+ elif mozinfo.isMac:
+ installdir = mozinstall.install(get_installer("dmg"), tmpdir.strpath)
+ mozinstall.uninstall(installdir)
+ assert not py.path.local(installdir).check()
+
+
+if __name__ == "__main__":
+ mozunit.main()