Commit 484031b8 authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

[Instant Start] Fix bug in GridTabSwitcher initialization (2)

Similar to http://crrev.com/c/2328038, this CL moves more things that
should happen after native is ready to appropriate places. This CL
fixes the drag-and-drop misbehavior when instant start is on.

Bug: 1111122
Change-Id: I84cfc6d7dc04d392f3af6d115e3b2a79fb6c3f19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2326858
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795556}
parent fd506b57
......@@ -38,6 +38,7 @@ import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.e
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.finishActivity;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.getSwipeToDismissAction;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.leaveTabSwitcher;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.mergeAllNormalTabsToAGroup;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.rotateDeviceToOrientation;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.switchTabModel;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabModelTabCount;
......@@ -1991,7 +1992,7 @@ public class StartSurfaceLayoutTest {
@Test
@MediumTest
// clang-format off
@EnableFeatures({ChromeFeatureList.INSTANT_START})
@EnableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID, ChromeFeatureList.INSTANT_START})
// TODO(crbug.com/1112557): Remove this test when critical tests in StartSurfaceLayoutTest are
// running with InstantStart on.
public void testSetup_WithInstantStart() throws Exception {
......@@ -2004,6 +2005,14 @@ public class StartSurfaceLayoutTest {
// closure.
closeFirstTabInTabSwitcher();
verifyTabSwitcherCardCount(cta, 0);
// Verify TabGroupModelFilter is correctly setup by checking if tab switcher changes with
// tab grouping.
createTabs(cta, false, 3);
enterTabSwitcher(cta);
verifyTabSwitcherCardCount(cta, 2);
mergeAllNormalTabsToAGroup(cta);
verifyTabSwitcherCardCount(cta, 1);
}
private void enterTabGroupManualSelection(ChromeTabbedActivity cta) {
......
......@@ -80,6 +80,7 @@ public class TabListCoordinator implements Destroyable {
private final Rect mThumbnailLocationOfCurrentTab = new Rect();
private final Context mContext;
private final TabListModel mModel;
private final @UiType int mItemType;
private boolean mIsInitialized;
private ViewTreeObserver.OnGlobalLayoutListener mGlobalLayoutListener;
......@@ -115,6 +116,7 @@ public class TabListCoordinator implements Destroyable {
@Nullable TabListMediator.SelectionDelegateProvider selectionDelegateProvider,
@NonNull ViewGroup parentView, boolean attachToParent, String componentName) {
mMode = mode;
mItemType = itemType;
mContext = context;
mModel = new TabListModel();
mAdapter = new SimpleRecyclerViewAdapter(mModel);
......@@ -256,18 +258,6 @@ public class TabListCoordinator implements Destroyable {
false));
}
// TODO(crbug.com/1004570) : Support drag and drop, and swipe to dismiss when
// CLOSE_TAB_SUGGESTIONS is enabled.
if ((mMode == TabListMode.GRID || mMode == TabListMode.LIST)
&& selectionDelegateProvider == null) {
ItemTouchHelper touchHelper = new ItemTouchHelper(mMediator.getItemTouchHelperCallback(
context.getResources().getDimension(R.dimen.swipe_to_dismiss_threshold),
context.getResources().getDimension(R.dimen.tab_grid_merge_threshold),
context.getResources().getDimension(R.dimen.bottom_sheet_peek_height),
tabModelSelector.getCurrentModel().getProfile()));
touchHelper.attachToRecyclerView(mRecyclerView);
}
if (mMode == TabListMode.GRID && selectionDelegateProvider == null) {
// TODO(crbug.com/964406): unregister the listener when we don't need it.
mGlobalLayoutListener = this::updateThumbnailLocation;
......@@ -293,10 +283,21 @@ public class TabListCoordinator implements Destroyable {
mIsInitialized = true;
mMediator.initWithNative(Profile.getLastUsedRegularProfile());
Profile profile = Profile.getLastUsedRegularProfile();
mMediator.initWithNative(profile);
if (dynamicResourceLoader != null) {
mRecyclerView.createDynamicView(dynamicResourceLoader);
}
if ((mMode == TabListMode.GRID || mMode == TabListMode.LIST)
&& mItemType != UiType.SELECTABLE) {
ItemTouchHelper touchHelper = new ItemTouchHelper(mMediator.getItemTouchHelperCallback(
mContext.getResources().getDimension(R.dimen.swipe_to_dismiss_threshold),
mContext.getResources().getDimension(R.dimen.tab_grid_merge_threshold),
mContext.getResources().getDimension(R.dimen.bottom_sheet_peek_height),
profile));
touchHelper.attachToRecyclerView(mRecyclerView);
}
}
/**
......
......@@ -567,8 +567,7 @@ class TabListMediator {
}
};
if (mTabModelSelector.getTabModelFilterProvider().getCurrentTabModelFilter()
instanceof TabGroupModelFilter) {
if (TabUiFeatureUtilities.isTabGroupsAndroidEnabled()) {
mTabGroupObserver = new EmptyTabGroupModelFilterObserver() {
@Override
public void didMoveWithinGroup(
......@@ -696,13 +695,6 @@ class TabListMediator {
public void didCreateGroup(
List<Tab> tabs, List<Integer> tabOriginalIndex, boolean isSameGroup) {}
};
((TabGroupModelFilter) mTabModelSelector.getTabModelFilterProvider().getTabModelFilter(
false))
.addTabGroupObserver(mTabGroupObserver);
((TabGroupModelFilter) mTabModelSelector.getTabModelFilterProvider().getTabModelFilter(
true))
.addTabGroupObserver(mTabGroupObserver);
}
// TODO(meiliang): follow up with unit tests to test the close signal is sent correctly with
......@@ -766,6 +758,17 @@ class TabListMediator {
mTabListFaviconProvider.initWithNative(profile);
mTabModelSelector.getTabModelFilterProvider().addTabModelFilterObserver(mTabModelObserver);
if (mTabGroupObserver != null) {
assert mTabModelSelector.getTabModelFilterProvider().getCurrentTabModelFilter()
instanceof TabGroupModelFilter;
((TabGroupModelFilter) mTabModelSelector.getTabModelFilterProvider().getTabModelFilter(
false))
.addTabGroupObserver(mTabGroupObserver);
((TabGroupModelFilter) mTabModelSelector.getTabModelFilterProvider().getTabModelFilter(
true))
.addTabGroupObserver(mTabGroupObserver);
}
if (TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled()) {
mTabGroupTitleEditor = new TabGroupTitleEditor(mTabModelSelector) {
@Override
......
......@@ -284,7 +284,7 @@ public class TabUiTestHelper {
* Merge all normal tabs into a single tab group.
* @param cta The current running activity.
*/
static void mergeAllNormalTabsToAGroup(ChromeTabbedActivity cta) {
public static void mergeAllNormalTabsToAGroup(ChromeTabbedActivity cta) {
mergeAllTabsToAGroup(cta, false);
}
......
......@@ -2287,7 +2287,11 @@ public class TabListMediatorUnitTest {
mTabContentManager::getTabThumbnailWithCallback, mTitleProvider,
mTabListFaviconProvider, actionOnRelatedTabs, null, null, handler,
getClass().getSimpleName(), uiType);
// TabGroupModelFilterObserver is registered when native is ready.
assertThat(mTabGroupModelFilterObserverCaptor.getAllValues().isEmpty(), equalTo(true));
mMediator.initWithNative(mProfile);
assertThat(mTabGroupModelFilterObserverCaptor.getAllValues().isEmpty(), equalTo(false));
// There are two TabModelObserver and two TabGroupModelFilter.Observer added when
// initializing TabListMediator, one set from TabListMediator and the other from
......
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