OLD | NEW |
---|---|
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 """ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 """ | 62 """ |
63 return 'Test: %s' % (' -> '.join(self._test)) | 63 return 'Test: %s' % (' -> '.join(self._test)) |
64 | 64 |
65 def runTest(self): | 65 def runTest(self): |
66 """Run the test case.""" | 66 """Run the test case.""" |
67 # |test| is an array of alternating state names and action names, starting | 67 # |test| is an array of alternating state names and action names, starting |
68 # and ending with state names. Therefore, its length must be odd. | 68 # and ending with state names. Therefore, its length must be odd. |
69 self.assertEqual(1, len(self._test) % 2, | 69 self.assertEqual(1, len(self._test) % 2, |
70 'The length of test array must be odd') | 70 'The length of test array must be odd') |
71 | 71 |
72 # TODO(sukolsak): run a reset command that puts the machine in clean state. | 72 self._RunCleanCommand() |
73 | 73 |
74 state = self._test[0] | 74 state = self._test[0] |
75 self._VerifyState(state) | 75 self._VerifyState(state) |
76 | 76 |
77 # Starting at index 1, we loop through pairs of (action, state). | 77 # Starting at index 1, we loop through pairs of (action, state). |
78 for i in range(1, len(self._test), 2): | 78 for i in range(1, len(self._test), 2): |
79 action = self._test[i] | 79 action = self._test[i] |
80 self._RunCommand(self._config.actions[action]) | 80 self._RunCommand(self._config.actions[action]) |
81 | 81 |
82 state = self._test[i + 1] | 82 state = self._test[i + 1] |
(...skipping 28 matching lines...) Expand all Loading... | |
111 Args: | 111 Args: |
112 command: A command to run. It is expanded using ResolvePath. | 112 command: A command to run. It is expanded using ResolvePath. |
113 """ | 113 """ |
114 resolved_command = self._path_resolver.ResolvePath(command) | 114 resolved_command = self._path_resolver.ResolvePath(command) |
115 script_dir = os.path.dirname(os.path.abspath(__file__)) | 115 script_dir = os.path.dirname(os.path.abspath(__file__)) |
116 exit_status = subprocess.call(resolved_command, shell=True, cwd=script_dir) | 116 exit_status = subprocess.call(resolved_command, shell=True, cwd=script_dir) |
117 if exit_status != 0: | 117 if exit_status != 0: |
118 self.fail('Command %s returned non-zero exit status %s' % ( | 118 self.fail('Command %s returned non-zero exit status %s' % ( |
119 resolved_command, exit_status)) | 119 resolved_command, exit_status)) |
120 | 120 |
121 def _RunCleanCommand(self): | |
122 """Puts the machine in the clean state (i.e. Chrome not installed).""" | |
123 # TODO(sukolsak): Read the clean state from the config file and clean | |
124 # the machine according to it. | |
125 # TODO(sukolsak): Handle Chrome SxS installs. | |
126 command = ('python uninstall_chrome.py ' | |
127 '--chrome-long-name="$CHROME_LONG_NAME" --silent & ' | |
128 'python uninstall_chrome.py ' | |
129 '--chrome-long-name="$CHROME_LONG_NAME" --system-level --silent') | |
130 resolved_command = self._path_resolver.ResolvePath(command) | |
131 script_dir = os.path.dirname(os.path.abspath(__file__)) | |
132 subprocess.call(resolved_command, shell=True, cwd=script_dir) | |
133 | |
121 | 134 |
122 def MergePropertyDictionaries(current_property, new_property): | 135 def MergePropertyDictionaries(current_property, new_property): |
123 """Merges the new property dictionary into the current property dictionary. | 136 """Merges the new property dictionary into the current property dictionary. |
124 | 137 |
125 This is different from general dictionary merging in that, in case there are | 138 This is different from general dictionary merging in that, in case there are |
126 keys with the same name, we merge values together in the first level, and we | 139 keys with the same name, we merge values together in the first level, and we |
127 override earlier values in the second level. For more details, take a look at | 140 override earlier values in the second level. For more details, take a look at |
128 http://goo.gl/uE0RoR | 141 http://goo.gl/uE0RoR |
129 | 142 |
130 Args: | 143 Args: |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 | 217 |
205 | 218 |
206 def main(): | 219 def main(): |
207 usage = 'usage: %prog [options] config_filename' | 220 usage = 'usage: %prog [options] config_filename' |
208 parser = optparse.OptionParser(usage, description='Test the installer.') | 221 parser = optparse.OptionParser(usage, description='Test the installer.') |
209 parser.add_option('--build-dir', default='out', | 222 parser.add_option('--build-dir', default='out', |
210 help='Path to main build directory (the parent of the ' | 223 help='Path to main build directory (the parent of the ' |
211 'Release or Debug directory)') | 224 'Release or Debug directory)') |
212 parser.add_option('--target', default='Release', | 225 parser.add_option('--target', default='Release', |
213 help='Build target (Release or Debug)') | 226 help='Build target (Release or Debug)') |
227 parser.add_option('--force-clean', action='store_true', dest='force_clean', | |
228 default=False, help='Force cleaning existing installations') | |
214 options, args = parser.parse_args() | 229 options, args = parser.parse_args() |
215 if len(args) != 1: | 230 if len(args) != 1: |
216 parser.error('Incorrect number of arguments.') | 231 parser.error('Incorrect number of arguments.') |
217 config_filename = args[0] | 232 config_filename = args[0] |
218 | 233 |
234 if not options.force_clean: | |
235 prompt = ('Warning: This script will uninstall Chrome or Chromium if they ' | |
gab
2013/09/13 15:06:19
Instead of always prompting how about an option on
sukolsak
2013/09/13 15:59:33
Then we will only warn the user only when the regi
gab
2013/09/13 20:12:55
I'd say yes, I think we shouldn't delete a real/fu
sukolsak
2013/09/13 23:11:14
Done.
| |
236 'are installed. Do you want to continue? (y/N) ') | |
237 if raw_input(prompt).strip() != 'y': | |
238 print >> sys.stderr, 'User aborted' | |
239 return 1 | |
240 | |
219 mini_installer_path = os.path.join(options.build_dir, options.target, | 241 mini_installer_path = os.path.join(options.build_dir, options.target, |
220 'mini_installer.exe') | 242 'mini_installer.exe') |
221 assert os.path.exists(mini_installer_path), ('Could not find file %s' % | 243 assert os.path.exists(mini_installer_path), ('Could not find file %s' % |
222 mini_installer_path) | 244 mini_installer_path) |
223 config = ParseConfigFile(config_filename) | 245 config = ParseConfigFile(config_filename) |
224 if not RunTests(mini_installer_path, config): | 246 if not RunTests(mini_installer_path, config): |
225 return 1 | 247 return 1 |
226 return 0 | 248 return 0 |
227 | 249 |
228 | 250 |
229 if __name__ == '__main__': | 251 if __name__ == '__main__': |
230 sys.exit(main()) | 252 sys.exit(main()) |
OLD | NEW |