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

Side by Side Diff: android_webview/test/shell/src/org/chromium/android_webview/test/AwJUnit4ClassRunner.java

Issue 2933623002: Create AwJUnit4ClassRunner AwActivityTestRule and convert AwContentsTest (Closed)
Patch Set: address bo's comments Created 3 years, 4 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
(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.Log;
17 import org.chromium.base.test.BaseJUnit4ClassRunner;
18 import org.chromium.base.test.BaseTestResult.PreTestHook;
19 import org.chromium.base.test.util.CommandLineFlags;
20 import org.chromium.base.test.util.parameter.SkipCommandLineParameterization;
21 import org.chromium.policy.test.annotations.Policies;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 /**
27 * A custom runner for //chrome JUnit4 tests.
28 */
29 public final class AwJUnit4ClassRunner extends BaseJUnit4ClassRunner {
30 /**
31 * Create an AwJUnit4ClassRunner to run {@code klass} and initialize values
32 *
33 * @param klass Test class to run
34 * @throws InitializationError if the test class is malformed
35 */
36 public AwJUnit4ClassRunner(Class<?> klass) throws InitializationError {
37 super(klass, null, defaultPreTestHooks());
38 }
39
40 private static List<PreTestHook> defaultPreTestHooks() {
41 return CollectionUtil.newArrayList(Policies.getRegistrationHook());
42 }
43
44 @Override
45 protected List<FrameworkMethod> getChildren() {
46 List<FrameworkMethod> result = new ArrayList<>();
47 Log.w("#YOLAND-SIZE",
boliu 2017/07/27 17:32:18 no random logs, and below
48 Integer.toString(computeTestMethods().size()) + " tests in total first");
49 for (FrameworkMethod method : computeTestMethods()) {
50 if (method.getAnnotation(SkipCommandLineParameterization.class) == n ull) {
51 result.add(new WebViewMultiProcessFrameworkMethod(method));
52 }
53 result.add(method);
54 }
55 Log.w("#YOLAND-SIZE", Integer.toString(result.size()) + " tests in total ");
56 return result;
57 }
58
59 @Override
60 protected void runChild(FrameworkMethod method, RunNotifier notifier) {
61 CommandLineFlags.setUp(InstrumentationRegistry.getTargetContext(), metho d.getMethod());
62 if (method instanceof WebViewMultiProcessFrameworkMethod) {
63 CommandLine.getInstance().appendSwitch(AwSwitches.WEBVIEW_SANDBOXED_ RENDERER);
64 }
65 super.runChild(method, notifier);
66 }
67
68 /**
69 * Custom FrameworkMethod class indicate this test method will run in multip rocess mode.
70 *
71 * The clas also add "__multiprocess_mode" postfix to the test name.
72 */
73 private static class WebViewMultiProcessFrameworkMethod extends FrameworkMet hod {
74 public WebViewMultiProcessFrameworkMethod(FrameworkMethod method) {
75 super(method.getMethod());
76 }
77
78 @Override
79 public String getName() {
80 return super.getName() + "__multiprocess_mode";
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (obj instanceof WebViewMultiProcessFrameworkMethod) {
86 WebViewMultiProcessFrameworkMethod method =
87 (WebViewMultiProcessFrameworkMethod) obj;
88 return super.equals(obj) && method.getName().equals(getName());
89 }
90 return false;
91 }
92
93 @Override
94 public int hashCode() {
95 int result = 17;
96 result = 31 * result + super.hashCode();
97 result = 31 * result + getName().hashCode();
98 return result;
99 }
100 }
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698