diff options
author | jbudorick <jbudorick@chromium.org> | 2015-01-07 07:44:54 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-07 15:45:38 +0000 |
commit | e976259f57e544198c6f421ab86d5f654fe52795 (patch) | |
tree | df9a0402ec3be6b1cce4e0736ff66c67d8e58456 /base/test/android | |
parent | 69053126a2bd1cde775e5d583eb4eaf6ef7a31ea (diff) | |
download | chromium_src-e976259f57e544198c6f421ab86d5f654fe52795.zip chromium_src-e976259f57e544198c6f421ab86d5f654fe52795.tar.gz chromium_src-e976259f57e544198c6f421ab86d5f654fe52795.tar.bz2 |
[Android] Add a device-side test HTTP server via ChromeInstrumentationTestRunner.
BUG=444049
Review URL: https://codereview.chromium.org/814143005
Cr-Commit-Position: refs/heads/master@{#310286}
Diffstat (limited to 'base/test/android')
-rw-r--r-- | base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java b/base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java new file mode 100644 index 0000000..b6c103d --- /dev/null +++ b/base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java @@ -0,0 +1,96 @@ +// Copyright 2014 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.base.test; + +import android.content.Context; +import android.os.Build; +import android.os.Bundle; +import android.test.AndroidTestRunner; +import android.test.InstrumentationTestRunner; +import android.util.Log; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.chromium.base.test.util.MinAndroidSdkLevel; + +/** + * An Instrumentation test runner that checks SDK level for tests with specific requirements. + */ +public class BaseInstrumentationTestRunner extends InstrumentationTestRunner { + + private static final String TAG = "BaseInstrumentationTestRunner"; + + @Override + protected AndroidTestRunner getAndroidTestRunner() { + return new BaseAndroidTestRunner(getContext()); + } + + /** + * Skips tests that don't meet the requirements of the current device. + */ + public class BaseAndroidTestRunner extends AndroidTestRunner { + private final Context mContext; + + public BaseAndroidTestRunner(Context context) { + mContext = context; + } + + @Override + public void setTest(Test test) { + super.setTest(test); + TestSuite revisedTestSuite = new TestSuite(); + for (TestCase testCase : this.getTestCases()) { + Class<?> testClass = testCase.getClass(); + if (shouldSkip(testClass, testCase)) { + revisedTestSuite.addTest(new SkippedTest(testCase)); + Bundle skipResult = new Bundle(); + skipResult.putBoolean("test_skipped", true); + sendStatus(0, skipResult); + } else { + revisedTestSuite.addTest(testCase); + } + } + super.setTest(revisedTestSuite); + } + + protected boolean shouldSkip(Class<?> testClass, TestCase testCase) { + if (testClass.isAnnotationPresent(MinAndroidSdkLevel.class)) { + MinAndroidSdkLevel v = testClass.getAnnotation(MinAndroidSdkLevel.class); + if (Build.VERSION.SDK_INT < v.value()) { + Log.i(TAG, "Test " + testClass.getName() + "#" + testCase.getName() + + " is not enabled at SDK level " + Build.VERSION.SDK_INT + + "."); + return true; + } + } + return false; + } + + protected Context getContext() { + return mContext; + } + } + + /** + * Replaces a TestCase that should be skipped. + */ + public static class SkippedTest extends TestCase { + + public SkippedTest(TestCase skipped) { + super(skipped.getClass().getName() + "#" + skipped.getName()); + } + + @Override + protected void runTest() throws Throwable { + } + + @Override + public String toString() { + return "SKIPPED " + super.toString(); + } + } +} |