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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
#!/usr/bin/env python
# Copyright (c) 2011 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 pyauto_functional
import pyauto
import re
from pyauto_errors import AutomationCommandTimeout
from pyauto_errors import JSONInterfaceError
class ChromeosProxy(pyauto.PyUITest):
"""Tests for ChromeOS proxy.
The following tests are for UI testing to verify the user defined
proxy settings can be set and saved. The proxy addresses used in these
tests are not real proxies and are used for testing purposes.
"""
# The list of the default ports by protocol. The default ports
# for https and ftp are both 80 as explained in crosbug.com/14390#c3.
DEFAULT_PORTS = {
'http' : 80,
'https': 80,
'ftp' : 80,
'socks' : 1080,
}
# Defines the translation used for entering fields.
MANUAL_PROXY_FIELDS = {
'http' : { 'url' : 'httpurl', 'port' : 'httpport' },
'https' : { 'url' : 'httpsurl', 'port' : 'httpsport' },
'ftp' : { 'url' : 'ftpurl', 'port' : 'ftpport' },
'socks' : { 'url' : 'socks', 'port' : 'socksport' },
}
def setUp(self):
pyauto.PyUITest.setUp(self)
self.ResetProxySettingsOnChromeOS()
def tearDown(self):
self.ResetProxySettingsOnChromeOS()
pyauto.PyUITest.tearDown(self)
def _BasicSetManualProxyFieldTest(self, proxy_type, proxy_url,
proxy_port=None):
"""Basic test for setting one manual port field and verifying it is saved
Args:
proxy_type: One of http, https, ftp, or socks.
proxy_url: The URL of the proxy server.
proxy_port: The port number. May be left blank to imply using the default
port. The default ports are defined by self.DEFAULT_PORTS.
"""
if proxy_type == 'socks':
url_path = proxy_type
else:
url_path = proxy_type + 'url'
port_path = proxy_type + 'port'
proxy_dict = {
'url_path': url_path,
'port_path': port_path,
'proxy_url': proxy_url,
'proxy_port': proxy_port,
}
self.SetProxySettingOnChromeOS(proxy_dict)
result = self.GetProxySettingsOnChromeOS()
self.assertEqual(result['type'], self.PROXY_TYPE_MANUAL, 'Proxy type '
'should be Manual but instead we got %s.' %
self.GetProxyTypeName(result['type']))
self.assertTrue(url_path in result,
'No %s url entry was saved' % proxy_type)
self.assertEqual(result[url_path], proxy_url,
'Saved proxy url %s does not match user set url %s.' %
(result[url_path], proxy_url))
# Verify the port. If proxy_port is empty, we verify the
# default port is used
if proxy_port is None:
self.assertEqual(ChromeosProxy.DEFAULT_PORTS[proxy_type],
result[port_path],
'Proxy port %d was used instead of default port %d.' %
(result[port_path],
ChromeosProxy.DEFAULT_PORTS[proxy_type]))
else:
self.assertEqual(proxy_port, result[port_path],
'Proxy port %d was used instead of user set port %d.' %
(result[port_path], proxy_port))
# Verify that all other proxy fields are not set.
for key, val in self.MANUAL_PROXY_FIELDS.iteritems():
if proxy_type != key:
self.assertFalse(result.get(val['url']), 'Only %s url should have '
'been set. %s url should have been left blank.' %
(proxy_type, key))
self.assertFalse(result.get(val['port']), 'Only %s port should have '
'been set. %s port should have been left blank.' %
(proxy_type, key))
def testSetHTTPProxySettingsDefaultPort(self):
"""Set the http proxy without a port and verify it saves.
If http proxy is provided but the port is not, the default port
should be used.
"""
self._BasicSetManualProxyFieldTest('http', '192.168.1.1')
def testSetHTTPProxySettingsDefaultPortByDomain(self):
"""Set the http proxy by domain without a port and verify it saves.
If http proxy is provided but the port is not, the default port
should be used.
"""
self._BasicSetManualProxyFieldTest('http', 'test_proxy.google.com')
def testSetHTTPSProxySettingsDefaultPort(self):
"""Set https proxy without a port and verify it saves.
If https proxy is provided but the port is not, the default port
should be used.
"""
self._BasicSetManualProxyFieldTest('https', '192.168.1.1')
def testSetHTTPSProxySettingsDefaultPortByDomain(self):
"""Set the https proxy by domain without a port and verify it saves.
If https proxy is provided but the port is not, the default port
should be used.
"""
self._BasicSetManualProxyFieldTest('https', 'test_proxy.google.com')
def testSetFTPProxySettingsDefaultPort(self):
"""Set ftp proxy without a port and verify it saves.
If ftp proxy is provided but the port is not, the default port
should be used.
"""
self._BasicSetManualProxyFieldTest('ftp', '192.168.1.1')
def testSetFTPSProxySettingsDefaultPortByDomain(self):
"""Set the ftp proxy by domain without a port and verify it saves.
If ftp proxy is provided but the port is not, the default port
should be used.
"""
self._BasicSetManualProxyFieldTest('ftp', 'test_proxy.google.com')
def testSetSocksProxySettingsDefaultPort(self):
"""Set socks proxy without a port and verify it saves.
If socks proxy is provided but the port is not, the default port
should be used.
"""
self._BasicSetManualProxyFieldTest('socks', '192.168.1.1')
def testSetSocksProxySettingsDefaultPortByDomain(self):
"""Set socks proxy without a port and verify it saves.
If socks proxy is provided but the port is not, the default port
should be used.
"""
self._BasicSetManualProxyFieldTest('socks', 'test_proxy.google.com')
def testSetHTTPProxySettings(self):
"""Set the http proxy and verify it saves."""
self._BasicSetManualProxyFieldTest('http', '192.168.1.1', 3128)
def testSetHTTPProxySettingsAndNavigate(self):
"""Set an invalid httpurl and verify that we cant navigate."""
invalid_url='10.10'
self._BasicSetManualProxyFieldTest('http', invalid_url, 3128)
self.assertRaises(AutomationCommandTimeout,
lambda: self.NavigateToURL('http://www.google.com'))
def testSetHTTPProxySettingsByDomain(self):
"""Set the http proxy by domain name and verify it saves."""
self._BasicSetManualProxyFieldTest('http', 'test_proxy.google.com', 3128)
def testSetHTTPSProxySettings(self):
"""Set the https proxy and verify it saves."""
self._BasicSetManualProxyFieldTest('https', '192.168.1.1', 6000)
def testSetHTTPSProxySettingsByDomain(self):
"""Set the https proxy by domain name and verify it saves."""
self._BasicSetManualProxyFieldTest('https', 'test_proxy.google.com', 6000)
def testSetFtpProxySettingsByDomain(self):
"""Set the ftpproxy by domain name and verify it saves."""
self._BasicSetManualProxyFieldTest('ftp', 'test_proxy.google.com', 7000)
def testSetFTPProxySettings(self):
"""Set the ftp proxy and verify it saves."""
self._BasicSetManualProxyFieldTest('ftp', '192.168.1.1', 7000)
def testSetSocksProxySettings(self):
"""Set the socks proxy and verify it saves."""
self._BasicSetManualProxyFieldTest('socks', '192.168.1.1', 3128)
def testSetSocksProxySettingsByDomain(self):
"""Set the Socks proxy by domain name and verify it saves."""
self._BasicSetManualProxyFieldTest('socks', 'test_proxy.google.com', 3128)
if __name__ == '__main__':
pyauto_functional.Main()
|