Beispiel #1
0
    def test_addon_details(self):
        # Generate installer stubs for a valid and invalid add-on manifest
        valid_addon = generate_addon('*****@*****.**',
                                     path=self.tmpdir)
        invalid_addon = generate_addon(
            '*****@*****.**', path=self.tmpdir)

        # Check valid add-on
        details = self.am.addon_details(valid_addon)
        self.assertEqual(details['id'], '*****@*****.**')
        self.assertEqual(details['name'], 'Test Add-on 1')
        self.assertEqual(details['unpack'], False)
        self.assertEqual(details['version'], '0.1')

        # Check invalid add-on
        self.assertRaises(mozprofile.addons.AddonFormatError,
                          self.am.addon_details, invalid_addon)

        # Check invalid path
        self.assertRaises(IOError, self.am.addon_details, '')

        # Check invalid add-on format
        addon_path = os.path.join(os.path.join(here, 'files'),
                                  'not_an_addon.txt')
        self.assertRaises(mozprofile.addons.AddonFormatError,
                          self.am.addon_details, addon_path)
Beispiel #2
0
def test_addon_details(tmpdir, am):
    tmpdir = tmpdir.strpath

    # Generate installer stubs for a valid and invalid add-on manifest
    valid_addon = generate_addon('*****@*****.**', path=tmpdir)
    invalid_addon = generate_addon(
        '*****@*****.**', path=tmpdir)

    # Check valid add-on
    details = am.addon_details(valid_addon)
    assert details['id'] == '*****@*****.**'
    assert details['name'] == 'Test Add-on 1'
    assert not details['unpack']
    assert details['version'] == '0.1'

    # Check invalid add-on
    with pytest.raises(mozprofile.addons.AddonFormatError):
        am.addon_details(invalid_addon)

    # Check invalid path
    with pytest.raises(IOError):
        am.addon_details('')

    # Check invalid add-on format
    addon_path = os.path.join(os.path.join(here, 'files'), 'not_an_addon.txt')
    with pytest.raises(mozprofile.addons.AddonFormatError):
        am.addon_details(addon_path)
Beispiel #3
0
    def test_install_addons_multiple_same_source(self):
        # Generate installer stubs for all possible types of addons
        addon_xpi = generate_addon('*****@*****.**',
                                   path=self.tmpdir)
        addon_folder = generate_addon('*****@*****.**',
                                      path=self.tmpdir,
                                      xpi=False)

        # The same folder should not be installed twice
        self.am.install_addons([addon_folder, addon_folder])
        self.assertEqual(self.am.installed_addons, [addon_folder])
        self.am.clean()

        # The same XPI file should not be installed twice
        self.am.install_addons([addon_xpi, addon_xpi])
        self.assertEqual(self.am.installed_addons, [addon_xpi])
        self.am.clean()

        # Even if it is the same id the add-on should be installed twice, if
        # specified via XPI and folder
        self.am.install_addons([addon_folder, addon_xpi])
        self.assertEqual(len(self.am.installed_addons), 2)
        self.assertIn(addon_folder, self.am.installed_addons)
        self.assertIn(addon_xpi, self.am.installed_addons)
        self.am.clean()
Beispiel #4
0
    def test_install_addons_multiple_same_source(self):
        # Generate installer stubs for all possible types of addons
        addon_xpi = generate_addon('*****@*****.**',
                                   path=self.tmpdir)
        addon_folder = generate_addon('*****@*****.**',
                                      path=self.tmpdir,
                                      xpi=False)

        # The same folder should not be installed twice
        self.am.install_addons([addon_folder, addon_folder])
        self.assertEqual(self.am.installed_addons, [addon_folder])
        self.am.clean()

        # The same XPI file should not be installed twice
        self.am.install_addons([addon_xpi, addon_xpi])
        self.assertEqual(self.am.installed_addons, [addon_xpi])
        self.am.clean()

        # Even if it is the same id the add-on should be installed twice, if
        # specified via XPI and folder
        self.am.install_addons([addon_folder, addon_xpi])
        self.assertEqual(len(self.am.installed_addons), 2)
        self.assertIn(addon_folder, self.am.installed_addons)
        self.assertIn(addon_xpi, self.am.installed_addons)
        self.am.clean()
Beispiel #5
0
def test_install_multiple_same_source(tmpdir, am):
    path = tmpdir.strpath

    # Generate installer stubs for all possible types of addons
    addon_xpi = generate_addon('*****@*****.**', path=path)
    addon_folder = generate_addon('*****@*****.**',
                                  path=path,
                                  xpi=False)

    # The same folder should not be installed twice
    am.install([addon_folder, addon_folder])
    assert am.installed_addons == [addon_folder]
    am.clean()

    # The same XPI file should not be installed twice
    am.install([addon_xpi, addon_xpi])
    assert am.installed_addons == [addon_xpi]
    am.clean()

    # Even if it is the same id the add-on should be installed twice, if
    # specified via XPI and folder
    am.install([addon_folder, addon_xpi])
    assert len(am.installed_addons) == 2
    assert addon_folder in am.installed_addons
    assert addon_xpi in am.installed_addons
    am.clean()
Beispiel #6
0
def test_install_unpack(tmpdir, am):
    tmpdir = tmpdir.strpath

    # Generate installer stubs for all possible types of addons
    addon_xpi = generate_addon('*****@*****.**',
                               path=tmpdir)
    addon_folder = generate_addon('*****@*****.**',
                                  path=tmpdir,
                                  xpi=False)
    addon_no_unpack = generate_addon('*****@*****.**',
                                     path=tmpdir)

    # Test unpack flag for add-on as XPI
    am.install(addon_xpi)
    assert am.installed_addons == [addon_xpi]
    am.clean()

    # Test unpack flag for add-on as folder
    am.install(addon_folder)
    assert am.installed_addons == [addon_folder]
    am.clean()

    # Test forcing unpack an add-on
    am.install(addon_no_unpack, unpack=True)
    assert am.installed_addons == [addon_no_unpack]
    am.clean()
Beispiel #7
0
def test_addon_details(tmpdir, am):
    tmpdir = tmpdir.strpath

    # Generate installer stubs for a valid and invalid add-on manifest
    valid_addon = generate_addon("*****@*****.**", path=tmpdir)
    invalid_addon = generate_addon(
        "*****@*****.**", path=tmpdir)

    # Check valid add-on
    details = am.addon_details(valid_addon)
    assert details["id"] == "*****@*****.**"
    assert details["name"] == "Test Add-on 1"
    assert not details["unpack"]
    assert details["version"] == "0.1"

    # Check invalid add-on
    with pytest.raises(mozprofile.addons.AddonFormatError):
        am.addon_details(invalid_addon)

    # Check invalid path
    with pytest.raises(IOError):
        am.addon_details("")

    # Check invalid add-on format
    addon_path = os.path.join(os.path.join(here, "files"), "not_an_addon.txt")
    with pytest.raises(mozprofile.addons.AddonFormatError):
        am.addon_details(addon_path)
Beispiel #8
0
    def test_clean_addons(self):

        addon_one = addon_stubs.generate_addon('empty-0-1.xpi')
        addon_two = addon_stubs.generate_addon('another-empty-0-1.xpi')

        self.am.install_addons(addon_one)
        installed_addons = [
            unicode(x[:-len('.xpi')]) for x in os.listdir(
                os.path.join(self.profile.profile, 'extensions', 'staged'))
        ]

        # Create a new profile based on an existing profile
        # Install an extra addon in the new profile
        # Cleanup addons
        duplicate_profile = mozprofile.profile.Profile(
            profile=self.profile.profile, addons=addon_two)
        duplicate_profile.addon_manager.clean_addons()

        addons_after_cleanup = [
            unicode(x[:-len('.xpi')]) for x in os.listdir(
                os.path.join(duplicate_profile.profile, 'extensions',
                             'staged'))
        ]
        # New addons installed should be removed by clean_addons()
        self.assertEqual(installed_addons, addons_after_cleanup)
Beispiel #9
0
    def test_addon_details(self):
        # Generate installer stubs for a valid and invalid add-on manifest
        valid_addon = generate_addon('*****@*****.**',
                                     path=self.tmpdir)
        invalid_addon = generate_addon('*****@*****.**',
                                       path=self.tmpdir)

        # Check valid add-on
        details = self.am.addon_details(valid_addon)
        self.assertEqual(details['id'], '*****@*****.**')
        self.assertEqual(details['name'], 'Test Add-on 1')
        self.assertEqual(details['unpack'], False)
        self.assertEqual(details['version'], '0.1')

        # Check invalid add-on
        self.assertRaises(mozprofile.addons.AddonFormatError,
                          self.am.addon_details, invalid_addon)

        # Check invalid path
        self.assertRaises(IOError,
                          self.am.addon_details, '')

        # Check invalid add-on format
        addon_path = os.path.join(os.path.join(here, 'files'), 'not_an_addon.txt')
        self.assertRaises(mozprofile.addons.AddonFormatError,
                          self.am.addon_details, addon_path)
Beispiel #10
0
    def test_install_from_path_backup(self):
        staged_path = os.path.join(self.profile_path, 'extensions')

        # Generate installer stubs for all possible types of addons
        addon_xpi = generate_addon('*****@*****.**',
                                   path=self.tmpdir)
        addon_folder = generate_addon('*****@*****.**',
                                      path=self.tmpdir,
                                      xpi=False)
        addon_name = generate_addon('*****@*****.**',
                                    path=self.tmpdir,
                                    name='*****@*****.**')

        # Test backup of xpi files
        self.am.install_from_path(addon_xpi)
        self.assertIsNone(self.am.backup_dir)

        self.am.install_from_path(addon_xpi)
        self.assertIsNotNone(self.am.backup_dir)
        self.assertEqual(os.listdir(self.am.backup_dir),
                         ['*****@*****.**'])

        self.am.clean()
        self.assertEqual(os.listdir(staged_path),
                         ['*****@*****.**'])
        self.am.clean()

        # Test backup of folders
        self.am.install_from_path(addon_folder)
        self.assertIsNone(self.am.backup_dir)

        self.am.install_from_path(addon_folder)
        self.assertIsNotNone(self.am.backup_dir)
        self.assertEqual(os.listdir(self.am.backup_dir),
                         ['*****@*****.**'])

        self.am.clean()
        self.assertEqual(os.listdir(staged_path),
                         ['*****@*****.**'])
        self.am.clean()

        # Test backup of xpi files with another file name
        self.am.install_from_path(addon_name)
        self.assertIsNone(self.am.backup_dir)

        self.am.install_from_path(addon_xpi)
        self.assertIsNotNone(self.am.backup_dir)
        self.assertEqual(os.listdir(self.am.backup_dir),
                         ['*****@*****.**'])

        self.am.clean()
        self.assertEqual(os.listdir(staged_path),
                         ['*****@*****.**'])
        self.am.clean()
Beispiel #11
0
    def test_install_from_path_backup(self):
        staged_path = os.path.join(self.profile_path, 'extensions', 'staged')

        # Generate installer stubs for all possible types of addons
        addon_xpi = generate_addon('*****@*****.**',
                                   path=self.tmpdir)
        addon_folder = generate_addon('*****@*****.**',
                                      path=self.tmpdir,
                                      xpi=False)
        addon_name = generate_addon('*****@*****.**',
                                    path=self.tmpdir,
                                    name='*****@*****.**')

        # Test backup of xpi files
        self.am.install_from_path(addon_xpi)
        self.assertIsNone(self.am.backup_dir)

        self.am.install_from_path(addon_xpi)
        self.assertIsNotNone(self.am.backup_dir)
        self.assertEqual(os.listdir(self.am.backup_dir),
                         ['*****@*****.**'])

        self.am.clean()
        self.assertEqual(os.listdir(staged_path),
                         ['*****@*****.**'])
        self.am.clean()

        # Test backup of folders
        self.am.install_from_path(addon_folder)
        self.assertIsNone(self.am.backup_dir)

        self.am.install_from_path(addon_folder)
        self.assertIsNotNone(self.am.backup_dir)
        self.assertEqual(os.listdir(self.am.backup_dir),
                         ['*****@*****.**'])

        self.am.clean()
        self.assertEqual(os.listdir(staged_path),
                         ['*****@*****.**'])
        self.am.clean()

        # Test backup of xpi files with another file name
        self.am.install_from_path(addon_name)
        self.assertIsNone(self.am.backup_dir)

        self.am.install_from_path(addon_xpi)
        self.assertIsNotNone(self.am.backup_dir)
        self.assertEqual(os.listdir(self.am.backup_dir),
                         ['*****@*****.**'])

        self.am.clean()
        self.assertEqual(os.listdir(staged_path),
                         ['*****@*****.**'])
        self.am.clean()
Beispiel #12
0
    def test_install_from_path_invalid_addons(self):
        # Generate installer stubs for all possible types of addons
        addons = []
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir,
                                     xpi=False))
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir))

        self.am.install_from_path(self.tmpdir)

        self.assertEqual(self.am.installed_addons, [])
Beispiel #13
0
    def test_install_from_path_invalid_addons(self):
        # Generate installer stubs for all possible types of addons
        addons = []
        addons.append(generate_addon('*****@*****.**',
                      path=self.tmpdir,
                      xpi=False))
        addons.append(generate_addon('*****@*****.**',
                      path=self.tmpdir))

        self.am.install_from_path(self.tmpdir)

        self.assertEqual(self.am.installed_addons, [])
Beispiel #14
0
def test_install_backup(tmpdir, am):
    tmpdir = tmpdir.strpath

    staged_path = os.path.join(am.profile, 'extensions')

    # Generate installer stubs for all possible types of addons
    addon_xpi = generate_addon('*****@*****.**',
                               path=tmpdir)
    addon_folder = generate_addon('*****@*****.**',
                                  path=tmpdir,
                                  xpi=False)
    addon_name = generate_addon('*****@*****.**',
                                path=tmpdir,
                                name='*****@*****.**')

    # Test backup of xpi files
    am.install(addon_xpi)
    assert am.backup_dir is None

    am.install(addon_xpi)
    assert am.backup_dir is not None
    assert os.listdir(am.backup_dir) == ['*****@*****.**']

    am.clean()
    assert os.listdir(staged_path) == ['*****@*****.**']
    am.clean()

    # Test backup of folders
    am.install(addon_folder)
    assert am.backup_dir is None

    am.install(addon_folder)
    assert am.backup_dir is not None
    assert os.listdir(am.backup_dir) == ['*****@*****.**']

    am.clean()
    assert os.listdir(staged_path) == ['*****@*****.**']
    am.clean()

    # Test backup of xpi files with another file name
    am.install(addon_name)
    assert am.backup_dir is None

    am.install(addon_xpi)
    assert am.backup_dir is not None
    assert os.listdir(am.backup_dir) == ['*****@*****.**']

    am.clean()
    assert os.listdir(staged_path) == ['*****@*****.**']
    am.clean()
Beispiel #15
0
def test_install_invalid_addons(tmpdir, am):
    tmpdir = tmpdir.strpath

    # Generate installer stubs for all possible types of addons
    addons = []
    addons.append(generate_addon('*****@*****.**',
                                 path=tmpdir,
                                 xpi=False))
    addons.append(generate_addon('*****@*****.**',
                                 path=tmpdir))

    am.install(tmpdir)

    assert am.installed_addons == []
Beispiel #16
0
    def test_noclean(self):
        """test `restore=True/False` functionality"""

        profile = tempfile.mkdtemp()
        tmpdir = tempfile.mkdtemp()
        try:

            # empty initially
            self.assertFalse(bool(os.listdir(profile)))

            # make an addon
            stub = addon_stubs.generate_addon(name='empty-0-1.xpi',
                                              path=tmpdir)

            # install it with a restore=True AddonManager
            addons  = mozprofile.addons.AddonManager(profile, restore=True)
            addons.install_from_path(stub)

            # now its there
            self.assertEqual(os.listdir(profile), ['extensions'])
            extensions = os.path.join(profile, 'extensions', 'staged')
            self.assertTrue(os.path.exists(extensions))
            contents = os.listdir(extensions)
            self.assertEqual(len(contents), 1)

            # del addons; now its gone though the directory tree exists
            del addons
            self.assertEqual(os.listdir(profile), ['extensions'])
            self.assertTrue(os.path.exists(extensions))
            contents = os.listdir(extensions)
            self.assertEqual(len(contents), 0)

        finally:
            mozfile.rmtree(tmpdir)
            mozfile.rmtree(profile)
Beispiel #17
0
def test_noclean(tmpdir):
    """test `restore=True/False` functionality"""
    profile = tmpdir.mkdtemp().strpath
    tmpdir = tmpdir.mkdtemp().strpath

    # empty initially
    assert not bool(os.listdir(profile))

    # make an addon
    addons = [
        generate_addon('*****@*****.**', path=tmpdir),
        os.path.join(here, 'addons', 'empty.xpi'),
    ]

    # install it with a restore=True AddonManager
    am = mozprofile.addons.AddonManager(profile, restore=True)

    for addon in addons:
        am.install(addon)

    # now its there
    assert os.listdir(profile) == ['extensions']
    staging_folder = os.path.join(profile, 'extensions')
    assert os.path.exists(staging_folder)
    assert len(os.listdir(staging_folder)) == 2

    del am

    assert os.listdir(profile) == ['extensions']
    assert os.path.exists(staging_folder)
    assert os.listdir(staging_folder) == []
Beispiel #18
0
    def test_remove_addon(self):
        addons = []
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir))
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir))

        self.am.install_from_path(self.tmpdir)

        extensions_path = os.path.join(self.profile_path, 'extensions')
        staging_path = os.path.join(extensions_path)

        for addon in self.am._addons:
            self.am.remove_addon(addon)

        self.assertEqual(os.listdir(staging_path), [])
        self.assertEqual(os.listdir(extensions_path), [])
Beispiel #19
0
def test_remove_addon(tmpdir, am):
    tmpdir = tmpdir.strpath

    addons = []
    addons.append(generate_addon('*****@*****.**', path=tmpdir))
    addons.append(generate_addon('*****@*****.**', path=tmpdir))

    am.install(tmpdir)

    extensions_path = os.path.join(am.profile, 'extensions')
    staging_path = os.path.join(extensions_path)

    for addon in am._addons:
        am.remove_addon(addon)

    assert os.listdir(staging_path) == []
    assert os.listdir(extensions_path) == []
Beispiel #20
0
    def test_install_from_path_backup(self):
        # Generate installer stubs for all possible types of addons
        addons = []
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir,
                                     xpi=False))
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir,
                                     xpi=False,
                                     name='*****@*****.**'))
        addons.sort()

        self.am.install_from_path(self.tmpdir)

        self.assertIsNotNone(self.am.backup_dir)
        self.assertEqual(os.listdir(self.am.backup_dir),
                         ['*****@*****.**'])
Beispiel #21
0
    def test_clean_addons(self):
        addon_one = generate_addon('*****@*****.**')
        addon_two = generate_addon('*****@*****.**')

        self.am.install_addons(addon_one)
        installed_addons = [unicode(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                            self.profile.profile, 'extensions', 'staged'))]

        # Create a new profile based on an existing profile
        # Install an extra addon in the new profile
        # Cleanup addons
        duplicate_profile = mozprofile.profile.Profile(profile=self.profile.profile,
                                                       addons=addon_two)
        duplicate_profile.addon_manager.clean_addons()

        addons_after_cleanup = [unicode(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                                duplicate_profile.profile, 'extensions', 'staged'))]
        # New addons installed should be removed by clean_addons()
        self.assertEqual(installed_addons, addons_after_cleanup)
Beispiel #22
0
    def test_install_from_path_backup(self):
        # Generate installer stubs for all possible types of addons
        addons = []
        addons.append(
            generate_addon('*****@*****.**',
                           path=self.tmpdir,
                           xpi=False))
        addons.append(
            generate_addon('*****@*****.**',
                           path=self.tmpdir,
                           xpi=False,
                           name='*****@*****.**'))
        addons.sort()

        self.am.install_from_path(self.tmpdir)

        self.assertIsNotNone(self.am.backup_dir)
        self.assertEqual(os.listdir(self.am.backup_dir),
                         ['*****@*****.**'])
Beispiel #23
0
def test_clean_addons(am):
    addon_one = generate_addon('*****@*****.**')
    addon_two = generate_addon('*****@*****.**')

    am.install(addon_one)
    installed_addons = [str(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                        am.profile, 'extensions'))]

    # Create a new profile based on an existing profile
    # Install an extra addon in the new profile
    # Cleanup addons
    duplicate_profile = mozprofile.profile.Profile(profile=am.profile,
                                                   addons=addon_two)
    duplicate_profile.addons.clean()

    addons_after_cleanup = [str(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                            duplicate_profile.profile, 'extensions'))]
    # New addons installed should be removed by clean_addons()
    assert installed_addons == addons_after_cleanup
Beispiel #24
0
    def test_install_from_path_folder(self):
        # Generate installer stubs for all possible types of addons
        addons = []
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir))
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir,
                                     xpi=False))
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir,
                                     name='addon-3'))
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir,
                                     name='addon-4',
                                     xpi=False))
        addons.sort()

        self.am.install_from_path(self.tmpdir)

        self.assertEqual(self.am.installed_addons, addons)
Beispiel #25
0
    def test_install_from_path_folder(self):
        # Generate installer stubs for all possible types of addons
        addons = []
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir))
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir,
                                     xpi=False))
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir,
                                     name='addon-3'))
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir,
                                     name='addon-4',
                                     xpi=False))
        addons.sort()

        self.am.install_from_path(self.tmpdir)

        self.assertEqual(self.am.installed_addons, addons)
Beispiel #26
0
    def test_install_from_path_after_reset(self):
        # Installing the same add-on after a reset should not cause a failure
        addon = generate_addon('*****@*****.**',
                               path=self.tmpdir, xpi=False)

        # We cannot use self.am because profile.reset() creates a new instance
        self.profile.addon_manager.install_from_path(addon)

        self.profile.reset()

        self.profile.addon_manager.install_from_path(addon)
        self.assertEqual(self.profile.addon_manager.installed_addons, [addon])
Beispiel #27
0
    def test_remove_addon(self):
        addons = []
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir))
        addons.append(generate_addon('*****@*****.**',
                                     path=self.tmpdir))

        self.am.install_from_path(self.tmpdir)

        extensions_path = os.path.join(self.am.profile, 'extensions')
        staging_path = os.path.join(extensions_path, 'staged')

        # Fake a run by virtually installing one of the staged add-ons
        shutil.move(os.path.join(staging_path, '*****@*****.**'),
                    extensions_path)

        for addon in self.am._addons:
            self.am.remove_addon(addon)

        self.assertEqual(os.listdir(staging_path), [])
        self.assertEqual(os.listdir(extensions_path), ['staged'])
Beispiel #28
0
def test_install_folder(tmpdir, am):
    tmpdir = tmpdir.strpath

    # Generate installer stubs for all possible types of addons
    addons = []
    addons.append(generate_addon('*****@*****.**', path=tmpdir))
    addons.append(
        generate_addon('*****@*****.**', path=tmpdir, xpi=False))
    addons.append(
        generate_addon('*****@*****.**', path=tmpdir,
                       name='addon-3'))
    addons.append(
        generate_addon('*****@*****.**',
                       path=tmpdir,
                       name='addon-4',
                       xpi=False))
    addons.sort()

    am.install(tmpdir)

    assert am.installed_addons == addons
Beispiel #29
0
    def test_install_from_path_after_reset(self):
        # Installing the same add-on after a reset should not cause a failure
        addon = generate_addon('*****@*****.**',
                               path=self.tmpdir, xpi=False)

        # We cannot use self.am because profile.reset() creates a new instance
        self.profile.addon_manager.install_from_path(addon)

        self.profile.reset()

        self.profile.addon_manager.install_from_path(addon)
        self.assertEqual(self.profile.addon_manager.installed_addons, [addon])
Beispiel #30
0
    def test_remove_addon(self):
        addons = []
        addons.append(
            generate_addon('*****@*****.**', path=self.tmpdir))
        addons.append(
            generate_addon('*****@*****.**', path=self.tmpdir))

        self.am.install_from_path(self.tmpdir)

        extensions_path = os.path.join(self.profile_path, 'extensions')
        staging_path = os.path.join(extensions_path, 'staged')

        # Fake a run by virtually installing one of the staged add-ons
        shutil.move(os.path.join(staging_path, '*****@*****.**'),
                    extensions_path)

        for addon in self.am._addons:
            self.am.remove_addon(addon)

        self.assertEqual(os.listdir(staging_path), [])
        self.assertEqual(os.listdir(extensions_path), ['staged'])
Beispiel #31
0
def test_install_after_reset(tmpdir, profile):
    tmpdir = tmpdir.strpath
    am = profile.addons

    # Installing the same add-on after a reset should not cause a failure
    addon = generate_addon('*****@*****.**', path=tmpdir, xpi=False)

    # We cannot use am because profile.reset() creates a new instance
    am.install(addon)
    profile.reset()

    am.install(addon)
    assert am.installed_addons == [addon]
Beispiel #32
0
    def test_install_from_path_xpi(self):
        addons_to_install = []
        addons_installed = []

        # Generate installer stubs and install them
        for ext in ['*****@*****.**', '*****@*****.**']:
            temp_addon = generate_addon(ext, path=self.tmpdir)
            addons_to_install.append(self.am.addon_details(temp_addon)['id'])
            self.am.install_from_path(temp_addon)

        # Generate a list of addons installed in the profile
        addons_installed = [str(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                            self.profile.profile, 'extensions'))]
        self.assertEqual(addons_to_install.sort(), addons_installed.sort())
Beispiel #33
0
    def test_install_from_path_xpi(self):
        addons_to_install = []
        addons_installed = []

        # Generate installer stubs and install them
        for ext in ['*****@*****.**', '*****@*****.**']:
            temp_addon = generate_addon(ext, path=self.tmpdir)
            addons_to_install.append(self.am.addon_details(temp_addon)['id'])
            self.am.install_from_path(temp_addon)

        # Generate a list of addons installed in the profile
        addons_installed = [unicode(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                            self.profile.profile, 'extensions', 'staged'))]
        self.assertEqual(addons_to_install.sort(), addons_installed.sort())
Beispiel #34
0
    def test_install_from_path_unpack(self):
        # Generate installer stubs for all possible types of addons
        addon_xpi = generate_addon('*****@*****.**',
                                   path=self.tmpdir)
        addon_folder = generate_addon('*****@*****.**',
                                      path=self.tmpdir,
                                      xpi=False)
        addon_no_unpack = generate_addon('*****@*****.**',
                                         path=self.tmpdir)

        # Test unpack flag for add-on as XPI
        self.am.install_from_path(addon_xpi)
        self.assertEqual(self.am.installed_addons, [addon_xpi])
        self.am.clean()

        # Test unpack flag for add-on as folder
        self.am.install_from_path(addon_folder)
        self.assertEqual(self.am.installed_addons, [addon_folder])
        self.am.clean()

        # Test forcing unpack an add-on
        self.am.install_from_path(addon_no_unpack, unpack=True)
        self.assertEqual(self.am.installed_addons, [addon_no_unpack])
        self.am.clean()
Beispiel #35
0
    def test_install_from_path_unpack(self):
        # Generate installer stubs for all possible types of addons
        addon_xpi = generate_addon('*****@*****.**',
                                   path=self.tmpdir)
        addon_folder = generate_addon('*****@*****.**',
                                      path=self.tmpdir,
                                      xpi=False)
        addon_no_unpack = generate_addon('*****@*****.**',
                                         path=self.tmpdir)

        # Test unpack flag for add-on as XPI
        self.am.install_from_path(addon_xpi)
        self.assertEqual(self.am.installed_addons, [addon_xpi])
        self.am.clean_addons()

        # Test unpack flag for add-on as folder
        self.am.install_from_path(addon_folder)
        self.assertEqual(self.am.installed_addons, [addon_folder])
        self.am.clean_addons()

        # Test forcing unpack an add-on
        self.am.install_from_path(addon_no_unpack, unpack=True)
        self.assertEqual(self.am.installed_addons, [addon_no_unpack])
        self.am.clean_addons()
Beispiel #36
0
def test_install_xpi(tmpdir, am):
    tmpdir = tmpdir.strpath

    addons_to_install = []
    addons_installed = []

    # Generate installer stubs and install them
    for ext in ['*****@*****.**', '*****@*****.**']:
        temp_addon = generate_addon(ext, path=tmpdir)
        addons_to_install.append(am.addon_details(temp_addon)['id'])
        am.install(temp_addon)

    # Generate a list of addons installed in the profile
    addons_installed = [str(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                        am.profile, 'extensions'))]
    assert addons_to_install.sort() == addons_installed.sort()
Beispiel #37
0
    def test_install_from_path(self):

        addons_to_install = []
        addons_installed = []

        # Generate installer stubs and install them
        tmpdir = tempfile.mkdtemp()
        for t in ['empty-0-1.xpi', 'another-empty-0-1.xpi']:
            temp_addon = addon_stubs.generate_addon(name=t, path=tmpdir)
            addons_to_install.append(self.am.addon_details(temp_addon)['id'])
            self.am.install_from_path(temp_addon)
        # Generate a list of addons installed in the profile
        addons_installed = [unicode(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                            self.profile.profile, 'extensions', 'staged'))]
        self.assertEqual(addons_to_install.sort(), addons_installed.sort())
        # Cleanup the temporary addon directories
        mozfile.rmtree(tmpdir)
Beispiel #38
0
    def test_install_from_path(self):

        addons_to_install = []
        addons_installed = []

        # Generate installer stubs and install them
        tmpdir = tempfile.mkdtemp()
        for t in ['empty-0-1.xpi', 'another-empty-0-1.xpi']:
            temp_addon = addon_stubs.generate_addon(name=t, path=tmpdir)
            addons_to_install.append(self.am.addon_details(temp_addon)['id'])
            self.am.install_from_path(temp_addon)
        # Generate a list of addons installed in the profile
        addons_installed = [unicode(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                            self.profile.profile, 'extensions', 'staged'))]
        self.assertEqual(addons_to_install.sort(), addons_installed.sort())
        # Cleanup the temporary addon directories
        mozfile.rmtree(tmpdir)
Beispiel #39
0
    def test_noclean(self):
        """test `restore=True/False` functionality"""

        server = mozhttpd.MozHttpd(docroot=os.path.join(here, 'addons'))
        server.start()

        profile = tempfile.mkdtemp()
        tmpdir = tempfile.mkdtemp()

        try:
            # empty initially
            self.assertFalse(bool(os.listdir(profile)))

            # make an addon
            addons = []
            addons.append(generate_addon('*****@*****.**',
                                         path=tmpdir))
            addons.append(server.get_url() + 'empty.xpi')

            # install it with a restore=True AddonManager
            am = mozprofile.addons.AddonManager(profile, restore=True)

            for addon in addons:
                am.install_from_path(addon)

            # now its there
            self.assertEqual(os.listdir(profile), ['extensions'])
            staging_folder = os.path.join(profile, 'extensions', 'staged')
            self.assertTrue(os.path.exists(staging_folder))
            self.assertEqual(len(os.listdir(staging_folder)), 2)

            # del addons; now its gone though the directory tree exists
            downloaded_addons = am.downloaded_addons
            del am

            self.assertEqual(os.listdir(profile), ['extensions'])
            self.assertTrue(os.path.exists(staging_folder))
            self.assertEqual(os.listdir(staging_folder), [])

            for addon in downloaded_addons:
                self.assertFalse(os.path.isfile(addon))

        finally:
            mozfile.rmtree(tmpdir)
            mozfile.rmtree(profile)
Beispiel #40
0
    def test_noclean(self):
        """test `restore=True/False` functionality"""

        server = mozhttpd.MozHttpd(docroot=os.path.join(here, 'addons'))
        server.start()

        profile = tempfile.mkdtemp()
        tmpdir = tempfile.mkdtemp()

        try:
            # empty initially
            self.assertFalse(bool(os.listdir(profile)))

            # make an addon
            addons = []
            addons.append(
                generate_addon('*****@*****.**', path=tmpdir))
            addons.append(server.get_url() + 'empty.xpi')

            # install it with a restore=True AddonManager
            am = mozprofile.addons.AddonManager(profile, restore=True)

            for addon in addons:
                am.install_from_path(addon)

            # now its there
            self.assertEqual(os.listdir(profile), ['extensions'])
            staging_folder = os.path.join(profile, 'extensions', 'staged')
            self.assertTrue(os.path.exists(staging_folder))
            self.assertEqual(len(os.listdir(staging_folder)), 2)

            # del addons; now its gone though the directory tree exists
            downloaded_addons = am.downloaded_addons
            del am

            self.assertEqual(os.listdir(profile), ['extensions'])
            self.assertTrue(os.path.exists(staging_folder))
            self.assertEqual(os.listdir(staging_folder), [])

            for addon in downloaded_addons:
                self.assertFalse(os.path.isfile(addon))

        finally:
            mozfile.rmtree(tmpdir)
            mozfile.rmtree(profile)
Beispiel #41
0
def test_install_error(am):
    """ Check install raises an error with an invalid addon"""
    temp_addon = generate_addon('*****@*****.**')
    # This should raise an error here
    with pytest.raises(Exception):
        am.install(temp_addon)
Beispiel #42
0
    def test_install_from_path_error(self):
        """ Check install_from_path raises an error with an invalid addon"""

        temp_addon = generate_addon('*****@*****.**')
        # This should raise an error here
        self.am.install_from_path(temp_addon)
Beispiel #43
0
    def test_install_from_path_error(self):
        """ Check install_from_path raises an error with an invalid addon"""

        temp_addon = generate_addon('*****@*****.**')
        # This should raise an error here
        self.am.install_from_path(temp_addon)