summaryrefslogtreecommitdiff
path: root/chromium/tools/chrome_proxy/webdriver/quic.py
blob: bd57e1177a65461b52ed011b11e89c33069b102f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import time

import common
from common import TestDriver
from common import IntegrationTest


class Quic(IntegrationTest):

  # Ensure Chrome uses DataSaver when QUIC is enabled. This test should pass
  # even if QUIC is disabled on the server side. In that case, Chrome should
  # fallback to using the non-QUIC proxies.
  def testCheckPageWithQuicProxy(self):
    with TestDriver() as t:
      t.AddChromeArg('--enable-spdy-proxy-auth')

      # Enable QUIC (including for non-core HTTPS proxies).
      t.AddChromeArg('--enable-quic')
      t.AddChromeArg('--force-fieldtrials=DataReductionProxyUseQuic/Enabled')
      t.AddChromeArg('--force-fieldtrial-params='
        'DataReductionProxyUseQuic.Enabled:enable_quic_non_core_proxies/true')
      # Enable usage of QUIC for non-core proxies via switch for older versions
      # of Chrome (M-59 and prior).
      t.AddChromeArg('--data-reduction-proxy-enable-quic-on-non-core-proxies')

      t.LoadURL('http://check.googlezip.net/test.html')
      responses = t.GetHTTPResponses()
      self.assertEqual(2, len(responses))
      for response in responses:
        self.assertHasChromeProxyViaHeader(response)

  # Ensure Chrome uses QUIC DataSaver proxy when QUIC is enabled. This test
  # may fail if QUIC is disabled on the server side.
  def testCheckPageWithQuicProxyTransaction(self):
    with TestDriver() as t:
      t.AddChromeArg('--enable-spdy-proxy-auth')

      # Enable QUIC (including for non-core HTTPS proxies).
      t.AddChromeArg('--enable-quic')
      t.AddChromeArg('--force-fieldtrials=DataReductionProxyUseQuic/Enabled')
      t.AddChromeArg('--force-fieldtrial-params='
        'DataReductionProxyUseQuic.Enabled:enable_quic_non_core_proxies/true')
      # Enable usage of QUIC for non-core proxies via switch for older versions
      # of Chrome (M-59 and prior).
      t.AddChromeArg('--data-reduction-proxy-enable-quic-on-non-core-proxies')

      t.LoadURL('http://check.googlezip.net/test.html')
      responses = t.GetHTTPResponses()
      self.assertEqual(2, len(responses))
      for response in responses:
        self.assertHasChromeProxyViaHeader(response)

      # Verify that histogram DataReductionProxy.Quic.ProxyStatus has at least 1
      # sample. This sample must be in bucket 0 (QUIC_PROXY_STATUS_AVAILABLE).
      proxy_status = t.GetHistogram('DataReductionProxy.Quic.ProxyStatus')
      self.assertLessEqual(1, proxy_status['count'])
      self.assertEqual(0, proxy_status['sum'])

      # Navigate to one more page to ensure that established QUIC connection
      # is used for the next request. Give 3 seconds extra headroom for the QUIC
      # connection to be established.
      time.sleep(3)
      t.LoadURL('http://check.googlezip.net/test.html')
      proxy_usage = t.GetHistogram('Net.QuicAlternativeProxy.Usage')
      # Bucket ALTERNATIVE_PROXY_USAGE_NO_RACE should have at least onesample.
      self.assertLessEqual(1, proxy_usage['buckets'][0]['count'])

if __name__ == '__main__':
  IntegrationTest.RunAllTests()