Chromium Code Reviews| Index: chrome/test/mini_installer/test_installer.py |
| diff --git a/chrome/test/mini_installer/test_installer.py b/chrome/test/mini_installer/test_installer.py |
| index c0c9a91e3b7314954d49ff6a0fb09ffef640403e..5aeab33fd1ab5ca98376ed4dea84fbbc79dad551 100644 |
| --- a/chrome/test/mini_installer/test_installer.py |
| +++ b/chrome/test/mini_installer/test_installer.py |
| @@ -19,9 +19,9 @@ import sys |
| import time |
| import traceback |
| import unittest |
| -import _winreg |
| from variable_expander import VariableExpander |
| +import cleanup |
| import verifier_runner |
| @@ -122,7 +122,8 @@ class InstallerTest(unittest.TestCase): |
| def tearDown(self): |
| """Cleans up the machine if the test case fails.""" |
| if self._clean_on_teardown: |
| - RunCleanCommand(True, self._variable_expander) |
| + RunCleanCommand(True, self._config.states[self._test[-1]], |
|
grt (UTC plus 2)
2017/03/14 09:19:44
rather than baking in the assumption that the last
zmin
2017/03/14 23:13:00
Done.
|
| + self._variable_expander) |
| def shortDescription(self): |
| """Overridden from unittest.TestCase. |
| @@ -168,30 +169,7 @@ def RunCommand(command, variable_expander): |
| raise Exception('Command %s returned non-zero exit status %s' % ( |
| expanded_command, exit_status)) |
| - |
| -def DeleteGoogleUpdateRegistration(system_level, registry_subkey, |
| - variable_expander): |
| - """Deletes Chrome's registration with Google Update. |
| - |
| - Args: |
| - system_level: True if system-level Chrome is to be deleted. |
| - registry_subkey: The pre-expansion registry subkey for the product. |
| - variable_expander: A VariableExpander object. |
| - """ |
| - root = (_winreg.HKEY_LOCAL_MACHINE if system_level |
| - else _winreg.HKEY_CURRENT_USER) |
| - key_name = variable_expander.Expand(registry_subkey) |
| - try: |
| - key_handle = _winreg.OpenKey(root, key_name, 0, |
| - _winreg.KEY_SET_VALUE | |
| - _winreg.KEY_WOW64_32KEY) |
| - _winreg.DeleteValue(key_handle, 'pv') |
| - except WindowsError: |
| - # The key isn't present, so there is no value to delete. |
| - pass |
| - |
| - |
| -def RunCleanCommand(force_clean, variable_expander): |
| +def RunCleanCommand(force_clean, clean_state, variable_expander): |
| """Puts the machine in the clean state (i.e. Chrome not installed). |
| Args: |
| @@ -199,33 +177,30 @@ def RunCleanCommand(force_clean, variable_expander): |
| installations. |
| variable_expander: A VariableExpander object. |
| """ |
| - # A list of (system_level, product_name, product_switch, registry_subkey) |
| + # A list of (product_name, product_switch) |
| # tuples for the possible installed products. |
| data = [ |
| - (False, '$CHROME_LONG_NAME', '', |
| - '$CHROME_UPDATE_REGISTRY_SUBKEY'), |
| - (True, '$CHROME_LONG_NAME', '--system-level', |
| - '$CHROME_UPDATE_REGISTRY_SUBKEY'), |
| + ('$CHROME_LONG_NAME', ''), |
| + ('$CHROME_LONG_NAME', '--system-level'), |
| ] |
| if variable_expander.Expand('$SUPPORTS_SXS') == 'True': |
| - data.append((False, '$CHROME_LONG_NAME_SXS', '', |
| - '$CHROME_UPDATE_REGISTRY_SUBKEY_SXS')) |
| + data.append(('$CHROME_LONG_NAME_SXS', '')) |
| interactive_option = '--interactive' if not force_clean else '' |
| - for system_level, product_name, product_switch, registry_subkey in data: |
| + for product_name, product_switch in data: |
| command = ('python uninstall_chrome.py ' |
| '--chrome-long-name="%s" ' |
| '--no-error-if-absent %s %s' % |
| (product_name, product_switch, interactive_option)) |
| try: |
| RunCommand(command, variable_expander) |
| - except: |
| + except (Exception, OSError, ValueError): |
| message = traceback.format_exception(*sys.exc_info()) |
| message.insert(0, 'Error cleaning up an old install with:\n') |
| LogMessage(''.join(message)) |
| - if force_clean: |
| - DeleteGoogleUpdateRegistration(system_level, registry_subkey, |
| - variable_expander) |
| + |
| + if force_clean: |
| + cleanup.CleanupRunner.Create().CleanAll(clean_state, variable_expander) |
| def MergePropertyDictionaries(current_property, new_property): |
| @@ -323,6 +298,7 @@ def ParseConfigFile(filename, variable_expander): |
| config.actions[action_name] = action_command |
| return config |
| +DEFAULT_CLEAN_STATE = 'clean' |
|
grt (UTC plus 2)
2017/03/14 09:19:44
how about making this an argument for the parser w
|
| def main(): |
| parser = argparse.ArgumentParser() |
| @@ -340,7 +316,8 @@ def main(): |
| parser.add_argument('--config', metavar='FILENAME', |
| help='Path to test configuration file') |
| parser.add_argument('test', nargs='*', |
| - help='Name(s) of tests to run.') |
| + help=('Name(s) of tests to run. For example, ' |
| + '__main__.InstallerTest.ChromeUserLevel')) |
| args = parser.parse_args() |
| if not args.config: |
| parser.error('missing mandatory --config FILENAME argument') |
| @@ -361,7 +338,8 @@ def main(): |
| next_version_mini_installer_path) |
| config = ParseConfigFile(args.config, variable_expander) |
| - RunCleanCommand(args.force_clean, variable_expander) |
| + RunCleanCommand(args.force_clean, config.states[DEFAULT_CLEAN_STATE], |
| + variable_expander) |
| for test in config.tests: |
| # If tests were specified via |tests|, their names are formatted like so: |
| test_name = '%s.%s.%s' % (InstallerTest.__module__, |