Commit 04be0df8 authored by Wei-Yin Chen (陳威尹)'s avatar Wei-Yin Chen (陳威尹) Committed by Commit Bot

Skip populating invisible GTS when switching tab model

Before this CL, when switching tab models, the GTS is populated even
if it is not visible. This led to loading the thumbnails
unnecessarily.

Bug: 1014792
Change-Id: Iecff9173e6e4a3ebae80961e067762c000c3caf7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869124
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarMei Liang <meiliang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708024}
parent acef6fd7
......@@ -641,8 +641,6 @@ public class StartSurfaceLayoutTest {
@Test
@MediumTest
@CommandLineFlags.Add({BASE_PARAMS})
@DisabledTest(message = "crbug.com/1014792, should not fetch all tabs in TabModel when we" +
"switch model")
public void testIncognitoToggle_thumbnailFetchCount() throws InterruptedException {
mActivityTestRule.loadUrl(mUrl);
int oldFetchCount = mTabListDelegate.getBitmapFetchCountForTesting();
......
......@@ -185,11 +185,12 @@ class TabSwitcherMediator implements TabSwitcher.Controller, TabListRecyclerView
TabList currentTabModelFilter =
mTabModelSelector.getTabModelFilterProvider().getCurrentTabModelFilter();
mResetHandler.resetWithTabList(currentTabModelFilter, false, mShowTabsInMruOrder);
mContainerViewModel.set(IS_INCOGNITO, currentTabModelFilter.isIncognito());
if (mTabGridDialogController != null) {
mTabGridDialogController.hideDialog(false);
}
if (!mContainerViewModel.get(IS_VISIBLE)) return;
mResetHandler.resetWithTabList(currentTabModelFilter, false, mShowTabsInMruOrder);
if (mIphProvider != null) {
mIphProvider.maybeShowIPH(mTabModelSelector.isIncognitoSelected());
}
......
......@@ -354,6 +354,8 @@ public class TabSwitcherMediatorUnitTest {
@Test
public void resetsAfterNewTabModelSelected_DialogEnabled() {
initAndAssertAllProperties();
mModel.set(TabListContainerProperties.IS_VISIBLE, true);
// Setup dialog reset handler. Default setup is that dialog handler is null.
mMediator.setTabGridDialogController(mTabGridDialogController);
......@@ -364,12 +366,13 @@ public class TabSwitcherMediatorUnitTest {
assertThat(mModel.get(TabListContainerProperties.IS_INCOGNITO), equalTo(true));
// Switching TabModels by itself shouldn't cause visibility changes.
assertThat(mModel.get(TabListContainerProperties.IS_VISIBLE), equalTo(false));
assertThat(mModel.get(TabListContainerProperties.IS_VISIBLE), equalTo(true));
}
@Test
public void resetsAfterNewTabModelSelected_DialogNotEnabled() {
initAndAssertAllProperties();
mModel.set(TabListContainerProperties.IS_VISIBLE, true);
doReturn(true).when(mTabModelFilter).isIncognito();
mTabModelSelectorObserverCaptor.getValue().onTabModelSelected(mTabModel, null);
......@@ -377,6 +380,24 @@ public class TabSwitcherMediatorUnitTest {
verify(mTabGridDialogController, never()).hideDialog(eq(false));
assertThat(mModel.get(TabListContainerProperties.IS_INCOGNITO), equalTo(true));
// Switching TabModels by itself shouldn't cause visibility changes.
assertThat(mModel.get(TabListContainerProperties.IS_VISIBLE), equalTo(true));
}
@Test
public void noResetsAfterNewTabModelSelected_InvisibleGTS() {
initAndAssertAllProperties();
assertThat(mModel.get(TabListContainerProperties.IS_VISIBLE), equalTo(false));
// Setup dialog reset handler. Default setup is that dialog handler is null.
mMediator.setTabGridDialogController(mTabGridDialogController);
doReturn(true).when(mTabModelFilter).isIncognito();
mTabModelSelectorObserverCaptor.getValue().onTabModelSelected(mTabModel, null);
verify(mResetHandler, never()).resetWithTabList(any(), anyBoolean(), anyBoolean());
verify(mTabGridDialogController).hideDialog(eq(false));
assertThat(mModel.get(TabListContainerProperties.IS_INCOGNITO), equalTo(true));
// Switching TabModels by itself shouldn't cause visibility changes.
assertThat(mModel.get(TabListContainerProperties.IS_VISIBLE), equalTo(false));
}
......
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