Chromium Code Reviews| 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..4ce411249566ccb6aab40f02e2ca6145d89b48fc |
| --- /dev/null |
| +++ b/components/cronet/android/test/smoketests/src/org/chromium/net/smoke/ChromiumNativeTestSupport.java |
| @@ -0,0 +1,125 @@ |
| +// 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 java.io.IOException; |
| + |
| +/** |
| + * Provides support for tests that depend on QUIC and HTTP2 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 HTTP2: |
| + return new Http2TestServer(context); |
| + case HTTP1: |
| + 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 { |
|
mef
2016/12/20 20:17:45
private
kapishnikov
2016/12/22 19:21:13
Done.
|
| + 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 Http2TestServer implements TestServer { |
|
mef
2016/12/20 20:17:45
private
kapishnikov
2016/12/22 19:21:13
Done.
|
| + private final Context mContext; |
| + |
| + Http2TestServer(Context context) { |
| + mContext = context; |
| + } |
| + |
| + @Override |
| + public boolean start() { |
| + try { |
| + return org.chromium.net.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 { |
| + org.chromium.net.Http2TestServer.shutdownHttp2TestServer(); |
| + } catch (Exception e) { |
| + Log.e(TAG, "Exception during Http2TestServer shutdown", e); |
| + } |
| + } |
| + |
| + @Override |
| + public String getSuccessURL() { |
| + return org.chromium.net.Http2TestServer.getEchoMethodUrl(); |
| + } |
| + |
| + @Override |
| + public void close() throws IOException { |
|
mef
2016/12/20 20:17:45
It seems that all implementations of close() call
kapishnikov
2016/12/22 19:21:13
This method is part of Closeable interface. It is
|
| + shutdown(); |
| + } |
| + } |
| +} |