Commit a693060f authored by Sinan Sahin's avatar Sinan Sahin Committed by Commit Bot

[Offline indicator v2] Add Java animations for the RecentTabsPage

Bug: 1075640, 1088071
Change-Id: I0bfefc0574a66af4d30754ee37c9b6fc709175ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2276671Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Sinan Sahin <sinansahin@google.com>
Cr-Commit-Position: refs/heads/master@{#784504}
parent 068cf75f
......@@ -15,7 +15,7 @@
android:id="@+id/recent_tabs_root"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingTop="@dimen/toolbar_height_no_shadow"
android:layout_marginTop="@dimen/toolbar_height_no_shadow"
android:background="@color/default_bg_color"
android:focusable="true"
android:focusableInTouchMode="true" >
......
......@@ -15,8 +15,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import androidx.core.view.ViewCompat;
import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus;
import org.chromium.chrome.R;
......@@ -292,19 +290,45 @@ public class RecentTabsPage
@Override
public void onBottomControlsHeightChanged(
int bottomControlsHeight, int bottomControlsMinHeight) {
updatePadding();
updateMargins();
}
@Override
public void onTopControlsHeightChanged(int topControlsHeight, int topControlsMinHeight) {
updatePadding();
updateMargins();
}
@Override
public void onControlsOffsetChanged(int topOffset, int topControlsMinHeightOffset,
int bottomOffset, int bottomControlsMinHeightOffset, boolean needsAnimate) {
updateMargins();
}
private void updatePadding() {
private void updateMargins() {
final View recentTabsRoot = mView.findViewById(R.id.recent_tabs_root);
ViewCompat.setPaddingRelative(recentTabsRoot, ViewCompat.getPaddingStart(recentTabsRoot),
mBrowserControlsStateProvider.getTopControlsHeight(),
ViewCompat.getPaddingEnd(recentTabsRoot),
mBrowserControlsStateProvider.getBottomControlsHeight());
final int topControlsHeight = mBrowserControlsStateProvider.getTopControlsHeight();
final int contentOffset = mBrowserControlsStateProvider.getContentOffset();
ViewGroup.MarginLayoutParams layoutParams =
(ViewGroup.MarginLayoutParams) recentTabsRoot.getLayoutParams();
int topMargin = layoutParams.topMargin;
// If the top controls are at the resting position or their height is decreasing, we want to
// update the margin. We don't do this if the controls height is increasing because changing
// the margin shrinks the view height to its final value, leaving a gap at the bottom until
// the animation finishes.
if (contentOffset >= topControlsHeight) {
topMargin = topControlsHeight;
}
// If the content offset is different from the margin, we use translationY to position the
// view in line with the content offset.
recentTabsRoot.setTranslationY(contentOffset - topMargin);
final int bottomMargin = mBrowserControlsStateProvider.getBottomControlsHeight();
if (topMargin != layoutParams.topMargin || bottomMargin != layoutParams.bottomMargin) {
layoutParams.topMargin = topMargin;
layoutParams.bottomMargin = bottomMargin;
recentTabsRoot.setLayoutParams(layoutParams);
}
}
}
......@@ -23,6 +23,7 @@ import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.RecentTabsPageTestUtils;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
......@@ -96,13 +97,7 @@ public class RecentTabsPageTest {
private RecentTabsPage loadRecentTabsPage() {
mActivityTestRule.loadUrl(UrlConstants.RECENT_TABS_URL);
CriteriaHelper.pollUiThread(new Criteria("RecentTabsPage never fully loaded") {
@Override
public boolean isSatisfied() {
return mTab.getNativePage() instanceof RecentTabsPage;
}
});
Assert.assertTrue(mTab.getNativePage() instanceof RecentTabsPage);
RecentTabsPageTestUtils.waitForRecentTabsPageLoaded(mTab);
return (RecentTabsPage) mTab.getNativePage();
}
......
......@@ -43,6 +43,7 @@ import org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.NewTabPageTestUtils;
import org.chromium.chrome.test.util.RecentTabsPageTestUtils;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.content_public.browser.test.util.Criteria;
......@@ -244,6 +245,52 @@ public class StatusIndicatorTest {
onView(withId(viewId)).check(matches(withTopMargin(0)));
}
@Test
@MediumTest
public void testShowAndHideOnRecentTabsPage() {
mActivityTestRule.loadUrl(UrlConstants.RECENT_TABS_URL);
final Tab tab = mActivityTestRule.getActivity().getActivityTab();
RecentTabsPageTestUtils.waitForRecentTabsPageLoaded(tab);
onView(withId(R.id.status_indicator)).check(matches(withEffectiveVisibility(GONE)));
onView(withId(R.id.control_container)).check(matches(withTopMargin(0)));
onView(withId(R.id.recent_tabs_root))
.check(matches(
withTopMargin(mBrowserControlsStateProvider.getTopControlsHeight())));
TestThreadUtils.runOnUiThreadBlocking(
() -> mStatusIndicatorCoordinator.show(
"Status", null, Color.BLACK, Color.WHITE, Color.WHITE));
// The status indicator will be immediately visible.
onView(withId(R.id.status_indicator)).check(matches(withEffectiveVisibility(VISIBLE)));
onView(withId(R.id.control_container))
.check(matches(withTopMargin(mStatusIndicatorContainer.getHeight())));
onView(withId(R.id.recent_tabs_root))
.check(matches(
withTopMargin(mBrowserControlsStateProvider.getTopControlsHeight())));
TestThreadUtils.runOnUiThreadBlocking(
() -> mStatusIndicatorCoordinator.updateContent("Exit status", null,
Color.WHITE, Color.BLACK, Color.BLACK, () -> {}));
// #updateContent shouldn't change the layout.
onView(withId(R.id.status_indicator)).check(matches(withEffectiveVisibility(VISIBLE)));
onView(withId(R.id.control_container))
.check(matches(withTopMargin(mStatusIndicatorContainer.getHeight())));
onView(withId(R.id.recent_tabs_root))
.check(matches(
withTopMargin(mBrowserControlsStateProvider.getTopControlsHeight())));
TestThreadUtils.runOnUiThreadBlocking(() -> mStatusIndicatorCoordinator.hide());
onView(withId(R.id.status_indicator)).check(matches(withEffectiveVisibility(GONE)));
onView(withId(R.id.control_container)).check(matches(withTopMargin(0)));
onView(withId(R.id.recent_tabs_root))
.check(matches(
withTopMargin(mBrowserControlsStateProvider.getTopControlsHeight())));
}
private static Matcher<View> withTopMargin(final int expected) {
return new TypeSafeMatcher<View>() {
private int mActual;
......
......@@ -205,6 +205,7 @@ android_library("chrome_java_test_support") {
"javatests/src/org/chromium/chrome/test/util/NewTabPageTestUtils.java",
"javatests/src/org/chromium/chrome/test/util/OmniboxTestUtils.java",
"javatests/src/org/chromium/chrome/test/util/OverviewModeBehaviorWatcher.java",
"javatests/src/org/chromium/chrome/test/util/RecentTabsPageTestUtils.java",
"javatests/src/org/chromium/chrome/test/util/SadTabRule.java",
"javatests/src/org/chromium/chrome/test/util/TabStripUtils.java",
"javatests/src/org/chromium/chrome/test/util/ToolbarTestUtils.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.test.util;
import org.junit.Assert;
import org.chromium.chrome.browser.ntp.RecentTabsPage;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
/**
* Utilities for testing the RecentTabsPage.
*/
public class RecentTabsPageTestUtils {
public static void waitForRecentTabsPageLoaded(final Tab tab) {
CriteriaHelper.pollUiThread(new Criteria("RecentTabsPage never fully loaded") {
@Override
public boolean isSatisfied() {
return tab.getNativePage() instanceof RecentTabsPage;
}
});
Assert.assertTrue(tab.getNativePage() instanceof RecentTabsPage);
}
}
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