Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: chrome/test/mini_installer/test_installer.py

Issue 520633005: Reduce flakes in the mini_installer test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notreached
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """This script tests the installer with test cases specified in the config file. 5 """This script tests the installer with test cases specified in the config file.
6 6
7 For each test case, it checks that the machine states after the execution of 7 For each test case, it checks that the machine states after the execution of
8 each command match the expected machine states. For more details, take a look at 8 each command match the expected machine states. For more details, take a look at
9 the design documentation at http://goo.gl/Q0rGM6 9 the design documentation at http://goo.gl/Q0rGM6
10 """ 10 """
11 11
12 import argparse 12 import argparse
13 import json 13 import json
14 import os 14 import os
15 import subprocess 15 import subprocess
16 import sys 16 import sys
17 import time 17 import time
18 import unittest 18 import unittest
19 import _winreg
19 20
20 from variable_expander import VariableExpander 21 from variable_expander import VariableExpander
21 import verifier_runner 22 import verifier_runner
22 23
23 24
24 class Config: 25 class Config:
25 """Describes the machine states, actions, and test cases. 26 """Describes the machine states, actions, and test cases.
26 27
27 Attributes: 28 Attributes:
28 states: A dictionary where each key is a state name and the associated value 29 states: A dictionary where each key is a state name and the associated value
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 variable_expander: A VariableExpander object. 138 variable_expander: A VariableExpander object.
138 """ 139 """
139 expanded_command = variable_expander.Expand(command) 140 expanded_command = variable_expander.Expand(command)
140 script_dir = os.path.dirname(os.path.abspath(__file__)) 141 script_dir = os.path.dirname(os.path.abspath(__file__))
141 exit_status = subprocess.call(expanded_command, shell=True, cwd=script_dir) 142 exit_status = subprocess.call(expanded_command, shell=True, cwd=script_dir)
142 if exit_status != 0: 143 if exit_status != 0:
143 raise Exception('Command %s returned non-zero exit status %s' % ( 144 raise Exception('Command %s returned non-zero exit status %s' % (
144 expanded_command, exit_status)) 145 expanded_command, exit_status))
145 146
146 147
148 def DeleteGoogleUpdateRegistration(system_level, variable_expander):
149 """Deletes Chrome's registration with Google Update.
150
151 Args:
152 system_level: True if system-level Chrome is to be deleted.
153 variable_expander: A VariableExpander object.
154 """
155 root = (_winreg.HKEY_LOCAL_MACHINE if system_level
156 else _winreg.HKEY_CURRENT_USER)
157 key_name = variable_expander.Expand('$CHROME_UPDATE_REGISTRY_SUBKEY')
158 try:
159 key_handle = _winreg.OpenKey(root, key_name, 0,
160 _winreg.KEY_SET_VALUE |
161 _winreg.KEY_WOW64_32KEY)
162 _winreg.DeleteValue(key_handle, 'pv')
163 except WindowsError:
164 # The key isn't present, so there is no value to delete.
165 pass
166
167
147 def RunCleanCommand(force_clean, variable_expander): 168 def RunCleanCommand(force_clean, variable_expander):
148 """Puts the machine in the clean state (i.e. Chrome not installed). 169 """Puts the machine in the clean state (i.e. Chrome not installed).
149 170
150 Args: 171 Args:
151 force_clean: A boolean indicating whether to force cleaning existing 172 force_clean: A boolean indicating whether to force cleaning existing
152 installations. 173 installations.
153 variable_expander: A VariableExpander object. 174 variable_expander: A VariableExpander object.
154 """ 175 """
155 # TODO(sukolsak): Read the clean state from the config file and clean
156 # the machine according to it.
157 # TODO(sukolsak): Handle Chrome SxS installs. 176 # TODO(sukolsak): Handle Chrome SxS installs.
158 commands = []
159 interactive_option = '--interactive' if not force_clean else '' 177 interactive_option = '--interactive' if not force_clean else ''
160 for level_option in ('', '--system-level'): 178 for system_level in (False, True):
161 commands.append('python uninstall_chrome.py ' 179 level_option = '--system-level' if system_level else ''
162 '--chrome-long-name="$CHROME_LONG_NAME" ' 180 command = ('python uninstall_chrome.py '
163 '--no-error-if-absent %s %s' % 181 '--chrome-long-name="$CHROME_LONG_NAME" '
164 (level_option, interactive_option)) 182 '--no-error-if-absent %s %s' %
165 RunCommand(' && '.join(commands), variable_expander) 183 (level_option, interactive_option))
184 RunCommand(command, variable_expander)
185 if force_clean:
186 DeleteGoogleUpdateRegistration(system_level, variable_expander)
166 187
167 188
168 def MergePropertyDictionaries(current_property, new_property): 189 def MergePropertyDictionaries(current_property, new_property):
169 """Merges the new property dictionary into the current property dictionary. 190 """Merges the new property dictionary into the current property dictionary.
170 191
171 This is different from general dictionary merging in that, in case there are 192 This is different from general dictionary merging in that, in case there are
172 keys with the same name, we merge values together in the first level, and we 193 keys with the same name, we merge values together in the first level, and we
173 override earlier values in the second level. For more details, take a look at 194 override earlier values in the second level. For more details, take a look at
174 http://goo.gl/uE0RoR 195 http://goo.gl/uE0RoR
175 196
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 trie[path] = value 385 trie[path] = value
365 return 386 return
366 directory, rest = path.split(TEST_SEPARATOR, 1) 387 directory, rest = path.split(TEST_SEPARATOR, 1)
367 if directory not in trie: 388 if directory not in trie:
368 trie[directory] = {} 389 trie[directory] = {}
369 _AddPathToTrie(trie[directory], rest, value) 390 _AddPathToTrie(trie[directory], rest, value)
370 391
371 392
372 if __name__ == '__main__': 393 if __name__ == '__main__':
373 sys.exit(main()) 394 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698