Roll src/third_party/WebKit 4619053:6b63e20 (svn 201059:201060)
[chromium-blink-merge.git] / tools / chrome_proxy / common / chrome_proxy_metrics_unittest.py
blob35c9e1bfb91045554350488f119fac7089cd64f0
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
3 # found in the LICENSE file.
5 import base64
6 import unittest
8 from common import chrome_proxy_metrics as metrics
9 from common import network_metrics_unittest as network_unittest
12 class ChromeProxyMetricTest(unittest.TestCase):
14 def testChromeProxyResponse(self):
15 # An https non-proxy response.
16 resp = metrics.ChromeProxyResponse(
17 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
18 url='https://test.url',
19 response_headers={
20 'Content-Type': 'text/html',
21 'Content-Length': str(len(network_unittest.HTML_BODY)),
22 'Via': 'some other via',
24 body=network_unittest.HTML_BODY))
25 self.assertFalse(resp.ShouldHaveChromeProxyViaHeader())
26 self.assertFalse(resp.HasChromeProxyViaHeader())
27 self.assertTrue(resp.IsValidByViaHeader())
29 # A proxied JPEG image response
30 resp = metrics.ChromeProxyResponse(
31 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
32 url='http://test.image',
33 response_headers={
34 'Content-Type': 'image/jpeg',
35 'Content-Encoding': 'gzip',
36 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER,
37 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL),
39 body=base64.b64encode(network_unittest.IMAGE_BODY),
40 base64_encoded_body=True))
41 self.assertTrue(resp.ShouldHaveChromeProxyViaHeader())
42 self.assertTrue(resp.HasChromeProxyViaHeader())
43 self.assertTrue(resp.IsValidByViaHeader())