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

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

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 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/sys_info_android.cc ('k') | base/time/time.h » ('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
new file mode 100644
index 0000000000000000000000000000000000000000..b6c103d6174e299fa28814920def04db6c2e484f
--- /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();
+ }
+ }
+}
« no previous file with comments | « base/sys_info_android.cc ('k') | base/time/time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698