| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.net.test; | 5 package org.chromium.net.test; |
| 6 | 6 |
| 7 import android.content.ComponentName; | 7 import android.content.ComponentName; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.ServiceConnection; | 10 import android.content.ServiceConnection; |
| 11 import android.os.Environment; |
| 11 import android.os.IBinder; | 12 import android.os.IBinder; |
| 12 import android.os.RemoteException; | 13 import android.os.RemoteException; |
| 13 | 14 |
| 14 import org.chromium.base.Log; | 15 import org.chromium.base.Log; |
| 15 | 16 |
| 16 import java.io.File; | 17 import java.io.File; |
| 17 | 18 |
| 18 /** A simple file server for java tests. | 19 /** A simple file server for java tests. |
| 19 * | 20 * |
| 20 * An example use: | 21 * An example use: |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 throw new EmbeddedTestServerFailure("Failed to start server.", e); | 188 throw new EmbeddedTestServerFailure("Failed to start server.", e); |
| 188 } | 189 } |
| 189 } | 190 } |
| 190 | 191 |
| 191 /** Create and initialize a server that serves files from the provided direc
tory. | 192 /** Create and initialize a server that serves files from the provided direc
tory. |
| 192 * | 193 * |
| 193 * This handles native object initialization, server configuration, and ser
ver initialization. | 194 * This handles native object initialization, server configuration, and ser
ver initialization. |
| 194 * On returning, the server is ready for use. | 195 * On returning, the server is ready for use. |
| 195 * | 196 * |
| 196 * @param context The context in which the server will run. | 197 * @param context The context in which the server will run. |
| 197 * @param directory The directory from which files should be served. | 198 * @param directory The directory from which files should be served. This m
ust be |
| 199 * Environment.getExternalStorageDirectory(). |
| 198 * @return The created server. | 200 * @return The created server. |
| 199 */ | 201 */ |
| 200 public static EmbeddedTestServer createAndStartFileServer(Context context, F
ile directory) | 202 public static EmbeddedTestServer createAndStartFileServer(Context context, F
ile directory) |
| 201 throws InterruptedException { | 203 throws InterruptedException { |
| 202 EmbeddedTestServer server = new EmbeddedTestServer(); | 204 // TODO(jbudorick): Update all callers to use createAndStartDefaultServe
r() directly. |
| 203 server.initializeNative(context); | 205 if (!directory.equals(Environment.getExternalStorageDirectory())) { |
| 204 server.serveFilesFromDirectory(directory); | 206 throw new IllegalArgumentException("Expected directory to be Externa
lStorageDirectory"); |
| 205 if (!server.start()) { | |
| 206 throw new EmbeddedTestServerFailure( | |
| 207 "Failed to start serving files from " + directory.getPath())
; | |
| 208 } | 207 } |
| 209 return server; | 208 return createAndStartDefaultServer(context); |
| 210 } | 209 } |
| 211 | 210 |
| 212 /** Create and initialize a server with the default handlers. | 211 /** Create and initialize a server with the default handlers. |
| 213 * | 212 * |
| 214 * This handles native object initialization, server configuration, and ser
ver initialization. | 213 * This handles native object initialization, server configuration, and ser
ver initialization. |
| 215 * On returning, the server is ready for use. | 214 * On returning, the server is ready for use. |
| 216 * | 215 * |
| 217 * @param context The context in which the server will run. | 216 * @param context The context in which the server will run. |
| 218 * @return The created server. | 217 * @return The created server. |
| 219 */ | 218 */ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 * | 276 * |
| 278 * This handles stopping the server and destroying the native object. | 277 * This handles stopping the server and destroying the native object. |
| 279 */ | 278 */ |
| 280 public void stopAndDestroyServer() { | 279 public void stopAndDestroyServer() { |
| 281 if (!shutdownAndWaitUntilComplete()) { | 280 if (!shutdownAndWaitUntilComplete()) { |
| 282 throw new EmbeddedTestServerFailure("Failed to stop server."); | 281 throw new EmbeddedTestServerFailure("Failed to stop server."); |
| 283 } | 282 } |
| 284 destroy(); | 283 destroy(); |
| 285 } | 284 } |
| 286 } | 285 } |
| OLD | NEW |