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.
7 from common
import chrome_proxy_metrics
as metrics
8 from telemetry
.core
import exceptions
9 from telemetry
.page
import page_test
11 class ChromeProxyValidation(page_test
.PageTest
):
12 """Base class for all chrome proxy correctness measurements."""
14 # Value of the extra via header. |None| if no extra via header is expected.
15 extra_via_header
= None
17 def __init__(self
, restart_after_each_page
=False, metrics
=None):
18 super(ChromeProxyValidation
, self
).__init
__(
19 needs_browser_restart_after_each_page
=restart_after_each_page
)
20 self
._metrics
= metrics
22 # Whether a timeout exception is expected during the test.
23 self
._expect
_timeout
= False
25 def CustomizeBrowserOptions(self
, options
):
26 # Enable the chrome proxy (data reduction proxy).
27 options
.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
29 def WillNavigateToPage(self
, page
, tab
):
30 tab
.ClearCache(force
=True)
32 self
._metrics
.Start(page
, tab
)
34 def ValidateAndMeasurePage(self
, page
, tab
, results
):
36 # Wait for the load event.
37 tab
.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300)
39 self
._metrics
.Stop(page
, tab
)
40 if ChromeProxyValidation
.extra_via_header
:
41 self
._metrics
.AddResultsForExtraViaHeader(
42 tab
, results
, ChromeProxyValidation
.extra_via_header
)
43 self
.AddResults(tab
, results
)
45 def AddResults(self
, tab
, results
):
46 raise NotImplementedError
48 def StopBrowserAfterPage(self
, browser
, page
): # pylint: disable=W0613
49 if hasattr(page
, 'restart_after') and page
.restart_after
:
53 def RunNavigateSteps(self
, page
, tab
):
54 # The redirect from safebrowsing causes a timeout. Ignore that.
56 super(ChromeProxyValidation
, self
).RunNavigateSteps(page
, tab
)
57 if self
._expect
_timeout
:
58 raise metrics
.ChromeProxyMetricException
, (
59 'Timeout was expected, but did not occur')
60 except exceptions
.TimeoutException
as e
:
61 if self
._expect
_timeout
:
62 logging
.warning('Navigation timeout on page %s',
63 page
.name
if page
.name
else page
.url
)