summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozprofile/tests/bug758250.py
blob: f25901a1999299549fc62e7e8efa38d7a6f052a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python

import mozprofile
import os
import shutil
import tempfile
import unittest


here = os.path.dirname(os.path.abspath(__file__))


class Bug758250(unittest.TestCase):
    """
    use of --profile in mozrunner just blows away addon sources:
    https://bugzilla.mozilla.org/show_bug.cgi?id=758250
    """

    def setUp(self):
        self.tmpdir = tempfile.mkdtemp()
        self.addon = os.path.join(here, 'addons', 'empty')

    def tearDown(self):
        # remove vestiges
        shutil.rmtree(self.tmpdir)

    def test_profile_addon_cleanup(self):

        # sanity check: the empty addon should be here
        self.assertTrue(os.path.exists(self.addon))
        self.assertTrue(os.path.isdir(self.addon))
        self.assertTrue(os.path.exists(os.path.join(self.addon, 'install.rdf')))

        # because we are testing data loss, let's make sure we make a copy
        shutil.rmtree(self.tmpdir)
        shutil.copytree(self.addon, self.tmpdir)
        self.assertTrue(os.path.exists(os.path.join(self.tmpdir, 'install.rdf')))

        # make a starter profile
        profile = mozprofile.FirefoxProfile()
        path = profile.profile

        # make a new profile based on the old
        newprofile = mozprofile.FirefoxProfile(profile=path, addons=[self.tmpdir])
        newprofile.cleanup()

        # the source addon *should* still exist
        self.assertTrue(os.path.exists(self.tmpdir))
        self.assertTrue(os.path.exists(os.path.join(self.tmpdir, 'install.rdf')))


if __name__ == '__main__':
    unittest.main()