OLD | NEW |
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; | |
14 | 11 |
15 import java.util.ArrayList; | 12 // TODO(mikecase): Add support for specifying the AndroidManifest for |
16 import java.util.List; | 13 // Robolectric tests. |
17 | 14 |
18 /** | 15 /** |
19 * Class that manages passing Android manifest information to Robolectric. | 16 * Class that manages passing Android manifest information to Robolectric. |
20 */ | 17 */ |
21 public class GNManifestFactory implements ManifestFactory { | 18 public class GNManifestFactory implements ManifestFactory { |
22 private static final String CHROMIUM_MANIFEST_PATH = "chromium.robolectric.m
anifest"; | 19 private static final String DEFAULT_PACKAGE_NAME = "org.robolectric.default"
; |
23 private static final String CHROMIUM_RES_DIRECTORIES = "chromium.robolectric
.resource.dirs"; | |
24 | 20 |
25 @Override | 21 @Override |
26 public ManifestIdentifier identify(Config config) { | 22 public ManifestIdentifier identify(Config config) { |
27 if (config.resourceDir() != null | 23 if (!config.manifest().equals(Config.NONE)) { |
28 && !config.resourceDir().equals(Config.DEFAULT_RES_FOLDER)) { | 24 throw new RuntimeException("Specifying custom manifest not currently
supported. " |
29 throw new RuntimeException("Resource dirs should be generated automa
tically by GN. " | 25 + "Please use annotation @Config(manifest = Config.NONE) on
Robolectric tests " |
30 + "Make sure you specify the correct app package_name in the
GN build file. " | 26 + "for the time being."); |
31 + "Make sure you run the tests using the generated run_<test
name> scripts."); | |
32 } | 27 } |
33 | |
34 if (config.manifest() != null && !config.manifest().equals(Config.NONE))
{ | |
35 throw new RuntimeException("Specify manifest path in GN build file."
); | |
36 } | |
37 | |
38 return new ManifestIdentifier(null, null, null, config.packageName(), nu
ll); | 28 return new ManifestIdentifier(null, null, null, config.packageName(), nu
ll); |
39 } | 29 } |
40 | 30 |
41 @Override | 31 @Override |
42 public AndroidManifest create(ManifestIdentifier manifestIdentifier) { | 32 public AndroidManifest create(ManifestIdentifier manifestIdentifier) { |
43 String manifestPath = System.getProperty(CHROMIUM_MANIFEST_PATH); | 33 String packageName = manifestIdentifier.getPackageName(); |
44 String resourceDirs = System.getProperty(CHROMIUM_RES_DIRECTORIES); | 34 if (packageName == null || packageName.equals("")) { |
45 | 35 packageName = DEFAULT_PACKAGE_NAME; |
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 } | |
51 } | 36 } |
52 | 37 |
53 FsFile manifestFile = null; | 38 return new AndroidManifest(null, null, null, packageName); |
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 }; | |
68 } | 39 } |
69 } | 40 } |
OLD | NEW |