# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import subprocess

# TODO(sukolsak): This should read the uninstall command from the registry and
# run that instead.
subprocess.call('mini_installer.exe --uninstall --multi-install --chrome',
                shell=True)

# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Uninstall Chrome.

This script reads the uninstall command from registry, calls it, and verifies
the output status code.
"""

import _winreg
import argparse
import subprocess
import sys


def main():
  parser = argparse.ArgumentParser(description='Uninstall Chrome.')
  parser.add_argument('--system-level', dest='system_level',
                      action='store_const', const=True, default=False,
                      help='Uninstall Chrome at system level.')
  args = parser.parse_args()

  # TODO(sukolsak): Add support for uninstalling MSI-based Chrome installs when
  # we support testing MSIs.
  if args.system_level:
    root_key = _winreg.HKEY_LOCAL_MACHINE
  else:
    root_key = _winreg.HKEY_CURRENT_USER
  sub_key = ('SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\'
             'Google Chrome')
  key = _winreg.OpenKey(root_key, sub_key, 0, _winreg.KEY_QUERY_VALUE)
  uninstall_string, _ = _winreg.QueryValueEx(key, 'UninstallString')
  exit_status = subprocess.call(uninstall_string, shell=True)
  # The exit status for successful uninstallation of Chrome is 19 (see
  # chrome/installer/util/util_constants.h).
  if exit_status != 19:
    raise Exception('Could not uninstall Chrome. The installer exited with '
                    'status %d.' % exit_status)
  return 0

if __name__ == '__main__':
  sys.exit(main())

Automate uninstallation of Chrome by running the uninstall command from the registry.
Automate uninstallation of Chrome by running the uninstall command from the registry.

NOTRY=True
BUG=264859
TEST=
1) Uninstall Chrome.
2) Put mini_installer.exe in the same folder as test_installer.py.
3) Run "python test_installer.py config\config.config".
4) The script will install Chrome and then uninstall Chrome. At each state, it will check that chrome.exe exists (or doesn't exist). You should see output similar to the following:

"Test: clean -> install chrome -> chrome_installed -> uninstall chrome -> clean ... ok

----------------------------------------------------------------------
Ran 1 test in 12.345s"

Review URL: https://chromiumcodereview.appspot.com/22815017

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@218797 0039d316-1c4b-4281-b951-d872f2087c98
