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

Unified Diff: base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java

Issue 951673002: Revert "Pull chromium at 2c3ffb2355a27c32f45e508ef861416b820c823b" (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months 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
« no previous file with comments | « base/process/process_win.cc ('k') | base/test/test_suite.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java
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
index a104831d57dff792cbd2219c843dba098a5e0745..b6c103d6174e299fa28814920def04db6c2e484f 100644
--- a/base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java
+++ b/base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java
@@ -4,20 +4,19 @@
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.TestResult;
+import junit.framework.TestSuite;
import org.chromium.base.test.util.MinAndroidSdkLevel;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* An Instrumentation test runner that checks SDK level for tests with specific requirements.
*/
@@ -25,94 +24,40 @@ public class BaseInstrumentationTestRunner extends InstrumentationTestRunner {
private static final String TAG = "BaseInstrumentationTestRunner";
- /**
- * An interface for classes that check whether a test case should be skipped.
- */
- public interface SkipCheck {
- /**
- * Checks whether the given test case should be skipped.
- *
- * @param testCase The test case to check.
- * @return Whether the test case should be skipped.
- */
- public boolean shouldSkip(TestCase testCase);
+ @Override
+ protected AndroidTestRunner getAndroidTestRunner() {
+ return new BaseAndroidTestRunner(getContext());
}
/**
- * A test result that can skip tests.
+ * Skips tests that don't meet the requirements of the current device.
*/
- public class SkippingTestResult extends TestResult {
-
- private final List<SkipCheck> mSkipChecks;
-
- /**
- * Creates an instance of SkippingTestResult.
- */
- public SkippingTestResult() {
- mSkipChecks = new ArrayList<SkipCheck>();
- }
-
- /**
- * Adds a check for whether a test should run.
- *
- * @param skipCheck The check to add.
- */
- public void addSkipCheck(SkipCheck skipCheck) {
- mSkipChecks.add(skipCheck);
- }
+ public class BaseAndroidTestRunner extends AndroidTestRunner {
+ private final Context mContext;
- private boolean shouldSkip(final TestCase test) {
- for (SkipCheck s : mSkipChecks) {
- if (s.shouldSkip(test)) return true;
- }
- return false;
+ public BaseAndroidTestRunner(Context context) {
+ mContext = context;
}
@Override
- protected void run(final TestCase test) {
- if (shouldSkip(test)) {
- startTest(test);
-
- Bundle skipResult = new Bundle();
- skipResult.putString("class", test.getClass().getName());
- skipResult.putString("test", test.getName());
- skipResult.putBoolean("test_skipped", true);
- sendStatus(0, skipResult);
-
- endTest(test);
- } else {
- super.run(test);
+ 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);
}
- }
- @Override
- protected AndroidTestRunner getAndroidTestRunner() {
- return new AndroidTestRunner() {
- @Override
- protected TestResult createTestResult() {
- SkippingTestResult r = new SkippingTestResult();
- r.addSkipCheck(new MinAndroidSdkLevelSkipCheck());
- return r;
- }
- };
- }
-
- /**
- * Checks the device's SDK level against any specified minimum requirement.
- */
- public static class MinAndroidSdkLevelSkipCheck implements SkipCheck {
-
- /**
- * If {@link org.chromium.base.test.util.MinAndroidSdkLevel} is present, checks its value
- * against the device's SDK level.
- *
- * @param testCase The test to check.
- * @return true if the device's SDK level is below the specified minimum.
- */
- @Override
- public boolean shouldSkip(TestCase testCase) {
- Class<?> testClass = testCase.getClass();
+ 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()) {
@@ -124,6 +69,28 @@ public class BaseInstrumentationTestRunner extends InstrumentationTestRunner {
}
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();
+ }
+ }
}
« no previous file with comments | « base/process/process_win.cc ('k') | base/test/test_suite.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698