Commit 7d0fbfd8 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

Revert "Android: TabThemeColorHelper"

This reverts commit bf9ab045.

Reason for revert: This seems like causing "chrome_public_test_apk on Android device Nexus 5X" fail.
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Android%20CFI
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Android%20CFI/3601
https://findit-for-me.appspot.com/waterfall/failure?url=https://build.chromium.org/p/chromium.memory/builders/Android%20CFI/builds/3602

Original change's description:
> Android: TabThemeColorHelper
> 
> This is to break the TabObserver present in Tab class down to feature
> level and eventually remove it. Theme color used for Tab is managed via
> Tab UserData. Relevant Tab methods also got migrated.
> 
> Bug: 877878
> Change-Id: If120beaaa370d07f6855ab666e380cc2318e945a
> Reviewed-on: https://chromium-review.googlesource.com/c/1304038
> Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
> Reviewed-by: Ted Choc <tedchoc@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#607422}

TBR=tedchoc@chromium.org,jinsukkim@chromium.org

Change-Id: I4bc704a509682873ef9f1a2e4f4fe82ac2a5cac2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 877878
Reviewed-on: https://chromium-review.googlesource.com/c/1333098Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607509}
parent 98a2b710
......@@ -13,7 +13,6 @@ import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabObserver;
import org.chromium.chrome.browser.tab.TabThemeColorHelper;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType;
......@@ -225,9 +224,8 @@ public class ActivityTabTaskDescriptionHelper {
*/
public void updateTaskDescription(String label, Bitmap icon) {
int color = mDefaultThemeColor;
TabThemeColorHelper tabTheme = TabThemeColorHelper.get(mCurrentTab);
if (mCurrentTab != null && !tabTheme.isDefaultColor()) {
color = tabTheme.getColor();
if (mCurrentTab != null && !mCurrentTab.isDefaultThemeColor()) {
color = mCurrentTab.getThemeColor();
}
ApiCompatibilityUtils.setTaskDescription(mActivity, label, icon, color);
}
......
......@@ -124,7 +124,6 @@ import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable;
import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.SyncController;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabThemeColorHelper;
import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager;
import org.chromium.chrome.browser.tabmodel.EmptyTabModel;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
......@@ -689,7 +688,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
@Override
public void onShown(Tab tab, @TabSelectionType int type) {
setStatusBarColor(tab, TabThemeColorHelper.getColor(tab));
setStatusBarColor(tab, tab.getThemeColor());
}
@Override
......@@ -723,9 +722,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
@Override
public void onContentChanged(Tab tab) {
if (getBottomSheet() != null) {
setStatusBarColor(tab, TabThemeColorHelper.get(tab).getDefaultColor());
}
if (getBottomSheet() != null) setStatusBarColor(tab, tab.getDefaultThemeColor());
}
};
......@@ -911,7 +908,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
* @param color The color that the status bar should be set to.
*/
protected void setStatusBarColor(@Nullable Tab tab, int color) {
setStatusBarColor(color, tab != null && TabThemeColorHelper.get(tab).isDefaultColor());
setStatusBarColor(color, tab != null && tab.isDefaultThemeColor());
}
/**
......
......@@ -121,7 +121,6 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabDelegateFactory;
import org.chromium.chrome.browser.tab.TabRedirectHandler;
import org.chromium.chrome.browser.tab.TabStateBrowserControlsVisibilityDelegate;
import org.chromium.chrome.browser.tab.TabThemeColorHelper;
import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager;
import org.chromium.chrome.browser.tabmodel.ChromeTabCreator;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
......@@ -2204,7 +2203,7 @@ public class ChromeTabbedActivity
public void onOverviewModeFinishedHiding() {
if (getAssistStatusHandler() != null) getAssistStatusHandler().updateAssistState();
if (getActivityTab() != null) {
setStatusBarColor(getActivityTab(), TabThemeColorHelper.getColor(getActivityTab()));
setStatusBarColor(getActivityTab(), getActivityTab().getThemeColor());
}
}
......
......@@ -49,7 +49,6 @@ import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.Fullscreen
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabObserver;
import org.chromium.chrome.browser.tab.TabThemeColorHelper;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabModel;
......@@ -876,7 +875,7 @@ public class CompositorViewHolder extends FrameLayout
@Override
public int getBrowserControlsBackgroundColor() {
return mTabVisible == null ? Color.WHITE : TabThemeColorHelper.getColor(mTabVisible);
return mTabVisible == null ? Color.WHITE : mTabVisible.getThemeColor();
}
@Override
......
......@@ -39,7 +39,6 @@ import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.tab.SadTab;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.Tab.TabHidingType;
import org.chromium.chrome.browser.tab.TabThemeColorHelper;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
......@@ -625,7 +624,7 @@ public class LayoutManager implements LayoutUpdateHost, LayoutProvider,
String url = tab.getUrl();
boolean isNativePage = tab.isNativePage()
|| (url != null && url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX));
int themeColor = TabThemeColorHelper.getColor(tab);
int themeColor = tab.getThemeColor();
boolean canUseLiveTexture = tab.getWebContents() != null && !SadTab.isShowing(tab)
&& !isNativePage && !tab.isHidden();
......
......@@ -89,6 +89,7 @@ import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabReparentingParams;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.browser.vr.VrModuleProvider;
import org.chromium.chrome.browser.widget.PulseDrawable;
import org.chromium.chrome.browser.widget.ViewHighlighter;
......@@ -377,6 +378,9 @@ public class Tab
*/
private long mDataSavedOnStartPageLoad;
private int mDefaultThemeColor;
private int mThemeColor;
/**
* The Text bubble used to display In Product help widget for download feature on videos.
*/
......@@ -410,6 +414,12 @@ public class Tab
auditor.notifyCertificateFailure(
PolicyAuditor.nativeGetCertificateFailure(getWebContents()),
getApplicationContext());
updateThemeColorIfNeeded(false);
}
@Override
public void onUrlUpdated(Tab tab) {
updateThemeColorIfNeeded(false);
}
@Override
......@@ -500,8 +510,8 @@ public class Tab
Resources resources = mThemedApplicationContext.getResources();
mIdealFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_size);
TabThemeColorHelper.createForTab(this);
mDefaultThemeColor = calculateDefaultThemeColor();
mThemeColor = calculateThemeColor(false);
// Restore data from the TabState, if it existed.
if (frozenState != null) {
......@@ -544,6 +554,11 @@ public class Tab
};
}
private int calculateDefaultThemeColor() {
Resources resources = mThemedApplicationContext.getResources();
return ColorUtils.getDefaultThemeColor(resources, mIncognito);
}
/**
* Restores member fields from the given TabState.
* @param state TabState containing information about this Tab.
......@@ -556,7 +571,8 @@ public class Tab
mTimestampMillis = state.timestampMillis;
mUrl = state.getVirtualUrlFromState();
TabThemeColorHelper.get(this).updateFromTabState(state);
mThemeColor = state.hasThemeColor() ? state.getThemeColor() : getDefaultThemeColor();
mTitle = state.getDisplayTitleFromState();
mIsTitleDirectionRtl = mTitle != null
&& LocalizationUtils.getFirstStrongCharacterDirection(mTitle)
......@@ -796,8 +812,8 @@ public class Tab
tabState.parentId = mParentId;
tabState.shouldPreserve = mShouldPreserve;
tabState.timestampMillis = mTimestampMillis;
tabState.themeColor = getThemeColor();
tabState.tabLaunchTypeAtCreation = mLaunchTypeAtCreation;
tabState.themeColor = TabThemeColorHelper.getColor(this);
return tabState;
}
......@@ -915,7 +931,64 @@ public class Tab
return Color.WHITE;
}
void notifyThemeColorChanged(int themeColor) {
/**
* @return The current theme color based on the value passed from the web contents and the
* security state.
*/
public int getThemeColor() {
return mThemeColor;
}
/**
* Calculate the theme color based on if the page is native, the theme color changed, etc.
* @param didWebContentsThemeColorChange If the theme color of the web contents is known to have
* changed.
* @return The theme color that should be used for this tab.
*/
private int calculateThemeColor(boolean didWebContentsThemeColorChange) {
if (isNativePage()) return mNativePage.getThemeColor();
// Start by assuming the current theme color is that one that should be used. This will
// either be transparent, the last theme color, or the color restored from TabState.
int themeColor = ColorUtils.isValidThemeColor(mThemeColor) || mThemeColor == 0
? mThemeColor
: getDefaultThemeColor();
// Only use the web contents for the theme color if it is known to have changed, This
// corresponds to the didChangeThemeColor in WebContentsObserver.
if (getWebContents() != null && didWebContentsThemeColorChange) {
themeColor = getWebContents().getThemeColor();
if (themeColor != 0 && !ColorUtils.isValidThemeColor(themeColor)) themeColor = 0;
}
// Do not apply the theme color if there are any security issues on the page.
int securityLevel = getSecurityLevel();
if (securityLevel == ConnectionSecurityLevel.DANGEROUS
|| securityLevel == ConnectionSecurityLevel.SECURE_WITH_POLICY_INSTALLED_CERT) {
themeColor = getDefaultThemeColor();
}
if (isShowingInterstitialPage()) themeColor = getDefaultThemeColor();
if (themeColor == Color.TRANSPARENT) themeColor = getDefaultThemeColor();
if (isIncognito()) themeColor = getDefaultThemeColor();
if (isPreview()) themeColor = getDefaultThemeColor();
// Ensure there is no alpha component to the theme color as that is not supported in the
// dependent UI.
themeColor |= 0xFF000000;
return themeColor;
}
/**
* Determines if the theme color has changed and notifies the listeners if it has.
* @param didWebContentsThemeColorChange If the theme color of the web contents is known to have
* changed.
*/
void updateThemeColorIfNeeded(boolean didWebContentsThemeColorChange) {
int themeColor = calculateThemeColor(didWebContentsThemeColorChange);
if (themeColor == mThemeColor) return;
mThemeColor = themeColor;
RewindableIterator<TabObserver> observers = getTabObservers();
while (observers.hasNext()) {
observers.next().onDidChangeThemeColor(this, themeColor);
......@@ -1143,6 +1216,10 @@ public class Tab
mNativePage.getView().addOnAttachStateChangeListener(mAttachStateChangeListener);
}
pushNativePageStateToNavigationEntry();
// Notifying of theme color change before content change because some of
// the observers depend on the theme information being correct in
// onContentChanged().
updateThemeColorIfNeeded(false);
notifyContentChanged();
destroyNativePageInternal(previousNativePage);
}
......@@ -1362,6 +1439,8 @@ public class Tab
public void attach(ChromeActivity activity, TabDelegateFactory tabDelegateFactory) {
assert mIsDetached;
updateWindowAndroid(activity.getWindowAndroid());
mDefaultThemeColor = calculateDefaultThemeColor();
updateThemeColorIfNeeded(false);
// Update for the controllers that need the Compositor from the new Activity.
attachTabContentManager(activity.getTabContentManager());
......@@ -1671,6 +1750,7 @@ public class Tab
SwipeRefreshHandler.from(this);
updateThemeColorIfNeeded(false);
notifyContentChanged();
// For browser tabs, we want to set accessibility focus to the page
......@@ -2870,6 +2950,21 @@ public class Tab
return tab;
}
/**
* @return Whether the theme color for this tab is the default color.
*/
public boolean isDefaultThemeColor() {
return isNativePage() || mDefaultThemeColor == getThemeColor();
}
/**
* @return The default theme color for this tab.
*/
@VisibleForTesting
public int getDefaultThemeColor() {
return mDefaultThemeColor;
}
/**
* @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
* foreground, or null if this isn't possible.
......
// Copyright 2018 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.tab;
import android.content.res.Resources;
import android.graphics.Color;
import android.support.annotation.Nullable;
import org.chromium.base.UserData;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.TabState;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.components.security_state.ConnectionSecurityLevel;
/**
* Manages theme color used for {@link Tab}. Destroyed together with the tab.
*/
public class TabThemeColorHelper extends EmptyTabObserver implements UserData {
private static final Class<TabThemeColorHelper> USER_DATA_KEY = TabThemeColorHelper.class;
private final Tab mTab;
private int mDefaultColor;
private int mColor;
public static void createForTab(Tab tab) {
assert get(tab) == null;
tab.getUserDataHost().setUserData(USER_DATA_KEY, new TabThemeColorHelper(tab));
}
@Nullable
public static TabThemeColorHelper get(Tab tab) {
return tab.getUserDataHost().getUserData(USER_DATA_KEY);
}
/** Convenience method that returns theme color of {@link Tab}. */
public static int getColor(Tab tab) {
return get(tab).getColor();
}
/** Convenience method that returns default theme color of {@link Tab}. */
public static int getDefaultColor(Tab tab) {
return get(tab).getDefaultColor();
}
private TabThemeColorHelper(Tab tab) {
mTab = tab;
mDefaultColor = calculateDefaultColor();
mColor = calculateThemeColor(false);
tab.addObserver(this);
}
private void updateDefaultColor() {
calculateDefaultColor();
updateIfNeeded(false);
}
private int calculateDefaultColor() {
Resources resources = mTab.getThemedApplicationContext().getResources();
return ColorUtils.getDefaultThemeColor(resources, mTab.isIncognito());
}
void updateFromTabState(TabState state) {
mColor = state.hasThemeColor() ? state.getThemeColor() : getDefaultColor();
updateIfNeeded(false);
}
/**
* Calculate the theme color based on if the page is native, the theme color changed, etc.
* @param didWebContentsThemeColorChange If the theme color of the web contents is known to have
* changed.
* @return The theme color that should be used for this tab.
*/
private int calculateThemeColor(boolean didWebContentsThemeColorChange) {
if (mTab.isNativePage()) return mTab.getNativePage().getThemeColor();
// Start by assuming the current theme color is that one that should be used. This will
// either be transparent, the last theme color, or the color restored from TabState.
int themeColor =
ColorUtils.isValidThemeColor(mColor) || mColor == 0 ? mColor : getDefaultColor();
// Only use the web contents for the theme color if it is known to have changed, This
// corresponds to the didChangeThemeColor in WebContentsObserver.
if (mTab.getWebContents() != null && didWebContentsThemeColorChange) {
themeColor = mTab.getWebContents().getThemeColor();
if (themeColor != 0 && !ColorUtils.isValidThemeColor(themeColor)) themeColor = 0;
}
// Do not apply the theme color if there are any security issues on the page.
int securityLevel = mTab.getSecurityLevel();
if (securityLevel == ConnectionSecurityLevel.DANGEROUS
|| securityLevel == ConnectionSecurityLevel.SECURE_WITH_POLICY_INSTALLED_CERT) {
themeColor = getDefaultColor();
}
if (mTab.isShowingInterstitialPage()) themeColor = getDefaultColor();
if (themeColor == Color.TRANSPARENT) themeColor = getDefaultColor();
if (mTab.isIncognito()) themeColor = getDefaultColor();
if (mTab.isPreview()) themeColor = getDefaultColor();
// Ensure there is no alpha component to the theme color as that is not supported in the
// dependent UI.
themeColor |= 0xFF000000;
return themeColor;
}
/**
* Determines if the theme color has changed and notifies the listeners if it has.
* @param didWebContentsThemeColorChange If the theme color of the web contents is known to have
* changed.
*/
public void updateIfNeeded(boolean didWebContentsThemeColorChange) {
int themeColor = calculateThemeColor(didWebContentsThemeColorChange);
if (themeColor == mColor) return;
mColor = themeColor;
mTab.notifyThemeColorChanged(themeColor);
}
/**
* @return Whether the theme color for this tab is the default color.
*/
public boolean isDefaultColor() {
return mTab.isNativePage() || mDefaultColor == getColor();
}
/**
* @return The default theme color for this tab.
*/
@VisibleForTesting
public int getDefaultColor() {
return mDefaultColor;
}
/**
* @return The current theme color based on the value passed from the web contents and the
* security state.
*/
public int getColor() {
return mColor;
}
// TabObserver
@Override
public void onSSLStateUpdated(Tab tab) {
updateIfNeeded(false);
}
@Override
public void onUrlUpdated(Tab tab) {
updateIfNeeded(false);
}
@Override
public void onDidFailLoad(
Tab tab, boolean isMainFrame, int errorCode, String description, String failingUrl) {
updateIfNeeded(true);
}
@Override
public void onDidFinishNavigation(Tab tab, String url, boolean isInMainFrame,
boolean isErrorPage, boolean hasCommitted, boolean isSameDocument,
boolean isFragmentNavigation, @Nullable Integer pageTransition, int errorCode,
int httpStatusCode) {
if (errorCode != 0) updateIfNeeded(true);
}
@Override
public void onDidAttachInterstitialPage(Tab tab) {
updateIfNeeded(false);
}
@Override
public void onDidDetachInterstitialPage(Tab tab) {
updateIfNeeded(false);
}
@Override
public void onActivityAttachmentChanged(Tab tab, boolean isAttached) {
updateDefaultColor();
}
@Override
public void onDestroyed(Tab tab) {
tab.removeObserver(this);
}
}
......@@ -186,6 +186,7 @@ public class TabWebContentsObserver extends TabWebContentsUserData {
@Override
public void didFailLoad(
boolean isMainFrame, int errorCode, String description, String failingUrl) {
mTab.updateThemeColorIfNeeded(true);
RewindableIterator<TabObserver> observers = mTab.getTabObservers();
while (observers.hasNext()) {
observers.next().onDidFailLoad(
......@@ -242,6 +243,7 @@ public class TabWebContentsObserver extends TabWebContentsUserData {
}
if (errorCode != 0) {
mTab.updateThemeColorIfNeeded(true);
if (isInMainFrame) mTab.didFailPageLoad(errorCode);
recordErrorInPolicyAuditor(url, errorDescription, errorCode);
......@@ -283,13 +285,14 @@ public class TabWebContentsObserver extends TabWebContentsUserData {
@Override
public void didChangeThemeColor(int color) {
TabThemeColorHelper.get(mTab).updateIfNeeded(true);
mTab.updateThemeColorIfNeeded(true);
}
@Override
public void didAttachInterstitialPage() {
InfoBarContainer.get(mTab).setVisibility(View.INVISIBLE);
mTab.showRenderedPage();
mTab.updateThemeColorIfNeeded(false);
RewindableIterator<TabObserver> observers = mTab.getTabObservers();
while (observers.hasNext()) {
......@@ -308,6 +311,7 @@ public class TabWebContentsObserver extends TabWebContentsUserData {
@Override
public void didDetachInterstitialPage() {
InfoBarContainer.get(mTab).setVisibility(View.VISIBLE);
mTab.updateThemeColorIfNeeded(false);
RewindableIterator<TabObserver> observers = mTab.getTabObservers();
while (observers.hasNext()) {
......
......@@ -79,7 +79,6 @@ import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.SadTab;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabObserver;
import org.chromium.chrome.browser.tab.TabThemeColorHelper;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModel;
......@@ -521,7 +520,6 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
@Override
public void onContentChanged(Tab tab) {
if (tab.isNativePage()) TabThemeColorHelper.get(tab).updateIfNeeded(false);
mToolbar.onTabContentViewChanged();
if (shouldShowCursorInLocationBar()) {
mLocationBar.showUrlBarCursorWithoutFocusAnimations();
......@@ -1687,8 +1685,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
}
int defaultPrimaryColor =
ColorUtils.getDefaultThemeColor(mToolbar.getResources(), isIncognito);
int primaryColor =
tab != null ? TabThemeColorHelper.getColor(tab) : defaultPrimaryColor;
int primaryColor = tab != null ? tab.getThemeColor() : defaultPrimaryColor;
updatePrimaryColor(primaryColor, false);
mToolbar.onTabOrModelChanged();
......
......@@ -11,7 +11,6 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabThemeColorHelper;
/**
* Helper functions for working with colors.
......@@ -99,10 +98,10 @@ public class ColorUtils {
* @return Alpha for the textbox given a Tab.
*/
public static float getTextBoxAlphaForToolbarBackground(Tab tab) {
int color = tab.getThemeColor();
if (tab.getNativePage() instanceof NewTabPage) {
if (((NewTabPage) tab.getNativePage()).isLocationBarShownInNTP()) return 0f;
}
int color = TabThemeColorHelper.getColor(tab);
return shouldUseOpaqueTextboxBackground(color)
? 1f : LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA;
}
......
......@@ -1511,7 +1511,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/tab/TabObserver.java",
"java/src/org/chromium/chrome/browser/tab/TabRedirectHandler.java",
"java/src/org/chromium/chrome/browser/tab/TabStateBrowserControlsVisibilityDelegate.java",
"java/src/org/chromium/chrome/browser/tab/TabThemeColorHelper.java",
"java/src/org/chromium/chrome/browser/tab/TabUma.java",
"java/src/org/chromium/chrome/browser/tab/TabViewAndroidDelegate.java",
"java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java",
......
......@@ -21,7 +21,6 @@ import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabThemeColorHelper;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.net.test.EmbeddedTestServer;
......@@ -85,14 +84,6 @@ public class TabThemeTest {
Assert.assertEquals(Integer.toHexString(color1), Integer.toHexString(color2));
}
private static int getThemeColor(Tab tab) throws ExecutionException {
return ThreadUtils.runOnUiThreadBlocking(() -> TabThemeColorHelper.getColor(tab));
}
private static int getDefaultThemeColor(Tab tab) throws ExecutionException {
return ThreadUtils.runOnUiThreadBlocking(() -> TabThemeColorHelper.getDefaultColor(tab));
}
/**
* Test that the toolbar has the correct color set.
*/
......@@ -116,34 +107,34 @@ public class TabThemeTest {
int curCallCount = themeColorHelper.getCallCount();
mActivityTestRule.loadUrl(testServer.getURL(THEMED_TEST_PAGE));
themeColorHelper.waitForCallback(curCallCount, 1);
assertColorsEqual(THEME_COLOR, getThemeColor(tab));
assertColorsEqual(THEME_COLOR, tab.getThemeColor());
// Navigate to a native page from a themed page.
mActivityTestRule.loadUrl("chrome://newtab");
// WebContents does not set theme color for native pages, so don't wait for the call.
int nativePageThemeColor = ThreadUtils.runOnUiThreadBlocking(
() -> tab.getNativePage().getThemeColor());
assertColorsEqual(nativePageThemeColor, getThemeColor(tab));
assertColorsEqual(nativePageThemeColor, tab.getThemeColor());
// Navigate to a themed page from a native page.
curCallCount = themeColorHelper.getCallCount();
mActivityTestRule.loadUrl(testServer.getURL(THEMED_TEST_PAGE));
themeColorHelper.waitForCallback(curCallCount, 1);
assertColorsEqual(THEME_COLOR, colorObserver.getColor());
assertColorsEqual(THEME_COLOR, getThemeColor(tab));
assertColorsEqual(THEME_COLOR, tab.getThemeColor());
// Navigate to a non-native non-themed page.
curCallCount = themeColorHelper.getCallCount();
mActivityTestRule.loadUrl(testServer.getURL(TEST_PAGE));
themeColorHelper.waitForCallback(curCallCount, 1);
assertColorsEqual(getDefaultThemeColor(tab), colorObserver.getColor());
assertColorsEqual(getDefaultThemeColor(tab), getThemeColor(tab));
assertColorsEqual(tab.getDefaultThemeColor(), colorObserver.getColor());
assertColorsEqual(tab.getDefaultThemeColor(), tab.getThemeColor());
// Navigate to a themed page from a non-native page.
curCallCount = themeColorHelper.getCallCount();
mActivityTestRule.loadUrl(testServer.getURL(THEMED_TEST_PAGE));
themeColorHelper.waitForCallback(curCallCount, 1);
assertColorsEqual(THEME_COLOR, colorObserver.getColor());
assertColorsEqual(THEME_COLOR, getThemeColor(tab));
assertColorsEqual(THEME_COLOR, tab.getThemeColor());
}
}
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