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

Side by Side Diff: tools/chrome_proxy/live_tests/chrome_proxy_metrics_unittest.py

Issue 1098253004: Move top_20 tests to a separate suite (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests 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
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
sclittle 2015/05/01 23:05:39 Could you update the run_tests script to run all t
bustamante 2015/05/01 23:54:11 It already does, I verified the tests are being ru
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import base64
6 import unittest
7
8 from common import chrome_proxy_metrics as com_metrics
9 from common import network_metrics_unittest as network_unittest
10 from live_tests import chrome_proxy_metrics as metrics
11 from telemetry.unittest_util import test_page_test_results
12
13 TEST_EXTRA_VIA_HEADER = '1.1 EXTRA_VIA_HEADER'
14
15 # Timeline events used in tests.
16 # An HTML not via proxy.
17 EVENT_HTML_DIRECT = network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
18 url='http://test.html1',
19 response_headers={
20 'Content-Type': 'text/html',
21 'Content-Length': str(len(network_unittest.HTML_BODY)),
22 },
23 body=network_unittest.HTML_BODY)
24
25 # An HTML via proxy.
26 EVENT_HTML_PROXY_VIA = (
27 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
28 url='http://test.html2',
29 response_headers={
30 'Content-Type': 'text/html',
31 'Content-Encoding': 'gzip',
32 'X-Original-Content-Length': str(len(network_unittest.HTML_BODY)),
33 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER,
34 },
35 body=network_unittest.HTML_BODY,
36 remote_port=443))
37
38 # An image via proxy with Via header.
39 EVENT_IMAGE_PROXY_VIA = (
40 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
41 url='http://test.image',
42 response_headers={
43 'Content-Type': 'image/jpeg',
44 'Content-Encoding': 'gzip',
45 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL),
46 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER,
47 },
48 body=base64.b64encode(network_unittest.IMAGE_BODY),
49 base64_encoded_body=True,
50 remote_port=443))
51
52 # An image via proxy with Via header and it is cached.
53 EVENT_IMAGE_PROXY_CACHED = (
54 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
55 url='http://test.image',
56 response_headers={
57 'Content-Type': 'image/jpeg',
58 'Content-Encoding': 'gzip',
59 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL),
60 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER,
61 },
62 body=base64.b64encode(network_unittest.IMAGE_BODY),
63 base64_encoded_body=True,
64 served_from_cache=True))
65
66
67 # An image fetched directly.
68 EVENT_IMAGE_DIRECT = (
69 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
70 url='http://test.image',
71 response_headers={
72 'Content-Type': 'image/jpeg',
73 'Content-Encoding': 'gzip',
74 },
75 body=base64.b64encode(network_unittest.IMAGE_BODY),
76 base64_encoded_body=True))
77
78
79 class ChromeProxyMetricTest(unittest.TestCase):
80
81 def testChromeProxyMetricForDataSaving(self):
82 metric = metrics.ChromeProxyMetric()
83 events = [
84 EVENT_HTML_DIRECT,
85 EVENT_HTML_PROXY_VIA,
86 EVENT_IMAGE_PROXY_CACHED,
87 EVENT_IMAGE_DIRECT]
88 metric.SetEvents(events)
89
90 self.assertTrue(len(events), len(list(metric.IterResponses(None))))
91 results = test_page_test_results.TestPageTestResults(self)
92
93 metric.AddResultsForDataSaving(None, results)
94 results.AssertHasPageSpecificScalarValue('resources_via_proxy', 'count', 2)
95 results.AssertHasPageSpecificScalarValue('resources_from_cache', 'count', 1)
96 results.AssertHasPageSpecificScalarValue('resources_direct', 'count', 2)
97
98 # Passing in zero responses should cause a failure.
99 metric.SetEvents([])
100 no_responses_exception = False
101 try:
102 metric.AddResultsForDataSaving(None, results)
103 except com_metrics.ChromeProxyMetricException:
104 no_responses_exception = True
105 self.assertTrue(no_responses_exception)
106
107
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698