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

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

Issue 820093002: Integration tests for desktop platforms and safebrowsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed test names. Add @classmethod. Created 5 years, 10 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
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 logging 5 import logging
6 import time 6 import time
7 7
8 from integration_tests import network_metrics 8 from integration_tests import network_metrics
9 from telemetry.page import page_test 9 from telemetry.page import page_test
10 from telemetry.value import scalar 10 from telemetry.value import scalar
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 # The Via header is valid if it is the old format or the new format 47 # The Via header is valid if it is the old format or the new format
48 # with 4-character version prefix, for example, 48 # with 4-character version prefix, for example,
49 # "1.1 Chrome-Compression-Proxy". 49 # "1.1 Chrome-Compression-Proxy".
50 return (CHROME_PROXY_VIA_HEADER_DEPRECATED in vias or 50 return (CHROME_PROXY_VIA_HEADER_DEPRECATED in vias or
51 any(v[4:] == CHROME_PROXY_VIA_HEADER for v in vias)) 51 any(v[4:] == CHROME_PROXY_VIA_HEADER for v in vias))
52 52
53 def IsValidByViaHeader(self): 53 def IsValidByViaHeader(self):
54 return (not self.ShouldHaveChromeProxyViaHeader() or 54 return (not self.ShouldHaveChromeProxyViaHeader() or
55 self.HasChromeProxyViaHeader()) 55 self.HasChromeProxyViaHeader())
56 56
57 def IsSafebrowsingResponse(self):
58 if (self.response.status == 307 and
59 self.response.GetHeader('X-Malware-Url') == '1' and
60 self.IsValidByViaHeader() and
61 self.response.GetHeader('Location') == self.response.url):
62 return True
63 return False
64
65 def GetChromeProxyClientType(self): 57 def GetChromeProxyClientType(self):
66 """Get the client type directive from the Chrome-Proxy request header. 58 """Get the client type directive from the Chrome-Proxy request header.
67 59
68 Returns: 60 Returns:
69 The client type directive from the Chrome-Proxy request header for the 61 The client type directive from the Chrome-Proxy request header for the
70 request that lead to this response. For example, if the request header 62 request that lead to this response. For example, if the request header
71 "Chrome-Proxy: c=android" is present, then this method would return 63 "Chrome-Proxy: c=android" is present, then this method would return
72 "android". Returns None if no client type directive is present. 64 "android". Returns None if no client type directive is present.
73 """ 65 """
74 if 'Chrome-Proxy' not in self.response.request_headers: 66 if 'Chrome-Proxy' not in self.response.request_headers:
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 'Exactly one response should be bypassed. ' 255 'Exactly one response should be bypassed. '
264 '(eligible_response_count=%d, bypass_count=%d)\n' % ( 256 '(eligible_response_count=%d, bypass_count=%d)\n' % (
265 eligible_response_count, bypass_count)) 257 eligible_response_count, bypass_count))
266 else: 258 else:
267 results.AddValue(scalar.ScalarValue( 259 results.AddValue(scalar.ScalarValue(
268 results.current_page, 'eligible_responses', 'count', 260 results.current_page, 'eligible_responses', 'count',
269 eligible_response_count)) 261 eligible_response_count))
270 results.AddValue(scalar.ScalarValue( 262 results.AddValue(scalar.ScalarValue(
271 results.current_page, 'bypass', 'count', bypass_count)) 263 results.current_page, 'bypass', 'count', bypass_count))
272 264
273 def AddResultsForSafebrowsing(self, tab, results): 265 def AddResultsForSafebrowsingOn(self, tab, results):
274 count = 0 266 results.AddValue(scalar.ScalarValue(
275 safebrowsing_count = 0 267 results.current_page, 'safebrowsing', 'timeout responses', 1))
276 268
269 def AddResultsForSafebrowsingOff(self, tab, results):
270 response_count = 0
277 for resp in self.IterResponses(tab): 271 for resp in self.IterResponses(tab):
278 count += 1 272 # Data reduction proxy should return the real response for sites with
279 if resp.IsSafebrowsingResponse(): 273 # malware.
280 safebrowsing_count += 1 274 response_count += 1
281 else: 275 if not resp.HasChromeProxyViaHeader():
282 r = resp.response 276 r = resp.response
283 raise ChromeProxyMetricException, ( 277 raise ChromeProxyMetricException, (
284 '%s: Not a valid safe browsing response.\n' 278 '%s: Safebrowsing feature should be off for desktop and webview.\n'
285 'Reponse: status=(%d, %s)\nHeaders:\n %s' % ( 279 'Reponse: status=(%d, %s)\nHeaders:\n %s' % (
286 r.url, r.status, r.status_text, r.headers)) 280 r.url, r.status, r.status_text, r.headers))
287 if count == safebrowsing_count: 281
288 results.AddValue(scalar.ScalarValue( 282 if response_count == 0:
289 results.current_page, 'safebrowsing', 'boolean', True))
290 else:
291 raise ChromeProxyMetricException, ( 283 raise ChromeProxyMetricException, (
292 'Safebrowsing failed (count=%d, safebrowsing_count=%d)\n' % ( 284 'Safebrowsing test failed: No valid responses received')
293 count, safebrowsing_count)) 285
286 results.AddValue(scalar.ScalarValue(
287 results.current_page, 'safebrowsing', 'responses', response_count))
294 288
295 def AddResultsForHTTPFallback(self, tab, results): 289 def AddResultsForHTTPFallback(self, tab, results):
296 via_fallback_count = 0 290 via_fallback_count = 0
297 291
298 for resp in self.IterResponses(tab): 292 for resp in self.IterResponses(tab):
299 if resp.ShouldHaveChromeProxyViaHeader(): 293 if resp.ShouldHaveChromeProxyViaHeader():
300 # All responses should have come through the HTTP fallback proxy, which 294 # All responses should have come through the HTTP fallback proxy, which
301 # means that they should have the via header, and if a remote port is 295 # means that they should have the via header, and if a remote port is
302 # defined, it should be port 80. 296 # defined, it should be port 80.
303 if (not resp.HasChromeProxyViaHeader() or 297 if (not resp.HasChromeProxyViaHeader() or
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 'Response for %s should have via header; proxy should no longer ' 406 'Response for %s should have via header; proxy should no longer '
413 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % ( 407 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % (
414 r.url, r.status, r.status_text, r.headers)) 408 r.url, r.status, r.status_text, r.headers))
415 else: 409 else:
416 via_count += 1 410 via_count += 1
417 411
418 results.AddValue(scalar.ScalarValue( 412 results.AddValue(scalar.ScalarValue(
419 results.current_page, 'bypass', 'count', bypass_count)) 413 results.current_page, 'bypass', 'count', bypass_count))
420 results.AddValue(scalar.ScalarValue( 414 results.AddValue(scalar.ScalarValue(
421 results.current_page, 'via', 'count', via_count)) 415 results.current_page, 'via', 'count', via_count))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698