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. | |
robertshield
2013/09/10 20:59:31
Also, consider adding a TODO to handle SxS install
sukolsak
2013/09/10 21:26:29
Done.
| |
125 command = ('python uninstall_chrome.py ' | |
126 '--chrome-long-name="$CHROME_LONG_NAME" & ' | |
robertshield
2013/09/10 20:59:31
Just to double check: it is my understanding that
sukolsak
2013/09/10 21:26:29
They will print an error message to stderr. For ex
| |
127 'python uninstall_chrome.py ' | |
128 '--chrome-long-name="$CHROME_LONG_NAME" --system-level') | |
129 resolved_command = self._path_resolver.ResolvePath(command) | |
130 script_dir = os.path.dirname(os.path.abspath(__file__)) | |
131 subprocess.call(resolved_command, shell=True, cwd=script_dir, | |
132 stderr=open(os.devnull, 'w')) | |
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 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' % | 234 assert os.path.exists(mini_installer_path), ('Could not find file %s' % |
222 mini_installer_path) | 235 mini_installer_path) |
223 config = ParseConfigFile(config_filename) | 236 config = ParseConfigFile(config_filename) |
224 if not RunTests(mini_installer_path, config): | 237 if not RunTests(mini_installer_path, config): |
225 return 1 | 238 return 1 |
226 return 0 | 239 return 0 |
227 | 240 |
228 | 241 |
229 if __name__ == '__main__': | 242 if __name__ == '__main__': |
230 sys.exit(main()) | 243 sys.exit(main()) |
OLD | NEW |