Commit 89ee6b6a authored by Mei Liang's avatar Mei Liang Committed by Commit Bot

[TabSelectionEditor] Add List mode supports

This CL enables TabSelectionEditor to show a List for low-end devices.

Change-Id: Ie60c1e7ddcda09c2f32e23c4de52be7e642e09e0
Bug: 1042889
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2103313
Commit-Queue: Mei Liang <meiliang@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751588}
parent e3e24fb5
<?xml version="1.0" encoding="utf-8"?>
<!-- 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. -->
<!-- TODO(crbug.com/1023557): Rename SelectableTabGridView to SelectableTabView. -->
<org.chromium.chrome.browser.tasks.tab_management.SelectableTabGridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/selectable_tab_list_card_item"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/tab_list_card_item"/>
</org.chromium.chrome.browser.tasks.tab_management.SelectableTabGridView>
\ No newline at end of file
...@@ -47,14 +47,20 @@ public class TabGridDialogCoordinator implements TabGridDialogMediator.DialogCon ...@@ -47,14 +47,20 @@ public class TabGridDialogCoordinator implements TabGridDialogMediator.DialogCon
mComponentName = animationSourceViewProvider == null ? "TabGridDialogFromStrip" mComponentName = animationSourceViewProvider == null ? "TabGridDialogFromStrip"
: "TabGridDialogInSwitcher"; : "TabGridDialogInSwitcher";
@TabListCoordinator.TabListMode
int mode = TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled()
&& SysUtils.isLowEndDevice()
? TabListCoordinator.TabListMode.LIST
: TabListCoordinator.TabListMode.GRID;
mToolbarPropertyModel = new PropertyModel(TabGridPanelProperties.ALL_KEYS); mToolbarPropertyModel = new PropertyModel(TabGridPanelProperties.ALL_KEYS);
mParentLayout = new TabGridDialogParent(context, containerView); mParentLayout = new TabGridDialogParent(context, containerView);
TabSelectionEditorCoordinator.TabSelectionEditorController controller = null; TabSelectionEditorCoordinator.TabSelectionEditorController controller = null;
if (TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled()) { if (TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled()) {
mTabSelectionEditorCoordinator = new TabSelectionEditorCoordinator( mTabSelectionEditorCoordinator = new TabSelectionEditorCoordinator(context,
context, containerView, tabModelSelector, tabContentManager, mParentLayout); containerView, tabModelSelector, tabContentManager, mParentLayout, mode);
controller = mTabSelectionEditorCoordinator.getController(); controller = mTabSelectionEditorCoordinator.getController();
} else { } else {
...@@ -65,15 +71,9 @@ public class TabGridDialogCoordinator implements TabGridDialogMediator.DialogCon ...@@ -65,15 +71,9 @@ public class TabGridDialogCoordinator implements TabGridDialogMediator.DialogCon
tabModelSelector, tabCreatorManager, resetHandler, animationSourceViewProvider, tabModelSelector, tabCreatorManager, resetHandler, animationSourceViewProvider,
controller, tabGroupTitleEditor, shareDelegateSupplier, mComponentName); controller, tabGroupTitleEditor, shareDelegateSupplier, mComponentName);
// TODO(crbug.com/1031349) : Remove the inline mode logic here, make the constructor to take mTabListCoordinator = new TabListCoordinator(mode, context, tabModelSelector,
// in a mode parameter instead. tabContentManager::getTabThumbnailWithCallback, null, false,
mTabListCoordinator = new TabListCoordinator( gridCardOnClickListenerProvider, mMediator.getTabGridDialogHandler(),
TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled()
&& SysUtils.isLowEndDevice()
? TabListCoordinator.TabListMode.LIST
: TabListCoordinator.TabListMode.GRID,
context, tabModelSelector, tabContentManager::getTabThumbnailWithCallback, null,
false, gridCardOnClickListenerProvider, mMediator.getTabGridDialogHandler(),
TabProperties.UiType.CLOSABLE, null, containerView, null, false, mComponentName); TabProperties.UiType.CLOSABLE, null, containerView, null, false, mComponentName);
TabListRecyclerView recyclerView = mTabListCoordinator.getContainerView(); TabListRecyclerView recyclerView = mTabListCoordinator.getContainerView();
......
...@@ -184,6 +184,13 @@ public class TabListCoordinator implements Destroyable { ...@@ -184,6 +184,13 @@ public class TabListCoordinator implements Destroyable {
return group; return group;
}, TabListViewBinder::bindListTab); }, TabListViewBinder::bindListTab);
mAdapter.registerType(UiType.SELECTABLE, parent -> {
ViewGroup group = (ViewGroup) LayoutInflater.from(context).inflate(
R.layout.selectable_tab_list_card_item, parentView, false);
group.setClickable(true);
return group;
}, TabListViewBinder::bindSelectableListTab);
} else { } else {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Attempting to create a tab list UI with invalid mode"); "Attempting to create a tab list UI with invalid mode");
......
...@@ -1185,13 +1185,9 @@ class TabListMediator { ...@@ -1185,13 +1185,9 @@ class TabListMediator {
tab.isIncognito())) tab.isIncognito()))
.with(TabProperties.IS_SELECTED, isSelected) .with(TabProperties.IS_SELECTED, isSelected)
.with(TabProperties.IPH_PROVIDER, showIPH ? mIphProvider : null) .with(TabProperties.IPH_PROVIDER, showIPH ? mIphProvider : null)
.with(TabProperties.TAB_SELECTED_LISTENER, tabSelectedListener)
.with(TabProperties.TAB_CLOSED_LISTENER, mTabClosedListener)
.with(CARD_ALPHA, 1f) .with(CARD_ALPHA, 1f)
.with(TabProperties.CARD_ANIMATION_STATUS, .with(TabProperties.CARD_ANIMATION_STATUS,
ClosableTabGridView.AnimationStatus.CARD_RESTORE) ClosableTabGridView.AnimationStatus.CARD_RESTORE)
.with(TabProperties.SELECTABLE_TAB_CLICKED_LISTENER,
mSelectableTabOnClickListener)
.with(TabProperties.TAB_SELECTION_DELEGATE, getTabSelectionDelegate()) .with(TabProperties.TAB_SELECTION_DELEGATE, getTabSelectionDelegate())
.with(TabProperties.IS_INCOGNITO, tab.isIncognito()) .with(TabProperties.IS_INCOGNITO, tab.isIncognito())
.with(TabProperties.SELECTED_TAB_BACKGROUND_DRAWABLE_ID, .with(TabProperties.SELECTED_TAB_BACKGROUND_DRAWABLE_ID,
...@@ -1232,6 +1228,11 @@ class TabListMediator { ...@@ -1232,6 +1228,11 @@ class TabListMediator {
actionButtonBackgroundColorList); actionButtonBackgroundColorList);
tabInfo.set(TabProperties.SELECTABLE_TAB_ACTION_BUTTON_SELECTED_BACKGROUND, tabInfo.set(TabProperties.SELECTABLE_TAB_ACTION_BUTTON_SELECTED_BACKGROUND,
actionbuttonSelectedBackgroundColorList); actionbuttonSelectedBackgroundColorList);
tabInfo.set(
TabProperties.SELECTABLE_TAB_CLICKED_LISTENER, mSelectableTabOnClickListener);
} else {
tabInfo.set(TabProperties.TAB_SELECTED_LISTENER, tabSelectedListener);
tabInfo.set(TabProperties.TAB_CLOSED_LISTENER, mTabClosedListener);
} }
if (index >= mModel.size()) { if (index >= mModel.size()) {
......
...@@ -8,6 +8,8 @@ import android.content.res.Resources; ...@@ -8,6 +8,8 @@ import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable; import android.graphics.drawable.InsetDrawable;
import android.os.Build; import android.os.Build;
import android.support.graphics.drawable.AnimatedVectorDrawableCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -16,6 +18,7 @@ import android.widget.TextView; ...@@ -16,6 +18,7 @@ import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.res.ResourcesCompat; import androidx.core.content.res.ResourcesCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.tab_ui.R; import org.chromium.chrome.tab_ui.R;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -76,4 +79,51 @@ class TabListViewBinder { ...@@ -76,4 +79,51 @@ class TabListViewBinder {
((TextView) fastView.findViewById(R.id.description)).setText(title); ((TextView) fastView.findViewById(R.id.description)).setText(title);
} }
} }
/**
* Bind a selectable tab to view.
* @param model The model to bind.
* @param view The view to bind to.
* @param propertyKey The property that changed.
*/
public static void bindSelectableListTab(
PropertyModel model, ViewGroup view, @Nullable PropertyKey propertyKey) {
bindListTab(model, view, propertyKey);
final int tabId = model.get(TabProperties.TAB_ID);
final int defaultLevel = view.getResources().getInteger(R.integer.list_item_level_default);
final int selectedLevel =
view.getResources().getInteger(R.integer.list_item_level_selected);
if (TabProperties.SELECTABLE_TAB_CLICKED_LISTENER == propertyKey) {
view.setOnClickListener(v -> {
model.get(TabProperties.SELECTABLE_TAB_CLICKED_LISTENER).run(tabId);
((SelectableTabGridView) view).onClick();
});
view.setOnLongClickListener(v -> {
model.get(TabProperties.SELECTABLE_TAB_CLICKED_LISTENER).run(tabId);
return ((SelectableTabGridView) view).onLongClick(view);
});
} else if (TabProperties.TAB_SELECTION_DELEGATE == propertyKey) {
assert model.get(TabProperties.TAB_SELECTION_DELEGATE) != null;
((SelectableTabGridView) view)
.setSelectionDelegate(model.get(TabProperties.TAB_SELECTION_DELEGATE));
((SelectableTabGridView) view).setItem(tabId);
} else if (TabProperties.IS_SELECTED == propertyKey) {
boolean isSelected = model.get(TabProperties.IS_SELECTED);
ImageView actionButton = (ImageView) view.findViewById(R.id.action_button);
actionButton.getBackground().setLevel(isSelected ? selectedLevel : defaultLevel);
DrawableCompat.setTintList(actionButton.getBackground().mutate(),
isSelected ? model.get(
TabProperties.SELECTABLE_TAB_ACTION_BUTTON_SELECTED_BACKGROUND)
: model.get(TabProperties.SELECTABLE_TAB_ACTION_BUTTON_BACKGROUND));
// The check should be invisible if not selected.
actionButton.getDrawable().setAlpha(isSelected ? 255 : 0);
ApiCompatibilityUtils.setImageTintList(actionButton,
isSelected ? model.get(TabProperties.CHECKED_DRAWABLE_STATE_LIST) : null);
if (isSelected) ((AnimatedVectorDrawableCompat) actionButton.getDrawable()).start();
}
}
} }
...@@ -9,9 +9,10 @@ import static org.chromium.chrome.browser.tasks.tab_management.TabListModel.Card ...@@ -9,9 +9,10 @@ import static org.chromium.chrome.browser.tasks.tab_management.TabListModel.Card
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.ViewGroup;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
...@@ -101,7 +102,7 @@ class TabSelectionEditorCoordinator { ...@@ -101,7 +102,7 @@ class TabSelectionEditorCoordinator {
} }
private final Context mContext; private final Context mContext;
private final View mParentView; private final ViewGroup mParentView;
private final TabModelSelector mTabModelSelector; private final TabModelSelector mTabModelSelector;
private final TabSelectionEditorLayout mTabSelectionEditorLayout; private final TabSelectionEditorLayout mTabSelectionEditorLayout;
private final TabListCoordinator mTabListCoordinator; private final TabListCoordinator mTabListCoordinator;
...@@ -110,19 +111,18 @@ class TabSelectionEditorCoordinator { ...@@ -110,19 +111,18 @@ class TabSelectionEditorCoordinator {
private final PropertyModelChangeProcessor mTabSelectionEditorLayoutChangeProcessor; private final PropertyModelChangeProcessor mTabSelectionEditorLayoutChangeProcessor;
private final TabSelectionEditorMediator mTabSelectionEditorMediator; private final TabSelectionEditorMediator mTabSelectionEditorMediator;
public TabSelectionEditorCoordinator(Context context, View parentView, public TabSelectionEditorCoordinator(Context context, ViewGroup parentView,
TabModelSelector tabModelSelector, TabContentManager tabContentManager, TabModelSelector tabModelSelector, TabContentManager tabContentManager,
@Nullable TabSelectionEditorMediator @Nullable TabSelectionEditorMediator
.TabSelectionEditorPositionProvider positionProvider) { .TabSelectionEditorPositionProvider positionProvider,
@TabListCoordinator.TabListMode int mode) {
mContext = context; mContext = context;
mParentView = parentView; mParentView = parentView;
mTabModelSelector = tabModelSelector; mTabModelSelector = tabModelSelector;
// TODO(crbug.com/1007598): construct TabListCoordinator with List mode if it's a low end mTabListCoordinator = new TabListCoordinator(mode, context, mTabModelSelector,
// device, and TabGroupContinuation is turned on. tabContentManager::getTabThumbnailWithCallback, null, false, null, null,
mTabListCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.GRID, context, TabProperties.UiType.SELECTABLE, this::getSelectionDelegate, mParentView, null,
mTabModelSelector, tabContentManager::getTabThumbnailWithCallback, null, false,
null, null, TabProperties.UiType.SELECTABLE, this::getSelectionDelegate, null, null,
false, COMPONENT_NAME); false, COMPONENT_NAME);
mTabListCoordinator.registerItemType(TabProperties.UiType.DIVIDER, mTabListCoordinator.registerItemType(TabProperties.UiType.DIVIDER,
new LayoutViewBuilder(R.layout.divider_preference), new LayoutViewBuilder(R.layout.divider_preference),
...@@ -197,4 +197,12 @@ class TabSelectionEditorCoordinator { ...@@ -197,4 +197,12 @@ class TabSelectionEditorCoordinator {
mTabSelectionEditorMediator.destroy(); mTabSelectionEditorMediator.destroy();
mTabSelectionEditorLayoutChangeProcessor.destroy(); mTabSelectionEditorLayoutChangeProcessor.destroy();
} }
/**
* @return The {@link TabSelectionEditorLayout} for testing.
*/
@VisibleForTesting
public TabSelectionEditorLayout getTabSelectionEditorLayoutForTesting() {
return mTabSelectionEditorLayout;
}
} }
...@@ -103,7 +103,7 @@ public class TabSwitcherCoordinator ...@@ -103,7 +103,7 @@ public class TabSwitcherCoordinator
PropertyModel containerViewModel = new PropertyModel(TabListContainerProperties.ALL_KEYS); PropertyModel containerViewModel = new PropertyModel(TabListContainerProperties.ALL_KEYS);
mTabSelectionEditorCoordinator = new TabSelectionEditorCoordinator( mTabSelectionEditorCoordinator = new TabSelectionEditorCoordinator(
context, container, tabModelSelector, tabContentManager, null); context, container, tabModelSelector, tabContentManager, null, mode);
mMediator = new TabSwitcherMediator(this, containerViewModel, tabModelSelector, mMediator = new TabSwitcherMediator(this, containerViewModel, tabModelSelector,
fullscreenManager, container, mTabSelectionEditorCoordinator.getController(), fullscreenManager, container, mTabSelectionEditorCoordinator.getController(),
......
...@@ -68,6 +68,9 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase { ...@@ -68,6 +68,9 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase {
private SelectionDelegate<Integer> mSelectionDelegate; private SelectionDelegate<Integer> mSelectionDelegate;
private int mSelectedTabBackgroundDrawableId = R.drawable.selected_tab_background; private int mSelectedTabBackgroundDrawableId = R.drawable.selected_tab_background;
private ViewGroup mSelectableTabListView;
private PropertyModelChangeProcessor mSelectableListMCP;
private TabListMediator.ThumbnailFetcher mMockThumbnailProvider = private TabListMediator.ThumbnailFetcher mMockThumbnailProvider =
new TabListMediator.ThumbnailFetcher(new TabListMediator.ThumbnailProvider() { new TabListMediator.ThumbnailFetcher(new TabListMediator.ThumbnailProvider() {
@Override @Override
...@@ -134,10 +137,13 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase { ...@@ -134,10 +137,13 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase {
R.layout.tab_strip_item, null); R.layout.tab_strip_item, null);
mSelectableTabGridView = (ViewGroup) getActivity().getLayoutInflater().inflate( mSelectableTabGridView = (ViewGroup) getActivity().getLayoutInflater().inflate(
R.layout.selectable_tab_grid_card_item, null); R.layout.selectable_tab_grid_card_item, null);
mSelectableTabListView = (ViewGroup) getActivity().getLayoutInflater().inflate(
R.layout.selectable_tab_list_card_item, null);
view.addView(mTabGridView); view.addView(mTabGridView);
view.addView(mTabStripView); view.addView(mTabStripView);
view.addView(mSelectableTabGridView); view.addView(mSelectableTabGridView);
view.addView(mSelectableTabListView);
}); });
mSelectionDelegate = new SelectionDelegate<>(); mSelectionDelegate = new SelectionDelegate<>();
...@@ -168,6 +174,8 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase { ...@@ -168,6 +174,8 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase {
mStripModel, mTabStripView, TabStripViewBinder::bind); mStripModel, mTabStripView, TabStripViewBinder::bind);
mSelectableMCP = PropertyModelChangeProcessor.create( mSelectableMCP = PropertyModelChangeProcessor.create(
mSelectableModel, mSelectableTabGridView, TabGridViewBinder::bindSelectableTab); mSelectableModel, mSelectableTabGridView, TabGridViewBinder::bindSelectableTab);
mSelectableListMCP = PropertyModelChangeProcessor.create(mSelectableModel,
mSelectableTabListView, TabListViewBinder::bindSelectableListTab);
}); });
} }
...@@ -184,10 +192,26 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase { ...@@ -184,10 +192,26 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase {
model.set(TabProperties.IS_SELECTED, false); model.set(TabProperties.IS_SELECTED, false);
Assert.assertTrue(selectedView.getVisibility() == View.GONE); Assert.assertTrue(selectedView.getVisibility() == View.GONE);
} }
mStripModel.set(TabProperties.IS_SELECTED, true); }
Assert.assertTrue(((FrameLayout) mTabStripView).getForeground() != null);
mStripModel.set(TabProperties.IS_SELECTED, false); private void testSelectableTabClickToSelect(
Assert.assertFalse(((FrameLayout) mTabStripView).getForeground() != null); ViewGroup view, PropertyModel model, boolean isLongClick) {
Runnable clickTask = () -> {
if (isLongClick) {
view.performLongClick();
} else {
view.performClick();
}
};
model.set(TabProperties.IS_SELECTED, false);
clickTask.run();
Assert.assertTrue(mSelectClicked.get());
mSelectClicked.set(false);
model.set(TabProperties.IS_SELECTED, true);
clickTask.run();
Assert.assertTrue(mSelectClicked.get());
} }
@Test @Test
...@@ -211,6 +235,17 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase { ...@@ -211,6 +235,17 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase {
mSelectableModel.set(TabProperties.IS_SELECTED, false); mSelectableModel.set(TabProperties.IS_SELECTED, false);
Assert.assertTrue(actionButton.getBackground().getLevel() == 0); Assert.assertTrue(actionButton.getBackground().getLevel() == 0);
Assert.assertEquals(0, actionButton.getDrawable().getAlpha()); Assert.assertEquals(0, actionButton.getDrawable().getAlpha());
testGridSelected(mSelectableTabListView, mSelectableModel);
mSelectableModel.set(TabProperties.IS_SELECTED, true);
ImageView actionButtonList = mSelectableTabListView.findViewById(R.id.action_button);
Assert.assertTrue(actionButtonList.getBackground().getLevel() == 1);
Assert.assertTrue(actionButtonList.getDrawable() != null);
Assert.assertEquals(255, actionButton.getDrawable().getAlpha());
mSelectableModel.set(TabProperties.IS_SELECTED, false);
Assert.assertTrue(actionButtonList.getBackground().getLevel() == 0);
Assert.assertEquals(0, actionButtonList.getDrawable().getAlpha());
} }
@Test @Test
...@@ -265,6 +300,9 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase { ...@@ -265,6 +300,9 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase {
mSelectableModel.set(TabProperties.TITLE, title); mSelectableModel.set(TabProperties.TITLE, title);
textView = mSelectableTabGridView.findViewById(R.id.tab_title); textView = mSelectableTabGridView.findViewById(R.id.tab_title);
Assert.assertEquals(textView.getText(), title); Assert.assertEquals(textView.getText(), title);
textView = mSelectableTabListView.findViewById(R.id.title);
Assert.assertEquals(textView.getText(), title);
} }
@Test @Test
...@@ -409,14 +447,11 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase { ...@@ -409,14 +447,11 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase {
Assert.assertFalse(mSelectClicked.get()); Assert.assertFalse(mSelectClicked.get());
mSelectClicked.set(false); mSelectClicked.set(false);
mSelectableModel.set(TabProperties.IS_SELECTED, false); testSelectableTabClickToSelect(mSelectableTabGridView, mSelectableModel, false);
mSelectableTabGridView.performClick(); testSelectableTabClickToSelect(mSelectableTabGridView, mSelectableModel, true);
Assert.assertTrue(mSelectClicked.get());
mSelectClicked.set(false);
mSelectableModel.set(TabProperties.IS_SELECTED, true); testSelectableTabClickToSelect(mSelectableTabListView, mSelectableModel, false);
mSelectableTabGridView.performClick(); testSelectableTabClickToSelect(mSelectableTabListView, mSelectableModel, true);
Assert.assertTrue(mSelectClicked.get());
} }
@Test @Test
......
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.tasks.tab_management; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.tasks.tab_management;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.view.ViewGroup;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
...@@ -14,7 +15,10 @@ import org.junit.Test; ...@@ -14,7 +15,10 @@ import org.junit.Test;
import org.junit.rules.TestRule; import org.junit.rules.TestRule;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.BaseSwitches;
import org.chromium.base.SysUtils;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.flags.CachedFeatureFlags; import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
...@@ -25,11 +29,14 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector; ...@@ -25,11 +29,14 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.tab_ui.R; import org.chromium.chrome.tab_ui.R;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule; import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.test.util.UiRestriction; import org.chromium.ui.test.util.UiRestriction;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -46,11 +53,15 @@ public class TabSelectionEditorTest { ...@@ -46,11 +53,15 @@ public class TabSelectionEditorTest {
@Rule @Rule
public TestRule mProcessor = new Features.InstrumentationProcessor(); public TestRule mProcessor = new Features.InstrumentationProcessor();
@Rule
public ChromeRenderTestRule mRenderTestRule = new ChromeRenderTestRule();
private TabSelectionEditorTestingRobot mRobot = new TabSelectionEditorTestingRobot(); private TabSelectionEditorTestingRobot mRobot = new TabSelectionEditorTestingRobot();
private TabModelSelector mTabModelSelector; private TabModelSelector mTabModelSelector;
private TabSelectionEditorCoordinator private TabSelectionEditorCoordinator
.TabSelectionEditorController mTabSelectionEditorController; .TabSelectionEditorController mTabSelectionEditorController;
private TabSelectionEditorLayout mTabSelectionEditorLayout;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
...@@ -64,10 +75,14 @@ public class TabSelectionEditorTest { ...@@ -64,10 +75,14 @@ public class TabSelectionEditorTest {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
TabSelectionEditorCoordinator tabSelectionEditorCoordinator = TabSelectionEditorCoordinator tabSelectionEditorCoordinator =
new TabSelectionEditorCoordinator(mActivityTestRule.getActivity(), new TabSelectionEditorCoordinator(mActivityTestRule.getActivity(),
mActivityTestRule.getActivity().getCurrentFocus(), mTabModelSelector, (ViewGroup) mActivityTestRule.getActivity().getCurrentFocus(),
mActivityTestRule.getActivity().getTabContentManager(), null); mTabModelSelector,
mActivityTestRule.getActivity().getTabContentManager(), null,
getMode());
mTabSelectionEditorController = tabSelectionEditorCoordinator.getController(); mTabSelectionEditorController = tabSelectionEditorCoordinator.getController();
mTabSelectionEditorLayout =
tabSelectionEditorCoordinator.getTabSelectionEditorLayoutForTesting();
}); });
} }
...@@ -76,6 +91,13 @@ public class TabSelectionEditorTest { ...@@ -76,6 +91,13 @@ public class TabSelectionEditorTest {
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, null); CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, null);
} }
private @TabListCoordinator.TabListMode int getMode() {
return TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled()
&& SysUtils.isLowEndDevice()
? TabListCoordinator.TabListMode.LIST
: TabListCoordinator.TabListMode.GRID;
}
@Test @Test
@MediumTest @MediumTest
public void testShowTabs() { public void testShowTabs() {
...@@ -240,6 +262,34 @@ public class TabSelectionEditorTest { ...@@ -240,6 +262,34 @@ public class TabSelectionEditorTest {
mRobot.resultRobot.verifyDividerNotClickableNotFocusable(); mRobot.resultRobot.verifyDividerNotClickableNotFocusable();
} }
@Test
@MediumTest
@Feature({"RenderTest"})
@CommandLineFlags.Add(BaseSwitches.ENABLE_LOW_END_DEVICE_MODE)
@EnableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testListViewAppearance() throws IOException {
List<Tab> tabs = getTabsInCurrentTabModel();
TestThreadUtils.runOnUiThreadBlocking(() -> { mTabSelectionEditorController.show(tabs); });
mRenderTestRule.render(mTabSelectionEditorLayout, "list_view");
}
@Test
@MediumTest
@Feature({"RenderTest"})
@CommandLineFlags.Add(BaseSwitches.ENABLE_LOW_END_DEVICE_MODE)
@EnableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testListViewAppearance_oneSelectedTab() throws IOException {
List<Tab> tabs = getTabsInCurrentTabModel();
TestThreadUtils.runOnUiThreadBlocking(() -> { mTabSelectionEditorController.show(tabs); });
mRobot.actionRobot.clickItemAtAdapterPosition(0);
mRenderTestRule.render(mTabSelectionEditorLayout, "list_view_one_selected_tab");
}
private List<Tab> getTabsInCurrentTabModel() { private List<Tab> getTabsInCurrentTabModel() {
List<Tab> tabs = new ArrayList<>(); List<Tab> tabs = new ArrayList<>();
......
3ca70f365224a2acf417e16eb8f70957c82a0dc1
\ No newline at end of file
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