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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
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..0034d4172dd084d7591522223fbb9de67057268e
--- /dev/null
+++ b/android_webview/test/shell/src/org/chromium/android_webview/test/AwJUnit4ClassRunner.java
@@ -0,0 +1,101 @@
+// 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.Log;
+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<>();
+ Log.w("#YOLAND-SIZE",
boliu 2017/07/27 17:32:18 no random logs, and below
+ Integer.toString(computeTestMethods().size()) + " tests in total first");
+ for (FrameworkMethod method : computeTestMethods()) {
+ if (method.getAnnotation(SkipCommandLineParameterization.class) == null) {
+ result.add(new WebViewMultiProcessFrameworkMethod(method));
+ }
+ result.add(method);
+ }
+ Log.w("#YOLAND-SIZE", Integer.toString(result.size()) + " tests in total");
+ return result;
+ }
+
+ @Override
+ protected void runChild(FrameworkMethod method, RunNotifier notifier) {
+ CommandLineFlags.setUp(InstrumentationRegistry.getTargetContext(), method.getMethod());
+ if (method instanceof WebViewMultiProcessFrameworkMethod) {
+ CommandLine.getInstance().appendSwitch(AwSwitches.WEBVIEW_SANDBOXED_RENDERER);
+ }
+ super.runChild(method, notifier);
+ }
+
+ /**
+ * Custom FrameworkMethod class indicate this test method will run in multiprocess mode.
+ *
+ * The clas also add "__multiprocess_mode" postfix to the test name.
+ */
+ private static class WebViewMultiProcessFrameworkMethod extends FrameworkMethod {
+ public WebViewMultiProcessFrameworkMethod(FrameworkMethod method) {
+ super(method.getMethod());
+ }
+
+ @Override
+ public String getName() {
+ return super.getName() + "__multiprocess_mode";
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof WebViewMultiProcessFrameworkMethod) {
+ WebViewMultiProcessFrameworkMethod method =
+ (WebViewMultiProcessFrameworkMethod) 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;
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698