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

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

Issue 1761383002: [Android] Restrict tests inheriting from DocumentModeTestBase to phones. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 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
Index: base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheck.java
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheck.java b/base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheck.java
new file mode 100644
index 0000000000000000000000000000000000000000..c95ae224364ba3065c1f47552efba0573d713ad6
--- /dev/null
+++ b/base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheck.java
@@ -0,0 +1,47 @@
+// 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.base.test.util;
+
+import android.os.Build;
+
+import junit.framework.TestCase;
+
+import org.chromium.base.Log;
+
+import java.lang.reflect.Method;
+
+/**
+ * Checks the device's SDK level against any specified minimum requirement.
+ */
+public class MinAndroidSdkLevelSkipCheck extends SkipCheck {
+
+ private static final String TAG = "base_test";
+
+ /**
+ * If {@link 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();
+ Method testMethod = getTestMethod(testCase);
+
+ int minSdkLevel = 0;
+ for (MinAndroidSdkLevel m : getAnnotations(testMethod, MinAndroidSdkLevel.class)) {
+ minSdkLevel = Math.max(minSdkLevel, m.value());
+ }
+
+ if (Build.VERSION.SDK_INT < minSdkLevel) {
+ Log.i(TAG, "Test " + testClass.getName() + "#" + testCase.getName()
+ + " is not enabled at SDK level " + Build.VERSION.SDK_INT
+ + ".");
+ return true;
+ }
+ return false;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698