1414import sys
1515import threading
1616import time
17- if (sys .version_info > (3 , 0 )):
17+ if (sys .version_info >= (3 , 0 )):
1818 from time import monotonic
1919 from urllib .parse import urlsplit # pylint: disable=import-error
2020 unicode = str
@@ -128,8 +128,12 @@ def prepare_browser(self, task):
128128 wait = True )
129129
130130 # DevTools-based CPU throttling for desktop and emulated mobile tests
131+ # This throttling should only be applied for:
132+ # 1. Normal test runs where cgroups throttling (--throttle) is disabled
133+ # 2. Lighthouse test runs where a custom config path is not specified
131134 if not self .options .android and \
132135 (task ['running_lighthouse' ] or not self .options .throttle ) and \
136+ (not task ['running_lighthouse' ] or not self .job ['lighthouse_config' ]) and \
133137 'throttle_cpu' in self .job :
134138 logging .debug ('DevTools CPU Throttle target: %0.3fx' , self .job ['throttle_cpu' ])
135139 if self .job ['throttle_cpu' ] > 1 :
@@ -340,7 +344,7 @@ def strip_non_text(self, data):
340344 self .strip_non_text (entry )
341345 elif isinstance (entry , str ) or isinstance (entry , unicode ):
342346 try :
343- if (sys .version_info > (3 , 0 )):
347+ if (sys .version_info >= (3 , 0 )):
344348 entry .encode ('utf-8' ).decode ('utf-8' )
345349 else :
346350 entry .decode ('utf-8' )
@@ -358,7 +362,7 @@ def strip_non_text(self, data):
358362 self .strip_non_text (entry )
359363 elif isinstance (entry , str ) or isinstance (entry , unicode ):
360364 try :
361- if (sys .version_info > (3 , 0 )):
365+ if (sys .version_info >= (3 , 0 )):
362366 entry .encode ('utf-8' ).decode ('utf-8' )
363367 else :
364368 entry .decode ('utf-8' )
@@ -498,6 +502,8 @@ def process_command(self, command):
498502 if 'target' in command :
499503 milliseconds = int (re .search (r'\d+' , str (command ['target' ])).group ())
500504 self .task ['activity_time' ] = max (0 , min (30 , float (milliseconds ) / 1000.0 ))
505+ elif command ['command' ] == 'setminimumstepseconds' :
506+ self .task ['minimumTestSeconds' ] = int (re .search (r'\d+' , str (command ['target' ])).group ())
501507 elif command ['command' ] == 'setuseragent' :
502508 self .task ['user_agent_string' ] = command ['target' ]
503509 elif command ['command' ] == 'setcookie' :
@@ -574,7 +580,8 @@ def run_lighthouse_test(self, task):
574580 """Run a lighthouse test against the current browser session"""
575581 task ['lighthouse_log' ] = ''
576582 if 'url' in self .job and self .job ['url' ] is not None :
577- self .job ['shaper' ].configure (self .job , task )
583+ if not self .job ['lighthouse_config' ]:
584+ self .job ['shaper' ].configure (self .job , task )
578585 output_path = os .path .join (task ['dir' ], 'lighthouse.json' )
579586 json_file = os .path .join (task ['dir' ], 'lighthouse.report.json' )
580587 json_gzip = os .path .join (task ['dir' ], 'lighthouse.json.gz' )
@@ -584,24 +591,33 @@ def run_lighthouse_test(self, task):
584591 command = ['lighthouse' ,
585592 '"{0}"' .format (self .job ['url' ]),
586593 '--channel' , 'wpt' ,
587- '--disable-network-throttling' ,
588- '--disable-cpu-throttling' ,
589- '--throttling-method' , 'provided' ,
590594 '--enable-error-reporting' ,
591595 '--max-wait-for-load' , str (int (time_limit * 1000 )),
592596 '--port' , str (task ['port' ]),
593597 '--output' , 'html' ,
594598 '--output' , 'json' ,
595599 '--output-path' , '"{0}"' .format (output_path )]
600+ if self .job ['lighthouse_config' ]:
601+ try :
602+ lighthouse_config_file = os .path .join (task ['dir' ], 'lighthouse-config.json' )
603+ with open (lighthouse_config_file , 'wt' ) as f_out :
604+ json .dump (json .loads (self .job ['lighthouse_config' ]), f_out )
605+ command .extend (['--config-path' , lighthouse_config_file ])
606+ except Exception :
607+ logging .exception ('Error adding custom config for lighthouse test' )
608+ else :
609+ command .extend (['--throttling-method' , 'provided' ])
596610 if self .job ['keep_lighthouse_trace' ]:
597611 command .append ('--save-assets' )
598612 if not self .job ['keep_lighthouse_screenshots' ]:
599613 command .extend (['--skip-audits' , 'screenshot-thumbnails' ])
600- if self .options .android or 'mobile' not in self . job or not self . job [ 'mobile' ] :
614+ if self .options .android :
601615 command .extend (['--emulated-form-factor' , 'none' ])
602616 if 'user_agent_string' in self .job :
603617 sanitized_user_agent = re .sub (r'[^a-zA-Z0-9_\-.;:/()\[\] ]+' , '' , self .job ['user_agent_string' ])
604618 command .append ('--chrome-flags="--user-agent=\' {0}\' "' .format (sanitized_user_agent ))
619+ elif 'mobile' not in self .job or not self .job ['mobile' ]:
620+ command .extend (['--emulated-form-factor' , 'desktop' ])
605621 if len (task ['block' ]):
606622 for pattern in task ['block' ]:
607623 pattern = "'" + pattern .replace ("'" , "'\\ ''" ) + "'"
0 commit comments