OLD | NEW |
(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.chrome.test; |
| 6 |
| 7 import android.test.AndroidTestRunner; |
| 8 import android.util.Log; |
| 9 |
| 10 import junit.framework.TestCase; |
| 11 import junit.framework.TestResult; |
| 12 |
| 13 import org.chromium.chrome.browser.util.FeatureUtilities; |
| 14 import org.chromium.chrome.test.util.DisableInTabbedMode; |
| 15 import org.chromium.test.reporter.TestStatusListener; |
| 16 |
| 17 import java.lang.reflect.Method; |
| 18 |
| 19 /** |
| 20 * An Instrumentation test runner that checks SDK level for tests with specific
requirements. |
| 21 */ |
| 22 public class ChromeStagingInstrumentationTestRunner extends ChromeInstrumentatio
nTestRunner { |
| 23 |
| 24 public static final String TAG = "ChromeInternalInstrumentationTestRunner"; |
| 25 |
| 26 @Override |
| 27 protected AndroidTestRunner getAndroidTestRunner() { |
| 28 AndroidTestRunner runner = new AndroidTestRunner() { |
| 29 @Override |
| 30 protected TestResult createTestResult() { |
| 31 SkippingTestResult r = new SkippingTestResult(); |
| 32 r.addSkipCheck(new MinAndroidSdkLevelSkipCheck()); |
| 33 r.addSkipCheck(new DisableInTabbedModeSkipCheck()); |
| 34 return r; |
| 35 } |
| 36 }; |
| 37 runner.addTestListener(new TestStatusListener(getContext())); |
| 38 return runner; |
| 39 } |
| 40 |
| 41 /** |
| 42 * Checks for tests that should only run in document mode. |
| 43 */ |
| 44 public class DisableInTabbedModeSkipCheck implements SkipCheck { |
| 45 |
| 46 /** |
| 47 * If the test is running in tabbed mode, checks for |
| 48 * {@link org.chromium.chrome.test.util.DisableInTabbedMode}. |
| 49 * |
| 50 * @param testCase The test to check. |
| 51 * @return Whether the test is running in tabbed mode and has been marke
d as disabled in |
| 52 * tabbed mode. |
| 53 */ |
| 54 @Override |
| 55 public boolean shouldSkip(TestCase testCase) { |
| 56 Class<?> testClass = testCase.getClass(); |
| 57 try { |
| 58 if (!FeatureUtilities.isDocumentMode(getContext())) { |
| 59 Method testMethod = testClass.getMethod(testCase.getName()); |
| 60 if (testMethod.isAnnotationPresent(DisableInTabbedMode.class
) |
| 61 || testClass.isAnnotationPresent(DisableInTabbedMode
.class)) { |
| 62 Log.i(TAG, "Test " + testClass.getName() + "#" + testCas
e.getName() |
| 63 + " is disabled in non-document mode."); |
| 64 return true; |
| 65 } |
| 66 } |
| 67 } catch (NoSuchMethodException e) { |
| 68 Log.e(TAG, "Couldn't find test method: " + e.toString()); |
| 69 } |
| 70 |
| 71 return false; |
| 72 } |
| 73 } |
| 74 } |
| 75 |
OLD | NEW |