Chromium Code Reviews| Index: net/test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java |
| diff --git a/net/test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java b/net/test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java |
| index 5c781e533a3a2198d3fd2c1b469d9868045b99fa..ff52e7d456293efde7e86699242da9c1eb3614ae 100644 |
| --- a/net/test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java |
| +++ b/net/test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java |
| @@ -79,14 +79,13 @@ public class EmbeddedTestServer { |
| /** Bind the service that will run the native server object. |
| * |
| * @param context The context to use to bind the service. This will also be used to unbind |
| - # the service at server destruction time. |
| + * the service at server destruction time. |
| */ |
| public void initializeNative(Context context) throws InterruptedException { |
| mContext = context; |
| Intent intent = new Intent(EMBEDDED_TEST_SERVER_SERVICE); |
| - intent.setClassName( |
| - "org.chromium.net.test.support", "org.chromium.net.test.EmbeddedTestServerService"); |
| + setIntentClassName(intent); |
| if (!mContext.bindService(intent, mConn, Context.BIND_AUTO_CREATE)) { |
| throw new EmbeddedTestServerFailure( |
| "Unable to bind to the EmbeddedTestServer service."); |
| @@ -112,6 +111,15 @@ public class EmbeddedTestServer { |
| } |
| } |
| + /** Set intent package and class name that will pass to the service. |
| + * |
| + * @param intent The intent to use to pass into the service. |
| + */ |
| + protected void setIntentClassName(Intent intent) { |
| + intent.setClassName( |
| + "org.chromium.net.test.support", "org.chromium.net.test.EmbeddedTestServerService"); |
| + } |
| + |
| /** Add the default handlers and serve files from the provided directory relative to the |
| * external storage directory. |
| * |
| @@ -232,13 +240,26 @@ public class EmbeddedTestServer { |
| */ |
| public static EmbeddedTestServer createAndStartServer(Context context) |
| throws InterruptedException { |
| - EmbeddedTestServer server = new EmbeddedTestServer(); |
| + return createAndStartServer(new EmbeddedTestServer(), context); |
| + } |
| + |
| + /** Create and initialize a server with the default handlers. |
| + * |
| + * This handles native object initialization, server configuration, and server initialization. |
| + * On returning, the server is ready for use. |
| + * |
| + * @param server The server instance that will be initialized. |
| + * @param context The context in which the server will run. |
| + * @return The created server. |
| + */ |
| + public static <T extends EmbeddedTestServer> T createAndStartServer(T server, Context context) |
|
jbudorick
2017/03/13 23:32:54
nit: maybe name this one "initializeAndStartServer
shenghuazhang
2017/03/17 01:07:15
Make sense! Will rename it.
|
| + throws InterruptedException { |
| server.initializeNative(context); |
| server.addDefaultHandlers(""); |
| if (!server.start()) { |
| throw new EmbeddedTestServerFailure("Failed to start serving using default handlers."); |
| } |
| - return server; |
| + return (T) server; |
|
jbudorick
2017/03/13 23:32:54
server is already an instance of T. Why is the cas
shenghuazhang
2017/03/17 01:07:15
Done.
|
| } |
| /** Get the full URL for the given relative URL. |