def _init_profile(self): preferences = dict(self.browser_config['preferences']) if self.test_config.get('preferences'): test_prefs = dict( [(i, utils.parse_pref(j)) for i, j in self.test_config['preferences'].items()] ) preferences.update(test_prefs) # interpolate webserver value in prefs webserver = self.browser_config['webserver'] if '://' not in webserver: webserver = 'http://' + webserver for name, value in preferences.items(): if type(value) is str: value = utils.interpolate(value, webserver=webserver) preferences[name] = value extensions = self.browser_config['extensions'][:] if self.test_config.get('extensions'): extensions.append(self.test_config['extensions']) profile = Profile.clone( os.path.normpath(self.test_config['profile_path']), self.profile_dir, restore=False) profile.set_preferences(preferences) profile.addon_manager.install_addons(extensions)
def _init_profile(self): preferences = dict(self.browser_config['preferences']) if self.test_config.get('preferences'): test_prefs = dict([ (i, utils.parse_pref(j)) for i, j in self.test_config['preferences'].items() ]) preferences.update(test_prefs) # interpolate webserver value in prefs webserver = self.browser_config['webserver'] if '://' not in webserver: webserver = 'http://' + webserver for name, value in preferences.items(): if type(value) is str: value = utils.interpolate(value, webserver=webserver) preferences[name] = value extensions = self.browser_config['extensions'][:] if self.test_config.get('extensions'): extensions.append(self.test_config['extensions']) if self.browser_config['develop'] or \ self.browser_config['branch_name'] == 'Try': extensions = [os.path.dirname(i) for i in extensions] profile = Profile.clone(os.path.normpath( self.test_config['profile_path']), self.profile_dir, restore=False) profile.set_preferences(preferences) profile.addon_manager.install_addons(extensions)
def test_cleanup_on_garbage_collected(self): clone = Profile.clone(self.profile.profile) profile_dir = clone.profile self.assertTrue(os.path.exists(profile_dir)) del clone # clone should be deleted self.assertFalse(os.path.exists(profile_dir))
def test_restore_false(self): # make a clone of this profile with restore=False clone = Profile.clone(self.profile.profile, restore=False) clone.cleanup() # clone should still be around on the filesystem self.assertTrue(os.path.exists(clone.profile))
def test_cleanup_on_garbage_collected(profile): clone = Profile.clone(profile.profile) profile_dir = clone.profile assert os.path.exists(profile_dir) del clone # clone should be deleted assert not os.path.exists(profile_dir)
def test_restore_true(self): # make a clone of this profile with restore=True clone = Profile.clone(self.profile.profile, restore=True) clone.cleanup() # clone should be deleted self.assertFalse(os.path.exists(clone.profile))
def test_cleanup_on_garbage_collected(self): clone = Profile.clone(self.profile.profile) self.addCleanup(mozfile.remove, clone.profile) profile_dir = clone.profile self.assertTrue(os.path.exists(profile_dir)) del clone # clone should be deleted self.assertFalse(os.path.exists(profile_dir))
def test_restore_false(profile): # make a clone of this profile with restore=False clone = Profile.clone(profile.profile, restore=False) try: clone.cleanup() # clone should still be around on the filesystem assert os.path.exists(clone.profile) finally: mozfile.remove(clone.profile)
def _init_profile(self): preferences = dict(self.browser_config['preferences']) if self.test_config.get('preferences'): test_prefs = dict([ (i, utils.parse_pref(j)) for i, j in self.test_config['preferences'].items() ]) preferences.update(test_prefs) # interpolate webserver value in prefs webserver = self.browser_config['webserver'] if '://' not in webserver: webserver = 'http://' + webserver for name, value in preferences.items(): if type(value) is str: value = utils.interpolate(value, webserver=webserver) preferences[name] = value extensions = self.browser_config['extensions'][:] if self.test_config.get('extensions'): extensions.append(self.test_config['extensions']) # downloading a profile instead of using the empty one if self.test_config['profile'] is not None: path = heavy.download_profile(self.test_config['profile']) self.test_config['profile_path'] = path profile = Profile.clone(os.path.normpath( self.test_config['profile_path']), self.profile_dir, restore=False) profile.set_preferences(preferences) # installing addons profile.addon_manager.install_addons(extensions) # installing webextensions webextensions = self.test_config.get('webextensions', None) if isinstance(webextensions, basestring): webextensions = [webextensions] if webextensions is not None: for webext in webextensions: filename = utils.interpolate(webext) if mozinfo.os == 'win': filename = filename.replace('/', '\\') if not filename.endswith('.xpi'): continue if not os.path.exists(filename): continue profile.addon_manager.install_from_path(filename)
def test_restore_true(self): counter = [0] def _feedback(dir, content): # Called by shutil.copytree on each visited directory. # Used here to display info. # # Returns the items that should be ignored by # shutil.copytree when copying the tree, so always returns # an empty list. counter[0] += 1 return [] # make a clone of this profile with restore=True clone = Profile.clone(self.profile.profile, restore=True, ignore=_feedback) self.addCleanup(mozfile.remove, clone.profile) clone.cleanup() # clone should be deleted self.assertFalse(os.path.exists(clone.profile)) self.assertTrue(counter[0] > 0)
def test_restore_true(profile): counter = [0] def _feedback(dir, content): # Called by shutil.copytree on each visited directory. # Used here to display info. # # Returns the items that should be ignored by # shutil.copytree when copying the tree, so always returns # an empty list. counter[0] += 1 return [] # make a clone of this profile with restore=True clone = Profile.clone(profile.profile, restore=True, ignore=_feedback) try: clone.cleanup() # clone should be deleted assert not os.path.exists(clone.profile) assert counter[0] > 0 finally: mozfile.remove(clone.profile)
def _init_profile(self): extensions = self.browser_config['extensions'][:] if self.test_config.get('extensions'): extensions.extend(self.test_config['extensions']) # downloading a profile instead of using the empty one if self.test_config['profile'] is not None: path = heavy.download_profile(self.test_config['profile']) self.test_config['profile_path'] = path profile_path = os.path.normpath(self.test_config['profile_path']) LOG.info("Cloning profile located at %s" % profile_path) def _feedback(directory, content): # Called by shutil.copytree on each visited directory. # Used here to display info. # # Returns the items that should be ignored by # shutil.copytree when copying the tree, so always returns # an empty list. sub = directory.split(profile_path)[-1].lstrip("/") if sub: LOG.info("=> %s" % sub) return [] profile = Profile.clone(profile_path, self.profile_dir, ignore=_feedback, restore=False) # build pref interpolation context webserver = self.browser_config['webserver'] if '://' not in webserver: webserver = 'http://' + webserver interpolation = { 'webserver': webserver, } # merge base profiles with open(os.path.join(self.profile_data_dir, 'profiles.json'), 'r') as fh: base_profiles = json.load(fh)['talos'] for name in base_profiles: path = os.path.join(self.profile_data_dir, name) LOG.info("Merging profile: {}".format(path)) profile.merge(path, interpolation=interpolation) # set test preferences preferences = self.browser_config.get('preferences', {}).copy() if self.test_config.get('preferences'): test_prefs = dict([ (i, utils.parse_pref(j)) for i, j in self.test_config['preferences'].items() ]) preferences.update(test_prefs) for name, value in preferences.items(): if type(value) is str: value = utils.interpolate(value, **interpolation) preferences[name] = value profile.set_preferences(preferences) # installing addons LOG.info("Installing Add-ons:") LOG.info(extensions) profile.addons.install(extensions) # installing webextensions webextensions = self.test_config.get('webextensions', None) if isinstance(webextensions, basestring): webextensions = [webextensions] if webextensions is not None: LOG.info("Installing Webextensions:") for webext in webextensions: filename = utils.interpolate(webext) if mozinfo.os == 'win': filename = filename.replace('/', '\\') if not filename.endswith('.xpi'): continue if not os.path.exists(filename): continue LOG.info(filename) profile.addons.install(filename)
def _init_profile(self): extensions = self.browser_config["extensions"][:] if self.test_config.get("extensions"): extensions.extend(self.test_config["extensions"]) # downloading a profile instead of using the empty one if self.test_config["profile"] is not None: path = heavy.download_profile(self.test_config["profile"]) self.test_config["profile_path"] = path profile_path = os.path.normpath(self.test_config["profile_path"]) LOG.info("Cloning profile located at %s" % profile_path) def _feedback(directory, content): # Called by shutil.copytree on each visited directory. # Used here to display info. # # Returns the items that should be ignored by # shutil.copytree when copying the tree, so always returns # an empty list. sub = directory.split(profile_path)[-1].lstrip("/") if sub: LOG.info("=> %s" % sub) return [] profile = Profile.clone( profile_path, self.profile_dir, ignore=_feedback, restore=False ) # build pref interpolation context webserver = self.browser_config["webserver"] if "://" not in webserver: webserver = "http://" + webserver interpolation = { "webserver": webserver, } # merge base profiles with open(os.path.join(self.profile_data_dir, "profiles.json"), "r") as fh: base_profiles = json.load(fh)["talos"] for name in base_profiles: path = os.path.join(self.profile_data_dir, name) LOG.info("Merging profile: {}".format(path)) profile.merge(path, interpolation=interpolation) # set test preferences preferences = self.browser_config.get("preferences", {}).copy() if self.test_config.get("preferences"): test_prefs = dict( [ (i, utils.parse_pref(j)) for i, j in self.test_config["preferences"].items() ] ) preferences.update(test_prefs) for name, value in preferences.items(): if type(value) is str: value = utils.interpolate(value, **interpolation) preferences[name] = value profile.set_preferences(preferences) # installing addons LOG.info("Installing Add-ons:") LOG.info(extensions) profile.addons.install(extensions) # installing webextensions webextensions_to_install = [] webextensions_folder = self.test_config.get("webextensions_folder", None) if isinstance(webextensions_folder, six.string_types): folder = utils.interpolate(webextensions_folder) for file in os.listdir(folder): if file.endswith(".xpi"): webextensions_to_install.append(os.path.join(folder, file)) webextensions = self.test_config.get("webextensions", None) if isinstance(webextensions, six.string_types): webextensions_to_install.append(webextensions) if webextensions_to_install is not None: LOG.info("Installing Webextensions:") for webext in webextensions_to_install: filename = utils.interpolate(webext) if mozinfo.os == "win": filename = filename.replace("/", "\\") if not filename.endswith(".xpi"): continue if not os.path.exists(filename): continue LOG.info(filename) profile.addons.install(filename)
def _init_profile(self): preferences = dict(self.browser_config['preferences']) if self.test_config.get('preferences'): test_prefs = dict( [(i, utils.parse_pref(j)) for i, j in self.test_config['preferences'].items()] ) preferences.update(test_prefs) # interpolate webserver value in prefs webserver = self.browser_config['webserver'] if '://' not in webserver: webserver = 'http://' + webserver for name, value in preferences.items(): if type(value) is str: value = utils.interpolate(value, webserver=webserver) preferences[name] = value extensions = self.browser_config['extensions'][:] if self.test_config.get('extensions'): extensions.append(self.test_config['extensions']) # downloading a profile instead of using the empty one if self.test_config['profile'] is not None: path = heavy.download_profile(self.test_config['profile']) self.test_config['profile_path'] = path profile_path = os.path.normpath(self.test_config['profile_path']) LOG.info("Cloning profile located at %s" % profile_path) def _feedback(directory, content): # Called by shutil.copytree on each visited directory. # Used here to display info. # # Returns the items that should be ignored by # shutil.copytree when copying the tree, so always returns # an empty list. sub = directory.split(profile_path)[-1].lstrip("/") if sub: LOG.info("=> %s" % sub) return [] profile = Profile.clone(profile_path, self.profile_dir, ignore=_feedback, restore=False) profile.set_preferences(preferences) # installing addons LOG.info("Installing Add-ons") profile.addon_manager.install_addons(extensions) # installing webextensions webextensions = self.test_config.get('webextensions', None) if isinstance(webextensions, basestring): webextensions = [webextensions] if webextensions is not None: LOG.info("Installing Webextensions") for webext in webextensions: filename = utils.interpolate(webext) if mozinfo.os == 'win': filename = filename.replace('/', '\\') if not filename.endswith('.xpi'): continue if not os.path.exists(filename): continue profile.addon_manager.install_from_path(filename)
def _init_profile(self): preferences = dict(self.browser_config['preferences']) if self.test_config.get('preferences'): test_prefs = dict( [(i, utils.parse_pref(j)) for i, j in self.test_config['preferences'].items()] ) preferences.update(test_prefs) # interpolate webserver value in prefs webserver = self.browser_config['webserver'] if '://' not in webserver: webserver = 'http://' + webserver for name, value in preferences.items(): if type(value) is str: value = utils.interpolate(value, webserver=webserver) preferences[name] = value extensions = self.browser_config['extensions'][:] if self.test_config.get('extensions'): extensions.extend(self.test_config['extensions']) # downloading a profile instead of using the empty one if self.test_config['profile'] is not None: path = heavy.download_profile(self.test_config['profile']) self.test_config['profile_path'] = path profile_path = os.path.normpath(self.test_config['profile_path']) LOG.info("Cloning profile located at %s" % profile_path) def _feedback(directory, content): # Called by shutil.copytree on each visited directory. # Used here to display info. # # Returns the items that should be ignored by # shutil.copytree when copying the tree, so always returns # an empty list. sub = directory.split(profile_path)[-1].lstrip("/") if sub: LOG.info("=> %s" % sub) return [] profile = Profile.clone(profile_path, self.profile_dir, ignore=_feedback, restore=False) profile.set_preferences(preferences) # installing addons LOG.info("Installing Add-ons:") LOG.info(extensions) profile.addon_manager.install_addons(extensions) # installing webextensions webextensions = self.test_config.get('webextensions', None) if isinstance(webextensions, basestring): webextensions = [webextensions] if webextensions is not None: LOG.info("Installing Webextensions:") for webext in webextensions: filename = utils.interpolate(webext) if mozinfo.os == 'win': filename = filename.replace('/', '\\') if not filename.endswith('.xpi'): continue if not os.path.exists(filename): continue LOG.info(filename) profile.addon_manager.install_from_path(filename)