Commit 923b1cc5 authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Show the Google G when scrolling down on the NTP

Bug: 1024062
Change-Id: I95c548a23c2a4903c57d724e124a5af0bf4b7966
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913712
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715123}
parent 4605dec6
......@@ -247,24 +247,18 @@ class StatusMediator {
mUrlHasFocus = urlHasFocus;
updateStatusVisibility();
updateLocationBarIcon();
// Show the icon when the url focus animation starts.
if (urlHasFocus
&& SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarCommonPropertiesModel.isIncognito())
&& SearchEngineLogoUtils.currentlyOnNTP(mToolbarCommonPropertiesModel)) {
setStatusIconShown(true);
}
}
void setUrlAnimationFinished(boolean urlHasFocus) {
if (!SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarCommonPropertiesModel.isIncognito())) {
if (!mDelegate.shouldShowSearchEngineLogo(mToolbarCommonPropertiesModel.isIncognito())) {
return;
}
// Hide the icon when the url unfocus animation finishes.
if (!urlHasFocus && SearchEngineLogoUtils.currentlyOnNTP(mToolbarCommonPropertiesModel)) {
// Note: When mUrlFocusPercent is non-zero, that means we're still in the focused state from
// scrolling on the NTP.
if (!urlHasFocus && MathUtils.areFloatsEqual(mUrlFocusPercent, 0f)
&& SearchEngineLogoUtils.currentlyOnNTP(mToolbarCommonPropertiesModel)) {
setStatusIconShown(false);
}
}
......@@ -279,11 +273,16 @@ class StatusMediator {
*/
void setUrlFocusChangePercent(float percent) {
mUrlFocusPercent = percent;
if (!SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarCommonPropertiesModel.isIncognito())) {
if (!mDelegate.shouldShowSearchEngineLogo(mToolbarCommonPropertiesModel.isIncognito())) {
return;
}
// Note: This uses mUrlFocusPercent rather than mUrlHasFocus because when the user scrolls
// the NTP we want the status icon to show.
if (mUrlFocusPercent > 0) {
setStatusIconShown(true);
}
// Only fade the animation on the new tab page.
if (SearchEngineLogoUtils.currentlyOnNTP(mToolbarCommonPropertiesModel)) {
float focusAnimationProgress = percent;
......
......@@ -28,6 +28,7 @@ import org.chromium.base.Callback;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.omnibox.UrlBarEditingTextStateProvider;
import org.chromium.chrome.browser.toolbar.ToolbarCommonPropertiesModel;
import org.chromium.chrome.test.util.browser.Features;
......@@ -41,6 +42,8 @@ import org.chromium.ui.modelutil.PropertyModel;
public final class StatusMediatorUnitTest {
private static final String TEST_SEARCH_URL = "https://www.test.com";
@Mock
NewTabPage mNewTabPage;
@Mock
Resources mResources;
@Mock
......@@ -84,6 +87,45 @@ public final class StatusMediatorUnitTest {
R.drawable.ic_logo_googleg_24dp, mModel.get(StatusProperties.STATUS_ICON_RES));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.OMNIBOX_SEARCH_ENGINE_LOGO)
public void searchEngineLogo_showGoogleLogo_hideAfterAnimationFinished() {
setupSearchEngineLogoForTesting(true, false, false);
doReturn(mNewTabPage).when(mToolbarCommonPropertiesModel).getNewTabPageForCurrentTab();
doReturn("chrome://newtab").when(mToolbarCommonPropertiesModel).getCurrentUrl();
mMediator.updateSearchEngineStatusIcon(true, true, TEST_SEARCH_URL);
mMediator.setUrlHasFocus(false);
mMediator.setUrlFocusChangePercent(0);
mMediator.setUrlAnimationFinished(true);
Assert.assertFalse(mModel.get(StatusProperties.SHOW_STATUS_ICON));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.OMNIBOX_SEARCH_ENGINE_LOGO)
public void searchEngineLogo_showGoogleLogo_noHideIconAfterAnimationFinishedWhenScrolled() {
setupSearchEngineLogoForTesting(true, false, false);
mMediator.setUrlHasFocus(false);
mMediator.setShowIconsWhenUrlFocused(true);
mMediator.updateSearchEngineStatusIcon(true, true, TEST_SEARCH_URL);
mMediator.setUrlFocusChangePercent(1f);
mMediator.setUrlAnimationFinished(true);
Assert.assertTrue(mModel.get(StatusProperties.SHOW_STATUS_ICON));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.OMNIBOX_SEARCH_ENGINE_LOGO)
public void searchEngineLogo_showGoogleLogoOnNtpScroll() {
setupSearchEngineLogoForTesting(true, false, false);
mMediator.setUrlHasFocus(false);
mMediator.setShowIconsWhenUrlFocused(true);
mMediator.updateSearchEngineStatusIcon(true, true, TEST_SEARCH_URL);
mMediator.setUrlFocusChangePercent(1f);
Assert.assertTrue(mModel.get(StatusProperties.SHOW_STATUS_ICON));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.OMNIBOX_SEARCH_ENGINE_LOGO)
public void searchEngineLogo_showGoogleLogo_whenScrolled() {
......@@ -95,6 +137,7 @@ public final class StatusMediatorUnitTest {
mMediator.updateSearchEngineStatusIcon(true, true, TEST_SEARCH_URL);
Assert.assertEquals(
R.drawable.ic_logo_googleg_24dp, mModel.get(StatusProperties.STATUS_ICON_RES));
Assert.assertTrue(mModel.get(StatusProperties.SHOW_STATUS_ICON));
}
@Test
......
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