OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.base.test; | |
6 | |
7 import android.app.Activity; | |
8 import android.test.ActivityInstrumentationTestCase2; | |
9 | |
10 import org.chromium.base.BaseChromiumApplication; | |
11 import org.chromium.base.CommandLine; | |
12 import org.chromium.base.test.util.CommandLineFlags; | |
13 | |
14 import java.lang.reflect.Method; | |
15 import java.util.Arrays; | |
16 import java.util.HashSet; | |
17 import java.util.Iterator; | |
18 import java.util.Set; | |
19 | |
20 /** | |
21 * Base class for all Activity-based Instrumentation tests. | |
22 * | |
23 * @param <T> The Activity type. | |
24 */ | |
25 public class BaseActivityInstrumentationTestCase<T extends Activity> | |
26 extends ActivityInstrumentationTestCase2<T> { | |
27 private static final String TAG = "BaseActivityInstrumentationTestCase"; | |
nyquist
2015/01/28 23:10:36
Nit: I don't think this field is used.
jbudorick
2015/01/29 04:46:45
Removed.
| |
28 | |
29 /** | |
30 * Creates a instance for running tests against an Activity of the given cla ss. | |
31 * | |
32 * @param activityClass The type of activity that will be tested. | |
33 */ | |
34 public BaseActivityInstrumentationTestCase(Class<T> activityClass) { | |
35 super(activityClass); | |
36 } | |
37 | |
38 /** | |
39 * Sets up the CommandLine with the appropriate flags. | |
40 * | |
41 * This will add the difference of the sets of flags specified by @CommandLi neFlags.Add and | |
nyquist
2015/01/28 23:10:36
Nit: How about using {@link CommandLineFlags.Add}
jbudorick
2015/01/29 04:46:45
Done.
| |
42 * @CommandLineFlags.Remove to the CommandLine. Note that trying to remove a flag set | |
Ted C
2015/01/29 00:39:51
This caveat scares me. If a test is explicitly tr
jbudorick
2015/01/29 04:46:45
Understandably so. Neither base::CommandLine nor o
jbudorick
2015/01/29 04:46:45
added {@link org.chromium.base.CommandLine} here
| |
43 * externally, i.e. by the command-line flags file, will not work. | |
44 */ | |
45 @Override | |
46 protected void setUp() throws Exception { | |
47 super.setUp(); | |
48 | |
49 CommandLine.reset(); | |
50 BaseChromiumApplication.initCommandLine(getInstrumentation().getTargetCo ntext()); | |
Ted C
2015/01/29 00:39:51
You might want to do what is in CommandLineTestUti
jbudorick
2015/01/29 04:46:45
Criteria & CriteriaHelper are in content/. I've re
| |
51 | |
52 Class<?> testClass = getClass(); | |
53 Method testMethod = testClass.getMethod(getName()); | |
54 | |
55 Set<String> flags = getClassFlags(testClass); | |
56 | |
57 if (testMethod.isAnnotationPresent(CommandLineFlags.Add.class)) { | |
58 flags.addAll( | |
59 Arrays.asList(testMethod.getAnnotation(CommandLineFlags.Add. class).value())); | |
60 } | |
61 | |
62 if (testMethod.isAnnotationPresent(CommandLineFlags.Remove.class)) { | |
63 flags.removeAll( | |
64 Arrays.asList(testMethod.getAnnotation(CommandLineFlags.Remo ve.class).value())); | |
65 } | |
66 | |
67 Iterator<String> flagIter = flags.iterator(); | |
68 while (flagIter.hasNext()) { | |
nyquist
2015/01/28 23:10:36
Nit: I often find it easier to read:
for (String f
jbudorick
2015/01/29 04:46:45
Done.
| |
69 CommandLine.getInstance().appendSwitch(flagIter.next()); | |
70 } | |
71 } | |
72 | |
73 private Set<String> getClassFlags(Class<?> testClass) { | |
nyquist
2015/01/28 23:10:36
Nit: This method should be static to signal that i
jbudorick
2015/01/29 04:46:45
Done.
| |
74 Class<?> superclass = testClass.getSuperclass(); | |
75 Set<String> flags = null; | |
nyquist
2015/01/28 23:10:36
Nit: You are always initializing this field below,
jbudorick
2015/01/29 04:46:45
Done.
| |
76 if (superclass != null) { | |
nyquist
2015/01/28 23:10:36
Optional nit: My personal preference is to not fli
jbudorick
2015/01/29 04:46:45
ternary conditional it is
| |
77 flags = getClassFlags(superclass); | |
78 } else { | |
79 flags = new HashSet<String>(); | |
80 } | |
81 | |
82 if (testClass.isAnnotationPresent(CommandLineFlags.Add.class)) { | |
Ted C
2015/01/29 00:39:51
Can this and the if below be abstracted out to a h
jbudorick
2015/01/29 04:46:45
Done.
| |
83 flags.addAll( | |
84 Arrays.asList(testClass.getAnnotation(CommandLineFlags.Add.c lass).value())); | |
85 } | |
86 | |
87 if (testClass.isAnnotationPresent(CommandLineFlags.Remove.class)) { | |
88 flags.removeAll( | |
89 Arrays.asList(testClass.getAnnotation(CommandLineFlags.Remov e.class).value())); | |
90 } | |
91 | |
92 return flags; | |
93 } | |
94 } | |
OLD | NEW |