Commit a657d1a6 authored by Maria Khomenko's avatar Maria Khomenko Committed by Commit Bot

Ensure all features are applied correctly.

When tests use a rule that enables features and the test enables yet
another feature separately only one set of features will end up getting
applied because the enable-feature/disable-feature flag is duplicated.
Ensure we aggregate all requests before applying.

BUG=786454

Change-Id: I79208e13f25de7c725d71f241481a454265d83c4
Reviewed-on: https://chromium-review.googlesource.com/830259Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: Maria Khomenko <mariakhomenko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524517}
parent ba5b7706
......@@ -5,6 +5,7 @@
package org.chromium.base.test.util;
import android.content.Context;
import android.text.TextUtils;
import org.junit.Assert;
import org.junit.Rule;
......@@ -22,6 +23,7 @@ import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -54,6 +56,8 @@ import java.util.Set;
* Note that this class should never be instantiated.
*/
public final class CommandLineFlags {
private static final String DISABLE_FEATURES = "disable-features";
private static final String ENABLE_FEATURES = "enable-features";
/**
* Adds command-line flags to the {@link org.chromium.base.CommandLine} for this test.
......@@ -88,15 +92,33 @@ public final class CommandLineFlags {
Assert.assertNotNull("Unable to get a non-null target context.", targetContext);
CommandLine.reset();
BaseChromiumApplication.initCommandLine(targetContext);
Set<String> enableFeatures = new HashSet<String>();
Set<String> disableFeatures = new HashSet<String>();
Set<String> flags = getFlags(element);
for (String flag : flags) {
String[] parsedFlags = flag.split("=", 2);
if (parsedFlags.length == 1) {
CommandLine.getInstance().appendSwitch(flag);
} else if (ENABLE_FEATURES.equals(parsedFlags[0])) {
// We collect enable/disable features flags separately and aggregate them because
// they may be specified multiple times, in which case the values will trample each
// other.
Collections.addAll(enableFeatures, parsedFlags[1].split(","));
} else if (DISABLE_FEATURES.equals(parsedFlags[0])) {
Collections.addAll(disableFeatures, parsedFlags[1].split(","));
} else {
CommandLine.getInstance().appendSwitchWithValue(parsedFlags[0], parsedFlags[1]);
}
}
if (enableFeatures.size() > 0) {
CommandLine.getInstance().appendSwitchWithValue(
ENABLE_FEATURES, TextUtils.join(",", enableFeatures));
}
if (disableFeatures.size() > 0) {
CommandLine.getInstance().appendSwitchWithValue(
DISABLE_FEATURES, TextUtils.join(",", disableFeatures));
}
}
private static Set<String> getFlags(AnnotatedElement type) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment