OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.android_webview.test; | |
6 | |
7 import android.support.test.InstrumentationRegistry; | |
8 | |
9 import org.junit.runner.notification.RunNotifier; | |
10 import org.junit.runners.model.FrameworkMethod; | |
11 import org.junit.runners.model.InitializationError; | |
12 | |
13 import org.chromium.android_webview.AwSwitches; | |
14 import org.chromium.base.CollectionUtil; | |
15 import org.chromium.base.CommandLine; | |
16 import org.chromium.base.test.BaseJUnit4ClassRunner; | |
17 import org.chromium.base.test.BaseTestResult.PreTestHook; | |
18 import org.chromium.base.test.util.CommandLineFlags; | |
19 import org.chromium.base.test.util.parameter.SkipCommandLineParameterization; | |
20 import org.chromium.policy.test.annotations.Policies; | |
21 | |
22 import java.util.ArrayList; | |
23 import java.util.List; | |
24 | |
25 /** | |
26 * A custom runner for //chrome JUnit4 tests. | |
27 */ | |
28 public final class AwJUnit4ClassRunner extends BaseJUnit4ClassRunner { | |
29 /** | |
30 * Create an AwJUnit4ClassRunner to run {@code klass} and initialize values | |
31 * | |
32 * @param klass Test class to run | |
33 * @throws InitializationError if the test class is malformed | |
34 */ | |
35 public AwJUnit4ClassRunner(Class<?> klass) throws InitializationError { | |
36 super(klass, null, defaultPreTestHooks()); | |
37 } | |
38 | |
39 private static List<PreTestHook> defaultPreTestHooks() { | |
40 return CollectionUtil.newArrayList(Policies.getRegistrationHook()); | |
41 } | |
42 | |
43 @Override | |
44 protected List<FrameworkMethod> getChildren() { | |
45 List<FrameworkMethod> result = new ArrayList<>(); | |
46 for (FrameworkMethod method : computeTestMethods()) { | |
47 if (method.getAnnotation(SkipCommandLineParameterization.class) == n ull) { | |
48 result.add(new WebViewParameterizedFrameworkMethod(method)); | |
49 } | |
50 result.add(method); | |
51 } | |
52 return result; | |
53 } | |
54 | |
55 @Override | |
56 protected void runChild(FrameworkMethod method, RunNotifier notifier) { | |
57 CommandLineFlags.setUp(InstrumentationRegistry.getTargetContext(), metho d.getMethod()); | |
58 if (method instanceof WebViewParameterizedFrameworkMethod) { | |
boliu
2017/07/20 21:22:47
I think you can be a bit more specific with the na
the real yoland
2017/07/27 00:29:48
Done
| |
59 CommandLine.getInstance().appendSwitch(AwSwitches.WEBVIEW_SANDBOXED_ RENDERER); | |
60 } | |
61 super.runChild(method, notifier); | |
62 } | |
63 | |
64 // TODO(yolandyan): replace this with Parameterized test method once the JUn it4 parameter CL | |
65 // lands | |
66 private static class WebViewParameterizedFrameworkMethod extends FrameworkMe thod { | |
67 public WebViewParameterizedFrameworkMethod(FrameworkMethod method) { | |
68 super(method.getMethod()); | |
69 } | |
70 | |
71 @Override | |
72 public String getName() { | |
73 return super.getName() + "__sandboxed_mode"; | |
boliu
2017/07/20 21:22:48
__multiprocess_mode?
the real yoland
2017/07/27 00:29:48
Done
| |
74 } | |
75 | |
76 @Override | |
77 public boolean equals(Object obj) { | |
boliu
2017/07/20 21:22:47
are these two necessary?
the real yoland
2017/07/27 00:29:48
Yes, I encounter a bug where the test runner ask f
| |
78 if (obj instanceof WebViewParameterizedFrameworkMethod) { | |
79 WebViewParameterizedFrameworkMethod method = | |
80 (WebViewParameterizedFrameworkMethod) obj; | |
81 return super.equals(obj) && method.getName().equals(getName()); | |
82 } | |
83 return false; | |
84 } | |
85 | |
86 @Override | |
87 public int hashCode() { | |
88 int result = 17; | |
89 result = 31 * result + super.hashCode(); | |
90 result = 31 * result + getName().hashCode(); | |
91 return result; | |
92 } | |
93 } | |
94 } | |
OLD | NEW |