Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | |
michael@0 | 3 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | # You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 6 | |
michael@0 | 7 | import mozinfo |
michael@0 | 8 | import mozinstall |
michael@0 | 9 | import mozfile |
michael@0 | 10 | import os |
michael@0 | 11 | import tarfile |
michael@0 | 12 | import tempfile |
michael@0 | 13 | import unittest |
michael@0 | 14 | import zipfile |
michael@0 | 15 | |
michael@0 | 16 | # Store file location at load time |
michael@0 | 17 | here = os.path.dirname(os.path.abspath(__file__)) |
michael@0 | 18 | |
michael@0 | 19 | class TestMozInstall(unittest.TestCase): |
michael@0 | 20 | |
michael@0 | 21 | @classmethod |
michael@0 | 22 | def setUpClass(cls): |
michael@0 | 23 | """ Setting up stub installers """ |
michael@0 | 24 | cls.dmg = os.path.join(here, 'Installer-Stubs', 'firefox.dmg') |
michael@0 | 25 | cls.exe = os.path.join(here, 'Installer-Stubs', 'firefox.exe') |
michael@0 | 26 | cls.zipfile = os.path.join(here, 'Installer-Stubs', 'firefox.zip') |
michael@0 | 27 | cls.bz2 = os.path.join(here, 'Installer-Stubs', 'firefox.tar.bz2') |
michael@0 | 28 | |
michael@0 | 29 | def setUp(self): |
michael@0 | 30 | self.tempdir = tempfile.mkdtemp() |
michael@0 | 31 | |
michael@0 | 32 | def tearDown(self): |
michael@0 | 33 | mozfile.rmtree(self.tempdir) |
michael@0 | 34 | |
michael@0 | 35 | def test_get_binary(self): |
michael@0 | 36 | """ Test mozinstall's get_binary method """ |
michael@0 | 37 | |
michael@0 | 38 | if mozinfo.isLinux: |
michael@0 | 39 | installdir = mozinstall.install(self.bz2, self.tempdir) |
michael@0 | 40 | binary = os.path.join(installdir, 'firefox') |
michael@0 | 41 | self.assertEqual(binary, mozinstall.get_binary(installdir, 'firefox')) |
michael@0 | 42 | |
michael@0 | 43 | elif mozinfo.isWin: |
michael@0 | 44 | installdir_exe = mozinstall.install(self.exe, |
michael@0 | 45 | os.path.join(self.tempdir, 'exe')) |
michael@0 | 46 | binary_exe = os.path.join(installdir_exe, 'firefox', 'firefox', |
michael@0 | 47 | 'firefox.exe') |
michael@0 | 48 | self.assertEqual(binary_exe, mozinstall.get_binary(installdir_exe, |
michael@0 | 49 | 'firefox')) |
michael@0 | 50 | |
michael@0 | 51 | installdir_zip = mozinstall.install(self.zipfile, |
michael@0 | 52 | os.path.join(self.tempdir, 'zip')) |
michael@0 | 53 | binary_zip = os.path.join(installdir_zip, 'firefox.exe') |
michael@0 | 54 | self.assertEqual(binary_zip, mozinstall.get_binary(installdir_zip, |
michael@0 | 55 | 'firefox')) |
michael@0 | 56 | |
michael@0 | 57 | elif mozinfo.isMac: |
michael@0 | 58 | installdir = mozinstall.install(self.dmg, self.tempdir) |
michael@0 | 59 | binary = os.path.join(installdir, 'Contents', 'MacOS', 'firefox') |
michael@0 | 60 | self.assertEqual(binary, mozinstall.get_binary(installdir, 'firefox')) |
michael@0 | 61 | |
michael@0 | 62 | def test_get_binary_error(self): |
michael@0 | 63 | """ Test an InvalidBinary error is raised """ |
michael@0 | 64 | |
michael@0 | 65 | tempdir_empty = tempfile.mkdtemp() |
michael@0 | 66 | self.assertRaises(mozinstall.InvalidBinary, mozinstall.get_binary, |
michael@0 | 67 | tempdir_empty, 'firefox') |
michael@0 | 68 | mozfile.rmtree(tempdir_empty) |
michael@0 | 69 | |
michael@0 | 70 | def test_is_installer(self): |
michael@0 | 71 | """ Test we can identify a correct installer """ |
michael@0 | 72 | |
michael@0 | 73 | if mozinfo.isLinux: |
michael@0 | 74 | self.assertTrue(mozinstall.is_installer(self.bz2)) |
michael@0 | 75 | |
michael@0 | 76 | if mozinfo.isWin: |
michael@0 | 77 | # test zip installer |
michael@0 | 78 | self.assertTrue(mozinstall.is_installer(self.zipfile)) |
michael@0 | 79 | |
michael@0 | 80 | # test exe installer |
michael@0 | 81 | self.assertTrue(mozinstall.is_installer(self.exe)) |
michael@0 | 82 | |
michael@0 | 83 | try: |
michael@0 | 84 | # test stub browser file |
michael@0 | 85 | # without pefile on the system this test will fail |
michael@0 | 86 | import pefile |
michael@0 | 87 | stub_exe = os.path.join(here, 'build_stub', 'firefox.exe') |
michael@0 | 88 | self.assertFalse(mozinstall.is_installer(stub_exe)) |
michael@0 | 89 | except ImportError: |
michael@0 | 90 | pass |
michael@0 | 91 | |
michael@0 | 92 | if mozinfo.isMac: |
michael@0 | 93 | self.assertTrue(mozinstall.is_installer(self.dmg)) |
michael@0 | 94 | |
michael@0 | 95 | def test_invalid_source_error(self): |
michael@0 | 96 | """ Test InvalidSource error is raised with an incorrect installer """ |
michael@0 | 97 | |
michael@0 | 98 | if mozinfo.isLinux: |
michael@0 | 99 | self.assertRaises(mozinstall.InvalidSource, mozinstall.install, |
michael@0 | 100 | self.dmg, 'firefox') |
michael@0 | 101 | |
michael@0 | 102 | elif mozinfo.isWin: |
michael@0 | 103 | self.assertRaises(mozinstall.InvalidSource, mozinstall.install, |
michael@0 | 104 | self.bz2, 'firefox') |
michael@0 | 105 | |
michael@0 | 106 | elif mozinfo.isMac: |
michael@0 | 107 | self.assertRaises(mozinstall.InvalidSource, mozinstall.install, |
michael@0 | 108 | self.exe, 'firefox') |
michael@0 | 109 | |
michael@0 | 110 | def test_install(self): |
michael@0 | 111 | """ Test mozinstall's install capability """ |
michael@0 | 112 | |
michael@0 | 113 | if mozinfo.isLinux: |
michael@0 | 114 | installdir = mozinstall.install(self.bz2, self.tempdir) |
michael@0 | 115 | self.assertEqual(os.path.join(self.tempdir, 'firefox'), installdir) |
michael@0 | 116 | |
michael@0 | 117 | elif mozinfo.isWin: |
michael@0 | 118 | installdir_exe = mozinstall.install(self.exe, |
michael@0 | 119 | os.path.join(self.tempdir, 'exe')) |
michael@0 | 120 | self.assertEqual(os.path.join(self.tempdir, 'exe', 'firefox'), |
michael@0 | 121 | installdir_exe) |
michael@0 | 122 | |
michael@0 | 123 | installdir_zip = mozinstall.install(self.zipfile, |
michael@0 | 124 | os.path.join(self.tempdir, 'zip')) |
michael@0 | 125 | self.assertEqual(os.path.join(self.tempdir, 'zip', 'firefox'), |
michael@0 | 126 | installdir_zip) |
michael@0 | 127 | |
michael@0 | 128 | elif mozinfo.isMac: |
michael@0 | 129 | installdir = mozinstall.install(self.dmg, self.tempdir) |
michael@0 | 130 | self.assertEqual(os.path.join(os.path.realpath(self.tempdir), |
michael@0 | 131 | 'FirefoxStub.app'), installdir) |
michael@0 | 132 | |
michael@0 | 133 | def test_uninstall(self): |
michael@0 | 134 | """ Test mozinstall's uninstall capabilites """ |
michael@0 | 135 | # Uninstall after installing |
michael@0 | 136 | |
michael@0 | 137 | if mozinfo.isLinux: |
michael@0 | 138 | installdir = mozinstall.install(self.bz2, self.tempdir) |
michael@0 | 139 | mozinstall.uninstall(installdir) |
michael@0 | 140 | self.assertFalse(os.path.exists(installdir)) |
michael@0 | 141 | |
michael@0 | 142 | elif mozinfo.isWin: |
michael@0 | 143 | # Exe installer for Windows |
michael@0 | 144 | installdir_exe = mozinstall.install(self.exe, |
michael@0 | 145 | os.path.join(self.tempdir, 'exe')) |
michael@0 | 146 | mozinstall.uninstall(installdir_exe) |
michael@0 | 147 | self.assertFalse(os.path.exists(installdir_exe)) |
michael@0 | 148 | |
michael@0 | 149 | # Zip installer for Windows |
michael@0 | 150 | installdir_zip = mozinstall.install(self.zipfile, |
michael@0 | 151 | os.path.join(self.tempdir, 'zip')) |
michael@0 | 152 | mozinstall.uninstall(installdir_zip) |
michael@0 | 153 | self.assertFalse(os.path.exists(installdir_zip)) |
michael@0 | 154 | |
michael@0 | 155 | elif mozinfo.isMac: |
michael@0 | 156 | installdir = mozinstall.install(self.dmg, self.tempdir) |
michael@0 | 157 | mozinstall.uninstall(installdir) |
michael@0 | 158 | self.assertFalse(os.path.exists(installdir)) |
michael@0 | 159 | |
michael@0 | 160 | if __name__ == '__main__': |
michael@0 | 161 | unittest.main() |