Added
Link Here
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 1997-2012 Oracle and/or its affiliates. All rights reserved. |
5 |
* |
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
7 |
* Other names may be trademarks of their respective owners. |
8 |
* |
9 |
* The contents of this file are subject to the terms of either the GNU |
10 |
* General Public License Version 2 only ("GPL") or the Common |
11 |
* Development and Distribution License("CDDL") (collectively, the |
12 |
* "License"). You may not use this file except in compliance with the |
13 |
* License. You can obtain a copy of the License at |
14 |
* http://www.netbeans.org/cddl-gplv2.html |
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
16 |
* specific language governing permissions and limitations under the |
17 |
* License. When distributing the software, include this License Header |
18 |
* Notice in each file and include the License file at |
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this |
20 |
* particular file as subject to the "Classpath" exception as provided |
21 |
* by Oracle in the GPL Version 2 section of the License file that |
22 |
* accompanied this code. If applicable, add the following below the |
23 |
* License Header, with the fields enclosed by brackets [] replaced by |
24 |
* your own identifying information: |
25 |
* "Portions Copyrighted [year] [name of copyright owner]" |
26 |
* |
27 |
* Contributor(s): |
28 |
* |
29 |
* The Original Software is NetBeans. The Initial Developer of the Original |
30 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun |
31 |
* Microsystems, Inc. All Rights Reserved. |
32 |
* |
33 |
* If you wish your version of this file to be governed by only the CDDL |
34 |
* or only the GPL Version 2, indicate your decision by adding |
35 |
* "[Contributor] elects to include this software in this distribution |
36 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
37 |
* single choice of license, a recipient has the option to distribute |
38 |
* your version of this file under either the CDDL, the GPL Version 2 or |
39 |
* to extend the choice of license to its licensees as provided above. |
40 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
41 |
* Version 2 license, then the option applies only if the new code is |
42 |
* made subject to such option by the copyright holder. |
43 |
*/ |
44 |
|
45 |
package org.netbeans.core.network.proxy; |
46 |
|
47 |
import java.lang.reflect.Field; |
48 |
import java.util.prefs.AbstractPreferences; |
49 |
import java.util.prefs.PreferenceChangeEvent; |
50 |
import java.util.prefs.PreferenceChangeListener; |
51 |
import java.util.prefs.Preferences; |
52 |
import junit.framework.TestResult; |
53 |
import org.netbeans.core.ProxySettings; |
54 |
import org.netbeans.junit.NbTestCase; |
55 |
import org.netbeans.junit.RandomlyFails; |
56 |
import org.openide.util.NbPreferences; |
57 |
|
58 |
/** Tests HTTP Proxy settings. |
59 |
* |
60 |
* @author Jiri Rechtacek |
61 |
* @see http://www.netbeans.org/issues/show_bug.cgi?id=51641 |
62 |
*/ |
63 |
@RandomlyFails |
64 |
public class HttpSettingsTest extends NbTestCase { |
65 |
private final Object sync = getEventQueueSync (); |
66 |
private static String SYSTEM_PROXY_HOST = "system.cache.org"; |
67 |
private static String SYSTEM_PROXY_PORT = "777"; |
68 |
private static String USER_PROXY_HOST = "my.webcache"; |
69 |
private static String USER_PROXY_PORT = "8080"; |
70 |
private static String USER_HTTPS_PROXY_HOST = "secure.webcache"; |
71 |
private static String USER_HTTPS_PROXY_PORT = "8080"; |
72 |
|
73 |
private Preferences proxyPreferences; |
74 |
private static String SILLY_USER_PROXY_HOST = "http://my.webcache"; |
75 |
private static String SILLY_SYSTEM_PROXY_HOST = "http://system.cache.org"; |
76 |
private static String SILLY_SYSTEM_PROXY_PORT = "777//"; |
77 |
private static String MY_NON_PROXY_HOSTS = "myhost.mydomain.net"; |
78 |
|
79 |
private static String NETBEANS_ORG = "*.netbeans.org"; |
80 |
private static String OTHER_ORG = "*.other.org"; |
81 |
|
82 |
public HttpSettingsTest (String name) { |
83 |
super (name); |
84 |
} |
85 |
|
86 |
@Override |
87 |
public void run (final TestResult result) { |
88 |
//just initialize Preferences before code NbTestCase |
89 |
Preferences.userRoot (); |
90 |
super.run (result); |
91 |
} |
92 |
|
93 |
@Override |
94 |
protected int timeOut () { |
95 |
return 20 * 1000; |
96 |
} |
97 |
|
98 |
@Override |
99 |
protected void setUp () throws Exception { |
100 |
super.setUp (); |
101 |
System.setProperty ("http.nonProxyHosts", NETBEANS_ORG + ',' + NETBEANS_ORG); |
102 |
new NbProxySelector(); |
103 |
proxyPreferences = NbPreferences.root ().node ("/org/netbeans/core"); |
104 |
proxyPreferences.addPreferenceChangeListener (new PreferenceChangeListener() { |
105 |
@Override |
106 |
public void preferenceChange(PreferenceChangeEvent arg0) { |
107 |
synchronized (sync) { |
108 |
sync.notifyAll (); |
109 |
} |
110 |
} |
111 |
}); |
112 |
System.setProperty ("netbeans.system_http_proxy", SYSTEM_PROXY_HOST + ":" + SYSTEM_PROXY_PORT); |
113 |
System.setProperty ("netbeans.system_http_non_proxy_hosts", OTHER_ORG); |
114 |
synchronized (sync) { |
115 |
if (! USER_PROXY_HOST.equals (proxyPreferences.get ("proxyHttpHost", ""))) { |
116 |
proxyPreferences.put ("proxyHttpHost", USER_PROXY_HOST); |
117 |
sync.wait (10000); |
118 |
} |
119 |
} |
120 |
synchronized (sync) { |
121 |
if (! USER_PROXY_PORT.equals (proxyPreferences.get ("proxyHttpPort", ""))) { |
122 |
proxyPreferences.put ("proxyHttpPort", USER_PROXY_PORT); |
123 |
sync.wait (10000); |
124 |
} |
125 |
} |
126 |
synchronized (sync) { |
127 |
if (! USER_HTTPS_PROXY_HOST.equals (proxyPreferences.get ("proxyHttpsHost", ""))) { |
128 |
proxyPreferences.put ("proxyHttpsHost", USER_HTTPS_PROXY_HOST); |
129 |
sync.wait (10000); |
130 |
} |
131 |
} |
132 |
synchronized (sync) { |
133 |
if (! USER_HTTPS_PROXY_PORT.equals (proxyPreferences.get ("proxyHttpsPort", ""))) { |
134 |
proxyPreferences.put ("proxyHttpsPort", USER_HTTPS_PROXY_PORT); |
135 |
sync.wait (10000); |
136 |
} |
137 |
} |
138 |
} |
139 |
|
140 |
private void sillySetUp () throws Exception { |
141 |
synchronized (sync) { |
142 |
if (ProxySettings.DIRECT_CONNECTION != (proxyPreferences.getInt ("proxyType", -1))) { |
143 |
proxyPreferences.putInt ("proxyType", ProxySettings.DIRECT_CONNECTION); |
144 |
sync.wait (); |
145 |
} |
146 |
} |
147 |
|
148 |
System.setProperty ("netbeans.system_http_proxy", SILLY_SYSTEM_PROXY_HOST + ":" + SILLY_SYSTEM_PROXY_PORT); |
149 |
synchronized (sync) { |
150 |
if (! SILLY_USER_PROXY_HOST.equals (proxyPreferences.get ("proxyHttpHost", ""))) { |
151 |
proxyPreferences.put ("proxyHttpHost", SILLY_USER_PROXY_HOST); |
152 |
sync.wait (10000); |
153 |
} |
154 |
} |
155 |
proxyPreferences.put ("proxyHttpPort", USER_PROXY_PORT); |
156 |
synchronized (sync) { |
157 |
if (! USER_PROXY_PORT.equals (proxyPreferences.get ("proxyHttpPort", ""))) { |
158 |
proxyPreferences.put ("proxyHttpPort", USER_PROXY_PORT); |
159 |
sync.wait (10000); |
160 |
} |
161 |
} |
162 |
} |
163 |
|
164 |
private void setUpAutoDirect () throws Exception { |
165 |
synchronized (sync) { |
166 |
if (ProxySettings.DIRECT_CONNECTION != (proxyPreferences.getInt ("proxyType", -1))) { |
167 |
proxyPreferences.putInt ("proxyType", ProxySettings.DIRECT_CONNECTION); |
168 |
sync.wait (); |
169 |
} |
170 |
} |
171 |
System.setProperty ("netbeans.system_http_proxy", "DIRECT"); |
172 |
synchronized (sync) { |
173 |
if (! "".equals (proxyPreferences.get ("proxyHttpHost", ""))) { |
174 |
proxyPreferences.put ("proxyHttpHost", ""); |
175 |
sync.wait (10000); |
176 |
} |
177 |
} |
178 |
synchronized (sync) { |
179 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
180 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
181 |
sync.wait (); |
182 |
} |
183 |
} |
184 |
} |
185 |
|
186 |
public void testDirectConnection () throws InterruptedException { |
187 |
System.setProperty ("http.proxyHost", ""); |
188 |
System.setProperty ("http.proxyPort", ""); |
189 |
synchronized (sync) { |
190 |
if (ProxySettings.DIRECT_CONNECTION != (proxyPreferences.getInt ("proxyType", -1))) { |
191 |
proxyPreferences.putInt ("proxyType", ProxySettings.DIRECT_CONNECTION); |
192 |
sync.wait (); |
193 |
} |
194 |
} |
195 |
assertEquals ("Proxy type DIRECT_CONNECTION.", ProxySettings.DIRECT_CONNECTION, ProxySettings.getProxyType ()); |
196 |
assertEquals ("No Proxy Host set.", null, System.getProperty ("http.proxyHost")); |
197 |
assertEquals ("No Proxy Port set.", null, System.getProperty ("http.proxyPort")); |
198 |
} |
199 |
|
200 |
public void testAutoDetectProxy () throws InterruptedException { |
201 |
System.setProperty ("http.proxyHost", ""); |
202 |
System.setProperty ("http.proxyPort", ""); |
203 |
synchronized (sync) { |
204 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
205 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
206 |
sync.wait (); |
207 |
} |
208 |
} |
209 |
assertEquals("Proxy type AUTO_DETECT_PROXY.", |
210 |
ProxySettings.AUTO_DETECT_PROXY, |
211 |
ProxySettings.getProxyType()); |
212 |
assertEquals("System Proxy Host: ", SYSTEM_PROXY_HOST, |
213 |
System.getProperty("http.proxyHost")); |
214 |
assertEquals("System Proxy Port: ", SYSTEM_PROXY_PORT, |
215 |
System.getProperty("http.proxyPort")); |
216 |
} |
217 |
|
218 |
public void testManualSetProxy () throws InterruptedException { |
219 |
synchronized (sync) { |
220 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
221 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
222 |
sync.wait (); |
223 |
} |
224 |
} |
225 |
assertEquals ("Proxy type MANUAL_SET_PROXY.", ProxySettings.MANUAL_SET_PROXY, ProxySettings.getProxyType ()); |
226 |
assertEquals ("Manual Set Proxy Host from ProxySettings: ", USER_PROXY_HOST, ProxySettings.getHttpHost ()); |
227 |
assertEquals ("Manual Set Proxy Port from ProxySettings: ", USER_PROXY_PORT, ProxySettings.getHttpPort ()); |
228 |
assertEquals ("Manual Set Proxy Host from System.getProperty(): ", USER_PROXY_HOST, System.getProperty ("http.proxyHost")); |
229 |
assertEquals ("Manual Set Proxy Port from System.getProperty(): ", USER_PROXY_PORT, System.getProperty ("http.proxyPort")); |
230 |
} |
231 |
|
232 |
public void testHttpsManualSetProxy () throws InterruptedException { |
233 |
synchronized (sync) { |
234 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
235 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
236 |
sync.wait (); |
237 |
} |
238 |
} |
239 |
assertEquals ("Proxy type MANUAL_SET_PROXY.", ProxySettings.MANUAL_SET_PROXY, ProxySettings.getProxyType ()); |
240 |
|
241 |
// HTTP |
242 |
assertEquals ("Manual Set Proxy Host from ProxySettings: ", USER_PROXY_HOST, ProxySettings.getHttpHost ()); |
243 |
assertEquals ("Manual Set Proxy Port from ProxySettings: ", USER_PROXY_PORT, ProxySettings.getHttpPort ()); |
244 |
assertEquals ("Manual Set Proxy Host from System.getProperty(): ", USER_PROXY_HOST, System.getProperty ("http.proxyHost")); |
245 |
assertEquals ("Manual Set Proxy Port from System.getProperty(): ", USER_PROXY_PORT, System.getProperty ("http.proxyPort")); |
246 |
|
247 |
// HTTPS |
248 |
assertEquals ("Manual Set HTTPS Proxy Host from ProxySettings: ", USER_HTTPS_PROXY_HOST, ProxySettings.getHttpsHost ()); |
249 |
assertEquals ("Manual Set HTTPS Proxy Port from ProxySettings: ", USER_HTTPS_PROXY_PORT, ProxySettings.getHttpsPort ()); |
250 |
assertEquals ("Manual Set HTTPS Proxy Host from System.getProperty(): ", USER_HTTPS_PROXY_HOST, System.getProperty ("https.proxyHost")); |
251 |
assertEquals ("Manual Set HTTPS Proxy Port from System.getProperty(): ", USER_HTTPS_PROXY_PORT, System.getProperty ("https.proxyPort")); |
252 |
} |
253 |
|
254 |
public void testIfTakeUpNonProxyFromProperty () { |
255 |
assertTrue (NETBEANS_ORG + " in one of Non-Proxy hosts.", ProxySettings.getNonProxyHosts ().indexOf (NETBEANS_ORG) != -1); |
256 |
} |
257 |
|
258 |
public void testNonProxy () throws InterruptedException { |
259 |
assertEquals ("The ProxySettings takes as same value as System properties in initial.", System.getProperty ("http.nonProxyHosts"), ProxySettings.getNonProxyHosts ()); |
260 |
|
261 |
// change value in ProxySettings |
262 |
synchronized (sync) { |
263 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
264 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
265 |
sync.wait (); |
266 |
} |
267 |
} |
268 |
synchronized (sync) { |
269 |
if (! MY_NON_PROXY_HOSTS.equals (proxyPreferences.get ("proxyNonProxyHosts", ""))) { |
270 |
proxyPreferences.put ("proxyNonProxyHosts", MY_NON_PROXY_HOSTS); |
271 |
sync.wait (); |
272 |
} |
273 |
} |
274 |
assertEquals ("ProxySettings returns new value.", "myhost.mydomain.net", ProxySettings.getNonProxyHosts ()); |
275 |
assertEquals ("System property http.nonProxyHosts was changed as well.", ProxySettings.getNonProxyHosts (), System.getProperty ("http.nonProxyHosts")); |
276 |
|
277 |
// switch proxy type to DIRECT_CONNECTION |
278 |
//System.setProperty ("http.nonProxyHosts", ""); |
279 |
synchronized (sync) { |
280 |
if (ProxySettings.DIRECT_CONNECTION != (proxyPreferences.getInt ("proxyType", -1))) { |
281 |
proxyPreferences.putInt ("proxyType", ProxySettings.DIRECT_CONNECTION); |
282 |
sync.wait (); |
283 |
} |
284 |
} |
285 |
Thread.sleep (1000); // XXX: tunning test on Windows platform, other platforms are passing |
286 |
assertEquals ("System.getProperty() doesn't return new value if DIRECT_CONNECTION set.", null, System.getProperty ("http.nonProxyHosts")); |
287 |
|
288 |
// switch proxy type back to MANUAL_SET_PROXY |
289 |
synchronized (sync) { |
290 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
291 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
292 |
sync.wait (); |
293 |
} |
294 |
} |
295 |
assertEquals ("ProxySettings again returns new value.", "myhost.mydomain.net", ProxySettings.getNonProxyHosts ()); |
296 |
assertEquals ("System property http.nonProxyHosts was changed as well.", ProxySettings.getNonProxyHosts (), System.getProperty ("http.nonProxyHosts")); |
297 |
|
298 |
// switch proxy type to AUTO_DETECT_PROXY |
299 |
synchronized (sync) { |
300 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
301 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
302 |
sync.wait (); |
303 |
} |
304 |
} |
305 |
log ("AUTO_DETECT_PROXY: ProxySettings.SystemProxySettings.getNonProxyHosts (): " + ProxySettings.getSystemNonProxyHosts()); |
306 |
log ("AUTO_DETECT_PROXY: System.getProperty (\"http.nonProxyHosts\"): " + System.getProperty ("http.nonProxyHosts")); |
307 |
assertTrue ("ProxySettings contains OTHER_ORG if AUTO_DETECT_PROXY set.", System.getProperty ("http.nonProxyHosts").indexOf (OTHER_ORG) > 0); |
308 |
|
309 |
// switch proxy type back to MANUAL_SET_PROXY |
310 |
synchronized (sync) { |
311 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
312 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
313 |
sync.wait (); |
314 |
} |
315 |
} |
316 |
assertEquals ("ProxySettings again returns new value.", "myhost.mydomain.net", ProxySettings.getNonProxyHosts ()); |
317 |
assertEquals ("System property http.nonProxyHosts was changed as well.", ProxySettings.getNonProxyHosts (), System.getProperty ("http.nonProxyHosts")); |
318 |
} |
319 |
|
320 |
public void testAvoidDuplicateNonProxySetting () throws InterruptedException { |
321 |
synchronized (sync) { |
322 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
323 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
324 |
sync.wait (); |
325 |
} |
326 |
} |
327 |
assertTrue (NETBEANS_ORG + " is among Non-proxy hosts detect from OS.", ProxySettings.getSystemNonProxyHosts().indexOf (NETBEANS_ORG) != -1); |
328 |
assertFalse (NETBEANS_ORG + " is in Non-Proxy hosts only once.", ProxySettings.getSystemNonProxyHosts().indexOf (NETBEANS_ORG) < ProxySettings.getNonProxyHosts ().lastIndexOf (NETBEANS_ORG)); |
329 |
assertEquals ("System property http.nonProxyHosts was changed as well.", ProxySettings.getSystemNonProxyHosts(), System.getProperty ("http.nonProxyHosts")); |
330 |
} |
331 |
|
332 |
public void testReadNonProxySettingFromSystem () throws InterruptedException { |
333 |
synchronized (sync) { |
334 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
335 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
336 |
sync.wait (); |
337 |
} |
338 |
} |
339 |
assertTrue (OTHER_ORG + " is among Non-proxy hosts detect from OS.", ProxySettings.getSystemNonProxyHosts().indexOf (OTHER_ORG) != -1); |
340 |
assertEquals ("System property http.nonProxyHosts was changed as well.", ProxySettings.getSystemNonProxyHosts(), System.getProperty ("http.nonProxyHosts")); |
341 |
} |
342 |
|
343 |
public void testSillySetManualProxy () throws Exception { |
344 |
sillySetUp (); |
345 |
synchronized (sync) { |
346 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
347 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
348 |
sync.wait (); |
349 |
} |
350 |
} |
351 |
assertEquals ("Proxy type MANUAL_SET_PROXY.", ProxySettings.MANUAL_SET_PROXY, ProxySettings.getProxyType ()); |
352 |
assertEquals ("Manual Set Proxy Host from ProxySettings doesn't return SILLY_USER_PROXY_HOST anymore.", USER_PROXY_HOST, ProxySettings.getHttpHost ()); |
353 |
assertEquals ("Manual Set Proxy Port from ProxySettings doesn't return SILLY_USER_PROXY_PORT anymore.", USER_PROXY_PORT, ProxySettings.getHttpPort ()); |
354 |
assertEquals ("Manual Set Proxy Host from System.getProperty(): ", USER_PROXY_HOST, System.getProperty ("http.proxyHost")); |
355 |
assertEquals ("Manual Set Proxy Port from System.getProperty(): ", USER_PROXY_PORT, System.getProperty ("http.proxyPort")); |
356 |
} |
357 |
|
358 |
public void testAutoDetectSillySetProxy () throws Exception { |
359 |
sillySetUp (); |
360 |
synchronized (sync) { |
361 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
362 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
363 |
sync.wait (); |
364 |
} |
365 |
} |
366 |
assertEquals ("Proxy type AUTO_DETECT_PROXY.", ProxySettings.AUTO_DETECT_PROXY, ProxySettings.getProxyType ()); |
367 |
assertEquals ("Auto Detected Proxy Host from ProxySettings doesn't return SILLY_SYSTEM_PROXY_HOST anymore.", SYSTEM_PROXY_HOST, ProxySettings.getSystemHttpHost()); |
368 |
assertEquals ("Auto Detected Proxy Port from ProxySettings doesn't return SILLY_SYSTEM_PROXY_PORT anymore.", SYSTEM_PROXY_PORT, ProxySettings.getSystemHttpPort()); |
369 |
assertEquals ("System Proxy Host: ", SYSTEM_PROXY_HOST, System.getProperty ("http.proxyHost")); |
370 |
assertEquals ("System Proxy Port: ", SYSTEM_PROXY_PORT, System.getProperty ("http.proxyPort")); |
371 |
} |
372 |
|
373 |
public void testSwitchAutoAndManualMode () throws Exception { |
374 |
setUpAutoDirect (); |
375 |
|
376 |
// ensure auto detect mode |
377 |
assertEquals("Proxy type AUTO_DETECT_PROXY.", |
378 |
ProxySettings.AUTO_DETECT_PROXY, |
379 |
ProxySettings.getProxyType()); |
380 |
assertEquals ("Auto Proxy Host from System.getProperty(): ", null, System.getProperty ("http.proxyHost")); |
381 |
assertEquals ("Auto Proxy Port from System.getProperty(): ", null, System.getProperty ("http.proxyPort")); |
382 |
|
383 |
// switch to manual |
384 |
proxyPreferences.put ("proxyHttpHost", "foo"); |
385 |
synchronized (sync) { |
386 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
387 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
388 |
sync.wait (); |
389 |
} |
390 |
} |
391 |
assertEquals ("Proxy type MANUAL_SET_PROXY.", ProxySettings.MANUAL_SET_PROXY, ProxySettings.getProxyType ()); |
392 |
assertEquals ("Auto Proxy Host from System.getProperty(): ", "foo", System.getProperty ("http.proxyHost")); |
393 |
|
394 |
// switch back to auto detect |
395 |
synchronized (sync) { |
396 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
397 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
398 |
sync.wait (); |
399 |
} |
400 |
} |
401 |
assertEquals("Proxy type AUTO_DETECT_PROXY.", |
402 |
ProxySettings.AUTO_DETECT_PROXY, |
403 |
ProxySettings.getProxyType()); |
404 |
assertEquals ("Auto Proxy Host from System.getProperty(): ", null, System.getProperty ("http.proxyHost")); |
405 |
assertEquals ("Auto Proxy Port from System.getProperty(): ", null, System.getProperty ("http.proxyPort")); |
406 |
|
407 |
} |
408 |
|
409 |
private Object getEventQueueSync() { |
410 |
try { |
411 |
Field f = AbstractPreferences.class.getDeclaredField("eventQueue"); |
412 |
f.setAccessible(true); |
413 |
return f.get(null); |
414 |
} catch (Exception ex) { |
415 |
throw new ExceptionInInitializerError(ex); |
416 |
} |
417 |
} |
418 |
} |