Removed
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; |
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.junit.NbTestCase; |
54 |
import org.netbeans.junit.RandomlyFails; |
55 |
import org.openide.util.NbPreferences; |
56 |
|
57 |
/** Tests HTTP Proxy settings. |
58 |
* |
59 |
* @author Jiri Rechtacek |
60 |
* @see http://www.netbeans.org/issues/show_bug.cgi?id=51641 |
61 |
*/ |
62 |
@RandomlyFails |
63 |
public class HttpSettingsTest extends NbTestCase { |
64 |
private final Object sync = getEventQueueSync (); |
65 |
private static String SYSTEM_PROXY_HOST = "system.cache.org"; |
66 |
private static String SYSTEM_PROXY_PORT = "777"; |
67 |
private static String USER_PROXY_HOST = "my.webcache"; |
68 |
private static String USER_PROXY_PORT = "8080"; |
69 |
private static String USER_HTTPS_PROXY_HOST = "secure.webcache"; |
70 |
private static String USER_HTTPS_PROXY_PORT = "8080"; |
71 |
|
72 |
private Preferences proxyPreferences; |
73 |
private static String SILLY_USER_PROXY_HOST = "http://my.webcache"; |
74 |
private static String SILLY_SYSTEM_PROXY_HOST = "http://system.cache.org"; |
75 |
private static String SILLY_SYSTEM_PROXY_PORT = "777//"; |
76 |
private static String MY_NON_PROXY_HOSTS = "myhost.mydomain.net"; |
77 |
|
78 |
private static String NETBEANS_ORG = "*.netbeans.org"; |
79 |
private static String OTHER_ORG = "*.other.org"; |
80 |
|
81 |
public HttpSettingsTest (String name) { |
82 |
super (name); |
83 |
} |
84 |
|
85 |
@Override |
86 |
public void run (final TestResult result) { |
87 |
//just initialize Preferences before code NbTestCase |
88 |
Preferences.userRoot (); |
89 |
super.run (result); |
90 |
} |
91 |
|
92 |
@Override |
93 |
protected int timeOut () { |
94 |
return 20 * 1000; |
95 |
} |
96 |
|
97 |
@Override |
98 |
protected void setUp () throws Exception { |
99 |
super.setUp (); |
100 |
System.setProperty ("http.nonProxyHosts", NETBEANS_ORG + ',' + NETBEANS_ORG); |
101 |
NbProxySelector.register(); |
102 |
proxyPreferences = NbPreferences.root ().node ("/org/netbeans/core"); |
103 |
proxyPreferences.addPreferenceChangeListener (new PreferenceChangeListener() { |
104 |
@Override |
105 |
public void preferenceChange(PreferenceChangeEvent arg0) { |
106 |
synchronized (sync) { |
107 |
sync.notifyAll (); |
108 |
} |
109 |
} |
110 |
}); |
111 |
System.setProperty ("netbeans.system_http_proxy", SYSTEM_PROXY_HOST + ":" + SYSTEM_PROXY_PORT); |
112 |
System.setProperty ("netbeans.system_http_non_proxy_hosts", OTHER_ORG); |
113 |
synchronized (sync) { |
114 |
if (! USER_PROXY_HOST.equals (proxyPreferences.get ("proxyHttpHost", ""))) { |
115 |
proxyPreferences.put ("proxyHttpHost", USER_PROXY_HOST); |
116 |
sync.wait (10000); |
117 |
} |
118 |
} |
119 |
synchronized (sync) { |
120 |
if (! USER_PROXY_PORT.equals (proxyPreferences.get ("proxyHttpPort", ""))) { |
121 |
proxyPreferences.put ("proxyHttpPort", USER_PROXY_PORT); |
122 |
sync.wait (10000); |
123 |
} |
124 |
} |
125 |
synchronized (sync) { |
126 |
if (! USER_HTTPS_PROXY_HOST.equals (proxyPreferences.get ("proxyHttpsHost", ""))) { |
127 |
proxyPreferences.put ("proxyHttpsHost", USER_HTTPS_PROXY_HOST); |
128 |
sync.wait (10000); |
129 |
} |
130 |
} |
131 |
synchronized (sync) { |
132 |
if (! USER_HTTPS_PROXY_PORT.equals (proxyPreferences.get ("proxyHttpsPort", ""))) { |
133 |
proxyPreferences.put ("proxyHttpsPort", USER_HTTPS_PROXY_PORT); |
134 |
sync.wait (10000); |
135 |
} |
136 |
} |
137 |
} |
138 |
|
139 |
private void sillySetUp () throws Exception { |
140 |
synchronized (sync) { |
141 |
if (ProxySettings.DIRECT_CONNECTION != (proxyPreferences.getInt ("proxyType", -1))) { |
142 |
proxyPreferences.putInt ("proxyType", ProxySettings.DIRECT_CONNECTION); |
143 |
sync.wait (); |
144 |
} |
145 |
} |
146 |
|
147 |
System.setProperty ("netbeans.system_http_proxy", SILLY_SYSTEM_PROXY_HOST + ":" + SILLY_SYSTEM_PROXY_PORT); |
148 |
synchronized (sync) { |
149 |
if (! SILLY_USER_PROXY_HOST.equals (proxyPreferences.get ("proxyHttpHost", ""))) { |
150 |
proxyPreferences.put ("proxyHttpHost", SILLY_USER_PROXY_HOST); |
151 |
sync.wait (10000); |
152 |
} |
153 |
} |
154 |
proxyPreferences.put ("proxyHttpPort", USER_PROXY_PORT); |
155 |
synchronized (sync) { |
156 |
if (! USER_PROXY_PORT.equals (proxyPreferences.get ("proxyHttpPort", ""))) { |
157 |
proxyPreferences.put ("proxyHttpPort", USER_PROXY_PORT); |
158 |
sync.wait (10000); |
159 |
} |
160 |
} |
161 |
} |
162 |
|
163 |
private void setUpAutoDirect () throws Exception { |
164 |
synchronized (sync) { |
165 |
if (ProxySettings.DIRECT_CONNECTION != (proxyPreferences.getInt ("proxyType", -1))) { |
166 |
proxyPreferences.putInt ("proxyType", ProxySettings.DIRECT_CONNECTION); |
167 |
sync.wait (); |
168 |
} |
169 |
} |
170 |
System.setProperty ("netbeans.system_http_proxy", "DIRECT"); |
171 |
synchronized (sync) { |
172 |
if (! "".equals (proxyPreferences.get ("proxyHttpHost", ""))) { |
173 |
proxyPreferences.put ("proxyHttpHost", ""); |
174 |
sync.wait (10000); |
175 |
} |
176 |
} |
177 |
synchronized (sync) { |
178 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
179 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
180 |
sync.wait (); |
181 |
} |
182 |
} |
183 |
} |
184 |
|
185 |
public void testDirectConnection () throws InterruptedException { |
186 |
System.setProperty ("http.proxyHost", ""); |
187 |
System.setProperty ("http.proxyPort", ""); |
188 |
synchronized (sync) { |
189 |
if (ProxySettings.DIRECT_CONNECTION != (proxyPreferences.getInt ("proxyType", -1))) { |
190 |
proxyPreferences.putInt ("proxyType", ProxySettings.DIRECT_CONNECTION); |
191 |
sync.wait (); |
192 |
} |
193 |
} |
194 |
assertEquals ("Proxy type DIRECT_CONNECTION.", ProxySettings.DIRECT_CONNECTION, ProxySettings.getProxyType ()); |
195 |
assertEquals ("No Proxy Host set.", null, System.getProperty ("http.proxyHost")); |
196 |
assertEquals ("No Proxy Port set.", null, System.getProperty ("http.proxyPort")); |
197 |
} |
198 |
|
199 |
public void testAutoDetectProxy () throws InterruptedException { |
200 |
System.setProperty ("http.proxyHost", ""); |
201 |
System.setProperty ("http.proxyPort", ""); |
202 |
synchronized (sync) { |
203 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
204 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
205 |
sync.wait (); |
206 |
} |
207 |
} |
208 |
assertEquals("Proxy type AUTO_DETECT_PROXY.", |
209 |
ProxySettings.AUTO_DETECT_PROXY, |
210 |
ProxySettings.getProxyType()); |
211 |
assertEquals("System Proxy Host: ", SYSTEM_PROXY_HOST, |
212 |
System.getProperty("http.proxyHost")); |
213 |
assertEquals("System Proxy Port: ", SYSTEM_PROXY_PORT, |
214 |
System.getProperty("http.proxyPort")); |
215 |
} |
216 |
|
217 |
public void testManualSetProxy () throws InterruptedException { |
218 |
synchronized (sync) { |
219 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
220 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
221 |
sync.wait (); |
222 |
} |
223 |
} |
224 |
assertEquals ("Proxy type MANUAL_SET_PROXY.", ProxySettings.MANUAL_SET_PROXY, ProxySettings.getProxyType ()); |
225 |
assertEquals ("Manual Set Proxy Host from ProxySettings: ", USER_PROXY_HOST, ProxySettings.getHttpHost ()); |
226 |
assertEquals ("Manual Set Proxy Port from ProxySettings: ", USER_PROXY_PORT, ProxySettings.getHttpPort ()); |
227 |
assertEquals ("Manual Set Proxy Host from System.getProperty(): ", USER_PROXY_HOST, System.getProperty ("http.proxyHost")); |
228 |
assertEquals ("Manual Set Proxy Port from System.getProperty(): ", USER_PROXY_PORT, System.getProperty ("http.proxyPort")); |
229 |
} |
230 |
|
231 |
public void testHttpsManualSetProxy () throws InterruptedException { |
232 |
synchronized (sync) { |
233 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
234 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
235 |
sync.wait (); |
236 |
} |
237 |
} |
238 |
assertEquals ("Proxy type MANUAL_SET_PROXY.", ProxySettings.MANUAL_SET_PROXY, ProxySettings.getProxyType ()); |
239 |
|
240 |
// HTTP |
241 |
assertEquals ("Manual Set Proxy Host from ProxySettings: ", USER_PROXY_HOST, ProxySettings.getHttpHost ()); |
242 |
assertEquals ("Manual Set Proxy Port from ProxySettings: ", USER_PROXY_PORT, ProxySettings.getHttpPort ()); |
243 |
assertEquals ("Manual Set Proxy Host from System.getProperty(): ", USER_PROXY_HOST, System.getProperty ("http.proxyHost")); |
244 |
assertEquals ("Manual Set Proxy Port from System.getProperty(): ", USER_PROXY_PORT, System.getProperty ("http.proxyPort")); |
245 |
|
246 |
// HTTPS |
247 |
assertEquals ("Manual Set HTTPS Proxy Host from ProxySettings: ", USER_HTTPS_PROXY_HOST, ProxySettings.getHttpsHost ()); |
248 |
assertEquals ("Manual Set HTTPS Proxy Port from ProxySettings: ", USER_HTTPS_PROXY_PORT, ProxySettings.getHttpsPort ()); |
249 |
assertEquals ("Manual Set HTTPS Proxy Host from System.getProperty(): ", USER_HTTPS_PROXY_HOST, System.getProperty ("https.proxyHost")); |
250 |
assertEquals ("Manual Set HTTPS Proxy Port from System.getProperty(): ", USER_HTTPS_PROXY_PORT, System.getProperty ("https.proxyPort")); |
251 |
} |
252 |
|
253 |
public void testIfTakeUpNonProxyFromProperty () { |
254 |
assertTrue (NETBEANS_ORG + " in one of Non-Proxy hosts.", ProxySettings.getNonProxyHosts ().indexOf (NETBEANS_ORG) != -1); |
255 |
} |
256 |
|
257 |
public void testNonProxy () throws InterruptedException { |
258 |
assertEquals ("The ProxySettings takes as same value as System properties in initial.", System.getProperty ("http.nonProxyHosts"), ProxySettings.getNonProxyHosts ()); |
259 |
|
260 |
// change value in ProxySettings |
261 |
synchronized (sync) { |
262 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
263 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
264 |
sync.wait (); |
265 |
} |
266 |
} |
267 |
synchronized (sync) { |
268 |
if (! MY_NON_PROXY_HOSTS.equals (proxyPreferences.get ("proxyNonProxyHosts", ""))) { |
269 |
proxyPreferences.put ("proxyNonProxyHosts", MY_NON_PROXY_HOSTS); |
270 |
sync.wait (); |
271 |
} |
272 |
} |
273 |
assertEquals ("ProxySettings returns new value.", "myhost.mydomain.net", ProxySettings.getNonProxyHosts ()); |
274 |
assertEquals ("System property http.nonProxyHosts was changed as well.", ProxySettings.getNonProxyHosts (), System.getProperty ("http.nonProxyHosts")); |
275 |
|
276 |
// switch proxy type to DIRECT_CONNECTION |
277 |
//System.setProperty ("http.nonProxyHosts", ""); |
278 |
synchronized (sync) { |
279 |
if (ProxySettings.DIRECT_CONNECTION != (proxyPreferences.getInt ("proxyType", -1))) { |
280 |
proxyPreferences.putInt ("proxyType", ProxySettings.DIRECT_CONNECTION); |
281 |
sync.wait (); |
282 |
} |
283 |
} |
284 |
Thread.sleep (1000); // XXX: tunning test on Windows platform, other platforms are passing |
285 |
assertEquals ("System.getProperty() doesn't return new value if DIRECT_CONNECTION set.", null, System.getProperty ("http.nonProxyHosts")); |
286 |
|
287 |
// switch proxy type back to MANUAL_SET_PROXY |
288 |
synchronized (sync) { |
289 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
290 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
291 |
sync.wait (); |
292 |
} |
293 |
} |
294 |
assertEquals ("ProxySettings again returns new value.", "myhost.mydomain.net", ProxySettings.getNonProxyHosts ()); |
295 |
assertEquals ("System property http.nonProxyHosts was changed as well.", ProxySettings.getNonProxyHosts (), System.getProperty ("http.nonProxyHosts")); |
296 |
|
297 |
// switch proxy type to AUTO_DETECT_PROXY |
298 |
synchronized (sync) { |
299 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
300 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
301 |
sync.wait (); |
302 |
} |
303 |
} |
304 |
log ("AUTO_DETECT_PROXY: ProxySettings.SystemProxySettings.getNonProxyHosts (): " + ProxySettings.SystemProxySettings.getNonProxyHosts ()); |
305 |
log ("AUTO_DETECT_PROXY: System.getProperty (\"http.nonProxyHosts\"): " + System.getProperty ("http.nonProxyHosts")); |
306 |
assertTrue ("ProxySettings contains OTHER_ORG if AUTO_DETECT_PROXY set.", System.getProperty ("http.nonProxyHosts").indexOf (OTHER_ORG) > 0); |
307 |
|
308 |
// switch proxy type back to MANUAL_SET_PROXY |
309 |
synchronized (sync) { |
310 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
311 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
312 |
sync.wait (); |
313 |
} |
314 |
} |
315 |
assertEquals ("ProxySettings again returns new value.", "myhost.mydomain.net", ProxySettings.getNonProxyHosts ()); |
316 |
assertEquals ("System property http.nonProxyHosts was changed as well.", ProxySettings.getNonProxyHosts (), System.getProperty ("http.nonProxyHosts")); |
317 |
} |
318 |
|
319 |
public void testAvoidDuplicateNonProxySetting () throws InterruptedException { |
320 |
synchronized (sync) { |
321 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
322 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
323 |
sync.wait (); |
324 |
} |
325 |
} |
326 |
assertTrue (NETBEANS_ORG + " is among Non-proxy hosts detect from OS.", ProxySettings.SystemProxySettings.getNonProxyHosts ().indexOf (NETBEANS_ORG) != -1); |
327 |
assertFalse (NETBEANS_ORG + " is in Non-Proxy hosts only once.", ProxySettings.SystemProxySettings.getNonProxyHosts ().indexOf (NETBEANS_ORG) < ProxySettings.getNonProxyHosts ().lastIndexOf (NETBEANS_ORG)); |
328 |
assertEquals ("System property http.nonProxyHosts was changed as well.", ProxySettings.SystemProxySettings.getNonProxyHosts (), System.getProperty ("http.nonProxyHosts")); |
329 |
} |
330 |
|
331 |
public void testReadNonProxySettingFromSystem () throws InterruptedException { |
332 |
synchronized (sync) { |
333 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
334 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
335 |
sync.wait (); |
336 |
} |
337 |
} |
338 |
assertTrue (OTHER_ORG + " is among Non-proxy hosts detect from OS.", ProxySettings.SystemProxySettings.getNonProxyHosts ().indexOf (OTHER_ORG) != -1); |
339 |
assertEquals ("System property http.nonProxyHosts was changed as well.", ProxySettings.SystemProxySettings.getNonProxyHosts (), System.getProperty ("http.nonProxyHosts")); |
340 |
} |
341 |
|
342 |
public void testSillySetManualProxy () throws Exception { |
343 |
sillySetUp (); |
344 |
synchronized (sync) { |
345 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
346 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
347 |
sync.wait (); |
348 |
} |
349 |
} |
350 |
assertEquals ("Proxy type MANUAL_SET_PROXY.", ProxySettings.MANUAL_SET_PROXY, ProxySettings.getProxyType ()); |
351 |
assertEquals ("Manual Set Proxy Host from ProxySettings doesn't return SILLY_USER_PROXY_HOST anymore.", USER_PROXY_HOST, ProxySettings.getHttpHost ()); |
352 |
assertEquals ("Manual Set Proxy Port from ProxySettings doesn't return SILLY_USER_PROXY_PORT anymore.", USER_PROXY_PORT, ProxySettings.getHttpPort ()); |
353 |
assertEquals ("Manual Set Proxy Host from System.getProperty(): ", USER_PROXY_HOST, System.getProperty ("http.proxyHost")); |
354 |
assertEquals ("Manual Set Proxy Port from System.getProperty(): ", USER_PROXY_PORT, System.getProperty ("http.proxyPort")); |
355 |
} |
356 |
|
357 |
public void testAutoDetectSillySetProxy () throws Exception { |
358 |
sillySetUp (); |
359 |
synchronized (sync) { |
360 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
361 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
362 |
sync.wait (); |
363 |
} |
364 |
} |
365 |
assertEquals ("Proxy type AUTO_DETECT_PROXY.", ProxySettings.AUTO_DETECT_PROXY, ProxySettings.getProxyType ()); |
366 |
assertEquals ("Auto Detected Proxy Host from ProxySettings doesn't return SILLY_SYSTEM_PROXY_HOST anymore.", SYSTEM_PROXY_HOST, ProxySettings.SystemProxySettings.getHttpHost ()); |
367 |
assertEquals ("Auto Detected Proxy Port from ProxySettings doesn't return SILLY_SYSTEM_PROXY_PORT anymore.", SYSTEM_PROXY_PORT, ProxySettings.SystemProxySettings.getHttpPort ()); |
368 |
assertEquals ("System Proxy Host: ", SYSTEM_PROXY_HOST, System.getProperty ("http.proxyHost")); |
369 |
assertEquals ("System Proxy Port: ", SYSTEM_PROXY_PORT, System.getProperty ("http.proxyPort")); |
370 |
} |
371 |
|
372 |
public void testSwitchAutoAndManualMode () throws Exception { |
373 |
setUpAutoDirect (); |
374 |
|
375 |
// ensure auto detect mode |
376 |
assertEquals("Proxy type AUTO_DETECT_PROXY.", |
377 |
ProxySettings.AUTO_DETECT_PROXY, |
378 |
ProxySettings.getProxyType()); |
379 |
assertEquals ("Auto Proxy Host from System.getProperty(): ", null, System.getProperty ("http.proxyHost")); |
380 |
assertEquals ("Auto Proxy Port from System.getProperty(): ", null, System.getProperty ("http.proxyPort")); |
381 |
|
382 |
// switch to manual |
383 |
proxyPreferences.put ("proxyHttpHost", "foo"); |
384 |
synchronized (sync) { |
385 |
if (ProxySettings.MANUAL_SET_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
386 |
proxyPreferences.putInt ("proxyType", ProxySettings.MANUAL_SET_PROXY); |
387 |
sync.wait (); |
388 |
} |
389 |
} |
390 |
assertEquals ("Proxy type MANUAL_SET_PROXY.", ProxySettings.MANUAL_SET_PROXY, ProxySettings.getProxyType ()); |
391 |
assertEquals ("Auto Proxy Host from System.getProperty(): ", "foo", System.getProperty ("http.proxyHost")); |
392 |
|
393 |
// switch back to auto detect |
394 |
synchronized (sync) { |
395 |
if (ProxySettings.AUTO_DETECT_PROXY != (proxyPreferences.getInt ("proxyType", -1))) { |
396 |
proxyPreferences.putInt ("proxyType", ProxySettings.AUTO_DETECT_PROXY); |
397 |
sync.wait (); |
398 |
} |
399 |
} |
400 |
assertEquals("Proxy type AUTO_DETECT_PROXY.", |
401 |
ProxySettings.AUTO_DETECT_PROXY, |
402 |
ProxySettings.getProxyType()); |
403 |
assertEquals ("Auto Proxy Host from System.getProperty(): ", null, System.getProperty ("http.proxyHost")); |
404 |
assertEquals ("Auto Proxy Port from System.getProperty(): ", null, System.getProperty ("http.proxyPort")); |
405 |
|
406 |
} |
407 |
|
408 |
private Object getEventQueueSync() { |
409 |
try { |
410 |
Field f = AbstractPreferences.class.getDeclaredField("eventQueue"); |
411 |
f.setAccessible(true); |
412 |
return f.get(null); |
413 |
} catch (Exception ex) { |
414 |
throw new ExceptionInInitializerError(ex); |
415 |
} |
416 |
} |
417 |
} |