def AddResultsForHTTPToDirectFallback(self, tab, results, fallback_response_host): via_fallback_count = 0 bypass_count = 0 responses = self.IterResponses(tab) # The first response(s) coming from fallback_response_host should be # through the HTTP fallback proxy. resp = next(responses, None) while resp and fallback_response_host in resp.response.url: if fallback_response_host in resp.response.url: if (not resp.HasChromeProxyViaHeader() or resp.remote_port != 80): r = resp.response raise ChromeProxyMetricException, ( 'Response for %s should have come through the fallback proxy.\n' 'Response: remote_port=%s status=(%d, %s)\nHeaders:\n %s' % (r.url, str(resp.remote_port), r.status, r.status_text, r.headers)) else: via_fallback_count += 1 resp = next(responses, None) # All other responses should be bypassed. while resp: if resp.HasChromeProxyViaHeader(): r = resp.response raise ChromeProxyMetricException, ( 'Response for %s should not have via header.\n' 'Response: status=(%d, %s)\nHeaders:\n %s' % (r.url, r.status, r.status_text, r.headers)) else: bypass_count += 1 resp = next(responses, None) # At least one response should go through the http proxy and be bypassed. if via_fallback_count == 0 or bypass_count == 0: raise ChromeProxyMetricException( 'There should be at least one response through the fallback proxy ' '(actual %s) and at least one bypassed response (actual %s)' % (via_fallback_count, bypass_count)) results.AddValue( scalar.ScalarValue(results.current_page, 'via_fallback', 'count', via_fallback_count)) results.AddValue( scalar.ScalarValue(results.current_page, 'bypass', 'count', bypass_count))
def AddResultsForBadHTTPSFallback(self, tab, results): via_count = 0 tab.WaitForDocumentReadyStateToBeComplete(timeout=30) for resp in self.IterResponses(tab): if resp.HasChromeProxyViaHeader() and (resp.remote_port == 80 or resp.remote_port == None): via_count += 1 else: r = resp.response raise ChromeProxyMetricException, ( 'Response for %s should have via header and be on port 80 after ' 'bad proxy HTTPS response.\nReponse: status=(%d)\nport=(%d)\n' 'Headers:\n %s' % ( r.url, r.status, resp.remote_port, r.headers)) if via_count == 0: raise ChromeProxyMetricException('No pages were tested!') results.AddValue(scalar.ScalarValue( results.current_page, 'via', 'count', via_count))
def AddResultsForBypassOnTimeout(self, tab, results): bypass_count = 0 # Wait maximum of 120 seconds for test to complete. Should complete soon # after 90 second test server delay in case of failure, and much sooner in # case of success. tab.WaitForDocumentReadyStateToBeComplete(timeout=120) for resp in self.IterResponses(tab): if resp.HasChromeProxyViaHeader() and not resp.response.url.endswith( 'favicon.ico'): r = resp.response raise ChromeProxyMetricException, ( 'Response for %s should not have via header after HTTP timeout.\n' 'Reponse: status=(%d)\nHeaders:\n %s' % ( r.url, r.status, r.headers)) elif not resp.response.url.endswith('favicon.ico'): bypass_count += 1 if bypass_count == 0: raise ChromeProxyMetricException('No pages were tested!') results.AddValue(scalar.ScalarValue( results.current_page, 'bypass', 'count', bypass_count))