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

Side by Side Diff: chrome/test/functional/chromeos_proxy.py

Issue 16045005: Migrate auto_tests about proxy configuration to browser_tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import pyauto_functional
7 import pyauto
8 import re
9 from pyauto_errors import AutomationCommandTimeout
10 from pyauto_errors import JSONInterfaceError
11
12 class ChromeosProxy(pyauto.PyUITest):
13 """Tests for ChromeOS proxy.
14
15 The following tests are for UI testing to verify the user defined
16 proxy settings can be set and saved. The proxy addresses used in these
17 tests are not real proxies and are used for testing purposes.
18 """
19
20 # The list of the default ports by protocol. The default ports
21 # for https and ftp are both 80 as explained in crosbug.com/14390#c3.
22 DEFAULT_PORTS = {
23 'http' : 80,
24 'https': 80,
25 'ftp' : 80,
26 'socks' : 1080,
27 }
28
29 # Defines the translation used for entering fields.
30 MANUAL_PROXY_FIELDS = {
31 'http' : { 'url' : 'httpurl', 'port' : 'httpport' },
32 'https' : { 'url' : 'httpsurl', 'port' : 'httpsport' },
33 'ftp' : { 'url' : 'ftpurl', 'port' : 'ftpport' },
34 'socks' : { 'url' : 'socks', 'port' : 'socksport' },
35 }
36
37 def setUp(self):
38 pyauto.PyUITest.setUp(self)
39 self.ResetProxySettingsOnChromeOS()
40
41 def tearDown(self):
42 self.ResetProxySettingsOnChromeOS()
43 pyauto.PyUITest.tearDown(self)
44
45 def _BasicSetManualProxyFieldTest(self, proxy_type, proxy_url,
46 proxy_port=None):
47 """Basic test for setting one manual port field and verifying it is saved
48
49 Args:
50 proxy_type: One of http, https, ftp, or socks.
51 proxy_url: The URL of the proxy server.
52 proxy_port: The port number. May be left blank to imply using the default
53 port. The default ports are defined by self.DEFAULT_PORTS.
54 """
55 if proxy_type == 'socks':
56 url_path = proxy_type
57 else:
58 url_path = proxy_type + 'url'
59 port_path = proxy_type + 'port'
60 proxy_dict = {
61 'url_path': url_path,
62 'port_path': port_path,
63 'proxy_url': proxy_url,
64 'proxy_port': proxy_port,
65 }
66
67 self.SetProxySettingOnChromeOS(proxy_dict)
68 result = self.GetProxySettingsOnChromeOS()
69
70 self.assertEqual(result['type'], self.PROXY_TYPE_MANUAL, 'Proxy type '
71 'should be Manual but instead we got %s.' %
72 self.GetProxyTypeName(result['type']))
73 self.assertTrue(url_path in result,
74 'No %s url entry was saved' % proxy_type)
75 self.assertEqual(result[url_path], proxy_url,
76 'Saved proxy url %s does not match user set url %s.' %
77 (result[url_path], proxy_url))
78 # Verify the port. If proxy_port is empty, we verify the
79 # default port is used
80 if proxy_port is None:
81 self.assertEqual(ChromeosProxy.DEFAULT_PORTS[proxy_type],
82 result[port_path],
83 'Proxy port %d was used instead of default port %d.' %
84 (result[port_path],
85 ChromeosProxy.DEFAULT_PORTS[proxy_type]))
86 else:
87 self.assertEqual(proxy_port, result[port_path],
88 'Proxy port %d was used instead of user set port %d.' %
89 (result[port_path], proxy_port))
90
91 # Verify that all other proxy fields are not set.
92 for key, val in self.MANUAL_PROXY_FIELDS.iteritems():
93 if proxy_type != key:
94 self.assertFalse(result.get(val['url']), 'Only %s url should have '
95 'been set. %s url should have been left blank.' %
96 (proxy_type, key))
97 self.assertFalse(result.get(val['port']), 'Only %s port should have '
98 'been set. %s port should have been left blank.' %
99 (proxy_type, key))
100
101 def testSetHTTPProxySettingsDefaultPort(self):
102 """Set the http proxy without a port and verify it saves.
103
104 If http proxy is provided but the port is not, the default port
105 should be used.
106 """
107 self._BasicSetManualProxyFieldTest('http', '192.168.1.1')
108
109 def testSetHTTPProxySettingsDefaultPortByDomain(self):
110 """Set the http proxy by domain without a port and verify it saves.
111
112 If http proxy is provided but the port is not, the default port
113 should be used.
114 """
115 self._BasicSetManualProxyFieldTest('http', 'test_proxy.google.com')
116
117 def testSetHTTPSProxySettingsDefaultPort(self):
118 """Set https proxy without a port and verify it saves.
119
120 If https proxy is provided but the port is not, the default port
121 should be used.
122 """
123 self._BasicSetManualProxyFieldTest('https', '192.168.1.1')
124
125 def testSetHTTPSProxySettingsDefaultPortByDomain(self):
126 """Set the https proxy by domain without a port and verify it saves.
127
128 If https proxy is provided but the port is not, the default port
129 should be used.
130 """
131 self._BasicSetManualProxyFieldTest('https', 'test_proxy.google.com')
132
133 def testSetFTPProxySettingsDefaultPort(self):
134 """Set ftp proxy without a port and verify it saves.
135
136 If ftp proxy is provided but the port is not, the default port
137 should be used.
138 """
139 self._BasicSetManualProxyFieldTest('ftp', '192.168.1.1')
140
141 def testSetFTPSProxySettingsDefaultPortByDomain(self):
142 """Set the ftp proxy by domain without a port and verify it saves.
143
144 If ftp proxy is provided but the port is not, the default port
145 should be used.
146 """
147 self._BasicSetManualProxyFieldTest('ftp', 'test_proxy.google.com')
148
149 def testSetSocksProxySettingsDefaultPort(self):
150 """Set socks proxy without a port and verify it saves.
151
152 If socks proxy is provided but the port is not, the default port
153 should be used.
154 """
155 self._BasicSetManualProxyFieldTest('socks', '192.168.1.1')
156
157 def testSetSocksProxySettingsDefaultPortByDomain(self):
158 """Set socks proxy without a port and verify it saves.
159
160 If socks proxy is provided but the port is not, the default port
161 should be used.
162 """
163 self._BasicSetManualProxyFieldTest('socks', 'test_proxy.google.com')
164
165 def testSetHTTPProxySettings(self):
166 """Set the http proxy and verify it saves."""
167 self._BasicSetManualProxyFieldTest('http', '192.168.1.1', 3128)
168
169 def testSetHTTPProxySettingsAndNavigate(self):
170 """Set an invalid httpurl and verify that we cant navigate."""
171 invalid_url='10.10'
172 self._BasicSetManualProxyFieldTest('http', invalid_url, 3128)
173 self.assertRaises(AutomationCommandTimeout,
174 lambda: self.NavigateToURL('http://www.google.com'))
175
176 def testSetHTTPProxySettingsByDomain(self):
177 """Set the http proxy by domain name and verify it saves."""
178 self._BasicSetManualProxyFieldTest('http', 'test_proxy.google.com', 3128)
179
180 def testSetHTTPSProxySettings(self):
181 """Set the https proxy and verify it saves."""
182 self._BasicSetManualProxyFieldTest('https', '192.168.1.1', 6000)
183
184 def testSetHTTPSProxySettingsByDomain(self):
185 """Set the https proxy by domain name and verify it saves."""
186 self._BasicSetManualProxyFieldTest('https', 'test_proxy.google.com', 6000)
187
188 def testSetFtpProxySettingsByDomain(self):
189 """Set the ftpproxy by domain name and verify it saves."""
190 self._BasicSetManualProxyFieldTest('ftp', 'test_proxy.google.com', 7000)
191
192 def testSetFTPProxySettings(self):
193 """Set the ftp proxy and verify it saves."""
194 self._BasicSetManualProxyFieldTest('ftp', '192.168.1.1', 7000)
195
196 def testSetSocksProxySettings(self):
197 """Set the socks proxy and verify it saves."""
198 self._BasicSetManualProxyFieldTest('socks', '192.168.1.1', 3128)
199
200 def testSetSocksProxySettingsByDomain(self):
201 """Set the Socks proxy by domain name and verify it saves."""
202 self._BasicSetManualProxyFieldTest('socks', 'test_proxy.google.com', 3128)
203
204
205 if __name__ == '__main__':
206 pyauto_functional.Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698