Chromium Code Reviews| Index: testing/android/junit/java/src/org/chromium/testing/local/GNManifestFactory.java |
| diff --git a/testing/android/junit/java/src/org/chromium/testing/local/GNManifestFactory.java b/testing/android/junit/java/src/org/chromium/testing/local/GNManifestFactory.java |
| index 09cec0738be785a7a2b99acff2375c88d4751f90..56005e3192b8cfa06e670d8876c4711debebca9a 100644 |
| --- a/testing/android/junit/java/src/org/chromium/testing/local/GNManifestFactory.java |
| +++ b/testing/android/junit/java/src/org/chromium/testing/local/GNManifestFactory.java |
| @@ -8,33 +8,60 @@ import org.robolectric.annotation.Config; |
| import org.robolectric.internal.ManifestFactory; |
| import org.robolectric.internal.ManifestIdentifier; |
| import org.robolectric.manifest.AndroidManifest; |
| +import org.robolectric.res.Fs; |
| +import org.robolectric.res.FsFile; |
| +import org.robolectric.res.ResourcePath; |
| -// TODO(mikecase): Add support for specifying the AndroidManifest for |
| -// Robolectric tests. |
| +import java.util.LinkedList; |
| +import java.util.List; |
| /** |
| * Class that manages passing Android manifest information to Robolectric. |
| */ |
| public class GNManifestFactory implements ManifestFactory { |
| - private static final String DEFAULT_PACKAGE_NAME = "org.robolectric.default"; |
| + private static final String CHROMIUM_MANIFEST_PATH = "chromium.robolectric.manifest"; |
| + private static final String CHROMIUM_RES_DIRECTORIES = "chromium.robolectric.resource.dirs"; |
| @Override |
| public ManifestIdentifier identify(Config config) { |
| - if (!config.manifest().equals(Config.NONE)) { |
| - throw new RuntimeException("Specifying custom manifest not currently supported. " |
| - + "Please use annotation @Config(manifest = Config.NONE) on Robolectric tests " |
| - + "for the time being."); |
| + if (config.resourceDir() != null |
| + && !config.resourceDir().equals(Config.DEFAULT_RES_FOLDER)) { |
| + throw new RuntimeException("Specify resource dir in GN build file."); |
| } |
| + |
| + if (config.manifest() != null && !config.manifest().equals(Config.NONE)) { |
| + throw new RuntimeException("Specify manifest path in GN build file."); |
| + } |
| + |
| return new ManifestIdentifier(null, null, null, config.packageName(), null); |
| } |
| @Override |
| public AndroidManifest create(ManifestIdentifier manifestIdentifier) { |
| - String packageName = manifestIdentifier.getPackageName(); |
| - if (packageName == null || packageName.equals("")) { |
| - packageName = DEFAULT_PACKAGE_NAME; |
| + String manifestPath = System.getProperty(CHROMIUM_MANIFEST_PATH); |
| + String resourceDirs = System.getProperty(CHROMIUM_RES_DIRECTORIES); |
| + |
| + final LinkedList<FsFile> resourceDirsList = new LinkedList<FsFile>(); |
|
agrieve
2017/04/11 00:25:04
nit: Why LinkedList? Looks like an ArrayList would
mikecase (-- gone --)
2017/04/11 18:04:31
Will fix in next patch. Missed this.
|
| + if (resourceDirs != null) { |
| + for (String resourceDir : resourceDirs.split(":")) { |
| + resourceDirsList.add(Fs.fileFromPath(resourceDir)); |
| + } |
| + } |
| + |
| + FsFile manifestFile = null; |
| + if (manifestPath != null) { |
| + manifestFile = Fs.fileFromPath(manifestPath); |
| } |
| - return new AndroidManifest(null, null, null, packageName); |
| + return new AndroidManifest(manifestFile, null, null, manifestIdentifier.getPackageName()) { |
| + @Override |
| + public List<ResourcePath> getIncludedResourcePaths() { |
| + List<ResourcePath> paths = super.getIncludedResourcePaths(); |
| + for (FsFile resourceDir : resourceDirsList) { |
| + paths.add(new ResourcePath(getRClass(), resourceDir, getAssetsDirectory())); |
| + } |
| + return paths; |
| + } |
| + }; |
| } |
| } |