OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import constants |
5 import logging | 6 import logging |
| 7 import traceback |
6 | 8 |
7 | 9 |
8 class FlagChanger(object): | 10 class FlagChanger(object): |
9 """Changes the flags Chrome runs with. | 11 """Changes the flags Chrome runs with. |
10 | 12 |
11 There are two different use cases for this file: | 13 There are two different use cases for this file: |
12 * Flags are permanently set by calling Set(). | 14 * Flags are permanently set by calling Set(). |
13 * Flags can be temporarily set for a particular set of unit tests. These | 15 * Flags can be temporarily set for a particular set of unit tests. These |
14 tests should call Restore() to revert the flags to their original state | 16 tests should call Restore() to revert the flags to their original state |
15 once the tests have completed. | 17 once the tests have completed. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 assert len(file_contents) == 1 and file_contents[0] == cmd_line, ( | 106 assert len(file_contents) == 1 and file_contents[0] == cmd_line, ( |
105 'Failed to set the command line file at %s' % self._cmdline_file) | 107 'Failed to set the command line file at %s' % self._cmdline_file) |
106 else: | 108 else: |
107 if use_root: | 109 if use_root: |
108 self._adb.RunShellCommandWithSU('rm ' + self._cmdline_file) | 110 self._adb.RunShellCommandWithSU('rm ' + self._cmdline_file) |
109 else: | 111 else: |
110 self._adb.RunShellCommand('rm ' + self._cmdline_file) | 112 self._adb.RunShellCommand('rm ' + self._cmdline_file) |
111 assert not self._adb.FileExistsOnDevice(self._cmdline_file), ( | 113 assert not self._adb.FileExistsOnDevice(self._cmdline_file), ( |
112 'Failed to remove the command line file at %s' % self._cmdline_file) | 114 'Failed to remove the command line file at %s' % self._cmdline_file) |
113 | 115 |
114 @staticmethod | 116 def _TokenizeFlags(self, line): |
115 def _TokenizeFlags(line): | |
116 """Changes the string containing the command line into a list of flags. | 117 """Changes the string containing the command line into a list of flags. |
117 | 118 |
118 Follows similar logic to CommandLine.java::tokenizeQuotedArguments: | 119 Follows similar logic to CommandLine.java::tokenizeQuotedArguments: |
119 * Flags are split using whitespace, unless the whitespace is within a | 120 * Flags are split using whitespace, unless the whitespace is within a |
120 pair of quotation marks. | 121 pair of quotation marks. |
121 * Unlike the Java version, we keep the quotation marks around switch | 122 * Unlike the Java version, we keep the quotation marks around switch |
122 values since we need them to re-create the file when new flags are | 123 values since we need them to re-create the file when new flags are |
123 appended. | 124 appended. |
124 | 125 |
125 Args: | 126 Args: |
(...skipping 26 matching lines...) Expand all Loading... |
152 | 153 |
153 # Tack on the last flag. | 154 # Tack on the last flag. |
154 if not current_flag: | 155 if not current_flag: |
155 if within_quotations: | 156 if within_quotations: |
156 logging.warn('Unterminated quoted argument: ' + line) | 157 logging.warn('Unterminated quoted argument: ' + line) |
157 else: | 158 else: |
158 tokenized_flags.append(current_flag) | 159 tokenized_flags.append(current_flag) |
159 | 160 |
160 # Return everything but the program name. | 161 # Return everything but the program name. |
161 return tokenized_flags[1:] | 162 return tokenized_flags[1:] |
OLD | NEW |