Index: components/cronet/android/test/smoketests/src/org/chromium/net/smoke/ChromiumNativeTestSupport.java |
diff --git a/components/cronet/android/test/smoketests/src/org/chromium/net/smoke/ChromiumNativeTestSupport.java b/components/cronet/android/test/smoketests/src/org/chromium/net/smoke/ChromiumNativeTestSupport.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f519cdaee231722b49a824fce740d62fd29eafc2 |
--- /dev/null |
+++ b/components/cronet/android/test/smoketests/src/org/chromium/net/smoke/ChromiumNativeTestSupport.java |
@@ -0,0 +1,126 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.net.smoke; |
+ |
+import android.content.Context; |
+ |
+import org.json.JSONObject; |
+ |
+import org.chromium.base.Log; |
+import org.chromium.net.CronetTestUtil; |
+import org.chromium.net.ExperimentalCronetEngine; |
+import org.chromium.net.Http2TestServer; |
+ |
+import java.io.IOException; |
+ |
+/** |
+ * Provides support for tests that depend on QUIC and H2 servers. |
+ */ |
+class ChromiumNativeTestSupport extends ChromiumJavaOnlyTestSupport { |
+ private static final String TAG = "NativeTestSupport"; |
+ |
+ @Override |
+ public TestServer createTestServer(Context context, Protocol protocol) { |
+ switch (protocol) { |
+ case QUIC: |
+ return new QuicTestServer(context); |
+ case H2: |
+ return new H2TestServer(context); |
+ case H1: |
+ return super.createTestServer(context, protocol); |
+ default: |
+ throw new RuntimeException("Unknown server protocol: " + protocol); |
+ } |
+ } |
+ |
+ @Override |
+ public void addHostResolverRules(JSONObject json) { |
+ try { |
+ JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules(); |
+ json.put("HostResolverRules", hostResolverParams); |
+ } catch (Exception e) { |
+ throw new RuntimeException(e); |
+ } |
+ } |
+ |
+ @Override |
+ public void installMockCertVerifierForTesting(ExperimentalCronetEngine.Builder builder) { |
+ CronetTestUtil.setMockCertVerifierForTesting( |
+ builder, org.chromium.net.QuicTestServer.createMockCertVerifier()); |
+ } |
+ |
+ @Override |
+ public void loadTestNativeLibrary() { |
+ System.loadLibrary("cronet_tests"); |
+ } |
+ |
+ static class QuicTestServer implements TestServer { |
+ private final Context mContext; |
+ |
+ QuicTestServer(Context context) { |
+ mContext = context; |
+ } |
+ |
+ @Override |
+ public boolean start() { |
+ org.chromium.net.QuicTestServer.startQuicTestServer(mContext); |
+ return true; |
+ } |
+ |
+ @Override |
+ public void shutdown() { |
+ org.chromium.net.QuicTestServer.shutdownQuicTestServer(); |
+ } |
+ |
+ @Override |
+ public String getSuccessURL() { |
+ return org.chromium.net.QuicTestServer.getServerURL() + "/simple.txt"; |
+ } |
+ |
+ @Override |
+ public void close() throws IOException { |
+ shutdown(); |
+ } |
+ } |
+ |
+ static class H2TestServer implements TestServer { |
+ private final Context mContext; |
+ |
+ H2TestServer(Context context) { |
+ mContext = context; |
+ } |
+ |
+ @Override |
+ public boolean start() { |
+ try { |
+ return Http2TestServer.startHttp2TestServer(mContext, |
+ org.chromium.net.QuicTestServer.getServerCert(), |
+ org.chromium.net.QuicTestServer.getServerCertKey()); |
+ } catch (Exception e) { |
+ Log.e(TAG, "Exception during Http2TestServer start", e); |
+ return false; |
+ } |
+ } |
+ |
+ @Override |
+ public void shutdown() { |
+ try { |
+ Http2TestServer.shutdownHttp2TestServer(); |
+ } catch (Exception e) { |
+ Log.e(TAG, "Exception during Http2TestServer shutdown", e); |
+ } |
+ } |
+ |
+ @Override |
+ public String getSuccessURL() { |
+ return Http2TestServer.getEchoMethodUrl(); |
+ } |
+ |
+ @Override |
+ public void close() throws IOException { |
+ shutdown(); |
+ } |
+ } |
+} |