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

Side by Side Diff: tools/chrome_proxy/webdriver/common.py

Issue 2538773004: Fix cmd line args override in common.py (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 argparse 5 import argparse
6 import json 6 import json
7 import os 7 import os
8 import shlex 8 import shlex
9 import sys 9 import sys
10 import time 10 import time
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 def __enter__(self): 71 def __enter__(self):
72 return self 72 return self
73 73
74 def __exit__(self, exc_type, exc_value, tb): 74 def __exit__(self, exc_type, exc_value, tb):
75 if self._driver: 75 if self._driver:
76 self._StopDriver() 76 self._StopDriver()
77 77
78 def _OverrideChromeArgs(self): 78 def _OverrideChromeArgs(self):
79 """ 79 """
80 Overrides any given flags in the code with those given on the command line. 80 Overrides any given arguments in the code with those given on the command
RyanSturm 2016/11/30 20:46:36 I'm a little confused about how this is used. Can
Robert Ogden 2016/12/01 01:23:04 CL description improved, but yes you were correct.
RyanSturm 2016/12/01 01:32:11 SGTM.
81 line. Arguments that need to be overridden may contain different values for
82 a flag given in the code. In that case, check by the flag whether to
83 override the argument.
81 """ 84 """
85 def GetDictKey(argument):
86 return argument.split('=', 1)[0]
82 if self._flags.browser_args and len(self._flags.browser_args) > 0: 87 if self._flags.browser_args and len(self._flags.browser_args) > 0:
83 for arg in shlex.split(self._flags.browser_args): 88 # Build a dict of flags mapped to the whole argument.
84 self._chrome_args.add(arg) 89 originalArgs = {}
RyanSturm 2016/11/30 20:46:36 s/originalArgs/original_args/ AFAIK naming for py
Robert Ogden 2016/12/01 01:23:04 Done.
90 for arg in self._chrome_args:
91 originalArgs[GetDictKey(arg)] = arg
92 # Override by flag.
93 for overrideArg in shlex.split(self._flags.browser_args):
RyanSturm 2016/11/30 20:46:36 s/overrideArg/override_arg/
Robert Ogden 2016/12/01 01:23:04 Done.
94 argKey = GetDictKey(overrideArg)
RyanSturm 2016/11/30 20:46:36 s/argKey/arg_key/
Robert Ogden 2016/12/01 01:23:04 Done.
95 if argKey in originalArgs:
96 self._chrome_args.remove(originalArgs[argKey])
97 self._chrome_args.add(overrideArg)
85 98
86 def _StartDriver(self): 99 def _StartDriver(self):
87 """ 100 """
88 Parses the flags to pass to Chromium, then starts the ChromeDriver. 101 Parses the flags to pass to Chromium, then starts the ChromeDriver.
89 """ 102 """
90 options = Options() 103 options = Options()
91 for arg in self._chrome_args: 104 for arg in self._chrome_args:
92 options.add_argument(arg) 105 options.add_argument(arg)
93 capabilities = {'loggingPrefs': {'performance': 'INFO'}} 106 capabilities = {'loggingPrefs': {'performance': 'INFO'}}
94 if self._flags.chrome_exec: 107 if self._flags.chrome_exec:
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 def Fail(self, msg): 217 def Fail(self, msg):
205 sys.stderr.write("**************************************\n") 218 sys.stderr.write("**************************************\n")
206 sys.stderr.write("**************************************\n") 219 sys.stderr.write("**************************************\n")
207 sys.stderr.write("** **\n") 220 sys.stderr.write("** **\n")
208 sys.stderr.write("** TEST FAILURE **\n") 221 sys.stderr.write("** TEST FAILURE **\n")
209 sys.stderr.write("** **\n") 222 sys.stderr.write("** **\n")
210 sys.stderr.write("**************************************\n") 223 sys.stderr.write("**************************************\n")
211 sys.stderr.write("**************************************\n") 224 sys.stderr.write("**************************************\n")
212 sys.stderr.write(msg, '\n') 225 sys.stderr.write(msg, '\n')
213 sys.exit(1) 226 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698