| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.testing.local; | 5 package org.chromium.testing.local; |
| 6 | 6 |
| 7 import org.junit.runners.model.InitializationError; | 7 import org.junit.runners.model.InitializationError; |
| 8 | |
| 9 import org.robolectric.RobolectricTestRunner; | 8 import org.robolectric.RobolectricTestRunner; |
| 10 import org.robolectric.annotation.Config; | 9 import org.robolectric.annotation.Config; |
| 11 import org.robolectric.manifest.AndroidManifest; | 10 import org.robolectric.internal.ManifestFactory; |
| 12 | 11 |
| 13 /** | 12 /** |
| 14 * A custom Robolectric Junit4 Test Runner. This test runner will ignore the | 13 * A custom Robolectric Junit4 Test Runner with Chromium specific settings. |
| 15 * API level written in the AndroidManifest as that can cause issues if | |
| 16 * Robolectric does not support that API level. The API level will be grabbed | |
| 17 * from the robolectric Config annotation, or just be | |
| 18 * |DEFAULT_ANDROID_API_LEVEL| | |
| 19 */ | 14 */ |
| 20 public class LocalRobolectricTestRunner extends RobolectricTestRunner { | 15 public class LocalRobolectricTestRunner extends RobolectricTestRunner { |
| 21 | 16 private static final int DEFAULT_SDK = 25; |
| 22 private static final int DEFAULT_ANDROID_API_LEVEL = 21; | |
| 23 | 17 |
| 24 public LocalRobolectricTestRunner(Class<?> testClass) throws InitializationE
rror { | 18 public LocalRobolectricTestRunner(Class<?> testClass) throws InitializationE
rror { |
| 25 super(testClass); | 19 super(testClass); |
| 26 } | 20 } |
| 27 | 21 |
| 28 @Override | 22 @Override |
| 29 protected int pickSdkVersion(Config config, AndroidManifest appManifest) { | 23 protected Config buildGlobalConfig() { |
| 30 // Pulling from the manifest is dangerous as the apk might target a vers
ion of | 24 return new Config.Builder().setSdk(DEFAULT_SDK).build(); |
| 31 // android that robolectric does not yet support. We still allow the API
level to | 25 } |
| 32 // be overridden with the Config annotation. | 26 |
| 33 if (config != null) { | 27 @Override |
| 34 if (config.sdk().length > 1) { | 28 protected ManifestFactory getManifestFactory(Config config) { |
| 35 throw new IllegalArgumentException( | 29 return new GNManifestFactory(); |
| 36 "RobolectricTestRunner does not support multiple values
for @Config.sdk"); | |
| 37 } else if (config.sdk().length == 1) { | |
| 38 return config.sdk()[0]; | |
| 39 } | |
| 40 } | |
| 41 return DEFAULT_ANDROID_API_LEVEL; | |
| 42 } | 30 } |
| 43 } | 31 } |
| OLD | NEW |