Index: android_webview/test/shell/src/org/chromium/android_webview/test/AwJUnit4ClassRunner.java |
diff --git a/android_webview/test/shell/src/org/chromium/android_webview/test/AwJUnit4ClassRunner.java b/android_webview/test/shell/src/org/chromium/android_webview/test/AwJUnit4ClassRunner.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5156946e6f6a34d57df8c2682bbcb5969586886a |
--- /dev/null |
+++ b/android_webview/test/shell/src/org/chromium/android_webview/test/AwJUnit4ClassRunner.java |
@@ -0,0 +1,94 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.android_webview.test; |
+ |
+import android.support.test.InstrumentationRegistry; |
+ |
+import org.junit.runner.notification.RunNotifier; |
+import org.junit.runners.model.FrameworkMethod; |
+import org.junit.runners.model.InitializationError; |
+ |
+import org.chromium.android_webview.AwSwitches; |
+import org.chromium.base.CollectionUtil; |
+import org.chromium.base.CommandLine; |
+import org.chromium.base.test.BaseJUnit4ClassRunner; |
+import org.chromium.base.test.BaseTestResult.PreTestHook; |
+import org.chromium.base.test.util.CommandLineFlags; |
+import org.chromium.base.test.util.parameter.SkipCommandLineParameterization; |
+import org.chromium.policy.test.annotations.Policies; |
+ |
+import java.util.ArrayList; |
+import java.util.List; |
+ |
+/** |
+ * A custom runner for //chrome JUnit4 tests. |
+ */ |
+public final class AwJUnit4ClassRunner extends BaseJUnit4ClassRunner { |
+ /** |
+ * Create an AwJUnit4ClassRunner to run {@code klass} and initialize values |
+ * |
+ * @param klass Test class to run |
+ * @throws InitializationError if the test class is malformed |
+ */ |
+ public AwJUnit4ClassRunner(Class<?> klass) throws InitializationError { |
+ super(klass, null, defaultPreTestHooks()); |
+ } |
+ |
+ private static List<PreTestHook> defaultPreTestHooks() { |
+ return CollectionUtil.newArrayList(Policies.getRegistrationHook()); |
+ } |
+ |
+ @Override |
+ protected List<FrameworkMethod> getChildren() { |
+ List<FrameworkMethod> result = new ArrayList<>(); |
+ for (FrameworkMethod method : computeTestMethods()) { |
+ if (method.getAnnotation(SkipCommandLineParameterization.class) == null) { |
+ result.add(new WebViewParameterizedFrameworkMethod(method)); |
+ } |
+ result.add(method); |
+ } |
+ return result; |
+ } |
+ |
+ @Override |
+ protected void runChild(FrameworkMethod method, RunNotifier notifier) { |
+ CommandLineFlags.setUp(InstrumentationRegistry.getTargetContext(), method.getMethod()); |
+ 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
|
+ CommandLine.getInstance().appendSwitch(AwSwitches.WEBVIEW_SANDBOXED_RENDERER); |
+ } |
+ super.runChild(method, notifier); |
+ } |
+ |
+ // TODO(yolandyan): replace this with Parameterized test method once the JUnit4 parameter CL |
+ // lands |
+ private static class WebViewParameterizedFrameworkMethod extends FrameworkMethod { |
+ public WebViewParameterizedFrameworkMethod(FrameworkMethod method) { |
+ super(method.getMethod()); |
+ } |
+ |
+ @Override |
+ public String getName() { |
+ return super.getName() + "__sandboxed_mode"; |
boliu
2017/07/20 21:22:48
__multiprocess_mode?
the real yoland
2017/07/27 00:29:48
Done
|
+ } |
+ |
+ @Override |
+ 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
|
+ if (obj instanceof WebViewParameterizedFrameworkMethod) { |
+ WebViewParameterizedFrameworkMethod method = |
+ (WebViewParameterizedFrameworkMethod) obj; |
+ return super.equals(obj) && method.getName().equals(getName()); |
+ } |
+ return false; |
+ } |
+ |
+ @Override |
+ public int hashCode() { |
+ int result = 17; |
+ result = 31 * result + super.hashCode(); |
+ result = 31 * result + getName().hashCode(); |
+ return result; |
+ } |
+ } |
+} |