Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(786)

Side by Side Diff: tools/chrome_proxy/integration_tests/chrome_proxy_measurements.py

Issue 1065763002: Add data reduction proxy integration tests for video compression. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with HEAD and address reviewer comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 integration_tests import chrome_proxy_metrics as metrics 9 from integration_tests import chrome_proxy_metrics as metrics
10 from metrics import loading 10 from metrics import loading
11 from telemetry.core import exceptions 11 from telemetry.core import exceptions
12 from telemetry.page import page_test 12 from telemetry.page import page_test
13 13
14 class ChromeProxyLatency(page_test.PageTest): 14 class ChromeProxyLatency(page_test.PageTest):
15 """Chrome proxy latency measurement.""" 15 """Chrome proxy latency measurement."""
16 16
17 def __init__(self, *args, **kwargs): 17 def __init__(self, *args, **kwargs):
18 super(ChromeProxyLatency, self).__init__(*args, **kwargs) 18 super(ChromeProxyLatency, self).__init__(*args, **kwargs)
19 self._metrics = metrics.ChromeProxyMetric() 19 self._metrics = metrics.ChromeProxyMetric()
20 self._enable_proxy = True
20 21
21 def CustomizeBrowserOptions(self, options): 22 def CustomizeBrowserOptions(self, options):
22 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') 23 if self._enable_proxy:
24 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
23 25
24 def WillNavigateToPage(self, page, tab): 26 def WillNavigateToPage(self, page, tab):
25 tab.ClearCache(force=True) 27 tab.ClearCache(force=True)
26 28
27 def ValidateAndMeasurePage(self, page, tab, results): 29 def ValidateAndMeasurePage(self, page, tab, results):
28 # Wait for the load event. 30 # Wait for the load event.
29 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) 31 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300)
30 self._metrics.AddResultsForLatency(tab, results) 32 self._metrics.AddResultsForLatency(tab, results)
31 33
32 34
35 class ChromeProxyLatencyDirect(ChromeProxyLatency):
36 """Direct fetch latency measurement."""
37 def __init__(self, *args, **kwargs):
38 super(ChromeProxyLatencyDirect, self).__init__(*args, **kwargs)
39 self._enable_proxy = False
40
41
33 class ChromeProxyDataSaving(page_test.PageTest): 42 class ChromeProxyDataSaving(page_test.PageTest):
34 """Chrome proxy data saving measurement.""" 43 """Chrome proxy data saving measurement."""
35 def __init__(self, *args, **kwargs): 44 def __init__(self, *args, **kwargs):
36 super(ChromeProxyDataSaving, self).__init__(*args, **kwargs) 45 super(ChromeProxyDataSaving, self).__init__(*args, **kwargs)
37 self._metrics = metrics.ChromeProxyMetric() 46 self._metrics = metrics.ChromeProxyMetric()
47 self._enable_proxy = True
38 48
39 def CustomizeBrowserOptions(self, options): 49 def CustomizeBrowserOptions(self, options):
40 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') 50 if self._enable_proxy:
51 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
41 52
42 def WillNavigateToPage(self, page, tab): 53 def WillNavigateToPage(self, page, tab):
43 tab.ClearCache(force=True) 54 tab.ClearCache(force=True)
44 self._metrics.Start(page, tab) 55 self._metrics.Start(page, tab)
45 56
46 def ValidateAndMeasurePage(self, page, tab, results): 57 def ValidateAndMeasurePage(self, page, tab, results):
47 # Wait for the load event. 58 # Wait for the load event.
48 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) 59 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300)
49 self._metrics.Stop(page, tab) 60 self._metrics.Stop(page, tab)
50 self._metrics.AddResultsForDataSaving(tab, results) 61 self._metrics.AddResultsForDataSaving(tab, results)
51 62
52 63
64 class ChromeProxyDataSavingDirect(ChromeProxyDataSaving):
65 """Direct fetch data saving measurement."""
66 def __init__(self, *args, **kwargs):
67 super(ChromeProxyDataSavingDirect, self).__init__(*args, **kwargs)
68 self._enable_proxy = False
69
70
53 class ChromeProxyValidation(page_test.PageTest): 71 class ChromeProxyValidation(page_test.PageTest):
54 """Base class for all chrome proxy correctness measurements.""" 72 """Base class for all chrome proxy correctness measurements."""
55 73
56 # Value of the extra via header. |None| if no extra via header is expected. 74 # Value of the extra via header. |None| if no extra via header is expected.
57 extra_via_header = None 75 extra_via_header = None
58 76
59 def __init__(self, restart_after_each_page=False): 77 def __init__(self, restart_after_each_page=False):
60 super(ChromeProxyValidation, self).__init__( 78 super(ChromeProxyValidation, self).__init__(
61 needs_browser_restart_after_each_page=restart_after_each_page) 79 needs_browser_restart_after_each_page=restart_after_each_page)
62 self._metrics = metrics.ChromeProxyMetric() 80 self._metrics = metrics.ChromeProxyMetric()
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 self._metrics.AddResultsForDataSaving, 422 self._metrics.AddResultsForDataSaving,
405 ], 423 ],
406 'bypass': [self._metrics.AddResultsForBypass], 424 'bypass': [self._metrics.AddResultsForBypass],
407 } 425 }
408 if not self._page.name in page_to_metrics: 426 if not self._page.name in page_to_metrics:
409 raise page_test.MeasurementFailure( 427 raise page_test.MeasurementFailure(
410 'Invalid page name (%s) in smoke. Page name must be one of:\n%s' % ( 428 'Invalid page name (%s) in smoke. Page name must be one of:\n%s' % (
411 self._page.name, page_to_metrics.keys())) 429 self._page.name, page_to_metrics.keys()))
412 for add_result in page_to_metrics[self._page.name]: 430 for add_result in page_to_metrics[self._page.name]:
413 add_result(tab, results) 431 add_result(tab, results)
432
433
434 PROXIED = metrics.PROXIED
435 DIRECT = metrics.DIRECT
436
437 class ChromeProxyVideoValidation(page_test.PageTest):
438 """Validation for video pages.
439
440 Measures pages using metrics.ChromeProxyVideoMetric. Pages can be fetched
441 either direct from the origin server or via the proxy. If a page is fetched
442 both ways, then the PROXIED and DIRECT measurements are compared to ensure
443 the same video was loaded in both cases.
444 """
445
446 def __init__(self):
447 super(ChromeProxyVideoValidation, self).__init__(
448 needs_browser_restart_after_each_page=True,
449 clear_cache_before_each_run=True)
450 # The type is _allMetrics[url][PROXIED,DIRECT][metricName] = value,
451 # where (metricName,value) is a metric computed by videowrapper.js.
452 self._allMetrics = {}
453
454 def CustomizeBrowserOptionsForSinglePage(self, page, options):
455 if page.use_chrome_proxy:
456 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
457
458 def DidNavigateToPage(self, page, tab):
459 self._currMetrics = metrics.ChromeProxyVideoMetric(tab)
460 self._currMetrics.Start(page, tab)
461
462 def ValidateAndMeasurePage(self, page, tab, results):
463 assert self._currMetrics
464 self._currMetrics.Stop(page, tab)
465 if page.url not in self._allMetrics:
466 self._allMetrics[page.url] = {}
467
468 # Verify this page.
469 if page.use_chrome_proxy:
470 self._currMetrics.AddResultsForProxied(tab, results)
471 self._allMetrics[page.url][PROXIED] = self._currMetrics.videoMetrics
472 else:
473 self._currMetrics.AddResultsForDirect(tab, results)
474 self._allMetrics[page.url][DIRECT] = self._currMetrics.videoMetrics
475 self._currMetrics = None
476
477 # Compare proxied and direct results for this url, if they exist.
478 m = self._allMetrics[page.url]
479 if PROXIED in m and DIRECT in m:
480 self._CompareProxiedAndDirectMetrics(page.url, m[PROXIED], m[DIRECT])
481
482 def _CompareProxiedAndDirectMetrics(self, url, pm, dm):
483 """Compare metrics from PROXIED and DIRECT fetches.
484
485 Compares video metrics computed by videowrapper.js for pages that were
486 fetch both PROXIED and DIRECT.
487
488 Args:
489 url: The url for the page being tested.
490 pm: Metrics when loaded by the Flywheel proxy.
491 dm: Metrics when loaded directly from the origin server.
492
493 Raises:
494 ChromeProxyMetricException on failure.
495 """
496 def err(s):
497 raise ChromeProxyMetricException, s
498
499 if not pm['ready']:
500 err('Proxied page did not load video: %s' % page.url)
501 if not dm['ready']:
502 err('Direct page did not load video: %s' % page.url)
503
504 # Compare metrics that should match for PROXIED and DIRECT.
505 for x in ('video_height', 'video_width', 'video_duration',
506 'decoded_frames'):
507 if x not in pm:
508 err('Proxied page has no %s: %s' % (x, page.url))
509 if x not in dm:
510 err('Direct page has no %s: %s' % (x, page.url))
511 if pm[x] != dm[x]:
512 err('Mismatch for %s (proxied=%s direct=%s): %s' %
513 (x, str(pm[x]), str(dm[x]), page.url))
514
515 # Proxied XOCL should match direct CL.
516 pxocl = pm['x_original_content_length_header']
517 dcl = dm['content_length_header']
518 if pxocl != dcl:
519 err('Mismatch for content length (proxied=%s direct=%s): %s' %
520 (str(pxocl), str(dcl), page.url))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698