Fix harmony URLConnectionTest hanging for 25sec.

The Handler for file:// URLs contains a fallback to FtpURLConnection
for URLs with nonempty host (with some exceptions).

URLConnectionTest.test_getContentType() contained a typo ("file:/"
instead of "file://"). This led to the URL having a non-empty host
value ("data"), which triggered a fallback to FtpURLConnection in
the Handler for file:// URLs.

The test attempted to resolve the host "data", eventually timing out.
getContentType() by itself swallows any IOException and just
returns null, and the test was written to tolerate null, so it didn't
fail. The test code hasn't been touched since the initial commit in
2009, which makes it hard to tell whether the null tolerance was
because someone had observed the test failing (but not understood
why), or perhaps wanted to make the test tolerant of poor
contentType detection.

This CL fixes the typo, which makes the test pass in milliseconds
rather than in 25+ seconds.

This CL also makes the test stricter by checking specifically for
"text/html" rather than a case-insensitive version of it or null.

It also checks for a file:// (as opposed to ftp://) URLConnection
for the two cases fixed by this CL and by http://r.android.com/82755
(commit 2587ef91ba693d73e97704e8163c050b286e7330).

The logic for fallback to FtpURLConnection remains in place; basic
test coverage for it exists in
org.apache.harmony.tests.java.net.URLTest#test_openConnection_FileProtocol
(this CL fixes a minor typo in that test name). The test appears to derive
from code written for https://issues.apache.org/jira/browse/HARMONY-5779

Test: atest CtsLibcoreTestCases:org.apache.harmony.luni.tests.java.net.URLConnectionTest
Test: atest CtsLibcoreTestCases:org.apache.harmony.tests.java.net.URLTest
Test: CtsLibcoreTestCases
Test: Checked that nothing else in CtsLibcoreTestCases relies on the
      fallback to FtpURLConnection by locally replacing it with an
      AssertionError and checking that the only failing test is
      test_openConnection_FileProtocol().
Fixes: 119607552
Change-Id: Ib5bf45f11e49c56a34fda5fe3cb27485c2d7176c
2 files changed