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

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

Issue 792303006: Remove the net-internals dependency from chrome proxy telemetry tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 11 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
« no previous file with comments | « tools/chrome_proxy/integration_tests/network_metrics.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 unittest 6 import unittest
7 7
8 from integration_tests import network_metrics 8 from integration_tests import network_metrics
9 from metrics import test_page_test_results 9 from metrics import test_page_test_results
10 from telemetry.timeline import event 10 from telemetry.timeline import event
11 11
12 12
13 HTML_BODY = """<!DOCTYPE HTML> 13 HTML_BODY = """<!DOCTYPE HTML>
14 <html> 14 <html>
15 <head> </head> 15 <head> </head>
16 <body> 16 <body>
17 <div id="test"> TEST HTML</div> 17 <div id="test"> TEST HTML</div>
18 </body> 18 </body>
19 </html>""" 19 </html>"""
20 IMAGE_BODY = """fake image data""" 20 IMAGE_BODY = """fake image data"""
21 GZIPPED_HTML_LEN = network_metrics.HTTPResponse.GetGizppedBodyLength(HTML_BODY) 21 GZIPPED_HTML_LEN = network_metrics.HTTPResponse.GetGizppedBodyLength(HTML_BODY)
22 # Make up original content length for the image. 22 # Make up original content length for the image.
23 IMAGE_OCL = 3 * len(IMAGE_BODY) 23 IMAGE_OCL = 3 * len(IMAGE_BODY)
24 24
25 25
26 class NetworkMetricTest(unittest.TestCase): 26 class NetworkMetricTest(unittest.TestCase):
27 @staticmethod 27 @staticmethod
28 def MakeNetworkTimelineEvent( 28 def MakeNetworkTimelineEvent(
29 url, response_headers, body=None, base64_encoded_body=False, 29 url, response_headers, body=None, base64_encoded_body=False,
30 served_from_cache=False, request_headers=None, status=200): 30 served_from_cache=False, request_headers=None, status=200,
31 remote_port=None):
31 if not request_headers: 32 if not request_headers:
32 request_headers = {} 33 request_headers = {}
33 e = event.TimelineEvent('network', 'HTTPResponse', 0, 0) 34 e = event.TimelineEvent('network', 'HTTPResponse', 0, 0)
34 e.args = {} 35 e.args = {}
35 e.args['requestId'] = 0 36 e.args['requestId'] = 0
36 e.args['response'] = { 37 e.args['response'] = {
37 'status': status, 38 'status': status,
38 'url': url, 39 'url': url,
39 'headers': response_headers, 40 'headers': response_headers,
40 'requestHeaders': request_headers, 41 'requestHeaders': request_headers,
42 'remotePort': remote_port,
41 } 43 }
42 e.args['body'] = body 44 e.args['body'] = body
43 e.args['base64_encoded_body'] = base64_encoded_body 45 e.args['base64_encoded_body'] = base64_encoded_body
44 e.args['served_from_cache'] = served_from_cache 46 e.args['served_from_cache'] = served_from_cache
45 return e 47 return e
46 48
47 def testHTTPResponse(self): 49 def testHTTPResponse(self):
48 url = 'http://test.url' 50 url = 'http://test.url'
49 self.assertLess(GZIPPED_HTML_LEN, len(HTML_BODY)) 51 self.assertLess(GZIPPED_HTML_LEN, len(HTML_BODY))
50 52
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 cl = len(HTML_BODY) + GZIPPED_HTML_LEN + len(IMAGE_BODY) 167 cl = len(HTML_BODY) + GZIPPED_HTML_LEN + len(IMAGE_BODY)
166 results.AssertHasPageSpecificScalarValue('content_length', 'bytes', cl) 168 results.AssertHasPageSpecificScalarValue('content_length', 'bytes', cl)
167 169
168 ocl = len(HTML_BODY) + len(HTML_BODY) + IMAGE_OCL 170 ocl = len(HTML_BODY) + len(HTML_BODY) + IMAGE_OCL
169 results.AssertHasPageSpecificScalarValue( 171 results.AssertHasPageSpecificScalarValue(
170 'original_content_length', 'bytes', ocl) 172 'original_content_length', 'bytes', ocl)
171 173
172 saving_percent = float(ocl - cl) * 100/ ocl 174 saving_percent = float(ocl - cl) * 100/ ocl
173 results.AssertHasPageSpecificScalarValue( 175 results.AssertHasPageSpecificScalarValue(
174 'data_saving', 'percent', saving_percent) 176 'data_saving', 'percent', saving_percent)
OLDNEW
« no previous file with comments | « tools/chrome_proxy/integration_tests/network_metrics.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698