Chromium Code Reviews| Index: components/cronet/android/test/smoketests/src/org/chromium/net/smoke/CronetTestBase.java |
| diff --git a/components/cronet/android/test/smoketests/src/org/chromium/net/smoke/CronetTestBase.java b/components/cronet/android/test/smoketests/src/org/chromium/net/smoke/CronetTestBase.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..68de5eafd94c12bfcd2ccb376a53d9bd98b8fa14 |
| --- /dev/null |
| +++ b/components/cronet/android/test/smoketests/src/org/chromium/net/smoke/CronetTestBase.java |
| @@ -0,0 +1,74 @@ |
| +// 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 android.test.AndroidTestCase; |
| + |
| +import org.chromium.net.CronetEngine; |
| +import org.chromium.net.ExperimentalCronetEngine; |
| +import org.chromium.net.UrlResponseInfo; |
| + |
| +/** |
| + * Base test class. This class should not import any classes from the org.chromium.base package. |
| + */ |
| +public class CronetTestBase extends AndroidTestCase { |
|
mef
2016/12/20 20:17:45
Maybe rename into CronetSmokeTestCase to avoid con
kapishnikov
2016/12/22 19:21:13
Good idea. Done. Renamed also NativeCronetTestBase
|
| + /** |
| + * The key in the string resource file that specifies {@link TestSupport} that should |
| + * be instantiated. |
| + */ |
| + private static final String SUPPORT_IMPL_RES_KEY = "TestSupportImplClass"; |
| + |
| + protected ExperimentalCronetEngine.Builder mCronetEngineBuilder; |
| + protected CronetEngine mCronetEngine; |
| + protected TestSupport mTestSupport; |
| + |
| + @Override |
| + protected void setUp() throws Exception { |
| + super.setUp(); |
| + mCronetEngineBuilder = new ExperimentalCronetEngine.Builder(getContext()); |
| + initTestSupport(); |
| + } |
| + |
| + @Override |
| + protected void tearDown() throws Exception { |
| + if (mCronetEngine != null) { |
| + mCronetEngine.shutdown(); |
| + } |
| + super.tearDown(); |
| + } |
| + |
| + protected void initCronetEngine() { |
| + mCronetEngine = mCronetEngineBuilder.build(); |
| + } |
| + |
| + static void assertSuccessfulNonEmptyResponse(UrlResponseInfo responseInfo, String url) { |
| + assertNotNull(responseInfo); |
| + assertFalse(responseInfo.wasCached()); |
| + assertEquals(url, responseInfo.getUrl()); |
| + assertEquals(url, responseInfo.getUrlChain().get(responseInfo.getUrlChain().size() - 1)); |
| + assertEquals(200, responseInfo.getHttpStatusCode()); |
| + assertTrue(responseInfo.toString().length() > 0); |
| + } |
| + |
| + static void assertJavaEngine(CronetEngine engine) { |
| + assertNotNull(engine); |
| + assertEquals("org.chromium.net.impl.JavaCronetEngine", engine.getClass().getName()); |
| + } |
| + |
| + static void assertNativeEngine(CronetEngine engine) { |
| + assertNotNull(engine); |
| + assertEquals("org.chromium.net.impl.CronetUrlRequestContext", engine.getClass().getName()); |
| + } |
| + |
| + private void initTestSupport() throws Exception { |
| + Context ctx = getContext(); |
| + String packageName = ctx.getPackageName(); |
|
mef
2016/12/20 20:17:45
Maybe add comment explaining that name of implemen
kapishnikov
2016/12/22 19:21:13
Done. The explanation is also present in TestSuppo
|
| + int resId = ctx.getResources().getIdentifier(SUPPORT_IMPL_RES_KEY, "string", packageName); |
| + String className = ctx.getResources().getString(resId); |
| + Class<? extends TestSupport> cl = Class.forName(className).asSubclass(TestSupport.class); |
| + mTestSupport = cl.newInstance(); |
| + } |
| +} |