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

Side by Side Diff: tools/chrome_proxy/webdriver/decorators.py

Issue 2826733002: Add Chrome version check decorators (Closed)
Patch Set: Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 # Copyright 2017 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 re
6
5 from common import ParseFlags 7 from common import ParseFlags
8 from common import TestDriver
6 9
7 10
8 # Platform-specific decorators. 11 # Platform-specific decorators.
9 # These decorators can be used to only run a test function for certain platforms 12 # These decorators can be used to only run a test function for certain platforms
10 # by annotating the function with them. 13 # by annotating the function with them.
11 14
12 def AndroidOnly(func): 15 def AndroidOnly(func):
13 def wrapper(*args, **kwargs): 16 def wrapper(*args, **kwargs):
14 if ParseFlags().android: 17 if ParseFlags().android:
15 func(*args, **kwargs) 18 func(*args, **kwargs)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 args[0].skipTest('This test runs on Mac OS only.') 68 args[0].skipTest('This test runs on Mac OS only.')
66 return wrapper 69 return wrapper
67 70
68 def NotMac(func): 71 def NotMac(func):
69 def wrapper(*args, **kwargs): 72 def wrapper(*args, **kwargs):
70 if sys.platform == 'darwin': 73 if sys.platform == 'darwin':
71 func(*args, **kwargs) 74 func(*args, **kwargs)
72 else: 75 else:
73 args[0].skipTest('This test does not run on Mac OS.') 76 args[0].skipTest('This test does not run on Mac OS.')
74 return wrapper 77 return wrapper
78
79 chrome_version = None
80
81 def GetChromeVersion():
82 with TestDriver() as t:
83 t.LoadURL('http://check.googlezip.net/connect')
bengr 2017/05/05 17:53:28 Maybe use a standard gen_204 page, or just scrape
84 ua = t.ExecuteJavascriptStatement('navigator.userAgent')
85 match = re.search('Chrome/[0-9\.]+', ua)
86 if not match:
87 raise Exception('Could not find Chrome version in User-Agent: %s' % ua)
88 chrome_version = ua[match.start():match.end()]
89 version = chrome_version[chrome_version.find('/') + 1:]
90 version_split = version.split('.')
91 milestone = int(version_split[0])
92 print 'Running on Chrome M%d (%s)' % (milestone, version)
93 return milestone
94
95 def ChromeVersionBeforeM(milestone):
96 def puesdo_wrapper(func):
97 def wrapper(*args, **kwargs):
98 global chrome_version
99 if chrome_version == None:
100 chrome_version = GetChromeVersion()
101 if chrome_version < milestone:
102 func(*args, **kwargs)
103 else:
104 args[0].skipTest('This test does not run above M%d.' % milestone)
105 return wrapper
106 return puesdo_wrapper
107
108 def ChromeVersionAfterM(milestone):
109 def puesdo_wrapper(func):
110 def wrapper(*args, **kwargs):
111 global chrome_version
112 if chrome_version == None:
113 chrome_version = GetChromeVersion()
114 if chrome_version >= milestone:
115 func(*args, **kwargs)
116 else:
117 args[0].skipTest('This test does not run below M%d.' % milestone)
118 return wrapper
119 return puesdo_wrapper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698