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

Update popup tab strip when switching tabs through swipe gesture

Currently, popup tabstrip doesn't update when user uses swipe gesture
to switch between tabs. This CL fixes this issue and adds some tests.

Bug: 1048732
Change-Id: I967769ccec7dc7220a7528b72c628e0f76fc1cfe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2037835Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738395}
parent eba19850
......@@ -74,6 +74,23 @@ public class TabGroupPopupUiMediator {
mFullscreenManager.addListener(mFullscreenListener);
mTabModelObserver = new EmptyTabModelObserver() {
@Override
public void didSelectTab(Tab tab, int type, int lastId) {
List<Tab> tabList = mTabModelSelector.getTabModelFilterProvider()
.getCurrentTabModelFilter()
.getRelatedTabList(lastId);
if (tabList.contains(tab)) return;
if (isCurrentTabInGroup()) {
if (isTabStripShowing()) {
mUiUpdater.updateTabGroupPopUi();
} else {
maybeShowTabStrip();
}
} else {
hideTabStrip();
}
}
@Override
public void willCloseTab(Tab tab, boolean animate) {
if (!isCurrentTabInGroup()) {
......
......@@ -63,9 +63,11 @@ public class TabGroupPopupUiMediatorUnitTest {
private static final String TAB1_TITLE = "Tab1";
private static final String TAB2_TITLE = "Tab2";
private static final String TAB3_TITLE = "Tab3";
private static final String TAB4_TITLE = "Tab4";
private static final int TAB1_ID = 456;
private static final int TAB2_ID = 789;
private static final int TAB3_ID = 123;
private static final int TAB4_ID = 357;
@Mock
TabModelSelectorImpl mTabModelSelector;
......@@ -161,6 +163,70 @@ public class TabGroupPopupUiMediatorUnitTest {
mModel.get(TabGroupPopupUiProperties.CONTENT_VIEW_ALPHA), equalTo(1 - hiddenRatio));
}
@Test
public void tabSelection_Show() {
// Mock that the strip is hidden.
mModel.set(TabGroupPopupUiProperties.IS_VISIBLE, false);
// Mock that tab1 and tab2 are in the same group, and tab 3 is a single tab.
createTabGroup(new ArrayList<>(Arrays.asList(mTab1, mTab2)), TAB1_ID);
createTabGroup(new ArrayList<>(Arrays.asList(mTab3)), TAB3_ID);
doReturn(mTab2).when(mTabModelSelector).getCurrentTab();
mTabModelObserverCaptor.getValue().didSelectTab(
mTab2, TabLaunchType.FROM_CHROME_UI, TAB3_ID);
assertThat(mModel.get(TabGroupPopupUiProperties.IS_VISIBLE), equalTo(true));
verify(mUpdater, never()).updateTabGroupPopUi();
}
@Test
public void tabSelection_Hide() {
// Mock that the strip is showing.
mModel.set(TabGroupPopupUiProperties.IS_VISIBLE, true);
// Mock that tab1 and tab2 are in the same group, and tab 3 is a single tab.
createTabGroup(new ArrayList<>(Arrays.asList(mTab1, mTab2)), TAB1_ID);
createTabGroup(new ArrayList<>(Arrays.asList(mTab3)), TAB3_ID);
doReturn(mTab3).when(mTabModelSelector).getCurrentTab();
mTabModelObserverCaptor.getValue().didSelectTab(
mTab3, TabLaunchType.FROM_CHROME_UI, TAB1_ID);
assertThat(mModel.get(TabGroupPopupUiProperties.IS_VISIBLE), equalTo(false));
verify(mUpdater, never()).updateTabGroupPopUi();
}
@Test
public void tabSelection_Update() {
// Mock that the strip is showing.
mModel.set(TabGroupPopupUiProperties.IS_VISIBLE, true);
// Mock that tab1 and tab2 are in the same group, tab3 and new tab are in the same group.
createTabGroup(new ArrayList<>(Arrays.asList(mTab1, mTab2)), TAB1_ID);
createTabGroup(
new ArrayList<>(Arrays.asList(mTab3, prepareTab(TAB4_ID, TAB4_TITLE))), TAB3_ID);
doReturn(mTab1).when(mTabModelSelector).getCurrentTab();
mTabModelObserverCaptor.getValue().didSelectTab(
mTab1, TabLaunchType.FROM_CHROME_UI, TAB3_ID);
assertThat(mModel.get(TabGroupPopupUiProperties.IS_VISIBLE), equalTo(true));
verify(mUpdater).updateTabGroupPopUi();
}
@Test
public void tabSelection_SameGroup() {
// Mock that the strip is showing.
mModel.set(TabGroupPopupUiProperties.IS_VISIBLE, true);
// Mock that tab1 and tab2 are in the same group.
createTabGroup(new ArrayList<>(Arrays.asList(mTab1, mTab2)), TAB1_ID);
doReturn(mTab1).when(mTabModelSelector).getCurrentTab();
mTabModelObserverCaptor.getValue().didSelectTab(
mTab1, TabLaunchType.FROM_CHROME_UI, TAB2_ID);
assertThat(mModel.get(TabGroupPopupUiProperties.IS_VISIBLE), equalTo(true));
verify(mUpdater, never()).updateTabGroupPopUi();
}
@Test
public void tabClosure_Hide() {
// Mock that the strip is showing.
......
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