| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.net.test; |
| 6 |
| 7 import android.content.Context; |
| 8 |
| 9 /** A simple file server for java android webview tests which extends |
| 10 * from class EmbeddedTestServer. It is able to add custom handlers |
| 11 * which registers with net::test_server::EmbeddedTestServer native code. |
| 12 * |
| 13 * An example use: |
| 14 * AwEmbeddedTestServer s = new AwEmbeddedTestServer(); |
| 15 * s.initializeNative(); |
| 16 * s.serveFilesFromDirectory("/path/to/my/directory"); |
| 17 * if (!s.start()) { |
| 18 * throw new SomeKindOfException("Unable to initialize EmbeddedTestServer.
"); |
| 19 * } |
| 20 * |
| 21 * // serve requests... |
| 22 * s.getURL("/foo/bar.txt"); |
| 23 * |
| 24 * s.shutdownAndWait(); |
| 25 * s.destroy(); |
| 26 * |
| 27 * Note that this runs net::test_server::EmbeddedTestServer in a service in a se
parate APK. |
| 28 */ |
| 29 public class AwEmbeddedTestServer extends EmbeddedTestServer { |
| 30 private static long[] sCustomHandlers; |
| 31 |
| 32 /** Create and initialize a server with the default and custom handlers. |
| 33 * |
| 34 * This handles native object initialization, server configuration, and ser
ver initialization. |
| 35 * On returning, the server is ready for use. |
| 36 * |
| 37 * @param context The context in which the server will run. |
| 38 * @return The created server. |
| 39 */ |
| 40 public static AwEmbeddedTestServer createAndStartServer(Context context) |
| 41 throws InterruptedException { |
| 42 AwEmbeddedTestServer server = new AwEmbeddedTestServer(); |
| 43 server.initializeNative(context); |
| 44 AwEmbeddedTestServer.sCustomHandlers = server.getCustomHandlers(); |
| 45 server.addDefaultHandlers(""); |
| 46 server.registerRequestHandlers(sCustomHandlers); |
| 47 if (!server.start()) { |
| 48 throw new EmbeddedTestServerFailure( |
| 49 "Failed to start serving using default or custom handlers.")
; |
| 50 } |
| 51 return server; |
| 52 } |
| 53 } |
| OLD | NEW |