Commit 033b53e3 authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android] Add tests for status bar color in overview mode

This CL:
- Adds tests for the status bar color in overview mode.
- Adds @Feature({"StatusBar"}) to all status bar tests
- Adds documentation for why ThemeTestUtils#assertStatusBarColor() is
L+

BUG=1015627

Change-Id: If17b35cad970942add9525229da3275ac31b6adb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2069501
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744149}
parent 2aaa5566
......@@ -514,6 +514,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/tracing/settings/TracingSettingsTest.java",
"javatests/src/org/chromium/chrome/browser/translate/TranslateCompactInfoBarTest.java",
"javatests/src/org/chromium/chrome/browser/translate/TranslateOptionsTest.java",
"javatests/src/org/chromium/chrome/browser/ui/system/StatusBarColorControllerTest.java",
"javatests/src/org/chromium/chrome/browser/undo_tab_close_snackbar/UndoBarControllerTest.java",
"javatests/src/org/chromium/chrome/browser/usage_stats/TabSuspensionTest.java",
"javatests/src/org/chromium/chrome/browser/video/FullscreenVideoTest.java",
......
......@@ -33,6 +33,7 @@ import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeSwitches;
......@@ -130,6 +131,7 @@ public class TrustedWebActivityTest {
*/
@Test
@MediumTest
@Feature({"StatusBar"})
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP_MR1)
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
// Customizing status bar color is disallowed for tablets.
......@@ -151,6 +153,7 @@ public class TrustedWebActivityTest {
*/
@Test
@MediumTest
@Feature({"StatusBar"})
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP_MR1)
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
public void testStatusBarColorNoPageThemeColor() throws ExecutionException, TimeoutException {
......@@ -181,6 +184,7 @@ public class TrustedWebActivityTest {
*/
@Test
@MediumTest
@Feature({"StatusBar"})
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP_MR1)
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
public void testStatusBarColorCertificateError() throws ExecutionException, TimeoutException {
......
......@@ -873,6 +873,7 @@ public class CustomTabActivityTest {
*/
@Test
@SmallTest
@Feature({"StatusBar"})
@RetryOnFailure
public void testToolbarColor() {
Intent intent = createMinimalCustomTabIntent();
......
......@@ -124,7 +124,7 @@ public class BrandColorTest {
@Test
@SmallTest
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
@Feature({"Omnibox"})
@Feature({"StatusBar", "Omnibox"})
public void testNoBrandColor() {
startMainActivityWithURL(getUrlWithBrandColor(""));
checkForBrandColor(mDefaultColor);
......@@ -136,7 +136,7 @@ public class BrandColorTest {
@Test
@SmallTest
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
@Feature({"Omnibox"})
@Feature({"StatusBar", "Omnibox"})
public void testBrandColorNoAlpha() {
startMainActivityWithURL(getUrlWithBrandColor(BRAND_COLOR_1));
checkForBrandColor(Color.parseColor(BRAND_COLOR_1));
......@@ -148,7 +148,7 @@ public class BrandColorTest {
@Test
@SmallTest
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
@Feature({"Omnibox"})
@Feature({"StatusBar", "Omnibox"})
public void testImmediateColorChange() {
startMainActivityWithURL(getUrlWithBrandColor(BRAND_COLOR_1));
checkForBrandColor(Color.parseColor(BRAND_COLOR_1));
......@@ -169,7 +169,7 @@ public class BrandColorTest {
@Test
@SmallTest
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
@Feature({"Omnibox"})
@Feature({"StatusBar", "Omnibox"})
public void testBrandColorWithLoadStarted() {
startMainActivityWithURL(getUrlWithBrandColor(BRAND_COLOR_1));
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> {
......@@ -188,7 +188,7 @@ public class BrandColorTest {
@Test
@SmallTest
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
@Feature({"Omnibox"})
@Feature({"StatusBar", "Omnibox"})
public void testNavigatingToNewBrandColor() {
startMainActivityWithURL(getUrlWithBrandColor(BRAND_COLOR_1));
checkForBrandColor(Color.parseColor(BRAND_COLOR_1));
......@@ -203,7 +203,7 @@ public class BrandColorTest {
@Test
@SmallTest
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
@Feature({"Omnibox"})
@Feature({"StatusBar", "Omnibox"})
public void testNavigatingToBrandColorAndBack() {
startMainActivityWithURL("about:blank");
checkForBrandColor(mDefaultColor);
......@@ -228,7 +228,7 @@ public class BrandColorTest {
@SmallTest
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
@DisableInTabbedMode
@Feature({"Omnibox"})
@Feature({"StatusBar", "Omnibox"})
public void testBrandColorInterstitial() {
final String brandColorUrl = getUrlWithBrandColor(BRAND_COLOR_1);
startMainActivityWithURL(brandColorUrl);
......
// 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.ui.system;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.support.test.filters.LargeTest;
import org.junit.After;
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.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.browser.ThemeTestUtils;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/**
* {@link StatusBarColorController} tests.
* There are additional status bar color tests in {@link BrandColorTest}.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class StatusBarColorControllerTest {
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Before
public void setUp() {
CachedFeatureFlags.setGridTabSwitcherEnabledForTesting(true);
mActivityTestRule.startMainActivityOnBlankPage();
}
@After
public void tearDown() {
CachedFeatureFlags.setGridTabSwitcherEnabledForTesting(null);
}
/**
* Test that the status bar color is toggled when toggling incognito while in overview mode.
*/
@Test
@LargeTest
@Feature({"StatusBar"})
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP_MR1)
public void testColorToggleIncongitoInOverview() {
ChromeTabbedActivity activity = mActivityTestRule.getActivity();
Resources resources = activity.getResources();
final int expectedOverviewStandardColor = defaultColorFallbackToBlack(
ChromeColors.getPrimaryBackgroundColor(resources, false));
final int expectedOverviewIncognitoColor = defaultColorFallbackToBlack(
ChromeColors.getPrimaryBackgroundColor(resources, true));
mActivityTestRule.loadUrlInNewTab(
"about:blank", true /* incognito */, TabLaunchType.FROM_CHROME_UI);
TabModelSelector tabModelSelector = activity.getTabModelSelector();
TestThreadUtils.runOnUiThreadBlocking(
() -> { tabModelSelector.selectModel(true /* incongito */); });
TestThreadUtils.runOnUiThreadBlocking(
() -> { activity.getLayoutManager().showOverview(false /* animate */); });
ThemeTestUtils.assertStatusBarColor(activity, expectedOverviewIncognitoColor);
TestThreadUtils.runOnUiThreadBlocking(
() -> { tabModelSelector.selectModel(false /* incongito */); });
ThemeTestUtils.assertStatusBarColor(activity, expectedOverviewStandardColor);
}
/**
* Test that the default color (and not the active tab's brand color) is used in overview mode.
*/
@Test
@LargeTest
@Feature({"StatusBar"})
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP_MR1)
public void testBrandColorIgnoredInOverview() throws Exception {
ChromeTabbedActivity activity = mActivityTestRule.getActivity();
Resources resources = activity.getResources();
final int expectedDefaultStandardColor =
defaultColorFallbackToBlack(ChromeColors.getDefaultThemeColor(resources, false));
String pageWithBrandColorUrl = mActivityTestRule.getTestServer().getURL(
"/chrome/test/data/android/theme_color_test.html");
mActivityTestRule.loadUrl(pageWithBrandColorUrl);
ThemeTestUtils.waitForThemeColor(activity, Color.RED);
ThemeTestUtils.assertStatusBarColor(activity, Color.RED);
TestThreadUtils.runOnUiThreadBlocking(
() -> { activity.getLayoutManager().showOverview(false /* animate */); });
ThemeTestUtils.assertStatusBarColor(activity, expectedDefaultStandardColor);
}
private int defaultColorFallbackToBlack(int color) {
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ? Color.BLACK : color;
}
}
......@@ -81,7 +81,7 @@ public class WebappSplashScreenTest {
@Test
@SmallTest
@Feature({"Webapps"})
@Feature({"StatusBar", "Webapps"})
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
public void testThemeColorWhenNotSpecified() {
......
......@@ -40,7 +40,7 @@ public class WebappSplashScreenThemeColorTest {
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP_MR1)
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
// Customizing status bar color is disallowed for tablets.
@Feature({"Webapps"})
@Feature({"StatusBar", "Webapps"})
public void testThemeColorWhenSpecified() {
// This is Color.Magenta with 50% opacity.
final int intentThemeColor = Color.argb(0x80, 0xFF, 0, 0xFF);
......@@ -57,7 +57,7 @@ public class WebappSplashScreenThemeColorTest {
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP_MR1)
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
// Customizing status bar color is disallowed for tablets.
@Feature({"Webapps"})
@Feature({"StatusBar", "Webapps"})
public void testThemeColorNotUsedIfPagesHasOne() throws ExecutionException, TimeoutException {
final int intentThemeColor = Color.MAGENTA;
final int pageThemeColor = Color.RED;
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.test.util.browser;
import android.annotation.TargetApi;
import android.os.Build;
import org.junit.Assert;
......@@ -39,7 +40,10 @@ public class ThemeTestUtils {
/**
* Asserts that the status bar color equals the passed-in color.
* Method is for Android L+ because it relies on Window#getStatusBarColor() which was introduced
* in L.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static void assertStatusBarColor(ChromeActivity activity, int expectedColor) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
expectedColor = ColorUtils.getDarkenedColorForStatusBar(expectedColor);
......
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