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.Context; | 7 import android.content.Context; |
8 import android.os.Build; | 8 import android.os.Build; |
9 import android.os.Handler; | 9 import android.os.Handler; |
10 import android.os.HandlerThread; | 10 import android.os.HandlerThread; |
11 | 11 |
12 import org.chromium.base.Log; | 12 import org.chromium.base.Log; |
13 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
14 import org.chromium.base.annotations.JNINamespace; | 14 import org.chromium.base.annotations.JNINamespace; |
15 import org.chromium.base.library_loader.LibraryLoader; | 15 import org.chromium.base.library_loader.LibraryLoader; |
16 import org.chromium.base.library_loader.LibraryProcessType; | 16 import org.chromium.base.library_loader.LibraryProcessType; |
17 import org.chromium.base.library_loader.ProcessInitException; | 17 import org.chromium.base.library_loader.ProcessInitException; |
| 18 import org.chromium.base.test.util.UrlUtils; |
18 | 19 |
19 import java.util.concurrent.Callable; | 20 import java.util.concurrent.Callable; |
20 import java.util.concurrent.ExecutionException; | 21 import java.util.concurrent.ExecutionException; |
21 import java.util.concurrent.FutureTask; | 22 import java.util.concurrent.FutureTask; |
22 import java.util.concurrent.atomic.AtomicInteger; | 23 import java.util.concurrent.atomic.AtomicInteger; |
23 | 24 |
24 /** | 25 /** |
25 * Java bindings for running a net::test_server::EmbeddedTestServer. | 26 * Java bindings for running a net::test_server::EmbeddedTestServer. |
26 * | 27 * |
27 * This should not be used directly. Use {@link EmbeddedTestServer} instead. | 28 * This should not be used directly. Use {@link EmbeddedTestServer} instead. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 return false; | 70 return false; |
70 } | 71 } |
71 | 72 |
72 mHandlerThread = new HandlerThread("EmbeddedTestServer" + sCount.getAndI
ncrement()); | 73 mHandlerThread = new HandlerThread("EmbeddedTestServer" + sCount.getAndI
ncrement()); |
73 mHandlerThread.start(); | 74 mHandlerThread.start(); |
74 mHandler = new Handler(mHandlerThread.getLooper()); | 75 mHandler = new Handler(mHandlerThread.getLooper()); |
75 | 76 |
76 runOnHandlerThread(new Callable<Void>() { | 77 runOnHandlerThread(new Callable<Void>() { |
77 @Override | 78 @Override |
78 public Void call() { | 79 public Void call() { |
79 if (mNativeEmbeddedTestServer == 0) nativeInit(); | 80 if (mNativeEmbeddedTestServer == 0) nativeInit(UrlUtils.getIsola
tedTestRoot()); |
80 assert mNativeEmbeddedTestServer != 0; | 81 assert mNativeEmbeddedTestServer != 0; |
81 return null; | 82 return null; |
82 } | 83 } |
83 }); | 84 }); |
84 return true; | 85 return true; |
85 } | 86 } |
86 | 87 |
87 /** Starts the server. | 88 /** Starts the server. |
88 * | 89 * |
89 * Note that this should be called after handlers are set up, including any
relevant calls | 90 * Note that this should be called after handlers are set up, including any
relevant calls |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 assert mNativeEmbeddedTestServer == 0; | 199 assert mNativeEmbeddedTestServer == 0; |
199 mNativeEmbeddedTestServer = nativePtr; | 200 mNativeEmbeddedTestServer = nativePtr; |
200 } | 201 } |
201 | 202 |
202 @CalledByNative | 203 @CalledByNative |
203 private void clearNativePtr() { | 204 private void clearNativePtr() { |
204 assert mNativeEmbeddedTestServer != 0; | 205 assert mNativeEmbeddedTestServer != 0; |
205 mNativeEmbeddedTestServer = 0; | 206 mNativeEmbeddedTestServer = 0; |
206 } | 207 } |
207 | 208 |
208 private native void nativeInit(); | 209 private native void nativeInit(String testDataDir); |
209 private native void nativeDestroy(long nativeEmbeddedTestServerAndroid); | 210 private native void nativeDestroy(long nativeEmbeddedTestServerAndroid); |
210 private native boolean nativeStart(long nativeEmbeddedTestServerAndroid); | 211 private native boolean nativeStart(long nativeEmbeddedTestServerAndroid); |
211 private native boolean nativeShutdownAndWaitUntilComplete(long nativeEmbedde
dTestServerAndroid); | 212 private native boolean nativeShutdownAndWaitUntilComplete(long nativeEmbedde
dTestServerAndroid); |
212 private native String nativeGetURL(long nativeEmbeddedTestServerAndroid, Str
ing relativeUrl); | 213 private native String nativeGetURL(long nativeEmbeddedTestServerAndroid, Str
ing relativeUrl); |
213 private native void nativeAddDefaultHandlers( | 214 private native void nativeAddDefaultHandlers( |
214 long nativeEmbeddedTestServerAndroid, String directoryPath); | 215 long nativeEmbeddedTestServerAndroid, String directoryPath); |
215 private native void nativeServeFilesFromDirectory( | 216 private native void nativeServeFilesFromDirectory( |
216 long nativeEmbeddedTestServerAndroid, String directoryPath); | 217 long nativeEmbeddedTestServerAndroid, String directoryPath); |
217 } | 218 } |
OLD | NEW |