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

Side by Side Diff: base/test/android/javatests/src/org/chromium/base/test/util/DisableIfSkipCheck.java

Issue 1519523002: [Android] Support conditional test disabling based on android.os.Build values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix one outdated use of SkipCheck Created 5 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.base.test.util;
6
7 import android.os.Build;
8
9 import junit.framework.TestCase;
10
11 import org.chromium.base.Log;
12
13 import java.lang.reflect.Method;
14 import java.util.Arrays;
15
16 /**
17 * Checks for conditional disables.
18 *
19 * Currently, this only includes checks against a few {@link android.os.Build} v alues.
20 */
21 public class DisableIfSkipCheck extends SkipCheck {
22
23 private static final String TAG = "cr_base_test";
24
25 @Override
26 public boolean shouldSkip(TestCase testCase) {
27 Method method = getTestMethod(testCase);
28 if (method == null) return true;
29
30 if (method.isAnnotationPresent(DisableIf.Build.class)) {
31 DisableIf.Build v = method.getAnnotation(DisableIf.Build.class);
32
33 if (abi(v) && hardware(v) && sdk(v)) {
34 if (!v.message().isEmpty()) {
35 Log.i(TAG, "%s is disabled: %s", testCase.toString(), v.mess age());
36 }
37 return true;
38 } else {
39 return false;
40 }
41 }
42
43 return false;
44 }
45
46 private boolean abi(DisableIf.Build v) {
47 if (v.supported_abis_includes().isEmpty()) return true;
48
49 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
50 return Arrays.asList(Build.SUPPORTED_ABIS).contains(
51 v.supported_abis_includes());
52 } else {
53 return Build.CPU_ABI.equals(v.supported_abis_includes())
54 || Build.CPU_ABI2.equals(v.supported_abis_includes());
55 }
56 }
57
58 private boolean hardware(DisableIf.Build v) {
59 return v.hardware_is().isEmpty() || Build.HARDWARE.equals(v.hardware_is( ));
60 }
61
62 private boolean sdk(DisableIf.Build v) {
63 return Build.VERSION.SDK_INT > v.sdk_is_greater_than()
64 && Build.VERSION.SDK_INT < v.sdk_is_less_than();
65 }
66
67 }
68
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698