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

Unified Diff: testing/android/junit/java/src/org/chromium/testing/local/GNManifestFactory.java

Issue 2767613002: Expose resources in Robolectric/JUnit tests. (Closed)
Patch Set: rebase! Created 3 years, 8 months 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 side-by-side diff with in-line comments
Download patch
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..49aaa622ee781fb2b1791402514cfbf162c35d13 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,62 @@ 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.ArrayList;
+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("Resource dirs should be generated automatically by GN. "
+ + "Make sure you specify the correct app package_name in the GN build file. "
+ + "Make sure you run the tests using the generated run_<test name> scripts.");
}
+
+ 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 List<FsFile> resourceDirsList = new ArrayList<FsFile>();
+ 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;
+ }
+ };
}
}
« no previous file with comments | « testing/android/OWNERS ('k') | testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698