Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 import logging | |
| 5 | |
| 6 from metrics import chrome_proxy | |
| 7 from telemetry.core import util | |
| 8 from telemetry.page import page_measurement | |
| 9 | |
| 10 | |
|
bengr
2014/03/12 18:17:36
I'm a little confused about the file naming. What'
bolian
2014/03/19 00:20:03
I am trying to fit into the Telemetry test structu
| |
| 11 class ChromeProxyLatency(page_measurement.PageMeasurement): | |
|
tonyg
2014/03/12 02:08:37
Rather than creating a new measurement, I recommen
bolian
2014/03/19 00:20:03
PageCycler measurement does not call LoadingMetric
| |
| 12 """Chrome proxy latency measurement.""" | |
| 13 | |
| 14 def __init__(self, *args, **kwargs): | |
| 15 super(ChromeProxyLatency, self).__init__(*args, **kwargs) | |
| 16 | |
| 17 def WillNavigateToPage(self, page, tab): | |
| 18 tab.ClearCache(force=True) | |
| 19 | |
| 20 def MeasurePage(self, page, tab, results): | |
| 21 # Wait for the load event. | |
| 22 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) | |
| 23 chrome_proxy.ChromeProxyLatency().AddResults(tab, results) | |
| 24 | |
| 25 | |
| 26 class ChromeProxyDataSaving(page_measurement.PageMeasurement): | |
| 27 """Chrome proxy data daving measurement.""" | |
| 28 def __init__(self, *args, **kwargs): | |
| 29 super(ChromeProxyDataSaving, self).__init__(*args, **kwargs) | |
| 30 self._metrics = chrome_proxy.ChromeProxyTimelineMetrics() | |
| 31 | |
| 32 def WillNavigateToPage(self, page, tab): | |
| 33 tab.ClearCache(force=True) | |
| 34 self._metrics.Start(page, tab) | |
| 35 | |
| 36 def MeasurePage(self, page, tab, results): | |
| 37 # Wait for the load event. | |
| 38 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) | |
| 39 self._metrics.Stop(page, tab) | |
| 40 self._metrics.AddResultsForDataSaving(tab, results) | |
| 41 | |
| 42 | |
| 43 class ChromeProxyValidation(page_measurement.PageMeasurement): | |
| 44 """Base class for all chrome proxy correctness measurement.""" | |
|
bengr
2014/03/12 18:17:36
nit: "measurements". Also, why "measurement" and n
bolian
2014/03/19 00:20:03
Done. A measurement is a page set in Telemetry ter
| |
| 45 | |
| 46 def __init__(self, restart_after_each_run=False): | |
| 47 super(ChromeProxyValidation, self).__init__( | |
| 48 needs_browser_restart_after_each_run=restart_after_each_run) | |
| 49 self._metrics = chrome_proxy.ChromeProxyTimelineMetrics() | |
| 50 self._page = None | |
| 51 # Whether a timeout exception is expected during the test. | |
| 52 self._expect_timeout = False | |
| 53 | |
| 54 def CustomizeBrowserOptions(self, options): | |
| 55 # Enable the chrome proxy (data reduction proxy). | |
| 56 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') | |
| 57 | |
| 58 def WillNavigateToPage(self, page, tab): | |
| 59 tab.ClearCache(force=True) | |
| 60 assert self._metrics | |
| 61 self._metrics.Start(page, tab) | |
| 62 | |
| 63 def MeasurePage(self, page, tab, results): | |
| 64 self._page = page | |
| 65 # Wait for the load event. | |
| 66 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) | |
| 67 assert self._metrics | |
| 68 self._metrics.Stop(page, tab) | |
| 69 self.AddResults(tab, results) | |
| 70 | |
| 71 def AddResults(self, tab, results): | |
| 72 raise NotImplementedError | |
| 73 | |
| 74 def StopBrowserAfterPage(self, browser, page): # pylint: disable=W0613 | |
| 75 if hasattr(page, 'restart_after') and page.restart_after: | |
| 76 return True | |
| 77 return False | |
| 78 | |
| 79 def RunNavigateSteps(self, page, tab): | |
| 80 # The redirect from safebrowsing causes a timeout. Ignore that. | |
| 81 try: | |
| 82 super(ChromeProxyValidation, self).RunNavigateSteps(page, tab) | |
| 83 except util.TimeoutException, e: | |
| 84 if self._expect_timeout: | |
| 85 logging.warning('Navigation timeout on page %s', | |
| 86 page.name if page.name else page.url) | |
| 87 else: | |
| 88 raise e | |
| 89 | |
| 90 | |
| 91 class ChromeProxyHeaders(ChromeProxyValidation): | |
| 92 """Correctness measurement for response headers.""" | |
| 93 | |
| 94 def __init__(self): | |
| 95 super(ChromeProxyHeaders, self).__init__() | |
| 96 | |
| 97 def AddResults(self, tab, results): | |
| 98 self._metrics.AddResultsForHeaderValidation(tab, results) | |
| 99 | |
| 100 | |
| 101 class ChromeProxyBypass(ChromeProxyValidation): | |
| 102 """Correctness measurement for bypass responses.""" | |
| 103 | |
| 104 def __init__(self): | |
| 105 super(ChromeProxyBypass, self).__init__(restart_after_each_run=True) | |
| 106 | |
| 107 def AddResults(self, tab, results): | |
| 108 self._metrics.AddResultsForBypass(tab, results) | |
| 109 | |
| 110 | |
| 111 class ChromeProxySafebrowsing(ChromeProxyValidation): | |
| 112 """Correctness measurement for safebrowsing.""" | |
| 113 | |
| 114 def __init__(self): | |
| 115 super(ChromeProxySafebrowsing, self).__init__() | |
| 116 | |
| 117 def WillNavigateToPage(self, page, tab): | |
| 118 super(ChromeProxySafebrowsing, self).WillNavigateToPage(page, tab) | |
| 119 self._expect_timeout = True | |
| 120 | |
| 121 def AddResults(self, tab, results): | |
| 122 self._metrics.AddResultsForSafebrowsing(tab, results) | |
| 123 | |
| 124 | |
| 125 class ChromeProxySmoke(ChromeProxyValidation): | |
| 126 """Smoke measurement for basic chrome proxy correctness.""" | |
| 127 | |
| 128 def __init__(self): | |
| 129 super(ChromeProxySmoke, self).__init__() | |
| 130 | |
| 131 def WillNavigateToPage(self, page, tab): | |
| 132 super(ChromeProxySmoke, self).WillNavigateToPage(page, tab) | |
| 133 if page.name == 'safebrowsing': | |
| 134 self._expect_timeout = True | |
| 135 | |
| 136 def AddResults(self, tab, results): | |
| 137 # Map a page name to its AddResults func. | |
| 138 page_to_metrics = { | |
| 139 'header validation': [self._metrics.AddResultsForHeaderValidation], | |
| 140 'compression: image': [ | |
| 141 self._metrics.AddResultsForHeaderValidation, | |
| 142 self._metrics.AddResultsForDataSaving, | |
| 143 ], | |
| 144 'compression: javascript': [ | |
| 145 self._metrics.AddResultsForHeaderValidation, | |
| 146 self._metrics.AddResultsForDataSaving, | |
| 147 ], | |
| 148 'compression: css': [ | |
| 149 self._metrics.AddResultsForHeaderValidation, | |
| 150 self._metrics.AddResultsForDataSaving, | |
| 151 ], | |
| 152 'bypass': [self._metrics.AddResultsForBypass], | |
| 153 'safebrowsing': [self._metrics.AddResultsForSafebrowsing], | |
| 154 } | |
| 155 if not self._page.name in page_to_metrics: | |
| 156 raise page_measurement.MeasurementFailure( | |
| 157 'Invalid page name (%s) in smoke. Page name must be one of:\n%s' % ( | |
| 158 self._page.name, page_to_metrics.keys())) | |
| 159 for add_result in page_to_metrics[self._page.name]: | |
| 160 add_result(tab, results) | |
| OLD | NEW |