 Chromium Code Reviews
 Chromium Code Reviews Issue 1761383002:
  [Android] Restrict tests inheriting from DocumentModeTestBase to phones.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1761383002:
  [Android] Restrict tests inheriting from DocumentModeTestBase to phones.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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; | 
| 
newt (away)
2016/03/07 18:07:09
One import from each top-level package. Impressive
 
jbudorick
2016/03/08 00:18:54
yeah, it felt weird writing it.
 | 
| + | 
| +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; | 
| + } | 
| +} |