Commit 9f6b1666 authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Add a range check when undo a closure in GTS

Bug: 1029419
Change-Id: I904d29eb86b61a4b8d13100e0146b868a5591af6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1946871Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720755}
parent b5bf966d
......@@ -455,7 +455,8 @@ class TabListMediator {
.getCurrentTabModelFilter();
int index = filter.indexOf(tab);
if (index == TabList.INVALID_TAB_INDEX
|| getRelatedTabsForId(tab.getId()).size() == 1) {
|| getRelatedTabsForId(tab.getId()).size() == 1
|| index >= mModel.size()) {
return;
}
Tab currentGroupSelectedTab = filter.getTabAt(index);
......
......@@ -25,6 +25,7 @@ import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.c
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.createTabGroup;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.createTabs;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.enterTabSwitcher;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabStripFaviconCount;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabSwitcherCardCount;
import android.graphics.Rect;
......@@ -58,7 +59,7 @@ import org.chromium.chrome.browser.flags.FeatureUtilities;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tasks.tab_groups.TabGroupModelFilter;
import org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.CardCountAssertion;
import org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.ChildrenCountAssertion;
import org.chromium.chrome.features.start_surface.StartSurfaceLayout;
import org.chromium.chrome.tab_ui.R;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -225,7 +226,7 @@ public class TabGridDialogTest {
@Test
@MediumTest
public void testUndoClosureInDialog() throws InterruptedException {
public void testUndoClosureInDialog_GTS() throws InterruptedException {
final ChromeTabbedActivity cta = mActivityTestRule.getActivity();
createTabs(cta, false, 2);
enterTabSwitcher(cta);
......@@ -255,6 +256,40 @@ public class TabGridDialogTest {
openDialogFromTabSwitcherAndVerify(cta, 2);
}
@Test
@MediumTest
public void testUndoClosureInDialog_TabStrip() throws InterruptedException {
final ChromeTabbedActivity cta = mActivityTestRule.getActivity();
createTabs(cta, false, 2);
enterTabSwitcher(cta);
verifyTabSwitcherCardCount(cta, 2);
// Create a tab group.
mergeAllTabsToAGroup(cta);
verifyTabSwitcherCardCount(cta, 1);
// Enter first tab page.
assertTrue(cta.getLayoutManager().overviewVisible());
clickFirstCardFromTabSwitcher(cta);
clickFirstTabFromDialog(cta);
// Open dialog from tab strip and verify dialog is showing correct content.
openDialogFromStripAndVerify(cta, 2);
// Click close button to close the first tab in group.
closeFirstTabInDialog(cta);
verifyShowingDialog(cta, 1);
// Exit dialog, wait for the undo bar showing and undo the closure.
TabUiTestHelper.clickScrimToExitDialog(cta);
CriteriaHelper.pollInstrumentationThread(() -> !isDialogShowing(cta));
CriteriaHelper.pollInstrumentationThread(this::verifyUndoBarShowingAndClickUndo);
// Verify the undo has happened.
verifyTabStripFaviconCount(cta, 2);
openDialogFromStripAndVerify(cta, 2);
}
private void mergeAllTabsToAGroup(ChromeTabbedActivity cta) {
List<Tab> tabGroup = new ArrayList<>();
TabModel tabModel = cta.getTabModelSelector().getModel(false);
......@@ -285,7 +320,7 @@ public class TabGridDialogTest {
private void verifyShowingDialog(ChromeTabbedActivity cta, int tabCount) {
onView(withId(R.id.tab_list_view))
.inRoot(withDecorView(not(cta.getWindow().getDecorView())))
.check(CardCountAssertion.havingTabCount(tabCount));
.check(ChildrenCountAssertion.havingTabCount(tabCount));
onView(allOf(withParent(withId(R.id.main_content)), withId(R.id.title)))
.inRoot(withDecorView(not(cta.getWindow().getDecorView())))
......
......@@ -135,7 +135,18 @@ public class TabUiTestHelper {
assertTrue(cta.getLayoutManager().overviewVisible());
onView(allOf(withParent(withId(org.chromium.chrome.R.id.compositor_view_holder)),
withId(R.id.tab_list_view)))
.check(CardCountAssertion.havingTabCount(count));
.check(ChildrenCountAssertion.havingTabCount(count));
}
/**
* Verify there are correct number of favicons in tab strip.
* @param cta The current running activity.
* @param count The correct number of favicons in tab strip.
*/
static void verifyTabStripFaviconCount(ChromeTabbedActivity cta, int count) {
assertFalse(cta.getLayoutManager().overviewVisible());
onView(allOf(withParent(withId(R.id.toolbar_container_view)), withId(R.id.tab_list_view)))
.check(ChildrenCountAssertion.havingTabCount(count));
}
/**
......@@ -364,14 +375,14 @@ public class TabUiTestHelper {
* Implementation of {@link ViewAssertion} to verify the {@link RecyclerView} has correct number
* of children, and children are showing correctly.
*/
public static class CardCountAssertion implements ViewAssertion {
public static class ChildrenCountAssertion implements ViewAssertion {
private int mExpectedCount;
public static CardCountAssertion havingTabCount(int tabCount) {
return new CardCountAssertion(tabCount);
public static ChildrenCountAssertion havingTabCount(int tabCount) {
return new ChildrenCountAssertion(tabCount);
}
public CardCountAssertion(int expectedCount) {
public ChildrenCountAssertion(int expectedCount) {
mExpectedCount = expectedCount;
}
......
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