Commit 955c8c92 authored by hush's avatar hush Committed by Commit bot

Revert of Revert "TestWebServer needs to use a free port." (patchset #1 of...

Revert of Revert "TestWebServer needs to use a free port." (patchset #1 of https://codereview.chromium.org/514443002/)

Reason for revert:
I will land the following CL to fix the findbugs warning
https://codereview.chromium.org/513583002/

Then I will revert the revert.

Original issue's description:
> Revert "TestWebServer needs to use a free port."
>
> Causing Android Build (dbg) findbugs to fail.
>
> This reverts commit c4a3f88c.
>
> BUG=none
> TBR=hush
>
> Committed to pending queue: https://chromium.googlesource.com/chromium/src/+/b055d91

TBR=ajwong@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=none

Review URL: https://codereview.chromium.org/512573002

Cr-Commit-Position: refs/heads/master@{#292218}
parent 681cc8e6
...@@ -60,10 +60,8 @@ import javax.net.ssl.X509TrustManager; ...@@ -60,10 +60,8 @@ import javax.net.ssl.X509TrustManager;
* *
* Based heavily on the CTSWebServer in Android. * Based heavily on the CTSWebServer in Android.
*/ */
public class TestWebServer { public final class TestWebServer {
private static final String TAG = "TestWebServer"; private static final String TAG = "TestWebServer";
private static final int SERVER_PORT = 4444;
private static final int SSL_SERVER_PORT = 4445;
public static final String SHUTDOWN_PREFIX = "/shutdown"; public static final String SHUTDOWN_PREFIX = "/shutdown";
...@@ -108,19 +106,21 @@ public class TestWebServer { ...@@ -108,19 +106,21 @@ public class TestWebServer {
public TestWebServer(boolean ssl) throws Exception { public TestWebServer(boolean ssl) throws Exception {
mSsl = ssl; mSsl = ssl;
if (mSsl) { if (mSsl) {
mServerUri = "https:";
if (sSecureInstance != null) { if (sSecureInstance != null) {
sSecureInstance.shutdown(); sSecureInstance.shutdown();
} }
mServerUri = "https://localhost:" + SSL_SERVER_PORT;
} else { } else {
mServerUri = "http:";
if (sInstance != null) { if (sInstance != null) {
sInstance.shutdown(); sInstance.shutdown();
} }
mServerUri = "http://localhost:" + SERVER_PORT;
} }
setInstance(this, mSsl); setInstance(this, mSsl);
mServerThread = new ServerThread(this, mSsl); mServerThread = new ServerThread(this, mSsl);
mServerThread.start(); mServerThread.start();
mServerUri += "//localhost:" + mServerThread.mSocket.getLocalPort();
} }
/** /**
...@@ -552,10 +552,9 @@ public class TestWebServer { ...@@ -552,10 +552,9 @@ public class TestWebServer {
if (mIsSsl) { if (mIsSsl) {
mSslContext = SSLContext.getInstance("TLS"); mSslContext = SSLContext.getInstance("TLS");
mSslContext.init(getKeyManagers(), null, null); mSslContext.init(getKeyManagers(), null, null);
mSocket = mSslContext.getServerSocketFactory().createServerSocket( mSocket = mSslContext.getServerSocketFactory().createServerSocket(0);
SSL_SERVER_PORT);
} else { } else {
mSocket = new ServerSocket(SERVER_PORT); mSocket = new ServerSocket(0);
} }
return; return;
} catch (IOException e) { } catch (IOException e) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment