Commit 7a6558db authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

ChromeFeatureList tests demonstrating behavior in instrumentation tests

Also allow any "*InstrumentationTest.java" to depend on chrome/android
even if in a module.

Bug: 1053463
Change-Id: Idfac74521187a4d8ee923732cbaf8e6bee108b47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2080579Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749380}
parent cbd63cb1
......@@ -2057,6 +2057,7 @@ chrome_test_apk_tmpl("chrome_public_test_apk") {
"//chrome/android/webapk/libs/runtime_library:runtime_library_javatests",
"//chrome/android/webapk/shell_apk:shell_apk_javatests",
"//chrome/browser/download/android:download_java_tests",
"//chrome/browser/flags:javatests",
"//chrome/browser/subresource_filter:subresource_filter_javatests",
"//chrome/browser/touch_to_fill/android:test_java",
"//chrome/browser/ui/android/appmenu/internal:javatests",
......
......@@ -430,6 +430,10 @@ include_rules = [
]
specific_include_rules = {
'.*InstrumentationTest\.java': [
# Android instrumentation tests depend on the whole app.
"+chrome/android",
],
"platform_util_linux.cc": [
# The following is used to call the org.freedesktop.FileManager1
# DBus interface to highlight a file within its parent folder
......
......@@ -65,3 +65,20 @@ java_library("flags_junit_tests") {
"//chrome/test/android:chrome_java_test_support",
]
}
android_library("javatests") {
testonly = true
sources = [ "android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureListInstrumentationTest.java" ]
deps = [
":java",
"//base:base_java",
"//base:base_java_test_support",
"//base/test:test_support_java",
"//chrome/android:chrome_java",
"//chrome/test/android:chrome_java_test_support",
"//third_party/android_sdk:android_test_mock_java",
"//third_party/android_support_test_runner:runner_java",
"//third_party/junit",
"//third_party/mockito:mockito_java",
]
}
// 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 android.util.ArrayMap;
import androidx.test.filters.MediumTest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import java.util.Map;
/**
* Tests the behavior of {@link ChromeFeatureList} in instrumentation tests.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class ChromeFeatureListInstrumentationTest {
@Rule
public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class);
@Before
public void setUp() throws Exception {
mActivityTestRule.startMainActivityOnBlankPage();
}
@Test
@MediumTest
public void testNoOverridesDefault() {
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
assertTrue(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_ENABLED));
}
@Test
@MediumTest
@EnableFeatures(ChromeFeatureList.TEST_DEFAULT_DISABLED)
@DisableFeatures(ChromeFeatureList.TEST_DEFAULT_ENABLED)
public void testAnnotations() {
assertTrue(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_ENABLED));
}
@Test
@MediumTest
public void testSetTestFeatures() {
Map<String, Boolean> overrides = new ArrayMap<>();
overrides.put(ChromeFeatureList.TEST_DEFAULT_DISABLED, true);
overrides.put(ChromeFeatureList.TEST_DEFAULT_ENABLED, false);
ChromeFeatureList.setTestFeatures(overrides);
assertTrue(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_ENABLED));
ChromeFeatureList.setTestFeatures(null);
}
}
......@@ -21,7 +21,7 @@ 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
* Tests the behavior of {@link ChromeFeatureList} in Robolectric unit tests when the rule
* Features.JUnitProcessor is present.
*/
@RunWith(BaseRobolectricTestRunner.class)
......@@ -59,9 +59,9 @@ public class ChromeFeatureListWithProcessorUnitTest {
* In unit tests, flags may have their value specified by the DisableFeatures annotation.
*/
@Test
@DisableFeatures(ChromeFeatureList.TEST_DEFAULT_DISABLED)
@DisableFeatures(ChromeFeatureList.TEST_DEFAULT_ENABLED)
public void testAnnotationDisabled_returnsDisabled() {
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_ENABLED));
}
/**
......@@ -83,8 +83,8 @@ public class ChromeFeatureListWithProcessorUnitTest {
@Test
public void testSetTestFeaturesDisabled_returnsDisabled() {
ChromeFeatureList.setTestFeatures(
Collections.singletonMap(ChromeFeatureList.TEST_DEFAULT_DISABLED, false));
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
Collections.singletonMap(ChromeFeatureList.TEST_DEFAULT_ENABLED, false));
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_ENABLED));
ChromeFeatureList.setTestFeatures(null);
}
}
......@@ -18,7 +18,7 @@ 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
* Tests the behavior of {@link ChromeFeatureList} in Robolectric unit tests when the rule
* Features.JUnitProcessor is NOT present.
*/
@RunWith(BaseRobolectricTestRunner.class)
......@@ -55,9 +55,9 @@ public class ChromeFeatureListWithoutProcessorUnitTest {
* work.
*/
@Test(expected = AssertionError.class)
@DisableFeatures(ChromeFeatureList.TEST_DEFAULT_DISABLED)
@DisableFeatures(ChromeFeatureList.TEST_DEFAULT_ENABLED)
public void testAnnotationDisabled_asserts() {
ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED);
ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_ENABLED);
}
/**
......@@ -79,8 +79,8 @@ public class ChromeFeatureListWithoutProcessorUnitTest {
@Test
public void testSetTestFeaturesDisabled_returnsDisabled() {
ChromeFeatureList.setTestFeatures(
Collections.singletonMap(ChromeFeatureList.TEST_DEFAULT_DISABLED, false));
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_DISABLED));
Collections.singletonMap(ChromeFeatureList.TEST_DEFAULT_ENABLED, false));
assertFalse(ChromeFeatureList.isEnabled(ChromeFeatureList.TEST_DEFAULT_ENABLED));
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