Merge changes I54d367fd,Ib789dc59
* changes: cronet: update tests to use android.net.http API cronet: use defaults to enable or disable tests
This commit is contained in:
@@ -26,10 +26,28 @@ cronet_test_java_defaults = "CronetTestJavaDefaultsEnabled"
|
||||
// as cronet_test_java_defaults may have different values
|
||||
// depending on the branch
|
||||
|
||||
java_defaults {
|
||||
name: "CronetTestJavaDefaultsEnabled",
|
||||
enabled: true,
|
||||
}
|
||||
|
||||
java_defaults {
|
||||
name: "CronetTestJavaDefaultsDisabled",
|
||||
enabled: false,
|
||||
}
|
||||
|
||||
java_defaults {
|
||||
name: "CronetTestJavaDefaults",
|
||||
defaults: [cronet_test_java_defaults],
|
||||
}
|
||||
|
||||
android_test {
|
||||
name: "CtsNetHttpTestCases",
|
||||
compile_multilib: "both", // Include both the 32 and 64 bit versions
|
||||
defaults: ["cts_defaults"],
|
||||
defaults: [
|
||||
"CronetTestJavaDefaults",
|
||||
"cts_defaults",
|
||||
],
|
||||
sdk_version: "test_current",
|
||||
srcs: [
|
||||
"src/**/*.java",
|
||||
@@ -47,7 +65,7 @@ android_test {
|
||||
"android.test.base",
|
||||
"android.test.mock",
|
||||
"androidx.annotation_annotation",
|
||||
"framework-cronet",
|
||||
"framework-tethering",
|
||||
"org.apache.http.legacy",
|
||||
],
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
<application android:networkSecurityConfig="@xml/network_security_config">
|
||||
<uses-library android:name="android.test.runner"/>
|
||||
<uses-library android:name="framework-cronet"/>
|
||||
</application>
|
||||
|
||||
<instrumentation
|
||||
|
||||
@@ -22,6 +22,10 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.http.HttpEngine;
|
||||
import android.net.http.UrlRequest;
|
||||
import android.net.http.UrlRequest.Status;
|
||||
import android.net.http.UrlResponseInfo;
|
||||
import android.net.http.cts.util.CronetCtsTestServer;
|
||||
import android.net.http.cts.util.TestStatusListener;
|
||||
import android.net.http.cts.util.TestUrlRequestCallback;
|
||||
@@ -31,10 +35,6 @@ import androidx.annotation.NonNull;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.chromium.net.CronetEngine;
|
||||
import org.chromium.net.UrlRequest;
|
||||
import org.chromium.net.UrlRequest.Status;
|
||||
import org.chromium.net.UrlResponseInfo;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -44,7 +44,7 @@ import org.junit.runner.RunWith;
|
||||
public class CronetUrlRequestTest {
|
||||
private static final String TAG = CronetUrlRequestTest.class.getSimpleName();
|
||||
|
||||
@NonNull private CronetEngine mCronetEngine;
|
||||
@NonNull private HttpEngine mHttpEngine;
|
||||
@NonNull private TestUrlRequestCallback mCallback;
|
||||
@NonNull private ConnectivityManager mCm;
|
||||
@NonNull private CronetCtsTestServer mTestServer;
|
||||
@@ -53,19 +53,19 @@ public class CronetUrlRequestTest {
|
||||
public void setUp() throws Exception {
|
||||
Context context = InstrumentationRegistry.getInstrumentation().getContext();
|
||||
mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
CronetEngine.Builder builder = new CronetEngine.Builder(context);
|
||||
builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_IN_MEMORY, 100 * 1024)
|
||||
.enableHttp2(true)
|
||||
// .enableBrotli(true)
|
||||
.enableQuic(true);
|
||||
mCronetEngine = builder.build();
|
||||
HttpEngine.Builder builder = new HttpEngine.Builder(context);
|
||||
builder.setEnableHttpCache(HttpEngine.Builder.HTTP_CACHE_IN_MEMORY, 100 * 1024)
|
||||
.setEnableHttp2(true)
|
||||
// .setEnableBrotli(true)
|
||||
.setEnableQuic(true);
|
||||
mHttpEngine = builder.build();
|
||||
mCallback = new TestUrlRequestCallback();
|
||||
mTestServer = new CronetCtsTestServer(context);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
mCronetEngine.shutdown();
|
||||
mHttpEngine.shutdown();
|
||||
mTestServer.shutdown();
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class CronetUrlRequestTest {
|
||||
}
|
||||
|
||||
private UrlRequest buildUrlRequest(String url) {
|
||||
return mCronetEngine.newUrlRequestBuilder(url, mCallback, mCallback.getExecutor()).build();
|
||||
return mHttpEngine.newUrlRequestBuilder(url, mCallback, mCallback.getExecutor()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package android.net.http.cts.util
|
||||
|
||||
import android.net.http.UrlRequest.StatusListener
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.TimeUnit
|
||||
import org.chromium.net.UrlRequest.StatusListener
|
||||
import org.junit.Assert.assertSame
|
||||
|
||||
private const val TIMEOUT_MS = 12000L
|
||||
|
||||
@@ -24,15 +24,14 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.net.http.CallbackException;
|
||||
import android.net.http.HttpException;
|
||||
import android.net.http.InlineExecutionProhibitedException;
|
||||
import android.net.http.UrlRequest;
|
||||
import android.net.http.UrlResponseInfo;
|
||||
import android.os.ConditionVariable;
|
||||
import android.os.StrictMode;
|
||||
|
||||
import org.chromium.net.CallbackException;
|
||||
import org.chromium.net.CronetException;
|
||||
import org.chromium.net.InlineExecutionProhibitedException;
|
||||
import org.chromium.net.UrlRequest;
|
||||
import org.chromium.net.UrlResponseInfo;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -50,7 +49,7 @@ public class TestUrlRequestCallback extends UrlRequest.Callback {
|
||||
public ArrayList<UrlResponseInfo> mRedirectResponseInfoList = new ArrayList<>();
|
||||
public ArrayList<String> mRedirectUrlList = new ArrayList<>();
|
||||
public UrlResponseInfo mResponseInfo;
|
||||
public CronetException mError;
|
||||
public HttpException mError;
|
||||
|
||||
public ResponseStep mResponseStep = ResponseStep.NOTHING;
|
||||
|
||||
@@ -89,7 +88,7 @@ public class TestUrlRequestCallback extends UrlRequest.Callback {
|
||||
// Signaled on each step when mAutoAdvance is false.
|
||||
private final ConditionVariable mStepBlock = new ConditionVariable();
|
||||
|
||||
// Executor Service for Cronet callbacks.
|
||||
// Executor Service for Http callbacks.
|
||||
private final ExecutorService mExecutorService;
|
||||
private Thread mExecutorThread;
|
||||
|
||||
@@ -349,7 +348,7 @@ public class TestUrlRequestCallback extends UrlRequest.Callback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(UrlRequest request, UrlResponseInfo info, CronetException error) {
|
||||
public void onFailed(UrlRequest request, UrlResponseInfo info, HttpException error) {
|
||||
// If the failure is because of prohibited direct execution, the test shouldn't fail
|
||||
// since the request already did.
|
||||
if (error.getCause() instanceof InlineExecutionProhibitedException) {
|
||||
|
||||
Reference in New Issue
Block a user