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 ...@@ -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.finishActivity;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.getSwipeToDismissAction; 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.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.rotateDeviceToOrientation;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.switchTabModel; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.switchTabModel;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabModelTabCount; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabModelTabCount;
...@@ -1991,7 +1992,7 @@ public class StartSurfaceLayoutTest { ...@@ -1991,7 +1992,7 @@ public class StartSurfaceLayoutTest {
@Test @Test
@MediumTest @MediumTest
// clang-format off // 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 // TODO(crbug.com/1112557): Remove this test when critical tests in StartSurfaceLayoutTest are
// running with InstantStart on. // running with InstantStart on.
public void testSetup_WithInstantStart() throws Exception { public void testSetup_WithInstantStart() throws Exception {
...@@ -2004,6 +2005,14 @@ public class StartSurfaceLayoutTest { ...@@ -2004,6 +2005,14 @@ public class StartSurfaceLayoutTest {
// closure. // closure.
closeFirstTabInTabSwitcher(); closeFirstTabInTabSwitcher();
verifyTabSwitcherCardCount(cta, 0); 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) { private void enterTabGroupManualSelection(ChromeTabbedActivity cta) {
......
...@@ -80,6 +80,7 @@ public class TabListCoordinator implements Destroyable { ...@@ -80,6 +80,7 @@ public class TabListCoordinator implements Destroyable {
private final Rect mThumbnailLocationOfCurrentTab = new Rect(); private final Rect mThumbnailLocationOfCurrentTab = new Rect();
private final Context mContext; private final Context mContext;
private final TabListModel mModel; private final TabListModel mModel;
private final @UiType int mItemType;
private boolean mIsInitialized; private boolean mIsInitialized;
private ViewTreeObserver.OnGlobalLayoutListener mGlobalLayoutListener; private ViewTreeObserver.OnGlobalLayoutListener mGlobalLayoutListener;
...@@ -115,6 +116,7 @@ public class TabListCoordinator implements Destroyable { ...@@ -115,6 +116,7 @@ public class TabListCoordinator implements Destroyable {
@Nullable TabListMediator.SelectionDelegateProvider selectionDelegateProvider, @Nullable TabListMediator.SelectionDelegateProvider selectionDelegateProvider,
@NonNull ViewGroup parentView, boolean attachToParent, String componentName) { @NonNull ViewGroup parentView, boolean attachToParent, String componentName) {
mMode = mode; mMode = mode;
mItemType = itemType;
mContext = context; mContext = context;
mModel = new TabListModel(); mModel = new TabListModel();
mAdapter = new SimpleRecyclerViewAdapter(mModel); mAdapter = new SimpleRecyclerViewAdapter(mModel);
...@@ -256,18 +258,6 @@ public class TabListCoordinator implements Destroyable { ...@@ -256,18 +258,6 @@ public class TabListCoordinator implements Destroyable {
false)); 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) { if (mMode == TabListMode.GRID && selectionDelegateProvider == null) {
// TODO(crbug.com/964406): unregister the listener when we don't need it. // TODO(crbug.com/964406): unregister the listener when we don't need it.
mGlobalLayoutListener = this::updateThumbnailLocation; mGlobalLayoutListener = this::updateThumbnailLocation;
...@@ -293,10 +283,21 @@ public class TabListCoordinator implements Destroyable { ...@@ -293,10 +283,21 @@ public class TabListCoordinator implements Destroyable {
mIsInitialized = true; mIsInitialized = true;
mMediator.initWithNative(Profile.getLastUsedRegularProfile()); Profile profile = Profile.getLastUsedRegularProfile();
mMediator.initWithNative(profile);
if (dynamicResourceLoader != null) { if (dynamicResourceLoader != null) {
mRecyclerView.createDynamicView(dynamicResourceLoader); 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 { ...@@ -567,8 +567,7 @@ class TabListMediator {
} }
}; };
if (mTabModelSelector.getTabModelFilterProvider().getCurrentTabModelFilter() if (TabUiFeatureUtilities.isTabGroupsAndroidEnabled()) {
instanceof TabGroupModelFilter) {
mTabGroupObserver = new EmptyTabGroupModelFilterObserver() { mTabGroupObserver = new EmptyTabGroupModelFilterObserver() {
@Override @Override
public void didMoveWithinGroup( public void didMoveWithinGroup(
...@@ -696,13 +695,6 @@ class TabListMediator { ...@@ -696,13 +695,6 @@ class TabListMediator {
public void didCreateGroup( public void didCreateGroup(
List<Tab> tabs, List<Integer> tabOriginalIndex, boolean isSameGroup) {} 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 // TODO(meiliang): follow up with unit tests to test the close signal is sent correctly with
...@@ -766,6 +758,17 @@ class TabListMediator { ...@@ -766,6 +758,17 @@ class TabListMediator {
mTabListFaviconProvider.initWithNative(profile); mTabListFaviconProvider.initWithNative(profile);
mTabModelSelector.getTabModelFilterProvider().addTabModelFilterObserver(mTabModelObserver); 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()) { if (TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled()) {
mTabGroupTitleEditor = new TabGroupTitleEditor(mTabModelSelector) { mTabGroupTitleEditor = new TabGroupTitleEditor(mTabModelSelector) {
@Override @Override
......
...@@ -284,7 +284,7 @@ public class TabUiTestHelper { ...@@ -284,7 +284,7 @@ public class TabUiTestHelper {
* Merge all normal tabs into a single tab group. * Merge all normal tabs into a single tab group.
* @param cta The current running activity. * @param cta The current running activity.
*/ */
static void mergeAllNormalTabsToAGroup(ChromeTabbedActivity cta) { public static void mergeAllNormalTabsToAGroup(ChromeTabbedActivity cta) {
mergeAllTabsToAGroup(cta, false); mergeAllTabsToAGroup(cta, false);
} }
......
...@@ -2287,7 +2287,11 @@ public class TabListMediatorUnitTest { ...@@ -2287,7 +2287,11 @@ public class TabListMediatorUnitTest {
mTabContentManager::getTabThumbnailWithCallback, mTitleProvider, mTabContentManager::getTabThumbnailWithCallback, mTitleProvider,
mTabListFaviconProvider, actionOnRelatedTabs, null, null, handler, mTabListFaviconProvider, actionOnRelatedTabs, null, null, handler,
getClass().getSimpleName(), uiType); getClass().getSimpleName(), uiType);
// TabGroupModelFilterObserver is registered when native is ready.
assertThat(mTabGroupModelFilterObserverCaptor.getAllValues().isEmpty(), equalTo(true));
mMediator.initWithNative(mProfile); mMediator.initWithNative(mProfile);
assertThat(mTabGroupModelFilterObserverCaptor.getAllValues().isEmpty(), equalTo(false));
// There are two TabModelObserver and two TabGroupModelFilter.Observer added when // There are two TabModelObserver and two TabGroupModelFilter.Observer added when
// initializing TabListMediator, one set from TabListMediator and the other from // 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