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 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 | 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): | |
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) |
52 | 63 |
53 | 64 |
65 class ChromeProxyDataSavingDirect(ChromeProxyDataSaving): | |
66 """Direct fetch data saving measurement.""" | |
67 def __init__(self, *args, **kwargs): | |
68 super(ChromeProxyDataSavingDirect, self).__init__(*args, **kwargs) | |
69 self._enable_proxy = False | |
70 | |
71 | |
54 class ChromeProxyValidation(page_test.PageTest): | 72 class ChromeProxyValidation(page_test.PageTest): |
55 """Base class for all chrome proxy correctness measurements.""" | 73 """Base class for all chrome proxy correctness measurements.""" |
56 | 74 |
57 def __init__(self, restart_after_each_page=False): | 75 def __init__(self, restart_after_each_page=False): |
58 super(ChromeProxyValidation, self).__init__( | 76 super(ChromeProxyValidation, self).__init__( |
59 needs_browser_restart_after_each_page=restart_after_each_page) | 77 needs_browser_restart_after_each_page=restart_after_each_page) |
60 self._metrics = metrics.ChromeProxyMetric() | 78 self._metrics = metrics.ChromeProxyMetric() |
61 self._page = None | 79 self._page = None |
62 # Whether a timeout exception is expected during the test. | 80 # Whether a timeout exception is expected during the test. |
63 self._expect_timeout = False | 81 self._expect_timeout = False |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 self._metrics.AddResultsForDataSaving, | 400 self._metrics.AddResultsForDataSaving, |
383 ], | 401 ], |
384 'bypass': [self._metrics.AddResultsForBypass], | 402 'bypass': [self._metrics.AddResultsForBypass], |
385 } | 403 } |
386 if not self._page.name in page_to_metrics: | 404 if not self._page.name in page_to_metrics: |
387 raise page_test.MeasurementFailure( | 405 raise page_test.MeasurementFailure( |
388 'Invalid page name (%s) in smoke. Page name must be one of:\n%s' % ( | 406 'Invalid page name (%s) in smoke. Page name must be one of:\n%s' % ( |
389 self._page.name, page_to_metrics.keys())) | 407 self._page.name, page_to_metrics.keys())) |
390 for add_result in page_to_metrics[self._page.name]: | 408 for add_result in page_to_metrics[self._page.name]: |
391 add_result(tab, results) | 409 add_result(tab, results) |
410 | |
411 | |
412 PROXIED = 'proxied' | |
sclittle
2015/04/11 00:13:02
I think you can just call metrics.PROXIED to use t
Tom Bergan
2015/05/01 23:48:28
Done.
| |
413 DIRECT = 'direct' | |
414 | |
415 class ChromeProxyVideoValidation(page_test.PageTest): | |
416 """Measures pages using metrics.ChromeProxyVideoMetric, then compares | |
sclittle
2015/04/11 00:13:02
See style guide for python classdoc style: https:/
Tom Bergan
2015/05/01 23:48:28
Done.
| |
417 the measurements from a direct fetch with measurements from a proxied | |
418 fetch. | |
419 """ | |
420 | |
421 def __init__(self): | |
422 super(ChromeProxyVideoValidation, self).__init__( | |
423 needs_browser_restart_after_each_page=True, | |
424 clear_cache_before_each_run=True) | |
425 # The type is _allMetrics[url][PROXIED,DIRECT][metricName] = value, | |
426 # where (metricName,value) is a metric computed by videowrapper.js. | |
427 self._allMetrics = {} | |
428 | |
429 def CustomizeBrowserOptionsForSinglePage(self, page, options): | |
430 if page.use_chrome_proxy: | |
431 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') | |
432 | |
433 def DidNavigateToPage(self, page, tab): | |
434 self._currMetrics = metrics.ChromeProxyVideoMetric(tab) | |
435 self._currMetrics.Start(page, tab) | |
436 | |
437 def ValidateAndMeasurePage(self, page, tab, results): | |
438 assert self._currMetrics | |
439 self._currMetrics.Stop(page, tab) | |
440 if page.url not in self._allMetrics: | |
441 self._allMetrics[page.url] = {} | |
442 | |
443 # Verify this page. | |
444 if page.use_chrome_proxy: | |
445 self._currMetrics.AddResultsForProxied(tab, results) | |
446 self._allMetrics[page.url][PROXIED] = self._currMetrics.videoMetrics | |
447 else: | |
448 self._currMetrics.AddResultsForDirect(tab, results) | |
449 self._allMetrics[page.url][DIRECT] = self._currMetrics.videoMetrics | |
450 self._currMetrics = None | |
451 | |
452 # Compare proxied and direct results for this url, if they exist. | |
453 m = self._allMetrics[page.url] | |
454 if PROXIED in m and DIRECT in m: | |
455 self._CompareProxiedAndDirectMetrics(page.url, m[PROXIED], m[DIRECT]) | |
456 | |
457 def _CompareProxiedAndDirectMetrics(self, url, pm, dm): | |
458 """ Compares video metrics computed by videowrapper.js for PROXIED and | |
sclittle
2015/04/11 00:13:02
See style guide for method doc style: https://goog
Tom Bergan
2015/05/01 23:48:28
Done.
| |
459 DIRECT pages. Raises ChromeProxyMetricException on failure. | |
460 | |
461 Arguments: | |
462 url: The url for the page being tested. | |
463 pm: Metrics when loaded by the Flywheel proxy. | |
464 dm: Metrics when loaded directly from the origin server. | |
465 """ | |
466 def err(s): | |
467 raise ChromeProxyMetricException, s | |
468 | |
469 if not pm['ready']: | |
470 err('Proxied page did not load video: %s' % page.url) | |
471 if not dm['ready']: | |
472 err('Direct page did not load video: %s' % page.url) | |
473 | |
474 # Compare metrics that should match for PROXIED and DIRECT. | |
475 for x in ('video_height', 'video_width', 'video_duration', | |
476 'decoded_frames'): | |
477 if x not in pm: | |
478 err('Proxied page has no %s: %s' % (x, page.url)) | |
479 if x not in dm: | |
480 err('Direct page has no %s: %s' % (x, page.url)) | |
481 if pm[x] != dm[x]: | |
482 err('Mismatch for %s (proxied=%s direct=%s): %s' % | |
483 (x, str(pm[x]), str(dm[x]), page.url)) | |
484 | |
485 # Proxied XOCL should match direct CL. | |
486 pxocl = pm['x_original_content_length_header'] | |
487 dcl = dm['content_length_header'] | |
488 if pxocl != dcl: | |
489 err('Mismatch for content length (proxied=%s direct=%s): %s' % | |
490 (str(pxocl), str(dcl), page.url)) | |
OLD | NEW |