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.base.test.util; | 5 package org.chromium.base.test.util; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 | 8 |
9 import junit.framework.Assert; | 9 import org.junit.Assert; |
10 | 10 |
11 import org.chromium.base.BaseChromiumApplication; | 11 import org.chromium.base.BaseChromiumApplication; |
12 import org.chromium.base.CommandLine; | 12 import org.chromium.base.CommandLine; |
13 import org.chromium.base.test.BaseTestResult.PreTestHook; | 13 import org.chromium.base.test.BaseTestResult.PreTestHook; |
14 import org.chromium.base.test.util.parameter.BaseParameter; | 14 import org.chromium.base.test.util.parameter.BaseParameter; |
15 | 15 |
16 import java.lang.annotation.ElementType; | 16 import java.lang.annotation.ElementType; |
17 import java.lang.annotation.Inherited; | 17 import java.lang.annotation.Inherited; |
18 import java.lang.annotation.Retention; | 18 import java.lang.annotation.Retention; |
19 import java.lang.annotation.RetentionPolicy; | 19 import java.lang.annotation.RetentionPolicy; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 * Note that this can only remove flags added via {@link Add} above. | 53 * Note that this can only remove flags added via {@link Add} above. |
54 */ | 54 */ |
55 @Inherited | 55 @Inherited |
56 @Retention(RetentionPolicy.RUNTIME) | 56 @Retention(RetentionPolicy.RUNTIME) |
57 @Target({ElementType.METHOD, ElementType.TYPE}) | 57 @Target({ElementType.METHOD, ElementType.TYPE}) |
58 public @interface Remove { | 58 public @interface Remove { |
59 String[] value(); | 59 String[] value(); |
60 } | 60 } |
61 | 61 |
62 /** | 62 /** |
| 63 * Sets up the CommandLine flags using a set of flag strings. |
| 64 * |
| 65 * This will add {@code flags} to the {@link org.chromium.base.CommandLine}. |
| 66 */ |
| 67 public static void setUp(Context targetContext, Set<String> flags) { |
| 68 Assert.assertNotNull("Unable to get a non-null target context.", targetC
ontext); |
| 69 CommandLine.reset(); |
| 70 BaseChromiumApplication.initCommandLine(targetContext); |
| 71 for (String flag : flags) { |
| 72 CommandLine.getInstance().appendSwitch(flag); |
| 73 } |
| 74 } |
| 75 |
| 76 /** |
63 * Sets up the CommandLine with the appropriate flags. | 77 * Sets up the CommandLine with the appropriate flags. |
64 * | 78 * |
65 * This will add the difference of the sets of flags specified by {@link Com
mandLineFlags.Add} | 79 * This will add the difference of the sets of flags specified by {@link Com
mandLineFlags.Add} |
66 * and {@link CommandLineFlags.Remove} to the {@link org.chromium.base.Comma
ndLine}. Note that | 80 * and {@link CommandLineFlags.Remove} to the {@link org.chromium.base.Comma
ndLine}. Note that |
67 * trying to remove a flag set externally, i.e. by the command-line flags fi
le, will not work. | 81 * trying to remove a flag set externally, i.e. by the command-line flags fi
le, will not work. |
68 */ | 82 */ |
69 public static void setUp(Context targetContext, AnnotatedElement element) { | 83 public static void setUp(Context targetContext, AnnotatedElement element) { |
70 Assert.assertNotNull("Unable to get a non-null target context.", targetC
ontext); | 84 setUp(targetContext, getFlags(element)); |
71 CommandLine.reset(); | |
72 BaseChromiumApplication.initCommandLine(targetContext); | |
73 Set<String> flags = getFlags(element); | |
74 for (String flag : flags) { | |
75 CommandLine.getInstance().appendSwitch(flag); | |
76 } | |
77 } | 85 } |
78 | 86 |
79 private static Set<String> getFlags(AnnotatedElement element) { | 87 private static Set<String> getFlags(AnnotatedElement element) { |
80 AnnotatedElement parent = (element instanceof Method) | 88 AnnotatedElement parent = (element instanceof Method) |
81 ? ((Method) element).getDeclaringClass() | 89 ? ((Method) element).getDeclaringClass() |
82 : ((Class) element).getSuperclass(); | 90 : ((Class<?>) element).getSuperclass(); |
83 Set<String> flags = (parent == null) ? new HashSet<String>() : getFlags(
parent); | 91 Set<String> flags = (parent == null) ? new HashSet<String>() : getFlags(
parent); |
84 | 92 |
85 if (element.isAnnotationPresent(CommandLineFlags.Add.class)) { | 93 if (element.isAnnotationPresent(CommandLineFlags.Add.class)) { |
86 flags.addAll( | 94 flags.addAll( |
87 Arrays.asList(element.getAnnotation(CommandLineFlags.Add.cla
ss).value())); | 95 Arrays.asList(element.getAnnotation(CommandLineFlags.Add.cla
ss).value())); |
88 } | 96 } |
89 | 97 |
90 if (element.isAnnotationPresent(CommandLineFlags.Remove.class)) { | 98 if (element.isAnnotationPresent(CommandLineFlags.Remove.class)) { |
91 List<String> flagsToRemove = | 99 List<String> flagsToRemove = |
92 Arrays.asList(element.getAnnotation(CommandLineFlags.Remove.
class).value()); | 100 Arrays.asList(element.getAnnotation(CommandLineFlags.Remove.
class).value()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 public static class Parameter extends BaseParameter { | 152 public static class Parameter extends BaseParameter { |
145 public static final String PARAMETER_TAG = "cmdlinearg-parameter"; | 153 public static final String PARAMETER_TAG = "cmdlinearg-parameter"; |
146 public static final String ADD_ARG = "add"; | 154 public static final String ADD_ARG = "add"; |
147 public static final String REMOVE_ARG = "remove"; | 155 public static final String REMOVE_ARG = "remove"; |
148 | 156 |
149 public Parameter(org.chromium.base.test.util.parameter.Parameter.Reader
parameterReader) { | 157 public Parameter(org.chromium.base.test.util.parameter.Parameter.Reader
parameterReader) { |
150 super(PARAMETER_TAG, parameterReader); | 158 super(PARAMETER_TAG, parameterReader); |
151 } | 159 } |
152 } | 160 } |
153 } | 161 } |
OLD | NEW |