summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjbudorick <jbudorick@chromium.org>2016-03-09 18:14:04 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-10 02:15:46 +0000
commitacf0dd8e8dbf43d03330609890cbdf2334e14c02 (patch)
tree14ee4fcfb6d748f8ec405804a8dfd5d2bb1092d0
parentf3890c75101ff9b07f48aed992285cc45bf5b4d5 (diff)
downloadchromium_src-acf0dd8e8dbf43d03330609890cbdf2334e14c02.zip
chromium_src-acf0dd8e8dbf43d03330609890cbdf2334e14c02.tar.gz
chromium_src-acf0dd8e8dbf43d03330609890cbdf2334e14c02.tar.bz2
[Android] Restrict tests inheriting from DocumentModeTestBase to phones.
BUG=589663 Review URL: https://codereview.chromium.org/1761383002 Cr-Commit-Position: refs/heads/master@{#380307}
-rw-r--r--base/BUILD.gn3
-rw-r--r--base/base.gyp3
-rw-r--r--base/test/android/javatests/src/org/chromium/base/test/BaseInstrumentationTestRunner.java101
-rw-r--r--base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheck.java47
-rw-r--r--base/test/android/javatests/src/org/chromium/base/test/util/Restriction.java2
-rw-r--r--base/test/android/javatests/src/org/chromium/base/test/util/RestrictionSkipCheck.java72
-rw-r--r--base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java21
-rw-r--r--base/test/android/junit/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheckTest.java93
-rw-r--r--base/test/android/junit/src/org/chromium/base/test/util/RestrictionSkipCheckTest.java127
-rw-r--r--base/test/android/junit/src/org/chromium/base/test/util/SkipCheckTest.java123
-rw-r--r--chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTestBase.java3
-rw-r--r--chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeInstrumentationTestRunner.java8
12 files changed, 503 insertions, 100 deletions
diff --git a/base/BUILD.gn b/base/BUILD.gn
index 925dd7a..f19c8f4 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -2071,6 +2071,9 @@ if (is_android) {
"android/junit/src/org/chromium/base/BaseChromiumApplicationTest.java",
"android/junit/src/org/chromium/base/LogTest.java",
"test/android/junit/src/org/chromium/base/test/util/DisableIfTest.java",
+ "test/android/junit/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheckTest.java",
+ "test/android/junit/src/org/chromium/base/test/util/RestrictionSkipCheckTest.java",
+ "test/android/junit/src/org/chromium/base/test/util/SkipCheckTest.java",
]
deps = [
":base_java",
diff --git a/base/base.gyp b/base/base.gyp
index 0388e98..5b20cfe 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -1558,6 +1558,9 @@
'src_paths': [
'../base/android/junit/',
'../base/test/android/junit/src/org/chromium/base/test/util/DisableIfTest.java',
+ '../base/test/android/junit/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheckTest.java',
+ '../base/test/android/junit/src/org/chromium/base/test/util/RestrictionSkipCheckTest.java',
+ '../base/test/android/junit/src/org/chromium/base/test/util/SkipCheckTest.java',
],
'test_type': 'junit',
'wrapper_script_name': 'helper/<(_target_name)',
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 fd6fafd..d875724 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
@@ -8,29 +8,19 @@ import android.app.ActivityOptions;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.os.Build;
import android.os.Bundle;
import android.test.AndroidTestRunner;
import android.test.InstrumentationTestRunner;
-import android.text.TextUtils;
-import junit.framework.TestCase;
import junit.framework.TestResult;
-import org.chromium.base.Log;
-import org.chromium.base.SysUtils;
import org.chromium.base.multidex.ChromiumMultiDexInstaller;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisableIfSkipCheck;
-import org.chromium.base.test.util.MinAndroidSdkLevel;
-import org.chromium.base.test.util.Restriction;
-import org.chromium.base.test.util.SkipCheck;
+import org.chromium.base.test.util.MinAndroidSdkLevelSkipCheck;
+import org.chromium.base.test.util.RestrictionSkipCheck;
import org.chromium.test.reporter.TestStatusListener;
-import java.lang.reflect.Method;
-
// TODO(jbudorick): Add support for on-device handling of timeouts.
/**
* An Instrumentation test runner that checks SDK level for tests with specific requirements.
@@ -67,97 +57,12 @@ public class BaseInstrumentationTestRunner extends InstrumentationTestRunner {
*/
protected void addTestHooks(BaseTestResult result) {
result.addSkipCheck(new MinAndroidSdkLevelSkipCheck());
- result.addSkipCheck(new RestrictionSkipCheck());
+ result.addSkipCheck(new RestrictionSkipCheck(getTargetContext()));
result.addSkipCheck(new DisableIfSkipCheck());
result.addPreTestHook(CommandLineFlags.getRegistrationHook());
}
-
- /**
- * Checks if any restrictions exist and skip the test if it meets those restrictions.
- */
- public class RestrictionSkipCheck extends SkipCheck {
- @Override
- public boolean shouldSkip(TestCase testCase) {
- Method method = getTestMethod(testCase);
- if (method == null) return true;
-
- Restriction restrictions = method.getAnnotation(Restriction.class);
- if (restrictions != null) {
- for (String restriction : restrictions.value()) {
- if (restrictionApplies(restriction)) {
- Log.i(TAG, "Test " + testCase.getClass().getName() + "#"
- + testCase.getName() + " skipped because of restriction "
- + restriction);
- return true;
- }
- }
- }
- return false;
- }
-
- protected boolean restrictionApplies(String restriction) {
- if (TextUtils.equals(restriction, Restriction.RESTRICTION_TYPE_LOW_END_DEVICE)
- && !SysUtils.isLowEndDevice()) {
- return true;
- }
- if (TextUtils.equals(restriction, Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE)
- && SysUtils.isLowEndDevice()) {
- return true;
- }
- if (TextUtils.equals(restriction, Restriction.RESTRICTION_TYPE_INTERNET)
- && !isNetworkAvailable()) {
- return true;
- }
- return false;
- }
-
- private boolean isNetworkAvailable() {
- final ConnectivityManager connectivityManager = (ConnectivityManager)
- getTargetContext().getSystemService(Context.CONNECTIVITY_SERVICE);
- final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
- return activeNetworkInfo != null && activeNetworkInfo.isConnected();
- }
- }
-
- /**
- * Checks the device's SDK level against any specified minimum requirement.
- */
- public static class MinAndroidSdkLevelSkipCheck extends SkipCheck {
-
- /**
- * 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;
- if (testClass.isAnnotationPresent(MinAndroidSdkLevel.class)) {
- minSdkLevel = Math.max(testClass.getAnnotation(MinAndroidSdkLevel.class).value(),
- minSdkLevel);
- }
- if (testMethod != null && testMethod.isAnnotationPresent(MinAndroidSdkLevel.class)) {
- minSdkLevel = Math.max(testMethod.getAnnotation(MinAndroidSdkLevel.class).value(),
- minSdkLevel);
- }
-
- 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;
- }
- }
-
@Override
public Context getTargetContext() {
return new ContextWrapper(super.getTargetContext()) {
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 0000000..c95ae22
--- /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;
+ }
+}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/Restriction.java b/base/test/android/javatests/src/org/chromium/base/test/util/Restriction.java
index 7c6dc22..9d27d42 100644
--- a/base/test/android/javatests/src/org/chromium/base/test/util/Restriction.java
+++ b/base/test/android/javatests/src/org/chromium/base/test/util/Restriction.java
@@ -15,7 +15,7 @@ import java.lang.annotation.Target;
* @Restriction({RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_SMALL_MEMORY})
* Test classes are free to define restrictions and enforce them using reflection at runtime.
*/
-@Target(ElementType.METHOD)
+@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Restriction {
/** Specifies the test is only valid on low end devices that have less memory. */
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/RestrictionSkipCheck.java b/base/test/android/javatests/src/org/chromium/base/test/util/RestrictionSkipCheck.java
new file mode 100644
index 0000000..b4beef2
--- /dev/null
+++ b/base/test/android/javatests/src/org/chromium/base/test/util/RestrictionSkipCheck.java
@@ -0,0 +1,72 @@
+// 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.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.text.TextUtils;
+
+import junit.framework.TestCase;
+
+import org.chromium.base.Log;
+import org.chromium.base.SysUtils;
+
+import java.lang.reflect.Method;
+
+/**
+ * Checks if any restrictions exist and skip the test if it meets those restrictions.
+ */
+public class RestrictionSkipCheck extends SkipCheck {
+
+ private static final String TAG = "base_test";
+
+ private final Context mTargetContext;
+
+ public RestrictionSkipCheck(Context targetContext) {
+ mTargetContext = targetContext;
+ }
+
+ @Override
+ public boolean shouldSkip(TestCase testCase) {
+ Method method = getTestMethod(testCase);
+ if (method == null) return true;
+
+ for (Restriction restriction : getAnnotations(method, Restriction.class)) {
+ for (String restrictionVal : restriction.value()) {
+ if (restrictionApplies(restrictionVal)) {
+ Log.i(TAG, "Test " + testCase.getClass().getName() + "#"
+ + testCase.getName() + " skipped because of restriction "
+ + restriction);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ protected boolean restrictionApplies(String restriction) {
+ if (TextUtils.equals(restriction, Restriction.RESTRICTION_TYPE_LOW_END_DEVICE)
+ && !SysUtils.isLowEndDevice()) {
+ return true;
+ }
+ if (TextUtils.equals(restriction, Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE)
+ && SysUtils.isLowEndDevice()) {
+ return true;
+ }
+ if (TextUtils.equals(restriction, Restriction.RESTRICTION_TYPE_INTERNET)
+ && !isNetworkAvailable()) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isNetworkAvailable() {
+ final ConnectivityManager connectivityManager = (ConnectivityManager)
+ mTargetContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
+ return activeNetworkInfo != null && activeNetworkInfo.isConnected();
+ }
+}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java b/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java
index cb21dfd..b55a838 100644
--- a/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java
+++ b/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java
@@ -8,7 +8,11 @@ import junit.framework.TestCase;
import org.chromium.base.Log;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
/**
* Check whether a test case should be skipped.
@@ -35,5 +39,22 @@ public abstract class SkipCheck {
return null;
}
}
+
+ protected static <T extends Annotation> List<T> getAnnotations(AnnotatedElement element,
+ Class<T> annotationClass) {
+ AnnotatedElement parent = (element instanceof Method)
+ ? ((Method) element).getDeclaringClass()
+ : ((Class) element).getSuperclass();
+ List<T> annotations = (parent == null)
+ ? new ArrayList<T>()
+ : getAnnotations(parent, annotationClass);
+ Annotation[] allAnnotations = element.getAnnotations();
+ for (Annotation a : allAnnotations) {
+ if (annotationClass.isInstance(a)) {
+ annotations.add((T) a);
+ }
+ }
+ return annotations;
+ }
}
diff --git a/base/test/android/junit/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheckTest.java b/base/test/android/junit/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheckTest.java
new file mode 100644
index 0000000..1ab2270
--- /dev/null
+++ b/base/test/android/junit/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheckTest.java
@@ -0,0 +1,93 @@
+// 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 junit.framework.TestCase;
+
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+/** Unit tests for MinAndroidSdkLevelSkipCheck. */
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE, reportSdk = 19)
+public class MinAndroidSdkLevelSkipCheckTest {
+
+ private static class UnannotatedBaseClass extends TestCase {
+ public UnannotatedBaseClass(String name) {
+ super(name);
+ }
+ @MinAndroidSdkLevel(18) public void min18Method() {}
+ @MinAndroidSdkLevel(20) public void min20Method() {}
+ }
+
+ @MinAndroidSdkLevel(18)
+ private static class Min18Class extends UnannotatedBaseClass {
+ public Min18Class(String name) {
+ super(name);
+ }
+ public void unannotatedMethod() {}
+ }
+
+ @MinAndroidSdkLevel(20)
+ private static class Min20Class extends UnannotatedBaseClass {
+ public Min20Class(String name) {
+ super(name);
+ }
+ public void unannotatedMethod() {}
+ }
+
+ private static class ExtendsMin18Class extends Min18Class {
+ public ExtendsMin18Class(String name) {
+ super(name);
+ }
+ public void unannotatedMethod() {}
+ }
+
+ private static class ExtendsMin20Class extends Min20Class {
+ public ExtendsMin20Class(String name) {
+ super(name);
+ }
+ public void unannotatedMethod() {}
+ }
+
+ @Test
+ public void testAnnotatedMethodAboveMin() {
+ Assert.assertFalse(new MinAndroidSdkLevelSkipCheck().shouldSkip(
+ new UnannotatedBaseClass("min18Method")));
+ }
+
+ @Test
+ public void testAnnotatedMethodBelowMin() {
+ Assert.assertTrue(new MinAndroidSdkLevelSkipCheck().shouldSkip(
+ new UnannotatedBaseClass("min20Method")));
+ }
+
+ @Test
+ public void testAnnotatedClassAboveMin() {
+ Assert.assertFalse(new MinAndroidSdkLevelSkipCheck().shouldSkip(
+ new Min18Class("unannotatedMethod")));
+ }
+
+ @Test
+ public void testAnnotatedClassBelowMin() {
+ Assert.assertTrue(new MinAndroidSdkLevelSkipCheck().shouldSkip(
+ new Min20Class("unannotatedMethod")));
+ }
+
+ @Test
+ public void testAnnotatedSuperclassAboveMin() {
+ Assert.assertFalse(new MinAndroidSdkLevelSkipCheck().shouldSkip(
+ new ExtendsMin18Class("unannotatedMethod")));
+ }
+
+ @Test
+ public void testAnnotatedSuperclassBelowMin() {
+ Assert.assertTrue(new MinAndroidSdkLevelSkipCheck().shouldSkip(
+ new ExtendsMin20Class("unannotatedMethod")));
+ }
+}
diff --git a/base/test/android/junit/src/org/chromium/base/test/util/RestrictionSkipCheckTest.java b/base/test/android/junit/src/org/chromium/base/test/util/RestrictionSkipCheckTest.java
new file mode 100644
index 0000000..4e9996b
--- /dev/null
+++ b/base/test/android/junit/src/org/chromium/base/test/util/RestrictionSkipCheckTest.java
@@ -0,0 +1,127 @@
+// 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.text.TextUtils;
+
+import junit.framework.TestCase;
+
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+/** Unit tests for RestrictionSkipCheck. */
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class RestrictionSkipCheckTest {
+
+ private static final String TEST_RESTRICTION_APPLIES =
+ "org.chromium.base.test.util.RestrictionSkipCheckTest.TEST_RESTRICTION_APPLIES";
+ private static final String TEST_RESTRICTION_DOES_NOT_APPLY =
+ "org.chromium.base.test.util.RestrictionSkipCheckTest.TEST_RESTRICTION_DOES_NOT_APPLY";
+
+ private static class TestRestrictionSkipCheck extends RestrictionSkipCheck {
+ public TestRestrictionSkipCheck() {
+ super(null);
+ }
+ protected boolean restrictionApplies(String restriction) {
+ return TextUtils.equals(restriction, TEST_RESTRICTION_APPLIES);
+ }
+ }
+
+ private static class UnannotatedBaseClass extends TestCase {
+ public UnannotatedBaseClass(String name) {
+ super(name);
+ }
+ @Restriction({TEST_RESTRICTION_APPLIES}) public void restrictedMethod() {}
+ @Restriction({TEST_RESTRICTION_DOES_NOT_APPLY}) public void unrestrictedMethod() {}
+ }
+
+ @Restriction({TEST_RESTRICTION_APPLIES})
+ private static class RestrictedClass extends UnannotatedBaseClass {
+ public RestrictedClass(String name) {
+ super(name);
+ }
+ public void unannotatedMethod() {}
+ }
+
+ @Restriction({TEST_RESTRICTION_DOES_NOT_APPLY})
+ private static class UnrestrictedClass extends UnannotatedBaseClass {
+ public UnrestrictedClass(String name) {
+ super(name);
+ }
+ public void unannotatedMethod() {}
+ }
+
+ @Restriction({
+ TEST_RESTRICTION_APPLIES,
+ TEST_RESTRICTION_DOES_NOT_APPLY})
+ private static class MultipleRestrictionsRestrictedClass extends UnannotatedBaseClass {
+ public MultipleRestrictionsRestrictedClass(String name) {
+ super(name);
+ }
+ public void unannotatedMethod() {}
+ }
+
+ private static class ExtendsRestrictedClass extends RestrictedClass {
+ public ExtendsRestrictedClass(String name) {
+ super(name);
+ }
+ public void unannotatedMethod() {}
+ }
+
+ private static class ExtendsUnrestrictedClass extends UnrestrictedClass {
+ public ExtendsUnrestrictedClass(String name) {
+ super(name);
+ }
+ public void unannotatedMethod() {}
+ }
+
+ @Test
+ public void testMethodRestricted() {
+ Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip(
+ new UnannotatedBaseClass("restrictedMethod")));
+ }
+
+ @Test
+ public void testMethodUnrestricted() {
+ Assert.assertFalse(new TestRestrictionSkipCheck().shouldSkip(
+ new UnannotatedBaseClass("unrestrictedMethod")));
+ }
+
+ @Test
+ public void testClassRestricted() {
+ Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip(
+ new RestrictedClass("unannotatedMethod")));
+ }
+
+ @Test
+ public void testClassUnrestricted() {
+ Assert.assertFalse(new TestRestrictionSkipCheck().shouldSkip(
+ new UnrestrictedClass("unannotatedMethod")));
+ }
+
+ @Test
+ public void testMultipleRestrictionsClassRestricted() {
+ Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip(
+ new MultipleRestrictionsRestrictedClass("unannotatedMethod")));
+ }
+
+ @Test
+ public void testSuperclassRestricted() {
+ Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip(
+ new ExtendsRestrictedClass("unannotatedMethod")));
+ }
+
+ @Test
+ public void testSuperclassUnrestricted() {
+ Assert.assertFalse(new TestRestrictionSkipCheck().shouldSkip(
+ new ExtendsUnrestrictedClass("unannotatedMethod")));
+ }
+
+}
+
diff --git a/base/test/android/junit/src/org/chromium/base/test/util/SkipCheckTest.java b/base/test/android/junit/src/org/chromium/base/test/util/SkipCheckTest.java
new file mode 100644
index 0000000..efca734
--- /dev/null
+++ b/base/test/android/junit/src/org/chromium/base/test/util/SkipCheckTest.java
@@ -0,0 +1,123 @@
+// 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 junit.framework.TestCase;
+
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+import java.util.List;
+
+/** Unit tests for SkipCheck. */
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class SkipCheckTest {
+
+ private static class TestableSkipCheck extends SkipCheck {
+ public static <T extends Annotation> List<T> getAnnotationsForTesting(
+ AnnotatedElement element, Class<T> annotationClass) {
+ return getAnnotations(element, annotationClass);
+ }
+
+ @Override
+ public boolean shouldSkip(TestCase t) {
+ return false;
+ }
+ }
+
+ @Retention(RetentionPolicy.RUNTIME)
+ private @interface TestAnnotation {}
+
+ private class UnannotatedBaseClass {
+ public void unannotatedMethod() {}
+ @TestAnnotation public void annotatedMethod() {}
+ }
+
+ @TestAnnotation
+ private class AnnotatedBaseClass {
+ public void unannotatedMethod() {}
+ @TestAnnotation public void annotatedMethod() {}
+ }
+
+ private class ExtendsAnnotatedBaseClass extends AnnotatedBaseClass {
+ public void anotherUnannotatedMethod() {}
+ }
+
+ @Test
+ public void getAnnotationsForClassNone() {
+ List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
+ UnannotatedBaseClass.class, TestAnnotation.class);
+ Assert.assertEquals(0, annotations.size());
+ }
+
+ @Test
+ public void getAnnotationsForClassOnClass() {
+ List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
+ AnnotatedBaseClass.class, TestAnnotation.class);
+ Assert.assertEquals(1, annotations.size());
+ }
+
+ @Test
+ public void getAnnotationsForClassOnSuperclass() {
+ List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
+ ExtendsAnnotatedBaseClass.class, TestAnnotation.class);
+ Assert.assertEquals(1, annotations.size());
+ }
+
+ @Test
+ public void getAnnotationsForMethodNone() throws NoSuchMethodException {
+ Method testMethod = UnannotatedBaseClass.class.getMethod("unannotatedMethod",
+ (Class[]) null);
+ List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
+ testMethod, TestAnnotation.class);
+ Assert.assertEquals(0, annotations.size());
+ }
+
+ @Test
+ public void getAnnotationsForMethodOnMethod() throws NoSuchMethodException {
+ Method testMethod = UnannotatedBaseClass.class.getMethod("annotatedMethod",
+ (Class[]) null);
+ List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
+ testMethod, TestAnnotation.class);
+ Assert.assertEquals(1, annotations.size());
+ }
+
+ @Test
+ public void getAnnotationsForMethodOnClass() throws NoSuchMethodException {
+ Method testMethod = AnnotatedBaseClass.class.getMethod("unannotatedMethod",
+ (Class[]) null);
+ List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
+ testMethod, TestAnnotation.class);
+ Assert.assertEquals(1, annotations.size());
+ }
+
+ @Test
+ public void getAnnotationsForMethodOnSuperclass() throws NoSuchMethodException {
+ Method testMethod = ExtendsAnnotatedBaseClass.class.getMethod("unannotatedMethod",
+ (Class[]) null);
+ List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
+ testMethod, TestAnnotation.class);
+ Assert.assertEquals(1, annotations.size());
+ }
+
+ @Test
+ public void getAnnotationsOverlapping() throws NoSuchMethodException {
+ Method testMethod = AnnotatedBaseClass.class.getMethod("annotatedMethod",
+ (Class[]) null);
+ List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
+ testMethod, TestAnnotation.class);
+ Assert.assertEquals(2, annotations.size());
+ }
+
+}
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTestBase.java b/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTestBase.java
index 687f7dc..b12dcdd 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTestBase.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTestBase.java
@@ -15,6 +15,7 @@ import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.MinAndroidSdkLevel;
+import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.ChromeTabbedActivity;
@@ -29,6 +30,7 @@ import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelSelector;
import org.chromium.chrome.test.MultiActivityTestBase;
import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.ApplicationTestUtils;
+import org.chromium.chrome.test.util.ChromeRestriction;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
@@ -45,6 +47,7 @@ import java.util.concurrent.Callable;
* tested using the DocumentActivityTestBase class.
*/
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
+@Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE)
public class DocumentModeTestBase extends MultiActivityTestBase {
protected static final String TAG = "document";
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeInstrumentationTestRunner.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeInstrumentationTestRunner.java
index 62264c8..671c9b2 100644
--- a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeInstrumentationTestRunner.java
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeInstrumentationTestRunner.java
@@ -4,6 +4,7 @@
package org.chromium.chrome.test;
+import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
@@ -15,6 +16,7 @@ import junit.framework.TestCase;
import org.chromium.base.test.BaseInstrumentationTestRunner;
import org.chromium.base.test.BaseTestResult;
+import org.chromium.base.test.util.RestrictionSkipCheck;
import org.chromium.base.test.util.SkipCheck;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.chrome.test.util.ChromeRestriction;
@@ -44,13 +46,17 @@ public class ChromeInstrumentationTestRunner extends BaseInstrumentationTestRunn
protected void addTestHooks(BaseTestResult result) {
super.addTestHooks(result);
result.addSkipCheck(new DisableInTabbedModeSkipCheck());
- result.addSkipCheck(new ChromeRestrictionSkipCheck());
+ result.addSkipCheck(new ChromeRestrictionSkipCheck(getTargetContext()));
result.addPreTestHook(Policies.getRegistrationHook());
}
private class ChromeRestrictionSkipCheck extends RestrictionSkipCheck {
+ public ChromeRestrictionSkipCheck(Context targetContext) {
+ super(targetContext);
+ }
+
@Override
protected boolean restrictionApplies(String restriction) {
if (TextUtils.equals(restriction, ChromeRestriction.RESTRICTION_TYPE_PHONE)