# HG changeset patch # User Kris Maglione # Date 1522105792 25200 # Node ID 22cd4c5fcb397d80fc7f693737dc1c827ce61d74 # Parent 07b6ec23fef28edfad2ba43d7ed62f4bf3122c82 Bug 1448221: Part 3 - Remove startup staging directory scan. r=aswan Only mozprofile test stuff removals. MozReview-Commit-ID: JHA1umCQS2D diff --git a/testing/mozbase/mozprofile/mozprofile/addons.py b/testing/mozbase/mozprofile/mozprofile/addons.py --- a/testing/mozbase/mozprofile/mozprofile/addons.py +++ b/testing/mozbase/mozprofile/mozprofile/addons.py @@ -87,17 +87,17 @@ class AddonManager(object): pass # Remove all downloaded add-ons for addon in self.downloaded_addons: mozfile.remove(addon) # restore backups if self.backup_dir and os.path.isdir(self.backup_dir): - extensions_path = os.path.join(self.profile, 'extensions', 'staged') + extensions_path = os.path.join(self.profile, 'extensions') for backup in os.listdir(self.backup_dir): backup_path = os.path.join(self.backup_dir, backup) shutil.move(backup_path, extensions_path) if not os.listdir(self.backup_dir): mozfile.remove(self.backup_dir) @@ -135,24 +135,20 @@ class AddonManager(object): return new_path def get_addon_path(self, addon_id): """Returns the path to the installed add-on :param addon_id: id of the add-on to retrieve the path from """ # By default we should expect add-ons being located under the - # extensions folder. Only if the application hasn't been run and - # installed the add-ons yet, it will be located under 'staged'. - # Also add-ons could have been unpacked by the application. + # extensions folder. extensions_path = os.path.join(self.profile, 'extensions') paths = [os.path.join(extensions_path, addon_id), - os.path.join(extensions_path, addon_id + '.xpi'), - os.path.join(extensions_path, 'staged', addon_id), - os.path.join(extensions_path, 'staged', addon_id + '.xpi')] + os.path.join(extensions_path, addon_id + '.xpi')] for path in paths: if os.path.exists(path): return path raise IOError('Add-on not found: %s' % addon_id) @classmethod def is_addon(self, addon_path): @@ -401,17 +397,17 @@ class AddonManager(object): # note: we might want to let Firefox do it in case of addon details orig_path = None if os.path.isfile(addon) and (unpack or addon_details['unpack']): orig_path = addon addon = tempfile.mkdtemp() mozfile.extract(orig_path, addon) # copy the addon to the profile - extensions_path = os.path.join(self.profile, 'extensions', 'staged') + extensions_path = os.path.join(self.profile, 'extensions') addon_path = os.path.join(extensions_path, addon_id) if os.path.isfile(addon): addon_path += '.xpi' # move existing xpi file to backup location to restore later if os.path.exists(addon_path): self.backup_dir = self.backup_dir or tempfile.mkdtemp() diff --git a/testing/mozbase/mozprofile/tests/test_addons.py b/testing/mozbase/mozprofile/tests/test_addons.py --- a/testing/mozbase/mozprofile/tests/test_addons.py +++ b/testing/mozbase/mozprofile/tests/test_addons.py @@ -2,17 +2,16 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. from __future__ import absolute_import import os -import shutil import tempfile import unittest import zipfile import mozunit from manifestparser import ManifestParser import mozfile @@ -162,17 +161,17 @@ class TestAddonsManager(unittest.TestCas # Generate installer stubs and install them for ext in ['test-addon-1@mozilla.org', 'test-addon-2@mozilla.org']: 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', 'staged'))] + self.profile.profile, 'extensions'))] self.assertEqual(addons_to_install.sort(), addons_installed.sort()) def test_install_from_path_folder(self): # Generate installer stubs for all possible types of addons addons = [] addons.append(generate_addon('test-addon-1@mozilla.org', path=self.tmpdir)) addons.append(generate_addon('test-addon-2@mozilla.org', @@ -239,17 +238,17 @@ class TestAddonsManager(unittest.TestCas 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]) def test_install_from_path_backup(self): - staged_path = os.path.join(self.profile_path, 'extensions', 'staged') + staged_path = os.path.join(self.profile_path, 'extensions') # Generate installer stubs for all possible types of addons addon_xpi = generate_addon('test-addon-1@mozilla.org', path=self.tmpdir) addon_folder = generate_addon('test-addon-1@mozilla.org', path=self.tmpdir, xpi=False) addon_name = generate_addon('test-addon-1@mozilla.org', @@ -327,17 +326,17 @@ class TestAddonsManager(unittest.TestCas addons = m.get() # Obtain details of addons to install from the manifest addons_to_install = [self.am.addon_details(x['path']).get('id') for x in addons] self.am.install_from_manifest(temp_manifest) # 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', 'staged'))] + self.profile.profile, 'extensions'))] self.assertEqual(addons_installed.sort(), addons_to_install.sort()) # Cleanup the temporary addon and manifest directories mozfile.rmtree(os.path.dirname(temp_manifest)) def test_addon_details(self): # Generate installer stubs for a valid and invalid add-on manifest valid_addon = generate_addon('test-addon-1@mozilla.org', @@ -367,27 +366,27 @@ class TestAddonsManager(unittest.TestCas @unittest.skip("Bug 900154") def test_clean_addons(self): addon_one = generate_addon('test-addon-1@mozilla.org') addon_two = generate_addon('test-addon-2@mozilla.org') self.am.install_addons(addon_one) installed_addons = [str(x[:-len('.xpi')]) for x in os.listdir(os.path.join( - self.profile.profile, 'extensions', 'staged'))] + self.profile.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=self.profile.profile, addons=addon_two) duplicate_profile.addon_manager.clean() addons_after_cleanup = [str(x[:-len('.xpi')]) for x in os.listdir(os.path.join( - duplicate_profile.profile, 'extensions', 'staged'))] + duplicate_profile.profile, 'extensions'))] # New addons installed should be removed by clean_addons() self.assertEqual(installed_addons, addons_after_cleanup) def test_noclean(self): """test `restore=True/False` functionality""" server = mozhttpd.MozHttpd(docroot=os.path.join(here, 'addons')) server.start() @@ -408,17 +407,17 @@ class TestAddonsManager(unittest.TestCas # 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') + staging_folder = os.path.join(profile, 'extensions') 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']) @@ -437,23 +436,19 @@ class TestAddonsManager(unittest.TestCas addons.append(generate_addon('test-addon-1@mozilla.org', path=self.tmpdir)) addons.append(generate_addon('test-addon-2@mozilla.org', 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, 'test-addon-1@mozilla.org.xpi'), - extensions_path) + 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), ['staged']) + self.assertEqual(os.listdir(extensions_path), []) if __name__ == '__main__': mozunit.main()