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

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: Reviewer comment: removed unused class ChromeProxyLatency 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 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):
16 """Chrome proxy latency measurement."""
17
18 def __init__(self, *args, **kwargs):
19 super(ChromeProxyLatency, self).__init__(*args, **kwargs)
20 self._metrics = metrics.ChromeProxyMetric()
21
22 def CustomizeBrowserOptions(self, options):
23 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
24
25 def WillNavigateToPage(self, page, tab):
26 tab.ClearCache(force=True)
27
28 def ValidateAndMeasurePage(self, page, tab, results):
29 # Wait for the load event.
30 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300)
31 self._metrics.AddResultsForLatency(tab, results)
32
33 15
34 class ChromeProxyDataSaving(page_test.PageTest): 16 class ChromeProxyDataSaving(page_test.PageTest):
35 """Chrome proxy data saving measurement.""" 17 """Chrome proxy data saving measurement."""
36 def __init__(self, *args, **kwargs): 18 def __init__(self, *args, **kwargs):
37 super(ChromeProxyDataSaving, self).__init__(*args, **kwargs) 19 super(ChromeProxyDataSaving, self).__init__(*args, **kwargs)
38 self._metrics = metrics.ChromeProxyMetric() 20 self._metrics = metrics.ChromeProxyMetric()
21 self._enable_proxy = True
39 22
40 def CustomizeBrowserOptions(self, options): 23 def CustomizeBrowserOptions(self, options):
41 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') 24 if self._enable_proxy:
25 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
42 26
43 def WillNavigateToPage(self, page, tab): 27 def WillNavigateToPage(self, page, tab):
44 tab.ClearCache(force=True) 28 tab.ClearCache(force=True)
45 self._metrics.Start(page, tab) 29 self._metrics.Start(page, tab)
46 30
47 def ValidateAndMeasurePage(self, page, tab, results): 31 def ValidateAndMeasurePage(self, page, tab, results):
48 # Wait for the load event. 32 # Wait for the load event.
49 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) 33 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300)
50 self._metrics.Stop(page, tab) 34 self._metrics.Stop(page, tab)
51 self._metrics.AddResultsForDataSaving(tab, results) 35 self._metrics.AddResultsForDataSaving(tab, results)
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 self._metrics.AddResultsForDataSaving, 349 self._metrics.AddResultsForDataSaving,
366 ], 350 ],
367 'bypass': [self._metrics.AddResultsForBypass], 351 'bypass': [self._metrics.AddResultsForBypass],
368 } 352 }
369 if not self._page.name in page_to_metrics: 353 if not self._page.name in page_to_metrics:
370 raise page_test.MeasurementFailure( 354 raise page_test.MeasurementFailure(
371 'Invalid page name (%s) in smoke. Page name must be one of:\n%s' % ( 355 'Invalid page name (%s) in smoke. Page name must be one of:\n%s' % (
372 self._page.name, page_to_metrics.keys())) 356 self._page.name, page_to_metrics.keys()))
373 for add_result in page_to_metrics[self._page.name]: 357 for add_result in page_to_metrics[self._page.name]:
374 add_result(tab, results) 358 add_result(tab, results)
359
360
361 PROXIED = metrics.PROXIED
362 DIRECT = metrics.DIRECT
363
364 class ChromeProxyVideoValidation(page_test.PageTest):
365 """Validation for video pages.
366
367 Measures pages using metrics.ChromeProxyVideoMetric. Pages can be fetched
368 either direct from the origin server or via the proxy. If a page is fetched
369 both ways, then the PROXIED and DIRECT measurements are compared to ensure
370 the same video was loaded in both cases.
371 """
372
373 def __init__(self):
374 super(ChromeProxyVideoValidation, self).__init__(
375 needs_browser_restart_after_each_page=True,
376 clear_cache_before_each_run=True)
377 # The type is _allMetrics[url][PROXIED,DIRECT][metricName] = value,
378 # where (metricName,value) is a metric computed by videowrapper.js.
379 self._allMetrics = {}
380
381 def CustomizeBrowserOptionsForSinglePage(self, page, options):
382 if page.use_chrome_proxy:
383 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
384
385 def DidNavigateToPage(self, page, tab):
386 self._currMetrics = metrics.ChromeProxyVideoMetric(tab)
387 self._currMetrics.Start(page, tab)
388
389 def ValidateAndMeasurePage(self, page, tab, results):
390 assert self._currMetrics
391 self._currMetrics.Stop(page, tab)
392 if page.url not in self._allMetrics:
393 self._allMetrics[page.url] = {}
394
395 # Verify this page.
396 if page.use_chrome_proxy:
397 self._currMetrics.AddResultsForProxied(tab, results)
398 self._allMetrics[page.url][PROXIED] = self._currMetrics.videoMetrics
399 else:
400 self._currMetrics.AddResultsForDirect(tab, results)
401 self._allMetrics[page.url][DIRECT] = self._currMetrics.videoMetrics
402 self._currMetrics = None
403
404 # Compare proxied and direct results for this url, if they exist.
405 m = self._allMetrics[page.url]
406 if PROXIED in m and DIRECT in m:
407 self._CompareProxiedAndDirectMetrics(page.url, m[PROXIED], m[DIRECT])
408
409 def _CompareProxiedAndDirectMetrics(self, url, pm, dm):
410 """Compare metrics from PROXIED and DIRECT fetches.
411
412 Compares video metrics computed by videowrapper.js for pages that were
413 fetch both PROXIED and DIRECT.
414
415 Args:
416 url: The url for the page being tested.
417 pm: Metrics when loaded by the Flywheel proxy.
418 dm: Metrics when loaded directly from the origin server.
419
420 Raises:
421 ChromeProxyMetricException on failure.
422 """
423 def err(s):
424 raise ChromeProxyMetricException, s
425
426 if not pm['ready']:
427 err('Proxied page did not load video: %s' % page.url)
428 if not dm['ready']:
429 err('Direct page did not load video: %s' % page.url)
430
431 # Compare metrics that should match for PROXIED and DIRECT.
432 for x in ('video_height', 'video_width', 'video_duration',
433 'decoded_frames'):
434 if x not in pm:
435 err('Proxied page has no %s: %s' % (x, page.url))
436 if x not in dm:
437 err('Direct page has no %s: %s' % (x, page.url))
438 if pm[x] != dm[x]:
439 err('Mismatch for %s (proxied=%s direct=%s): %s' %
440 (x, str(pm[x]), str(dm[x]), page.url))
441
442 # Proxied XOCL should match direct CL.
443 pxocl = pm['x_original_content_length_header']
444 dcl = dm['content_length_header']
445 if pxocl != dcl:
446 err('Mismatch for content length (proxied=%s direct=%s): %s' %
447 (str(pxocl), str(dcl), page.url))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698