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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/test/CommandLineInitRule.java

Issue 2954393003: Fix test crashes related to AccountManagerHelper. (Closed)
Patch Set: . 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: chrome/android/javatests/src/org/chromium/chrome/browser/test/CommandLineInitRule.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/test/CommandLineInitRule.java b/chrome/android/javatests/src/org/chromium/chrome/browser/test/CommandLineInitRule.java
new file mode 100644
index 0000000000000000000000000000000000000000..979e2b6b3a0c232cab536fe42ccbb0f235532560
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/test/CommandLineInitRule.java
@@ -0,0 +1,39 @@
+// 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.chrome.browser.test;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import org.chromium.base.CommandLine;
+
+import java.util.Arrays;
+
+/**
+ * JUnit rule for setting command line arguments before initializing the browser.
+ *
+ * Having it as its own rule allows us to chain it using RuleChain and allows it to be explicitly
+ * run prior to initializing the browser.
+ */
+public class CommandLineInitRule implements TestRule {
+ private String[] mArgs;
+
+ public CommandLineInitRule(String[] args) {
+ if (args != null) {
+ mArgs = Arrays.copyOf(args, args.length);
+ }
+ }
+
+ @Override
+ public Statement apply(Statement base, Description description) {
+ return new Statement() {
+ @Override
+ public void evaluate() {
+ CommandLine.init(mArgs);
+ }
+ };
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698