Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.os.ConditionVariable; | |
| 8 | |
| 9 import org.chromium.base.annotations.CalledByNative; | |
| 7 import org.chromium.base.annotations.JNINamespace; | 10 import org.chromium.base.annotations.JNINamespace; |
| 8 | 11 |
| 9 /** | 12 /** |
| 10 * Utilities for Cronet testing | 13 * Utilities for Cronet testing |
| 11 */ | 14 */ |
| 12 @JNINamespace("cronet") | 15 @JNINamespace("cronet") |
| 13 public class CronetTestUtil { | 16 public class CronetTestUtil { |
| 17 private static final ConditionVariable sHostResolverBlock = new ConditionVar iable(); | |
| 18 | |
| 14 /** | 19 /** |
| 15 * Start QUIC server on local host. | 20 * Registers customized DNS mapping for testing host names used by test serv ers. |
|
mef
2016/01/26 21:45:03
I think we should specify fake host names as stati
pauljensen
2016/01/29 17:10:09
They can be accessed via other APIs; I've listed t
| |
| 16 * @return non-zero QUIC server port number on success or 0 if failed. | 21 * @param cronetEngine {@link CronetEngine} that this mapping should apply t o. |
| 22 * @param isLegacyAPI {@code true} if this context adapter is a part of the | |
|
mef
2016/01/26 21:45:03
obsolete @param.
pauljensen
2016/01/29 17:10:09
Done.
| |
| 23 * old API. | |
| 24 * @param destination host to map to (e.g. 127.0.0.1) | |
| 17 */ | 25 */ |
| 18 public static int startQuicServer() { | 26 public static void registerHostResolverProc(CronetEngine cronetEngine, Strin g destination) { |
| 19 return nativeStartQuicServer(); | 27 long contextAdapter = |
| 28 ((CronetUrlRequestContext) cronetEngine).getUrlRequestContextAda pter(); | |
| 29 nativeRegisterHostResolverProc(contextAdapter, false, destination); | |
| 30 sHostResolverBlock.block(); | |
| 31 sHostResolverBlock.close(); | |
| 20 } | 32 } |
| 21 | 33 |
| 22 private static native int nativeStartQuicServer(); | 34 /** |
| 35 * Registers customized DNS mapping for testing host names used by test serv ers. | |
| 36 * @param requestFactory {@link HttpUrlRequestFactory} that this mapping sho uld apply to. | |
| 37 * @param isLegacyAPI {@code true} if this context adapter is a part of the | |
|
mef
2016/01/26 21:45:03
obsolete @param.
pauljensen
2016/01/29 17:10:09
Done.
| |
| 38 * old API. | |
| 39 * @param destination host to map to (e.g. 127.0.0.1) | |
| 40 */ | |
| 41 public static void registerHostResolverProc( | |
| 42 HttpUrlRequestFactory requestFactory, String destination) { | |
| 43 long contextAdapter = ((ChromiumUrlRequestFactory) requestFactory) | |
| 44 .getRequestContext() | |
| 45 .getUrlRequestContextAdapter(); | |
| 46 nativeRegisterHostResolverProc(contextAdapter, true, destination); | |
| 47 sHostResolverBlock.block(); | |
| 48 sHostResolverBlock.close(); | |
| 49 } | |
| 50 | |
| 51 @CalledByNative | |
| 52 private static void onHostResolverProcRegistered() { | |
| 53 sHostResolverBlock.open(); | |
| 54 } | |
| 55 | |
| 56 private static native void nativeRegisterHostResolverProc( | |
| 57 long contextAdapter, boolean isLegacyAPI, String destination); | |
| 23 } | 58 } |
| OLD | NEW |