| OLD | NEW |
| 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 re | 8 import re |
| 9 import socket | 9 import socket |
| 10 import shlex | 10 import shlex |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 # Build a dict of flags mapped to the whole argument. | 105 # Build a dict of flags mapped to the whole argument. |
| 106 original_args = {} | 106 original_args = {} |
| 107 for arg in self._chrome_args: | 107 for arg in self._chrome_args: |
| 108 original_args[GetDictKey(arg)] = arg | 108 original_args[GetDictKey(arg)] = arg |
| 109 # Override flags given in code with any command line arguments. | 109 # Override flags given in code with any command line arguments. |
| 110 for override_arg in shlex.split(self._flags.browser_args[0]): | 110 for override_arg in shlex.split(self._flags.browser_args[0]): |
| 111 arg_key = GetDictKey(override_arg) | 111 arg_key = GetDictKey(override_arg) |
| 112 if arg_key in original_args: | 112 if arg_key in original_args: |
| 113 self._chrome_args.remove(original_args[arg_key]) | 113 self._chrome_args.remove(original_args[arg_key]) |
| 114 self._chrome_args.add(override_arg) | 114 self._chrome_args.add(override_arg) |
| 115 # Always add the flag that allows histograms to be queried in javascript. |
| 116 self._chrome_args.add('--enable-stats-collection-bindings') |
| 115 | 117 |
| 116 def _StartDriver(self): | 118 def _StartDriver(self): |
| 117 """Parses the flags to pass to Chromium, then starts the ChromeDriver. | 119 """Parses the flags to pass to Chromium, then starts the ChromeDriver. |
| 118 | 120 |
| 119 If running Android, the Android package name is passed to ChromeDriver here. | 121 If running Android, the Android package name is passed to ChromeDriver here. |
| 120 """ | 122 """ |
| 121 self._OverrideChromeArgs() | 123 self._OverrideChromeArgs() |
| 122 capabilities = { | 124 capabilities = { |
| 123 'loggingPrefs': {'performance': 'INFO'}, | 125 'loggingPrefs': {'performance': 'INFO'}, |
| 124 'chromeOptions': { | 126 'chromeOptions': { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 Behavior is analogous to 'function(){ return <script> }();' | 248 Behavior is analogous to 'function(){ return <script> }();' |
| 247 | 249 |
| 248 Args: | 250 Args: |
| 249 script: A string of Javascript code. | 251 script: A string of Javascript code. |
| 250 timeout: Timeout for the Javascript code to return in seconds. | 252 timeout: Timeout for the Javascript code to return in seconds. |
| 251 Returns: | 253 Returns: |
| 252 A string of the verbatim output from the Javascript execution. | 254 A string of the verbatim output from the Javascript execution. |
| 253 """ | 255 """ |
| 254 return self.ExecuteJavascript("return " + script, timeout) | 256 return self.ExecuteJavascript("return " + script, timeout) |
| 255 | 257 |
| 258 def GetHistogram(self, histogram): |
| 259 js_query = 'statsCollectionController.getBrowserHistogram("%s")' % histogram |
| 260 string_response = self.ExecuteJavascriptStatement(js_query) |
| 261 return json.loads(string_response) |
| 262 |
| 256 def GetPerformanceLogs(self, method_filter=r'Network\.responseReceived'): | 263 def GetPerformanceLogs(self, method_filter=r'Network\.responseReceived'): |
| 257 """Returns all logged Performance events from Chrome. | 264 """Returns all logged Performance events from Chrome. |
| 258 | 265 |
| 259 Args: | 266 Args: |
| 260 method_filter: A regex expression to match the method of logged events | 267 method_filter: A regex expression to match the method of logged events |
| 261 against. Only logs who's method matches the regex will be returned. | 268 against. Only logs who's method matches the regex will be returned. |
| 262 Returns: | 269 Returns: |
| 263 Performance logs as a list of dicts, since the last time this function was | 270 Performance logs as a list of dicts, since the last time this function was |
| 264 called. | 271 called. |
| 265 """ | 272 """ |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 """ | 401 """ |
| 395 sys.stderr.write("**************************************\n") | 402 sys.stderr.write("**************************************\n") |
| 396 sys.stderr.write("**************************************\n") | 403 sys.stderr.write("**************************************\n") |
| 397 sys.stderr.write("** **\n") | 404 sys.stderr.write("** **\n") |
| 398 sys.stderr.write("** TEST FAILURE **\n") | 405 sys.stderr.write("** TEST FAILURE **\n") |
| 399 sys.stderr.write("** **\n") | 406 sys.stderr.write("** **\n") |
| 400 sys.stderr.write("**************************************\n") | 407 sys.stderr.write("**************************************\n") |
| 401 sys.stderr.write("**************************************\n") | 408 sys.stderr.write("**************************************\n") |
| 402 sys.stderr.write(msg, '\n') | 409 sys.stderr.write(msg, '\n') |
| 403 sys.exit(1) | 410 sys.exit(1) |
| OLD | NEW |