Commit 669cb067 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

ChromeFeatureList meta tests demonstrating its behavior in unit tests.

Bug: 1053463
Change-Id: I3fd46315c971c6377e194f956b769950b9129d1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2064183Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743325}
parent c1d01aac
...@@ -664,6 +664,7 @@ junit_binary("chrome_junit_tests") { ...@@ -664,6 +664,7 @@ junit_binary("chrome_junit_tests") {
"//chrome/android/webapk/libs/client:client_java", "//chrome/android/webapk/libs/client:client_java",
"//chrome/android/webapk/libs/common:common_java", "//chrome/android/webapk/libs/common:common_java",
"//chrome/android/webapk/test:junit_test_support", "//chrome/android/webapk/test:junit_test_support",
"//chrome/browser/flags:flags_junit_tests",
"//chrome/browser/image_fetcher:java", "//chrome/browser/image_fetcher:java",
"//chrome/browser/preferences:preferences_junit_tests", "//chrome/browser/preferences:preferences_junit_tests",
"//chrome/browser/thumbnail:java", "//chrome/browser/thumbnail:java",
......
...@@ -24,3 +24,21 @@ generate_jni("jni_headers") { ...@@ -24,3 +24,21 @@ generate_jni("jni_headers") {
"android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java", "android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java",
] ]
} }
java_library("flags_junit_tests") {
# Skip platform checks since Robolectric depends on requires_android targets.
bypass_platform_checks = true
testonly = true
sources = [
"android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureListWithProcessorUnitTest.java",
"android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureListWithoutProcessorUnitTest.java",
]
deps = [
":java",
"//base:base_java",
"//base:base_java_test_support",
"//base:base_junit_test_support",
"//base/test:test_support_java",
"//chrome/test/android:chrome_java_test_support",
]
}
...@@ -199,6 +199,8 @@ const base::Feature* kFeaturesExposedToJava[] = { ...@@ -199,6 +199,8 @@ const base::Feature* kFeaturesExposedToJava[] = {
&kTabReparenting, &kTabReparenting,
&kTabSwitcherOnReturn, &kTabSwitcherOnReturn,
&kTabToGTSAnimation, &kTabToGTSAnimation,
&kTestDefaultDisabled,
&kTestDefaultEnabled,
&kTrustedWebActivityPostMessage, &kTrustedWebActivityPostMessage,
&kStartSurfaceAndroid, &kStartSurfaceAndroid,
&kUmaBackgroundSessions, &kUmaBackgroundSessions,
...@@ -591,6 +593,12 @@ const base::Feature kTabSwitcherOnReturn{"TabSwitcherOnReturn", ...@@ -591,6 +593,12 @@ const base::Feature kTabSwitcherOnReturn{"TabSwitcherOnReturn",
const base::Feature kTabToGTSAnimation{"TabToGTSAnimation", const base::Feature kTabToGTSAnimation{"TabToGTSAnimation",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kTestDefaultDisabled{"TestDefaultDisabled",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kTestDefaultEnabled{"TestDefaultEnabled",
base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kTrustedWebActivityPostMessage{ const base::Feature kTrustedWebActivityPostMessage{
"TrustedWebActivityPostMessage", base::FEATURE_DISABLED_BY_DEFAULT}; "TrustedWebActivityPostMessage", base::FEATURE_DISABLED_BY_DEFAULT};
......
...@@ -122,6 +122,8 @@ extern const base::Feature kTabGridLayoutAndroid; ...@@ -122,6 +122,8 @@ extern const base::Feature kTabGridLayoutAndroid;
extern const base::Feature kTabReparenting; extern const base::Feature kTabReparenting;
extern const base::Feature kTabSwitcherOnReturn; extern const base::Feature kTabSwitcherOnReturn;
extern const base::Feature kTabToGTSAnimation; extern const base::Feature kTabToGTSAnimation;
extern const base::Feature kTestDefaultDisabled;
extern const base::Feature kTestDefaultEnabled;
extern const base::Feature kTrustedWebActivityPostMessage; extern const base::Feature kTrustedWebActivityPostMessage;
extern const base::Feature kStartSurfaceAndroid; extern const base::Feature kStartSurfaceAndroid;
extern const base::Feature kUmaBackgroundSessions; extern const base::Feature kUmaBackgroundSessions;
......
...@@ -358,6 +358,8 @@ public abstract class ChromeFeatureList { ...@@ -358,6 +358,8 @@ public abstract class ChromeFeatureList {
public static final String TAB_REPARENTING = "TabReparenting"; public static final String TAB_REPARENTING = "TabReparenting";
public static final String TAB_SWITCHER_ON_RETURN = "TabSwitcherOnReturn"; public static final String TAB_SWITCHER_ON_RETURN = "TabSwitcherOnReturn";
public static final String TAB_TO_GTS_ANIMATION = "TabToGTSAnimation"; public static final String TAB_TO_GTS_ANIMATION = "TabToGTSAnimation";
public static final String TEST_DEFAULT_DISABLED = "TestDefaultDisabled";
public static final String TEST_DEFAULT_ENABLED = "TestDefaultEnabled";
public static final String TOUCH_TO_FILL_ANDROID = "TouchToFillAndroid"; public static final String TOUCH_TO_FILL_ANDROID = "TouchToFillAndroid";
public static final String TRUSTED_WEB_ACTIVITY = "TrustedWebActivity"; public static final String TRUSTED_WEB_ACTIVITY = "TrustedWebActivity";
public static final String TRUSTED_WEB_ACTIVITY_POST_MESSAGE = "TrustedWebActivityPostMessage"; public static final String TRUSTED_WEB_ACTIVITY_POST_MESSAGE = "TrustedWebActivityPostMessage";
......
// Copyright 2020 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.flags;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import java.util.Collections;
/**
* Shows the behavior of {@link ChromeFeatureList} in Robolectric unit tests when the rule
* Features.JUnitProcessor is present.
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class ChromeFeatureListWithProcessorUnitTest {
@Rule
public TestRule mProcessor = new Features.JUnitProcessor();
/**
* In unit tests, all flags checked must have their value specified.
*/
@Test(expected = IllegalArgumentException.class)
public void testNoOverridesDefaultDisabled_throws() {
ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED);
}
/**
* In unit tests, all flags checked must have their value specified.
*/
@Test(expected = IllegalArgumentException.class)
public void testNoOverridesDefaultEnabled_throws() {
ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_ENABLED);
}
/**
* In unit tests, flags may have their value specified by the EnableFeatures annotation.
*/
@Test
@EnableFeatures(ChromeFeatureList.TEST_DEFAULT_DISABLED)
public void testAnnotationEnabled_returnsEnabled() {
assertTrue(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
}
/**
* In unit tests, flags may have their value specified by the DisableFeatures annotation.
*/
@Test
@DisableFeatures(ChromeFeatureList.TEST_DEFAULT_DISABLED)
public void testAnnotationDisabled_returnsDisabled() {
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
}
/**
* In unit tests, flags may have their value specified by calling
* {@link ChromeFeatureList#setTestFeatures(java.util.Map)}.
*/
@Test
public void testSetTestFeaturesEnabled_returnsEnabled() {
ChromeFeatureList.setTestFeatures(
Collections.singletonMap(ChromeFeatureList.TEST_DEFAULT_DISABLED, true));
assertTrue(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
ChromeFeatureList.setTestFeatures(null);
}
/**
* In unit tests, flags may have their value specified by calling
* {@link ChromeFeatureList#setTestFeatures(java.util.Map)}.
*/
@Test
public void testSetTestFeaturesDisabled_returnsDisabled() {
ChromeFeatureList.setTestFeatures(
Collections.singletonMap(ChromeFeatureList.TEST_DEFAULT_DISABLED, false));
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
ChromeFeatureList.setTestFeatures(null);
}
}
// Copyright 2020 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.flags;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import java.util.Collections;
/**
* Shows the behavior of {@link ChromeFeatureList} in Robolectric unit tests when the rule
* Features.JUnitProcessor is NOT present.
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class ChromeFeatureListWithoutProcessorUnitTest {
/**
* In unit tests, all flags checked must have their value specified.
*/
@Test(expected = AssertionError.class)
public void testNoOverridesDefaultDisabled_asserts() {
ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED);
}
/**
* In unit tests, all flags checked must have their value specified.
*/
@Test(expected = AssertionError.class)
public void testNoOverridesDefaultEnabled_asserts() {
ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_ENABLED);
}
/**
* In unit tests without a Features.JUnitProcessor, the EnableFeatures annotation does not
* work.
*/
@Test(expected = AssertionError.class)
@EnableFeatures(ChromeFeatureList.TEST_DEFAULT_DISABLED)
public void testAnnotationEnabled_asserts() {
ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED);
}
/**
* In unit tests without a Features.JUnitProcessor, the DisableFeatures annotation does not
* work.
*/
@Test(expected = AssertionError.class)
@DisableFeatures(ChromeFeatureList.TEST_DEFAULT_DISABLED)
public void testAnnotationDisabled_asserts() {
ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED);
}
/**
* In unit tests without a Features.JUnitProcessor, flags may have their value specified by
* calling {@link ChromeFeatureList#setTestFeatures(java.util.Map)}.
*/
@Test
public void testSetTestFeaturesEnabled_returnsEnabled() {
ChromeFeatureList.setTestFeatures(
Collections.singletonMap(ChromeFeatureList.TEST_DEFAULT_DISABLED, true));
assertTrue(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
ChromeFeatureList.setTestFeatures(null);
}
/**
* In unit tests without a Features.JUnitProcessor, flags may have their value specified by
* calling {@link ChromeFeatureList#setTestFeatures(java.util.Map)}.
*/
@Test
public void testSetTestFeaturesDisabled_returnsDisabled() {
ChromeFeatureList.setTestFeatures(
Collections.singletonMap(ChromeFeatureList.TEST_DEFAULT_DISABLED, false));
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
ChromeFeatureList.setTestFeatures(null);
}
}
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