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 DirectFetchLatency(ChromeProxyLatency): | |
sclittle
2015/04/10 23:01:49
Maybe name this ChromeProxyLatencyDirect to be con
Tom Bergan
2015/04/10 23:41:05
Done.
| |
37 """Direct fetch latency measurement.""" | |
38 def __init__(self, *args, **kwargs): | |
39 super(DirectFetchLatency, 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 DirectFetchDataSaving(ChromeProxyDataSaving): | |
66 """Direct fetch data saving measurement.""" | |
67 def __init__(self, *args, **kwargs): | |
68 super(DirectFetchDataSaving, 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 class ChromeProxyVideoValidation(page_test.PageTest): | |
413 """Video correctness measurements.""" | |
sclittle
2015/04/10 23:01:49
Please add more detailed description.
Tom Bergan
2015/04/10 23:41:05
Done.
| |
414 | |
415 def __init__(self): | |
416 super(ChromeProxyVideoValidation, self).__init__( | |
417 needs_browser_restart_after_each_page=True, | |
418 clear_cache_before_each_run=True) | |
419 self._allMetrics = {} | |
sclittle
2015/04/10 23:01:49
Please add a comment describing what _allMetrics i
Tom Bergan
2015/04/10 23:41:05
Done.
| |
420 | |
421 def CustomizeBrowserOptionsForSinglePage(self, page, options): | |
422 if page.use_chrome_proxy: | |
423 options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth') | |
424 | |
425 def DidNavigateToPage(self, page, tab): | |
426 self._currMetrics = metrics.ChromeProxyVideoMetric(tab) | |
427 self._currMetrics.Start(page, tab) | |
428 | |
429 def ValidateAndMeasurePage(self, page, tab, results): | |
430 assert self._currMetrics | |
431 self._currMetrics.Stop(page, tab) | |
432 if page.url not in self._allMetrics: | |
433 self._allMetrics[page.url] = {} | |
434 # Verify this page. | |
sclittle
2015/04/10 23:01:49
nit: the code in this method looks dense, could yo
Tom Bergan
2015/04/10 23:41:05
Done.
| |
435 if page.use_chrome_proxy: | |
436 self._currMetrics.AddResultsForProxied(tab, results) | |
437 self._allMetrics[page.url]['proxied'] = self._currMetrics.videoMetrics | |
438 else: | |
439 self._currMetrics.AddResultsForDirect(tab, results) | |
440 self._allMetrics[page.url]['direct'] = self._currMetrics.videoMetrics | |
441 self._currMetrics = None | |
442 # Compare proxied and direct results for this url, if they exist. | |
443 m = self._allMetrics[page.url] | |
444 if 'proxied' in m and 'direct' in m: | |
445 self._CompareProxiedAndDirectMetrics(page.url, m['proxied'], m['direct']) | |
446 | |
447 def _CompareProxiedAndDirectMetrics(self, url, pm, dm): | |
sclittle
2015/04/10 23:01:49
What is this method for? Please add a comment
Tom Bergan
2015/04/10 23:41:05
Done.
| |
448 def err(s): | |
449 raise ChromeProxyMetricException, s | |
450 | |
451 if not pm['ready']: | |
452 err('Proxied page did not load video: %s' % page.url) | |
453 if not dm['ready']: | |
454 err('Direct page did not load video: %s' % page.url) | |
455 | |
456 for x in ('video_height', 'video_width', 'video_duration', | |
sclittle
2015/04/10 23:01:49
Add a comment describing the purpose of this for l
Tom Bergan
2015/04/10 23:41:05
Done.
| |
457 'decoded_frames'): | |
458 if x not in pm: | |
459 err('Proxied page has no %s: %s' % (x, page.url)) | |
460 if x not in dm: | |
461 err('Direct page has no %s: %s' % (x, page.url)) | |
462 if pm[x] != dm[x]: | |
463 err('Mismatch for %s (proxied=%s direct=%s): %s' % | |
464 (x, str(pm[x]), str(dm[x]), page.url)) | |
465 | |
466 # Proxied XOCL should match direct CL. | |
467 pxocl = pm['x_original_content_length_header'] | |
468 dcl = dm['content_length_header'] | |
469 if pxocl != dcl: | |
470 err('Mismatch for content length (proxied=%s direct=%s): %s' % | |
471 (str(pxocl), str(dcl), page.url)) | |
OLD | NEW |