Commit d7bb1e1e authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Add tests for adaptive toolbar in grid tab switcher

This CL adds e2e test to verify behavior of adaptive toolbar in grid
tab switcher. Situations that are tested are:
* Portrait and landscape +GTS +Duet
* Portrait and landscape +GTS -Duet
* Portrait and landscape -GTS +Duet

Bug: 1012014
Change-Id: Ib82f38a60f8f8649d6961a59463e743dbbe0d7b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1938464
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721750}
parent c5062a1f
......@@ -492,6 +492,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/toolbar/ToolbarProgressBarTest.java",
"javatests/src/org/chromium/chrome/browser/toolbar/ToolbarTest.java",
"javatests/src/org/chromium/chrome/browser/toolbar/bottom/BottomToolbarTest.java",
"javatests/src/org/chromium/chrome/browser/toolbar/top/AdaptiveToolbarTest.java",
"javatests/src/org/chromium/chrome/browser/toolbar/top/BrandColorTest.java",
"javatests/src/org/chromium/chrome/browser/toolbar/top/TabSwitcherActionMenuTest.java",
"javatests/src/org/chromium/chrome/browser/toolbar/top/TabSwitcherActionMenuRenderTest.java",
......
......@@ -131,7 +131,7 @@ public class TabUiTestHelper {
* @param cta The current running activity.
* @param count The correct number of cards in tab switcher.
*/
static void verifyTabSwitcherCardCount(ChromeTabbedActivity cta, int count) {
public static void verifyTabSwitcherCardCount(ChromeTabbedActivity cta, int count) {
assertTrue(cta.getLayoutManager().overviewVisible());
onView(allOf(withParent(withId(org.chromium.chrome.R.id.compositor_view_holder)),
withId(R.id.tab_list_view)))
......@@ -191,7 +191,7 @@ public class TabUiTestHelper {
* @param cta The current running activity.
* @param orientation The target orientation we want the screen to rotate to.
*/
static void rotateDeviceToOrientation(ChromeTabbedActivity cta, int orientation) {
public static void rotateDeviceToOrientation(ChromeTabbedActivity cta, int orientation) {
if (cta.getResources().getConfiguration().orientation == orientation) return;
assertTrue(orientation == Configuration.ORIENTATION_LANDSCAPE
|| orientation == Configuration.ORIENTATION_PORTRAIT);
......
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.toolbar;
import android.app.Activity;
import android.content.ComponentCallbacks;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
......@@ -14,7 +15,6 @@ import android.os.Message;
import android.os.SystemClock;
import android.support.v7.app.ActionBar;
import android.text.TextUtils;
import android.view.OrientationEventListener;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnClickListener;
......@@ -218,7 +218,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
private final Handler mHandler = new Handler();
private final ChromeActivity mActivity;
private UrlFocusChangeListener mLocationBarFocusObserver;
private OrientationEventListener mOrientationEventListener;
private ComponentCallbacks mComponentCallbacks;
private BrowserStateBrowserControlsVisibilityDelegate mControlsVisibilityDelegate;
private int mFullscreenFocusToken = TokenHolder.INVALID_TOKEN;
......@@ -247,6 +247,8 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
private AppMenuHandler mAppMenuHandler;
private int mCurrentOrientation;
/**
* Creates a ToolbarManager object.
*
......@@ -272,13 +274,20 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
mToolbarActionModeCallback = new ToolbarActionModeCallback();
mBookmarkBridgeSupplier = new ObservableSupplierImpl<>();
mOrientationEventListener = new OrientationEventListener(activity) {
mComponentCallbacks = new ComponentCallbacks() {
@Override
public void onOrientationChanged(int orientation) {
onOrientationChange();
public void onConfigurationChanged(Configuration configuration) {
int newOrientation = configuration.orientation;
if (newOrientation == mCurrentOrientation) {
return;
}
mCurrentOrientation = newOrientation;
onOrientationChange(newOrientation);
}
@Override
public void onLowMemory() {}
};
mOrientationEventListener.enable();
mActivity.registerComponentCallbacks(mComponentCallbacks);
mLocationBarFocusObserver = new UrlFocusChangeListener() {
/** The params used to control how the scrim behaves when shown for the omnibox. */
......@@ -1304,8 +1313,8 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
if (mTabThemeColorProvider != null) mTabThemeColorProvider.removeThemeColorObserver(this);
if (mAppThemeColorProvider != null) mAppThemeColorProvider.destroy();
mOrientationEventListener.disable();
mOrientationEventListener = null;
mActivity.unregisterComponentCallbacks(mComponentCallbacks);
mComponentCallbacks = null;
mShareDelegateSupplier.removeObserver(mShareDelegateSupplierCallback);
}
......@@ -1313,13 +1322,12 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
/**
* Called when the orientation of the activity has changed.
*/
public void onOrientationChange() {
private void onOrientationChange(int newOrientation) {
if (mActionModeController != null) mActionModeController.showControlsOnOrientationChange();
if (mBottomControlsCoordinator != null && FeatureUtilities.isBottomToolbarEnabled()
&& FeatureUtilities.isAdaptiveToolbarEnabled()) {
mIsBottomToolbarVisible = mActivity.getResources().getConfiguration().orientation
!= Configuration.ORIENTATION_LANDSCAPE;
mIsBottomToolbarVisible = newOrientation != Configuration.ORIENTATION_LANDSCAPE;
mToolbar.onBottomToolbarVisibilityChanged(mIsBottomToolbarVisible);
mBottomControlsCoordinator.setBottomControlsVisible(mIsBottomToolbarVisible);
if (mAppMenuButtonHelper != null) {
......
// Copyright 2019 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.toolbar.top;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.enterTabSwitcher;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.rotateDeviceToOrientation;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabSwitcherCardCount;
import android.content.res.Configuration;
import android.support.test.filters.MediumTest;
import android.view.View;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.flags.FeatureUtilities;
import org.chromium.chrome.features.start_surface.StartSurfaceLayout;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.ui.test.util.UiRestriction;
/** End-to-end tests for adaptive toolbar. */
@RunWith(ChromeJUnit4ClassRunner.class)
// clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
public class AdaptiveToolbarTest {
// Params to turn off new tab variation in GTS.
private static final String NO_NEW_TAB_VARIATION_PARAMS = "force-fieldtrial-params=" +
"Study.Group:tab_grid_layout_android_new_tab/false";
// clang-format on
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Rule
public TestRule mProcessor = new Features.InstrumentationProcessor();
@Before
public void setUp() {
FeatureUtilities.setTabGroupsAndroidEnabledForTesting(false);
}
@After
public void tearDown() {
FeatureUtilities.setGridTabSwitcherEnabledForTesting(null);
FeatureUtilities.setIsBottomToolbarEnabledForTesting(null);
}
private void setupFlagsAndLaunchActivity(
boolean isBottomToolbarEnabled, boolean isGridTabSwitcherEnabled) {
FeatureUtilities.setGridTabSwitcherEnabledForTesting(isGridTabSwitcherEnabled);
FeatureUtilities.setIsBottomToolbarEnabledForTesting(isBottomToolbarEnabled);
mActivityTestRule.startMainActivityFromLauncher();
CriteriaHelper.pollUiThread(mActivityTestRule.getActivity()
.getTabModelSelector()
.getTabModelFilterProvider()
.getCurrentTabModelFilter()::isTabModelRestored);
}
@Test
@MediumTest
// clang-format off
@CommandLineFlags.Add({"enable-features=" + ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID +
"<Study", "force-fieldtrials=Study/Group", NO_NEW_TAB_VARIATION_PARAMS})
public void testTopToolbar_WithGTS_WithBottomToolbar() throws InterruptedException {
// clang-format on
setupFlagsAndLaunchActivity(true, true);
final ChromeTabbedActivity cta = mActivityTestRule.getActivity();
Layout layout = cta.getLayoutManager().getOverviewLayout();
assertTrue(layout instanceof StartSurfaceLayout);
enterTabSwitcher(cta);
verifyTabSwitcherCardCount(cta, 1);
checkTopToolbarButtonsExistence(true);
checkTopToolbarButtonsVisibility(false);
rotateDeviceToOrientation(cta, Configuration.ORIENTATION_LANDSCAPE);
checkTopToolbarButtonsExistence(true);
checkTopToolbarButtonsVisibility(true);
}
@Test
@MediumTest
// clang-format off
@CommandLineFlags.Add({"enable-features=" + ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID +
"<Study", "force-fieldtrials=Study/Group", NO_NEW_TAB_VARIATION_PARAMS})
public void testTopToolbar_WithGTS_WithoutBottomToolbar() throws InterruptedException {
// clang-format on
setupFlagsAndLaunchActivity(false, true);
final ChromeTabbedActivity cta = mActivityTestRule.getActivity();
Layout layout = cta.getLayoutManager().getOverviewLayout();
assertTrue(layout instanceof StartSurfaceLayout);
enterTabSwitcher(cta);
verifyTabSwitcherCardCount(cta, 1);
checkTopToolbarButtonsExistence(true);
checkTopToolbarButtonsVisibility(true);
rotateDeviceToOrientation(cta, Configuration.ORIENTATION_LANDSCAPE);
checkTopToolbarButtonsExistence(true);
checkTopToolbarButtonsVisibility(true);
}
@Test
@MediumTest
public void testTopToolbar_WithoutGTS_WithBottomToolbar() throws InterruptedException {
setupFlagsAndLaunchActivity(true, false);
final ChromeTabbedActivity cta = mActivityTestRule.getActivity();
Layout layout = cta.getLayoutManager().getOverviewLayout();
assertFalse(layout instanceof StartSurfaceLayout);
enterTabSwitcher(cta);
checkTopToolbarButtonsExistence(false);
rotateDeviceToOrientation(cta, Configuration.ORIENTATION_LANDSCAPE);
checkTopToolbarButtonsExistence(false);
}
private void checkTopToolbarButtonsExistence(boolean isNotNull) {
onView(withId(R.id.tab_switcher_toolbar)).check((v, noMatchingViewException) -> {
View newTabButton = v.findViewById(R.id.new_tab_button);
View menuButton = v.findViewById(R.id.menu_button_wrapper);
if (isNotNull) {
assertNotNull(newTabButton);
assertNotNull(menuButton);
} else {
assertNull(newTabButton);
assertNull(menuButton);
}
});
}
private void checkTopToolbarButtonsVisibility(boolean isVisible) {
int visibility = isVisible ? View.VISIBLE : View.GONE;
onView(withId(R.id.tab_switcher_toolbar)).check((v, noMatchingViewException) -> {
View newTabButton = v.findViewById(R.id.new_tab_button);
View menuButton = v.findViewById(R.id.menu_button_wrapper);
assertEquals(visibility, newTabButton.getVisibility());
assertEquals(visibility, menuButton.getVisibility());
});
}
}
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