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

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

Issue 2672803002: [Telemetry refactor] Migrate clients to new JavaScript API (batch 3) (Closed)
Patch Set: add comment on tools/android Created 3 years, 10 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 json 5 import json
6 import logging 6 import logging
7 import os 7 import os
8 import time 8 import time
9 9
10 from common import chrome_proxy_metrics 10 from common import chrome_proxy_metrics
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 raise ChromeProxyMetricException, ( 75 raise ChromeProxyMetricException, (
76 'Expected at least one response through the proxy, but zero such ' 76 'Expected at least one response through the proxy, but zero such '
77 'responses were received.') 77 'responses were received.')
78 results.AddValue(scalar.ScalarValue( 78 results.AddValue(scalar.ScalarValue(
79 results.current_page, 'checked_via_header', 'count', via_count)) 79 results.current_page, 'checked_via_header', 'count', via_count))
80 80
81 def AddResultsForLatency(self, tab, results): 81 def AddResultsForLatency(self, tab, results):
82 # TODO(bustamante): This is a hack to workaround crbug.com/467174, 82 # TODO(bustamante): This is a hack to workaround crbug.com/467174,
83 # once fixed just pull down window.performance.timing object and 83 # once fixed just pull down window.performance.timing object and
84 # reference that everywhere. 84 # reference that everywhere.
85 load_event_start = tab.EvaluateJavaScript( 85 load_event_start = tab.EvaluateJavaScript2(
86 'window.performance.timing.loadEventStart') 86 'window.performance.timing.loadEventStart')
87 navigation_start = tab.EvaluateJavaScript( 87 navigation_start = tab.EvaluateJavaScript2(
88 'window.performance.timing.navigationStart') 88 'window.performance.timing.navigationStart')
89 dom_content_loaded_event_start = tab.EvaluateJavaScript( 89 dom_content_loaded_event_start = tab.EvaluateJavaScript2(
90 'window.performance.timing.domContentLoadedEventStart') 90 'window.performance.timing.domContentLoadedEventStart')
91 fetch_start = tab.EvaluateJavaScript( 91 fetch_start = tab.EvaluateJavaScript2(
92 'window.performance.timing.fetchStart') 92 'window.performance.timing.fetchStart')
93 request_start = tab.EvaluateJavaScript( 93 request_start = tab.EvaluateJavaScript2(
94 'window.performance.timing.requestStart') 94 'window.performance.timing.requestStart')
95 domain_lookup_end = tab.EvaluateJavaScript( 95 domain_lookup_end = tab.EvaluateJavaScript2(
96 'window.performance.timing.domainLookupEnd') 96 'window.performance.timing.domainLookupEnd')
97 domain_lookup_start = tab.EvaluateJavaScript( 97 domain_lookup_start = tab.EvaluateJavaScript2(
98 'window.performance.timing.domainLookupStart') 98 'window.performance.timing.domainLookupStart')
99 connect_end = tab.EvaluateJavaScript( 99 connect_end = tab.EvaluateJavaScript2(
100 'window.performance.timing.connectEnd') 100 'window.performance.timing.connectEnd')
101 connect_start = tab.EvaluateJavaScript( 101 connect_start = tab.EvaluateJavaScript2(
102 'window.performance.timing.connectStart') 102 'window.performance.timing.connectStart')
103 response_end = tab.EvaluateJavaScript( 103 response_end = tab.EvaluateJavaScript2(
104 'window.performance.timing.responseEnd') 104 'window.performance.timing.responseEnd')
105 response_start = tab.EvaluateJavaScript( 105 response_start = tab.EvaluateJavaScript2(
106 'window.performance.timing.responseStart') 106 'window.performance.timing.responseStart')
107 107
108 # NavigationStart relative markers in milliseconds. 108 # NavigationStart relative markers in milliseconds.
109 load_start = (float(load_event_start) - navigation_start) 109 load_start = (float(load_event_start) - navigation_start)
110 results.AddValue(scalar.ScalarValue( 110 results.AddValue(scalar.ScalarValue(
111 results.current_page, 'load_start', 'ms', load_start)) 111 results.current_page, 'load_start', 'ms', load_start))
112 112
113 dom_content_loaded_start = ( 113 dom_content_loaded_start = (
114 float(dom_content_loaded_event_start) - navigation_start) 114 float(dom_content_loaded_event_start) - navigation_start)
115 results.AddValue(scalar.ScalarValue( 115 results.AddValue(scalar.ScalarValue(
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 raise ChromeProxyMetricException, ( 424 raise ChromeProxyMetricException, (
425 'Expected at least one https response was expected, but zero such ' 425 'Expected at least one https response was expected, but zero such '
426 'responses were received.') 426 'responses were received.')
427 427
428 results.AddValue(scalar.ScalarValue( 428 results.AddValue(scalar.ScalarValue(
429 results.current_page, 'bypass', 'count', bypass_count)) 429 results.current_page, 'bypass', 'count', bypass_count))
430 430
431 def AddResultsForHTML5Test(self, tab, results): 431 def AddResultsForHTML5Test(self, tab, results):
432 # Wait for the number of "points" of HTML5 compatibility to appear to verify 432 # Wait for the number of "points" of HTML5 compatibility to appear to verify
433 # the HTML5 elements have loaded successfully. 433 # the HTML5 elements have loaded successfully.
434 tab.WaitForJavaScriptExpression( 434 tab.WaitForJavaScriptCondition2(
435 'document.getElementsByClassName("pointsPanel")', 15) 435 'document.getElementsByClassName("pointsPanel")', timeout=15)
436 436
437 def AddResultsForYouTube(self, tab, results): 437 def AddResultsForYouTube(self, tab, results):
438 # Wait for the video to begin playing. 438 # Wait for the video to begin playing.
439 tab.WaitForJavaScriptExpression( 439 tab.WaitForJavaScriptCondition2(
440 'window.playerState == YT.PlayerState.PLAYING', 30) 440 'window.playerState == YT.PlayerState.PLAYING', timeout=30)
441 441
442 def AddResultsForBypass(self, tab, results, url_pattern=""): 442 def AddResultsForBypass(self, tab, results, url_pattern=""):
443 bypass_count = 0 443 bypass_count = 0
444 skipped_count = 0 444 skipped_count = 0
445 445
446 for resp in self.IterResponses(tab): 446 for resp in self.IterResponses(tab):
447 # Only check the url's that contain the specified pattern. 447 # Only check the url's that contain the specified pattern.
448 if url_pattern and url_pattern not in resp.response.url: 448 if url_pattern and url_pattern not in resp.response.url:
449 skipped_count += 1 449 skipped_count += 1
450 continue 450 continue
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 664
665 # Wait until 30 seconds before the bypass should expire, and fetch a page. 665 # Wait until 30 seconds before the bypass should expire, and fetch a page.
666 # It should not have the via header because the proxy should still be 666 # It should not have the via header because the proxy should still be
667 # bypassed. 667 # bypassed.
668 time.sleep(bypass_seconds_min - 30) 668 time.sleep(bypass_seconds_min - 30)
669 669
670 tab.ClearCache(force=True) 670 tab.ClearCache(force=True)
671 before_metrics = ChromeProxyMetric() 671 before_metrics = ChromeProxyMetric()
672 before_metrics.Start(results.current_page, tab) 672 before_metrics.Start(results.current_page, tab)
673 tab.Navigate('http://chromeproxy-test.appspot.com/default') 673 tab.Navigate('http://chromeproxy-test.appspot.com/default')
674 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 10) 674 tab.WaitForJavaScriptCondition2(
675 'performance.timing.loadEventStart', timeout=10)
675 before_metrics.Stop(results.current_page, tab) 676 before_metrics.Stop(results.current_page, tab)
676 677
677 for resp in before_metrics.IterResponses(tab): 678 for resp in before_metrics.IterResponses(tab):
678 if resp.HasChromeProxyViaHeader(): 679 if resp.HasChromeProxyViaHeader():
679 r = resp.response 680 r = resp.response
680 raise ChromeProxyMetricException, ( 681 raise ChromeProxyMetricException, (
681 'Response for %s should not have via header; proxy should still ' 682 'Response for %s should not have via header; proxy should still '
682 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % ( 683 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % (
683 r.url, r.status, r.status_text, r.headers)) 684 r.url, r.status, r.status_text, r.headers))
684 else: 685 else:
685 bypass_count += 1 686 bypass_count += 1
686 if bypass_count == 0: 687 if bypass_count == 0:
687 raise ChromeProxyMetricException, ( 688 raise ChromeProxyMetricException, (
688 'Expected at least one response to be bypassed before the bypass ' 689 'Expected at least one response to be bypassed before the bypass '
689 'expired, but zero such responses were received.') 690 'expired, but zero such responses were received.')
690 691
691 # Wait until 30 seconds after the bypass should expire, and fetch a page. It 692 # Wait until 30 seconds after the bypass should expire, and fetch a page. It
692 # should have the via header since the proxy should no longer be bypassed. 693 # should have the via header since the proxy should no longer be bypassed.
693 time.sleep((bypass_seconds_max + 30) - (bypass_seconds_min - 30)) 694 time.sleep((bypass_seconds_max + 30) - (bypass_seconds_min - 30))
694 695
695 tab.ClearCache(force=True) 696 tab.ClearCache(force=True)
696 after_metrics = ChromeProxyMetric() 697 after_metrics = ChromeProxyMetric()
697 after_metrics.Start(results.current_page, tab) 698 after_metrics.Start(results.current_page, tab)
698 tab.Navigate('http://chromeproxy-test.appspot.com/default') 699 tab.Navigate('http://chromeproxy-test.appspot.com/default')
699 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 10) 700 tab.WaitForJavaScriptCondition2(
701 'performance.timing.loadEventStart', timeout=10)
700 after_metrics.Stop(results.current_page, tab) 702 after_metrics.Stop(results.current_page, tab)
701 703
702 for resp in after_metrics.IterResponses(tab): 704 for resp in after_metrics.IterResponses(tab):
703 if not resp.HasChromeProxyViaHeader(): 705 if not resp.HasChromeProxyViaHeader():
704 r = resp.response 706 r = resp.response
705 raise ChromeProxyMetricException, ( 707 raise ChromeProxyMetricException, (
706 'Response for %s should have via header; proxy should no longer ' 708 'Response for %s should have via header; proxy should no longer '
707 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % ( 709 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % (
708 r.url, r.status, r.status_text, r.headers)) 710 r.url, r.status, r.status_text, r.headers))
709 else: 711 else:
(...skipping 29 matching lines...) Expand all
739 'Reponse: status=(%d, %s)\nHeaders:\n %s' % ( 741 'Reponse: status=(%d, %s)\nHeaders:\n %s' % (
740 r.url, r.status, r.status_text, r.headers)) 742 r.url, r.status, r.status_text, r.headers))
741 else: 743 else:
742 bypass_count += 1 744 bypass_count += 1
743 745
744 # Navigate to a test page and verify it's being bypassed. 746 # Navigate to a test page and verify it's being bypassed.
745 tab.ClearCache(force=True) 747 tab.ClearCache(force=True)
746 before_metrics = ChromeProxyMetric() 748 before_metrics = ChromeProxyMetric()
747 before_metrics.Start(results.current_page, tab) 749 before_metrics.Start(results.current_page, tab)
748 tab.Navigate('http://chromeproxy-test.appspot.com/default') 750 tab.Navigate('http://chromeproxy-test.appspot.com/default')
749 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 10) 751 tab.WaitForJavaScriptCondition2(
752 'performance.timing.loadEventStart', timeout=10)
750 before_metrics.Stop(results.current_page, tab) 753 before_metrics.Stop(results.current_page, tab)
751 754
752 for resp in before_metrics.IterResponses(tab): 755 for resp in before_metrics.IterResponses(tab):
753 if resp.HasChromeProxyViaHeader(): 756 if resp.HasChromeProxyViaHeader():
754 r = resp.response 757 r = resp.response
755 raise ChromeProxyMetricException, ( 758 raise ChromeProxyMetricException, (
756 'Response for %s should not have via header; proxy should still ' 759 'Response for %s should not have via header; proxy should still '
757 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % ( 760 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % (
758 r.url, r.status, r.status_text, r.headers)) 761 r.url, r.status, r.status_text, r.headers))
759 else: 762 else:
760 bypass_count += 1 763 bypass_count += 1
761 if bypass_count == 0: 764 if bypass_count == 0:
762 raise ChromeProxyMetricException, ( 765 raise ChromeProxyMetricException, (
763 'Expected at least one response to be bypassed before the bypass ' 766 'Expected at least one response to be bypassed before the bypass '
764 'expired, but zero such responses were received.') 767 'expired, but zero such responses were received.')
765 768
766 # Wait for the bypass to expire, with the overhead of the previous steps 769 # Wait for the bypass to expire, with the overhead of the previous steps
767 # the bypass duration will have been exceeded after this delay. 770 # the bypass duration will have been exceeded after this delay.
768 time.sleep(bypass_seconds) 771 time.sleep(bypass_seconds)
769 772
770 # Navigate to the test pass again and verify data saver is no longer 773 # Navigate to the test pass again and verify data saver is no longer
771 # bypassed. 774 # bypassed.
772 tab.ClearCache(force=True) 775 tab.ClearCache(force=True)
773 after_metrics = ChromeProxyMetric() 776 after_metrics = ChromeProxyMetric()
774 after_metrics.Start(results.current_page, tab) 777 after_metrics.Start(results.current_page, tab)
775 tab.Navigate('http://chromeproxy-test.appspot.com/default') 778 tab.Navigate('http://chromeproxy-test.appspot.com/default')
776 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 10) 779 tab.WaitForJavaScriptCondition2(
780 'performance.timing.loadEventStart', timeout=10)
777 after_metrics.Stop(results.current_page, tab) 781 after_metrics.Stop(results.current_page, tab)
778 782
779 for resp in after_metrics.IterResponses(tab): 783 for resp in after_metrics.IterResponses(tab):
780 if not resp.HasChromeProxyViaHeader(): 784 if not resp.HasChromeProxyViaHeader():
781 r = resp.response 785 r = resp.response
782 raise ChromeProxyMetricException, ( 786 raise ChromeProxyMetricException, (
783 'Response for %s should have via header; proxy should no longer ' 787 'Response for %s should have via header; proxy should no longer '
784 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % ( 788 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % (
785 r.url, r.status, r.status_text, r.headers)) 789 r.url, r.status, r.status_text, r.headers))
786 else: 790 else:
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 973
970 Wraps the video metrics produced by videowrapper.js, such as the video 974 Wraps the video metrics produced by videowrapper.js, such as the video
971 duration and size in pixels. Also checks a few basic HTTP response headers 975 duration and size in pixels. Also checks a few basic HTTP response headers
972 such as Content-Type and Content-Length in the video responses. 976 such as Content-Type and Content-Length in the video responses.
973 """ 977 """
974 978
975 def __init__(self, tab): 979 def __init__(self, tab):
976 super(ChromeProxyVideoMetric, self).__init__() 980 super(ChromeProxyVideoMetric, self).__init__()
977 with open(os.path.join(os.path.dirname(__file__), 'videowrapper.js')) as f: 981 with open(os.path.join(os.path.dirname(__file__), 'videowrapper.js')) as f:
978 js = f.read() 982 js = f.read()
979 tab.ExecuteJavaScript(js) 983 tab.ExecuteJavaScript2(js)
980 984
981 def Start(self, page, tab): 985 def Start(self, page, tab):
982 tab.ExecuteJavaScript('window.__chromeProxyCreateVideoWrappers()') 986 tab.ExecuteJavaScript2('window.__chromeProxyCreateVideoWrappers()')
983 self.videoMetrics = None 987 self.videoMetrics = None
984 super(ChromeProxyVideoMetric, self).Start(page, tab) 988 super(ChromeProxyVideoMetric, self).Start(page, tab)
985 989
986 def Stop(self, page, tab): 990 def Stop(self, page, tab):
987 tab.WaitForJavaScriptExpression('window.__chromeProxyVideoLoaded', 30) 991 tab.WaitForJavaScriptCondition2(
988 m = tab.EvaluateJavaScript('window.__chromeProxyVideoMetrics') 992 'window.__chromeProxyVideoLoaded', timeout=30)
993 m = tab.EvaluateJavaScript2('window.__chromeProxyVideoMetrics')
989 994
990 # Now wait for the video to stop playing. 995 # Now wait for the video to stop playing.
991 # Give it 2x the total duration to account for buffering. 996 # Give it 2x the total duration to account for buffering.
992 waitTime = 2 * m['video_duration'] 997 waitTime = 2 * m['video_duration']
993 tab.WaitForJavaScriptExpression('window.__chromeProxyVideoEnded', waitTime) 998 tab.WaitForJavaScriptCondition2(
999 'window.__chromeProxyVideoEnded', timeout=waitTime)
994 1000
995 # Load the final metrics. 1001 # Load the final metrics.
996 m = tab.EvaluateJavaScript('window.__chromeProxyVideoMetrics') 1002 m = tab.EvaluateJavaScript2('window.__chromeProxyVideoMetrics')
997 self.videoMetrics = m 1003 self.videoMetrics = m
998 # Cast this to an integer as it is often approximate (for an unknown reason) 1004 # Cast this to an integer as it is often approximate (for an unknown reason)
999 m['video_duration'] = int(m['video_duration']) 1005 m['video_duration'] = int(m['video_duration'])
1000 super(ChromeProxyVideoMetric, self).Stop(page, tab) 1006 super(ChromeProxyVideoMetric, self).Stop(page, tab)
1001 1007
1002 def ResponseFromEvent(self, event): 1008 def ResponseFromEvent(self, event):
1003 return chrome_proxy_metrics.ChromeProxyResponse(event) 1009 return chrome_proxy_metrics.ChromeProxyResponse(event)
1004 1010
1005 def AddResults(self, tab, results): 1011 def AddResults(self, tab, results):
1006 raise NotImplementedError 1012 raise NotImplementedError
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 results.AddValue(scalar.ScalarValue(results.current_page, k, "", v)) 1066 results.AddValue(scalar.ScalarValue(results.current_page, k, "", v))
1061 1067
1062 1068
1063 class ChromeProxyInstrumentedVideoMetric(Metric): 1069 class ChromeProxyInstrumentedVideoMetric(Metric):
1064 """Metric for pages instrumented to evaluate video transcoding.""" 1070 """Metric for pages instrumented to evaluate video transcoding."""
1065 1071
1066 def __init__(self): 1072 def __init__(self):
1067 super(ChromeProxyInstrumentedVideoMetric, self).__init__() 1073 super(ChromeProxyInstrumentedVideoMetric, self).__init__()
1068 1074
1069 def Stop(self, page, tab): 1075 def Stop(self, page, tab):
1070 waitTime = tab.EvaluateJavaScript('test.waitTime') 1076 waitTime = tab.EvaluateJavaScript2('test.waitTime')
1071 tab.WaitForJavaScriptExpression('test.metrics.complete', waitTime) 1077 tab.WaitForJavaScriptCondition2('test.metrics.complete', timeout=waitTime)
1072 super(ChromeProxyInstrumentedVideoMetric, self).Stop(page, tab) 1078 super(ChromeProxyInstrumentedVideoMetric, self).Stop(page, tab)
1073 1079
1074 def AddResults(self, tab, results): 1080 def AddResults(self, tab, results):
1075 metrics = tab.EvaluateJavaScript('test.metrics') 1081 metrics = tab.EvaluateJavaScript2('test.metrics')
1076 for (k, v) in metrics.iteritems(): 1082 for (k, v) in metrics.iteritems():
1077 results.AddValue(scalar.ScalarValue(results.current_page, k, '', v)) 1083 results.AddValue(scalar.ScalarValue(results.current_page, k, '', v))
1078 try: 1084 try:
1079 complete = metrics['complete'] 1085 complete = metrics['complete']
1080 failed = metrics['failed'] 1086 failed = metrics['failed']
1081 if not complete: 1087 if not complete:
1082 raise ChromeProxyMetricException, 'Test not complete' 1088 raise ChromeProxyMetricException, 'Test not complete'
1083 if failed: 1089 if failed:
1084 raise ChromeProxyMetricException, 'failed' 1090 raise ChromeProxyMetricException, 'failed'
1085 except KeyError: 1091 except KeyError:
1086 raise ChromeProxyMetricException, 'No metrics found' 1092 raise ChromeProxyMetricException, 'No metrics found'
1087 1093
1088 # Returns whether |url| is a block-once test URL. Data Reduction Proxy has been 1094 # Returns whether |url| is a block-once test URL. Data Reduction Proxy has been
1089 # configured to always return block-once for these URLs. 1095 # configured to always return block-once for these URLs.
1090 def IsTestUrlForBlockOnce(url): 1096 def IsTestUrlForBlockOnce(url):
1091 return (url == 'http://check.googlezip.net/blocksingle/' or 1097 return (url == 'http://check.googlezip.net/blocksingle/' or
1092 url == ('http://chromeproxy-test.appspot.com/default?respBody=T0s=' 1098 url == ('http://chromeproxy-test.appspot.com/default?respBody=T0s='
1093 '&respHeader=eyJBY2Nlc3MtQ29udHJvbC1BbGxvdy1PcmlnaW4iOlsiKiJ' 1099 '&respHeader=eyJBY2Nlc3MtQ29udHJvbC1BbGxvdy1PcmlnaW4iOlsiKiJ'
1094 'dfQ==&respStatus=200&flywheelAction=block-once')) 1100 'dfQ==&respStatus=200&flywheelAction=block-once'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698