Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: components/cronet/android/test/smoketests/src/org/chromium/net/smoke/ChromiumNativeTestSupport.java

Issue 2561803002: Cronet smoke tests (Closed)
Patch Set: Moved to android.support.test.filters & added support for network-security-config Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c80bc931069de88445c6183fc526e49f1048734f
--- /dev/null
+++ b/components/cronet/android/test/smoketests/src/org/chromium/net/smoke/ChromiumNativeTestSupport.java
@@ -0,0 +1,113 @@
+// 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;
+
+/**
+ * Provides support for tests that depend on QUIC and HTTP2 servers.
+ */
+class ChromiumNativeTestSupport extends ChromiumPlatformOnlyTestSupport {
+ 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 experimentalOptionsJson) {
+ try {
+ JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules();
+ experimentalOptionsJson.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");
+ }
+
+ private 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";
+ }
+ }
+
+ private static class Http2TestServer implements TestServer {
+ 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();
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698