diff options
10 files changed, 71 insertions, 244 deletions
diff --git a/expectations/brokentests.txt b/expectations/brokentests.txt index 5cebb63..aa06985 100644 --- a/expectations/brokentests.txt +++ b/expectations/brokentests.txt @@ -142,13 +142,6 @@ ] }, { - description: "This test affects tests that are run after this one due to caching in URLConnection.", - result: EXEC_FAILED, - names: [ - "org.apache.harmony.luni.tests.java.net.ContentHandlerFactoryTest#test_createContentHandler" - ] -}, -{ description: "Causes OutOfMemoryError to test finalization", result: EXEC_FAILED, names: [ diff --git a/expectations/knownfailures.txt b/expectations/knownfailures.txt index 33913bd..1293b27 100644 --- a/expectations/knownfailures.txt +++ b/expectations/knownfailures.txt @@ -1464,6 +1464,7 @@ "com.squareup.okhttp.internal.spdy.SpdyConnectionTest", "com.squareup.okhttp.internal.http.HttpOverHttp20Draft09Test", "com.squareup.okhttp.internal.http.HttpOverSpdy3Test", + "com.squareup.okhttp.internal.http.ResponseCacheAdapterTest", "com.squareup.okhttp.internal.http.URLConnectionTest#npnSetsProtocolHeader_SPDY_3", "com.squareup.okhttp.internal.http.URLConnectionTest#npnSetsProtocolHeader_HTTP_2", "com.squareup.okhttp.internal.http.URLConnectionTest#zeroLengthPost_SPDY_3", diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java index 959f83c..42f88c1 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java @@ -24,31 +24,25 @@ import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.UnknownHostException; -import java.security.Permission; import java.util.ArrayList; import java.util.Enumeration; import org.apache.harmony.testframework.serialization.SerializationTest; import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; -import tests.support.Support_Configuration; public class InetAddressTest extends junit.framework.TestCase { /** * java.net.InetAddress#getByName(String) */ - public void test_getByNameUnknownHostException() { + public void test_getByName_exceptionContainsUsefulMessage() { // Related to HARMONY-5784 - - // loop a few times to flex the negative cache paths - for (int i = 0; i < 5; i++) { - try { - InetAddress.getByName("unknown.unknown.bad"); - fail("An UnknownHostException should have been thrown"); - } catch (UnknownHostException e) { - assertTrue(e.getMessage().contains("unknown.unknown.bad")); - } + try { + InetAddress.getByName("1.2.3.4hello"); + fail(); + } catch (UnknownHostException e) { + assertTrue(e.getMessage().contains("1.2.3.4hello")); } } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/SocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/SocketTest.java index 18d2cb2..4df92e2 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/SocketTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/SocketTest.java @@ -274,7 +274,7 @@ public class SocketTest extends junit.framework.TestCase { public void test_connect_unknownhost() throws Exception { Socket socket = new Socket(); try { - socket.connect(new InetSocketAddress("unknownhost.invalid", 12345)); + socket.connect(new InetSocketAddress("1.2.3.4hello", 12345)); fail(); } catch (UnknownHostException expected) { } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/SocketFactoryTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/SocketFactoryTest.java index e939a9b..d566ee3 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/SocketFactoryTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/SocketFactoryTest.java @@ -65,7 +65,7 @@ public class SocketFactoryTest extends TestCase { assertTrue("Failed to create socket", s.getPort() == sport); try { - sf.createSocket("bla-bla", sport); + sf.createSocket("1.2.3.4hello", sport); fail("UnknownHostException wasn't thrown"); } catch (UnknownHostException expected) { } @@ -180,7 +180,7 @@ public class SocketFactoryTest extends TestCase { assertTrue("1: Failed to create socket", s.getPort() == sport); try { - sf.createSocket("bla-bla", sport, InetAddress.getLocalHost(), 0); + sf.createSocket("1.2.3.4hello", sport, InetAddress.getLocalHost(), 0); fail("UnknownHostException wasn't thrown"); } catch (UnknownHostException expected) { } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketFactoryTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketFactoryTest.java index 0d91116..e890032 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketFactoryTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketFactoryTest.java @@ -61,52 +61,42 @@ public class SSLSocketFactoryTest extends TestCase { /** * javax.net.ssl.SSLSocketFactory#createSocket(Socket s, String host, int port, boolean autoClose) */ - public void test_createSocket() { + public void test_createSocket() throws Exception { SSLSocketFactory sf = (SSLSocketFactory)SSLSocketFactory.getDefault(); int sport = startServer("test_createSocket()"); int[] invalid = { Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE }; - try { - Socket st = new Socket("localhost", sport); - Socket s = sf.createSocket(st, "localhost", sport, false); - assertFalse(s.isClosed()); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } - try { - Socket st = new Socket("localhost", sport); - Socket s = sf.createSocket(st, "localhost", sport, true); - s.close(); - assertTrue(st.isClosed()); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + + + Socket st = new Socket("localhost", sport); + Socket s = sf.createSocket(st, "localhost", sport, false); + assertFalse(s.isClosed()); + + st = new Socket("localhost", sport); + s = sf.createSocket(st, "localhost", sport, true); + s.close(); + assertTrue(st.isClosed()); + try { sf.createSocket(null, "localhost", sport, true); - fail("IOException wasn't thrown"); - } catch (IOException ioe) { - // expected - } catch (NullPointerException e) { - // expected + fail(); + } catch (NullPointerException expected) { } + for (int i = 0; i < invalid.length; i++) { try { - Socket s = sf.createSocket(new Socket(), "localhost", 1080, false); - fail("IOException wasn't thrown"); - } catch (IOException ioe) { - // expected + s = sf.createSocket(new Socket(), "localhost", 1080, false); + fail(); + } catch (IOException expected) { } } try { - Socket st = new Socket("bla-bla", sport); - Socket s = sf.createSocket(st, "bla-bla", sport, false); - fail("UnknownHostException wasn't thrown: " + "bla-bla"); - } catch (UnknownHostException uhe) { - // expected - } catch (Exception e) { - fail(e + " was thrown instead of UnknownHostException"); + st = new Socket("1.2.3.4hello", sport); + s = sf.createSocket(st, "1.2.3.4hello", sport, false); + fail(); + } catch (UnknownHostException expected) { } } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java index b4cbde2..950d534 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java @@ -158,7 +158,7 @@ public class SSLSocketTest extends TestCase { } try { - getSSLSocket("bla-bla", sport); + getSSLSocket("1.2.3.4hello", sport); fail(); } catch (UnknownHostException expected) { } @@ -199,7 +199,7 @@ public class SSLSocketTest extends TestCase { } try { - getSSLSocket("bla-bla", sport, InetAddress.getLocalHost(), 0); + getSSLSocket("1.2.3.4hello", sport, InetAddress.getLocalHost(), 0); fail(); } catch (UnknownHostException expected) { } diff --git a/luni/src/main/java/java/lang/System.java b/luni/src/main/java/java/lang/System.java index 68af967..55ca762 100644 --- a/luni/src/main/java/java/lang/System.java +++ b/luni/src/main/java/java/lang/System.java @@ -830,8 +830,7 @@ public final class System { * Returns the value of a particular system property or {@code null} if no * such property exists. * - * <p>The following properties are always provided by the Dalvik VM <b>and - * cannot be modified</b>: + * <p>The following properties are always provided by the Dalvik VM:</p> * <p><table BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> * <tr BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> * <td><b>Name</b></td> <td><b>Meaning</b></td> <td><b>Example</b></td></tr> @@ -872,8 +871,8 @@ public final class System { * * </table> * - * <p>It is an error to override anyone of these properties. Any attempt to - * do so will leave their values unchanged. + * <p> All of the above properties except for {@code user.home} and {@code java.io.tmpdir} + * <b>cannot be modified</b>. Any attempt to change them will be a no-op. * * @param propertyName * the name of the system property to look up. diff --git a/luni/src/test/java/libcore/java/net/OldCookieHandlerTest.java b/luni/src/test/java/libcore/java/net/OldCookieHandlerTest.java index 249c326..0e11d50 100644 --- a/luni/src/test/java/libcore/java/net/OldCookieHandlerTest.java +++ b/luni/src/test/java/libcore/java/net/OldCookieHandlerTest.java @@ -16,6 +16,9 @@ package libcore.java.net; +import com.google.mockwebserver.MockResponse; +import com.google.mockwebserver.MockWebServer; + import java.io.IOException; import java.net.CookieHandler; import java.net.URI; @@ -27,65 +30,57 @@ import tests.support.Support_Configuration; public class OldCookieHandlerTest extends TestCase { - URI getURI, putURI; - String link = "http://" + Support_Configuration.SpecialInetTestAddress + "/"; - boolean isGetCalled = false; - boolean isPutCalled = false; - boolean completedSuccessfully = false; - public void test_CookieHandler() { assertNull(CookieHandler.getDefault()); } - public void test_get_put() { + public void test_get_put() throws Exception { MockCookieHandler mch = new MockCookieHandler(); CookieHandler defaultHandler = CookieHandler.getDefault(); - CookieHandler.setDefault(mch); - - class TestThread extends Thread { - public void run() { - try { - URL url = new URL(link); - URLConnection conn = url.openConnection(); - conn.getContent(); - url = new URL(link); - conn = url.openConnection(); - conn.getContent(); - completedSuccessfully = true; - } catch (Exception e) { - e.printStackTrace(); - } - } - } try { - TestThread thread = new TestThread(); + CookieHandler.setDefault(mch); - thread.start(); - try { - thread.join(); - } catch (InterruptedException e) { - fail("InterruptedException was thrown."); - } + MockWebServer server = new MockWebServer(); + server.play(); + server.enqueue(new MockResponse().addHeader("Set-Cookie2: a=\"android\"; " + + "Comment=\"this cookie is delicious\"; " + + "CommentURL=\"http://google.com/\"; " + + "Discard; " + + "Domain=\"" + server.getCookieDomain() + "\"; " + + "Max-Age=\"60\"; " + + "Path=\"/path\"; " + + "Port=\"80,443," + server.getPort() + "\"; " + + "Secure; " + + "Version=\"1\"")); - assertTrue(isGetCalled); - assertTrue(isPutCalled); - assertTrue(completedSuccessfully); + URLConnection connection = server.getUrl("/path/foo").openConnection(); + connection.getContent(); + + assertTrue(mch.wasGetCalled()); + assertTrue(mch.wasPutCalled()); } finally { CookieHandler.setDefault(defaultHandler); } } - class MockCookieHandler extends CookieHandler { + private static class MockCookieHandler extends CookieHandler { + private boolean getCalled = false; + private boolean putCalled = false; public Map get(URI uri, Map requestHeaders) throws IOException { - getURI = uri; - isGetCalled = true; + getCalled = true; return requestHeaders; } public void put(URI uri, Map responseHeaders) throws IOException { - putURI = uri; - isPutCalled = true; + putCalled = true; + } + + public boolean wasGetCalled() { + return getCalled; + } + public boolean wasPutCalled() { + return putCalled; } } } diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java deleted file mode 100644 index f3d5518..0000000 --- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.apache.harmony.luni.tests.java.net; - -import junit.framework.TestCase; - -import tests.support.Support_Configuration; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.net.ContentHandler; -import java.net.ContentHandlerFactory; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; - -public class ContentHandlerFactoryTest extends TestCase { - - ContentHandlerFactory oldFactory = null; - Field factoryField = null; - - boolean isTestable = false; - - boolean isGetContentCalled = false; - boolean isCreateContentHandlerCalled = false; - - // SideEffect: This test affects tests that are run after this one. - // The reason are side effects due to caching in URLConnection. - // Maybe this test needs to be run in isolation. - public void test_createContentHandler() throws IOException { - - TestContentHandlerFactory factory = new TestContentHandlerFactory(); - - if(isTestable) { - - assertFalse(isCreateContentHandlerCalled); - - URL url = new URL("http://" + - Support_Configuration.SpecialInetTestAddress); - - URLConnection.setContentHandlerFactory(factory); - - URLConnection con = url.openConnection(); - - try { - con.getContent(); - assertTrue(isCreateContentHandlerCalled); - assertTrue(isGetContentCalled); - } catch (Exception e) { - throw new RuntimeException(e); - } - - isGetContentCalled = false; - - try { - con.getContent(new Class[] {}); - assertTrue(isGetContentCalled); - } catch (Exception e) { - throw new RuntimeException(e); - } - - try { - con.setContentHandlerFactory(factory); - fail("java.lang.Error was not thrown."); - } catch(java.lang.Error e) { - //expected - } - - try { - con.setContentHandlerFactory(null); - fail("java.lang.Error was not thrown."); - } catch(java.lang.Error e) { - //expected - } - - } else { - ContentHandler ch = factory.createContentHandler("text/plain"); - URL url; - try { - url = new URL("http://" + - Support_Configuration.SpecialInetTestAddress); - assertNotNull(ch.getContent(url.openConnection())); - } catch (MalformedURLException e) { - fail("MalformedURLException was thrown: " + e.getMessage()); - } catch (IOException e) { - fail("IOException was thrown."); - } - } - } - - public void setUp() { - Field [] fields = URLConnection.class.getDeclaredFields(); - int counter = 0; - for (Field field : fields) { - if (ContentHandlerFactory.class.equals(field.getType())) { - counter++; - factoryField = field; - } - } - - if(counter == 1) { - - isTestable = true; - - factoryField.setAccessible(true); - try { - oldFactory = (ContentHandlerFactory) factoryField.get(null); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException was thrown during setUp: " - + e.getMessage()); - } catch (IllegalAccessException e) { - fail("IllegalAccessException was thrown during setUp: " - + e.getMessage()); - } - } - } - - public void tearDown() { - if(isTestable) { - try { - factoryField.set(null, oldFactory); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException was thrown during tearDown: " - + e.getMessage()); - } catch (IllegalAccessException e) { - fail("IllegalAccessException was thrown during tearDown: " - + e.getMessage()); - } - } - } - - public class TestContentHandler extends ContentHandler { - - public Object getContent(URLConnection u) { - isGetContentCalled = true; - return null; - } - } - - public class TestContentHandlerFactory implements ContentHandlerFactory { - - public ContentHandler createContentHandler(String mimetype) { - isCreateContentHandlerCalled = true; - return new TestContentHandler(); - } - } -} |