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

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

Issue 2819983002: (Reland) Expose resources in Robolectric/JUnit tests. (Closed)
Patch Set: Fix 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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.robolectric.annotation.Config; 7 import org.robolectric.annotation.Config;
8 import org.robolectric.internal.ManifestFactory; 8 import org.robolectric.internal.ManifestFactory;
9 import org.robolectric.internal.ManifestIdentifier; 9 import org.robolectric.internal.ManifestIdentifier;
10 import org.robolectric.manifest.AndroidManifest; 10 import org.robolectric.manifest.AndroidManifest;
11 import org.robolectric.res.Fs;
12 import org.robolectric.res.FsFile;
13 import org.robolectric.res.ResourcePath;
11 14
12 // TODO(mikecase): Add support for specifying the AndroidManifest for 15 import java.util.ArrayList;
13 // Robolectric tests. 16 import java.util.List;
14 17
15 /** 18 /**
16 * Class that manages passing Android manifest information to Robolectric. 19 * Class that manages passing Android manifest information to Robolectric.
17 */ 20 */
18 public class GNManifestFactory implements ManifestFactory { 21 public class GNManifestFactory implements ManifestFactory {
19 private static final String DEFAULT_PACKAGE_NAME = "org.robolectric.default" ; 22 private static final String CHROMIUM_MANIFEST_PATH = "chromium.robolectric.m anifest";
23 private static final String CHROMIUM_RES_DIRECTORIES = "chromium.robolectric .resource.dirs";
20 24
21 @Override 25 @Override
22 public ManifestIdentifier identify(Config config) { 26 public ManifestIdentifier identify(Config config) {
23 if (!config.manifest().equals(Config.NONE)) { 27 if (config.resourceDir() != null
24 throw new RuntimeException("Specifying custom manifest not currently supported. " 28 && !config.resourceDir().equals(Config.DEFAULT_RES_FOLDER)) {
25 + "Please use annotation @Config(manifest = Config.NONE) on Robolectric tests " 29 throw new RuntimeException("Resource dirs should be generated automa tically by GN. "
26 + "for the time being."); 30 + "Make sure you specify the correct app package_name in the GN build file. "
31 + "Make sure you run the tests using the generated run_<test name> scripts.");
27 } 32 }
33
34 if (config.manifest() != null && !config.manifest().equals(Config.NONE)) {
35 throw new RuntimeException("Specify manifest path in GN build file." );
36 }
37
28 return new ManifestIdentifier(null, null, null, config.packageName(), nu ll); 38 return new ManifestIdentifier(null, null, null, config.packageName(), nu ll);
29 } 39 }
30 40
31 @Override 41 @Override
32 public AndroidManifest create(ManifestIdentifier manifestIdentifier) { 42 public AndroidManifest create(ManifestIdentifier manifestIdentifier) {
33 String packageName = manifestIdentifier.getPackageName(); 43 String manifestPath = System.getProperty(CHROMIUM_MANIFEST_PATH);
34 if (packageName == null || packageName.equals("")) { 44 String resourceDirs = System.getProperty(CHROMIUM_RES_DIRECTORIES);
35 packageName = DEFAULT_PACKAGE_NAME; 45
46 final List<FsFile> resourceDirsList = new ArrayList<FsFile>();
47 if (resourceDirs != null) {
48 for (String resourceDir : resourceDirs.split(":")) {
49 resourceDirsList.add(Fs.fileFromPath(resourceDir));
50 }
36 } 51 }
37 52
38 return new AndroidManifest(null, null, null, packageName); 53 FsFile manifestFile = null;
54 if (manifestPath != null) {
55 manifestFile = Fs.fileFromPath(manifestPath);
56 }
57
58 return new AndroidManifest(manifestFile, null, null, manifestIdentifier. getPackageName()) {
59 @Override
60 public List<ResourcePath> getIncludedResourcePaths() {
61 List<ResourcePath> paths = super.getIncludedResourcePaths();
62 for (FsFile resourceDir : resourceDirsList) {
63 paths.add(new ResourcePath(getRClass(), resourceDir, getAsse tsDirectory()));
64 }
65 return paths;
66 }
67 };
39 } 68 }
40 } 69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698