Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 base64 | 5 import base64 |
| 6 import logging | 6 import logging |
| 7 import urlparse | 7 import urlparse |
| 8 | 8 |
| 9 from common.chrome_proxy_measurements import ChromeProxyValidation | 9 from common.chrome_proxy_measurements import ChromeProxyValidation |
| 10 from integration_tests import chrome_proxy_metrics as metrics | 10 from integration_tests import chrome_proxy_metrics as metrics |
| 11 from metrics import loading | 11 from metrics import loading |
| 12 from telemetry.core import exceptions | 12 from telemetry.core import exceptions |
| 13 from telemetry.page import page_test | 13 from telemetry.page import page_test |
| 14 | 14 |
| 15 class ChromeProxyLatency(page_test.PageTest): | 15 class ChromeProxyLatency(page_test.PageTest): |
| 16 """Chrome proxy latency measurement.""" | 16 """Chrome proxy latency measurement.""" |
| 17 | 17 |
| 18 def __init__(self, *args, **kwargs): | 18 def __init__(self, *args, **kwargs): |
| 19 super(ChromeProxyLatency, self).__init__(*args, **kwargs) | 19 super(ChromeProxyLatency, self).__init__(*args, **kwargs) |
| 20 self._metrics = metrics.ChromeProxyMetric() | 20 self._metrics = metrics.ChromeProxyMetric() |
| 21 self._enable_proxy = True | |
| 21 | 22 |
| 22 def CustomizeBrowserOptions(self, options): | 23 def CustomizeBrowserOptions(self, options): |
| 23 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') | 24 if self._enable_proxy: |
| 25 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') | |
| 24 | 26 |
| 25 def WillNavigateToPage(self, page, tab): | 27 def WillNavigateToPage(self, page, tab): |
| 26 tab.ClearCache(force=True) | 28 tab.ClearCache(force=True) |
| 27 | 29 |
| 28 def ValidateAndMeasurePage(self, page, tab, results): | 30 def ValidateAndMeasurePage(self, page, tab, results): |
| 29 # Wait for the load event. | 31 # Wait for the load event. |
| 30 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) | 32 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) |
| 31 self._metrics.AddResultsForLatency(tab, results) | 33 self._metrics.AddResultsForLatency(tab, results) |
| 32 | 34 |
| 33 | 35 |
| 36 class ChromeProxyLatencyDirect(ChromeProxyLatency): | |
|
sclittle
2015/05/20 21:30:28
I don't think this measurement is used by any benc
| |
| 37 """Direct fetch latency measurement.""" | |
| 38 def __init__(self, *args, **kwargs): | |
| 39 super(ChromeProxyLatencyDirect, self).__init__(*args, **kwargs) | |
| 40 self._enable_proxy = False | |
| 41 | |
| 42 | |
| 34 class ChromeProxyDataSaving(page_test.PageTest): | 43 class ChromeProxyDataSaving(page_test.PageTest): |
| 35 """Chrome proxy data saving measurement.""" | 44 """Chrome proxy data saving measurement.""" |
| 36 def __init__(self, *args, **kwargs): | 45 def __init__(self, *args, **kwargs): |
| 37 super(ChromeProxyDataSaving, self).__init__(*args, **kwargs) | 46 super(ChromeProxyDataSaving, self).__init__(*args, **kwargs) |
| 38 self._metrics = metrics.ChromeProxyMetric() | 47 self._metrics = metrics.ChromeProxyMetric() |
| 48 self._enable_proxy = True | |
| 39 | 49 |
| 40 def CustomizeBrowserOptions(self, options): | 50 def CustomizeBrowserOptions(self, options): |
| 41 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') | 51 if self._enable_proxy: |
| 52 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') | |
| 42 | 53 |
| 43 def WillNavigateToPage(self, page, tab): | 54 def WillNavigateToPage(self, page, tab): |
| 44 tab.ClearCache(force=True) | 55 tab.ClearCache(force=True) |
| 45 self._metrics.Start(page, tab) | 56 self._metrics.Start(page, tab) |
| 46 | 57 |
| 47 def ValidateAndMeasurePage(self, page, tab, results): | 58 def ValidateAndMeasurePage(self, page, tab, results): |
| 48 # Wait for the load event. | 59 # Wait for the load event. |
| 49 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) | 60 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) |
| 50 self._metrics.Stop(page, tab) | 61 self._metrics.Stop(page, tab) |
| 51 self._metrics.AddResultsForDataSaving(tab, results) | 62 self._metrics.AddResultsForDataSaving(tab, results) |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 self._metrics.AddResultsForDataSaving, | 376 self._metrics.AddResultsForDataSaving, |
| 366 ], | 377 ], |
| 367 'bypass': [self._metrics.AddResultsForBypass], | 378 'bypass': [self._metrics.AddResultsForBypass], |
| 368 } | 379 } |
| 369 if not self._page.name in page_to_metrics: | 380 if not self._page.name in page_to_metrics: |
| 370 raise page_test.MeasurementFailure( | 381 raise page_test.MeasurementFailure( |
| 371 'Invalid page name (%s) in smoke. Page name must be one of:\n%s' % ( | 382 'Invalid page name (%s) in smoke. Page name must be one of:\n%s' % ( |
| 372 self._page.name, page_to_metrics.keys())) | 383 self._page.name, page_to_metrics.keys())) |
| 373 for add_result in page_to_metrics[self._page.name]: | 384 for add_result in page_to_metrics[self._page.name]: |
| 374 add_result(tab, results) | 385 add_result(tab, results) |
| 386 | |
| 387 | |
| 388 PROXIED = metrics.PROXIED | |
| 389 DIRECT = metrics.DIRECT | |
| 390 | |
| 391 class ChromeProxyVideoValidation(page_test.PageTest): | |
| 392 """Validation for video pages. | |
| 393 | |
| 394 Measures pages using metrics.ChromeProxyVideoMetric. Pages can be fetched | |
| 395 either direct from the origin server or via the proxy. If a page is fetched | |
| 396 both ways, then the PROXIED and DIRECT measurements are compared to ensure | |
| 397 the same video was loaded in both cases. | |
| 398 """ | |
| 399 | |
| 400 def __init__(self): | |
| 401 super(ChromeProxyVideoValidation, self).__init__( | |
| 402 needs_browser_restart_after_each_page=True, | |
| 403 clear_cache_before_each_run=True) | |
| 404 # The type is _allMetrics[url][PROXIED,DIRECT][metricName] = value, | |
| 405 # where (metricName,value) is a metric computed by videowrapper.js. | |
| 406 self._allMetrics = {} | |
| 407 | |
| 408 def CustomizeBrowserOptionsForSinglePage(self, page, options): | |
| 409 if page.use_chrome_proxy: | |
| 410 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') | |
| 411 | |
| 412 def DidNavigateToPage(self, page, tab): | |
| 413 self._currMetrics = metrics.ChromeProxyVideoMetric(tab) | |
| 414 self._currMetrics.Start(page, tab) | |
| 415 | |
| 416 def ValidateAndMeasurePage(self, page, tab, results): | |
| 417 assert self._currMetrics | |
| 418 self._currMetrics.Stop(page, tab) | |
| 419 if page.url not in self._allMetrics: | |
| 420 self._allMetrics[page.url] = {} | |
| 421 | |
| 422 # Verify this page. | |
| 423 if page.use_chrome_proxy: | |
| 424 self._currMetrics.AddResultsForProxied(tab, results) | |
| 425 self._allMetrics[page.url][PROXIED] = self._currMetrics.videoMetrics | |
| 426 else: | |
| 427 self._currMetrics.AddResultsForDirect(tab, results) | |
| 428 self._allMetrics[page.url][DIRECT] = self._currMetrics.videoMetrics | |
| 429 self._currMetrics = None | |
| 430 | |
| 431 # Compare proxied and direct results for this url, if they exist. | |
| 432 m = self._allMetrics[page.url] | |
| 433 if PROXIED in m and DIRECT in m: | |
| 434 self._CompareProxiedAndDirectMetrics(page.url, m[PROXIED], m[DIRECT]) | |
| 435 | |
| 436 def _CompareProxiedAndDirectMetrics(self, url, pm, dm): | |
| 437 """Compare metrics from PROXIED and DIRECT fetches. | |
| 438 | |
| 439 Compares video metrics computed by videowrapper.js for pages that were | |
| 440 fetch both PROXIED and DIRECT. | |
| 441 | |
| 442 Args: | |
| 443 url: The url for the page being tested. | |
| 444 pm: Metrics when loaded by the Flywheel proxy. | |
| 445 dm: Metrics when loaded directly from the origin server. | |
| 446 | |
| 447 Raises: | |
| 448 ChromeProxyMetricException on failure. | |
| 449 """ | |
| 450 def err(s): | |
| 451 raise ChromeProxyMetricException, s | |
| 452 | |
| 453 if not pm['ready']: | |
| 454 err('Proxied page did not load video: %s' % page.url) | |
| 455 if not dm['ready']: | |
| 456 err('Direct page did not load video: %s' % page.url) | |
| 457 | |
| 458 # Compare metrics that should match for PROXIED and DIRECT. | |
| 459 for x in ('video_height', 'video_width', 'video_duration', | |
| 460 'decoded_frames'): | |
| 461 if x not in pm: | |
| 462 err('Proxied page has no %s: %s' % (x, page.url)) | |
| 463 if x not in dm: | |
| 464 err('Direct page has no %s: %s' % (x, page.url)) | |
| 465 if pm[x] != dm[x]: | |
| 466 err('Mismatch for %s (proxied=%s direct=%s): %s' % | |
| 467 (x, str(pm[x]), str(dm[x]), page.url)) | |
| 468 | |
| 469 # Proxied XOCL should match direct CL. | |
| 470 pxocl = pm['x_original_content_length_header'] | |
| 471 dcl = dm['content_length_header'] | |
| 472 if pxocl != dcl: | |
| 473 err('Mismatch for content length (proxied=%s direct=%s): %s' % | |
| 474 (str(pxocl), str(dcl), page.url)) | |
| OLD | NEW |