Chromium Code Reviews| 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() |
|
gab
2013/09/10 22:19:05
This shouldn't always be run by default imo... as
grt (UTC plus 2)
2013/09/11 03:01:41
I like the idea of:
1) having the test fail if it
sukolsak
2013/09/13 09:10:21
Done.
sukolsak
2013/09/13 09:10:21
Done.
Checking whether Chrome is installed (and i
| |
| 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" & ' | |
| 128 'python uninstall_chrome.py ' | |
| 129 '--chrome-long-name="$CHROME_LONG_NAME" --system-level') | |
| 130 resolved_command = self._path_resolver.ResolvePath(command) | |
| 131 script_dir = os.path.dirname(os.path.abspath(__file__)) | |
|
gab
2013/09/10 22:19:05
Since we now need |script_dir| in more than one pl
sukolsak
2013/09/13 09:10:21
|script_dir| doesn't seem like a state of an objec
| |
| 132 subprocess.call(resolved_command, shell=True, cwd=script_dir, | |
| 133 stderr=open(os.devnull, 'w')) | |
|
gab
2013/09/10 22:19:05
So we trash all stderr output :(... why? If it's o
sukolsak
2013/09/13 09:10:21
Done.
| |
| 134 | |
| 121 | 135 |
| 122 def MergePropertyDictionaries(current_property, new_property): | 136 def MergePropertyDictionaries(current_property, new_property): |
| 123 """Merges the new property dictionary into the current property dictionary. | 137 """Merges the new property dictionary into the current property dictionary. |
| 124 | 138 |
| 125 This is different from general dictionary merging in that, in case there are | 139 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 | 140 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 | 141 override earlier values in the second level. For more details, take a look at |
| 128 http://goo.gl/uE0RoR | 142 http://goo.gl/uE0RoR |
| 129 | 143 |
| 130 Args: | 144 Args: |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 assert os.path.exists(mini_installer_path), ('Could not find file %s' % | 235 assert os.path.exists(mini_installer_path), ('Could not find file %s' % |
| 222 mini_installer_path) | 236 mini_installer_path) |
| 223 config = ParseConfigFile(config_filename) | 237 config = ParseConfigFile(config_filename) |
| 224 if not RunTests(mini_installer_path, config): | 238 if not RunTests(mini_installer_path, config): |
| 225 return 1 | 239 return 1 |
| 226 return 0 | 240 return 0 |
| 227 | 241 |
| 228 | 242 |
| 229 if __name__ == '__main__': | 243 if __name__ == '__main__': |
| 230 sys.exit(main()) | 244 sys.exit(main()) |
| OLD | NEW |