Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 /** | 5 /** |
| 6 * Test suite for Android's default ProxySelector implementation. The purpose of these tests | 6 * Test suite for Android's default ProxySelector implementation. The purpose of these tests |
| 7 * is to check that the behaviour of the ProxySelector implementation matches wh at we have | 7 * is to check that the behaviour of the ProxySelector implementation matches wh at we have |
| 8 * implemented in net/proxy/proxy_config_service_android.cc. | 8 * implemented in net/proxy/proxy_config_service_android.cc. |
| 9 * | 9 * |
| 10 * IMPORTANT: These test cases are generated from net/android/tools/proxy_test_c ases.py, so if any | 10 * IMPORTANT: These test cases are generated from net/android/tools/proxy_test_c ases.py, so if any |
| 11 * of these tests fail, please be sure to edit that file and regenerate the test cases here and also | 11 * of these tests fail, please be sure to edit that file and regenerate the test cases here and also |
| 12 * in net/proxy/proxy_config_service_android_unittests.cc if required. | 12 * in net/proxy/proxy_config_service_android_unittests.cc if required. |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 package org.chromium.net; | 15 package org.chromium.net; |
| 16 | 16 |
| 17 import android.support.test.filters.SmallTest; | |
| 17 import android.test.InstrumentationTestCase; | 18 import android.test.InstrumentationTestCase; |
| 18 import android.test.suitebuilder.annotation.SmallTest; | |
| 19 | 19 |
| 20 import org.chromium.base.test.util.Feature; | 20 import org.chromium.base.test.util.Feature; |
| 21 | 21 |
| 22 import java.net.Proxy; | 22 import java.net.Proxy; |
| 23 import java.net.ProxySelector; | 23 import java.net.ProxySelector; |
| 24 import java.net.URI; | 24 import java.net.URI; |
| 25 import java.net.URISyntaxException; | 25 import java.net.URISyntaxException; |
| 26 import java.util.List; | 26 import java.util.List; |
| 27 import java.util.Properties; | 27 import java.util.Properties; |
| 28 | 28 |
| 29 public class AndroidProxySelectorTest extends InstrumentationTestCase { | 29 public class AndroidProxySelectorTest extends InstrumentationTestCase { |
| 30 Properties mProperties; | 30 Properties mProperties; |
| 31 | 31 |
| 32 public AndroidProxySelectorTest() { | 32 public AndroidProxySelectorTest() { |
| 33 // Start with a clean slate in case there is a system proxy configured. | 33 // Start with a clean slate in case there is a system proxy configured. |
| 34 mProperties = new Properties(); | 34 mProperties = new Properties(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 @Override | 37 @Override |
| 38 public void setUp() { | 38 public void setUp() { |
| 39 System.setProperties(mProperties); | 39 System.setProperties(mProperties); |
| 40 } | 40 } |
| 41 | 41 |
| 42 static String toString(Proxy proxy) { | 42 static String toString(Proxy proxy) { |
| 43 if (proxy == Proxy.NO_PROXY) | 43 if (proxy == Proxy.NO_PROXY) return "DIRECT"; |
|
jbudorick
2016/12/17 02:15:52
?
the real yoland
2016/12/17 03:31:53
This is presubmit error
jbudorick
2016/12/19 13:47:43
Acknowledged.
| |
| 44 return "DIRECT"; | |
| 45 // java.net.Proxy only knows about http and socks proxies. | 44 // java.net.Proxy only knows about http and socks proxies. |
| 46 Proxy.Type type = proxy.type(); | 45 Proxy.Type type = proxy.type(); |
| 47 switch (type) { | 46 switch (type) { |
| 48 case HTTP: | 47 case HTTP: |
| 49 return "PROXY " + proxy.address().toString(); | 48 return "PROXY " + proxy.address().toString(); |
| 50 case SOCKS: | 49 case SOCKS: |
| 51 return "SOCKS5 " + proxy.address().toString(); | 50 return "SOCKS5 " + proxy.address().toString(); |
| 52 case DIRECT: | 51 case DIRECT: |
| 53 return "DIRECT"; | 52 return "DIRECT"; |
| 54 default: | 53 default: |
| 55 // If a new proxy type is supported in future, add a case to mat ch it. | 54 // If a new proxy type is supported in future, add a case to mat ch it. |
| 56 fail("Unknown proxy type" + type); | 55 fail("Unknown proxy type" + type); |
| 57 return "unknown://"; | 56 return "unknown://"; |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 | 59 |
| 61 static String toString(List<Proxy> proxies) { | 60 static String toString(List<Proxy> proxies) { |
| 62 StringBuilder builder = new StringBuilder(); | 61 StringBuilder builder = new StringBuilder(); |
| 63 for (Proxy proxy : proxies) { | 62 for (Proxy proxy : proxies) { |
| 64 if (builder.length() > 0) | 63 if (builder.length() > 0) builder.append(';'); |
| 65 builder.append(';'); | |
| 66 builder.append(toString(proxy)); | 64 builder.append(toString(proxy)); |
| 67 } | 65 } |
| 68 return builder.toString(); | 66 return builder.toString(); |
| 69 } | 67 } |
| 70 | 68 |
| 71 static void checkMapping(String url, String expected) throws URISyntaxExcept ion { | 69 static void checkMapping(String url, String expected) throws URISyntaxExcept ion { |
| 72 URI uri = new URI(url); | 70 URI uri = new URI(url); |
| 73 List<Proxy> proxies = ProxySelector.getDefault().select(uri); | 71 List<Proxy> proxies = ProxySelector.getDefault().select(uri); |
| 74 assertEquals("Mapping", expected, toString(proxies)); | 72 assertEquals("Mapping", expected, toString(proxies)); |
| 75 } | 73 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 @SmallTest | 287 @SmallTest |
| 290 @Feature({"AndroidWebView"}) | 288 @Feature({"AndroidWebView"}) |
| 291 public void testHttpProxySupercedesSocks() throws Exception { | 289 public void testHttpProxySupercedesSocks() throws Exception { |
| 292 System.setProperty("proxyHost", "defaultproxy.com"); | 290 System.setProperty("proxyHost", "defaultproxy.com"); |
| 293 System.setProperty("socksProxyHost", "socksproxy.com"); | 291 System.setProperty("socksProxyHost", "socksproxy.com"); |
| 294 System.setProperty("socksProxyPort", "9000"); | 292 System.setProperty("socksProxyPort", "9000"); |
| 295 checkMapping("http://example.com/", "PROXY defaultproxy.com:80"); | 293 checkMapping("http://example.com/", "PROXY defaultproxy.com:80"); |
| 296 } | 294 } |
| 297 } | 295 } |
| 298 | 296 |
| OLD | NEW |