Commit 01bbb855 authored by Mei Liang's avatar Mei Liang Committed by Commit Bot

Avoid updating URL when Tab does not exist

The crash happens when a tab updates after model switched. The updated
tab does not exist in the current TabModel, therefore a null is returned
when we try to locate the selected tab. The simple fix is to null check
before we access the tab.

This CL also hides the onUrlUpdated logic behind the
TabGroupsContinuation flag.

Change-Id: I81090666328158f8a5a5e37459c54e48d0ef6325
Bug: 1035301
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1996130
Commit-Queue: Mei Liang <meiliang@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732493}
parent 97805ec6
...@@ -692,7 +692,7 @@ public class StartSurfaceLayoutTest { ...@@ -692,7 +692,7 @@ public class StartSurfaceLayoutTest {
@CommandLineFlags.Add({BASE_PARAMS}) @CommandLineFlags.Add({BASE_PARAMS})
@Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID, @Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID,
ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID}) ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testUrlUpdatedForUndoableClosedTabNotCrashing() throws Exception { public void testUrlUpdatedNotCrashing_ForUndoableClosedTab() throws Exception {
// clang-format on // clang-format on
FeatureUtilities.setTabGroupsAndroidEnabledForTesting(true); FeatureUtilities.setTabGroupsAndroidEnabledForTesting(true);
...@@ -712,6 +712,29 @@ public class StartSurfaceLayoutTest { ...@@ -712,6 +712,29 @@ public class StartSurfaceLayoutTest {
mUrl, PageTransition.TYPED | PageTransition.FROM_ADDRESS_BAR, tab); mUrl, PageTransition.TYPED | PageTransition.FROM_ADDRESS_BAR, tab);
} }
@Test
@MediumTest
// clang-format off
@CommandLineFlags.Add({BASE_PARAMS})
@Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID,
ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testUrlUpdatedNotCrashing_ForTabNotInCurrentModel() throws Exception {
// clang-format on
FeatureUtilities.setTabGroupsAndroidEnabledForTesting(true);
// Restart Chrome to have Group.
ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
mActivityTestRule.startMainActivityFromLauncher();
prepareTabs(1, 1, null);
enterGTSWithThumbnailChecking();
Tab tab = mActivityTestRule.getActivity().getTabModelSelector().getCurrentTab();
switchTabModel(false);
mActivityTestRule.loadUrlInTab(
mUrl, PageTransition.TYPED | PageTransition.FROM_ADDRESS_BAR, tab);
}
@Test @Test
@MediumTest @MediumTest
@Feature("TabSuggestion") @Feature("TabSuggestion")
......
...@@ -374,12 +374,13 @@ class TabListMediator { ...@@ -374,12 +374,13 @@ class TabListMediator {
@Override @Override
public void onUrlUpdated(Tab tab) { public void onUrlUpdated(Tab tab) {
if (!FeatureUtilities.isTabGroupsAndroidContinuationEnabled()) return;
int index = mModel.indexFromId(tab.getId()); int index = mModel.indexFromId(tab.getId());
if (index == TabModel.INVALID_TAB_INDEX && mActionsOnAllRelatedTabs if (index == TabModel.INVALID_TAB_INDEX && mActionsOnAllRelatedTabs) {
&& FeatureUtilities.isTabGroupsAndroidContinuationEnabled()) {
Tab currentGroupSelectedTab = Tab currentGroupSelectedTab =
TabGroupUtils.getSelectedTabInGroupForTab(mTabModelSelector, tab); TabGroupUtils.getSelectedTabInGroupForTab(mTabModelSelector, tab);
if (currentGroupSelectedTab == null) return;
index = mModel.indexFromId(currentGroupSelectedTab.getId()); index = mModel.indexFromId(currentGroupSelectedTab.getId());
} }
...@@ -1203,6 +1204,7 @@ class TabListMediator { ...@@ -1203,6 +1204,7 @@ class TabListMediator {
} }
private String getUrlForTab(Tab tab) { private String getUrlForTab(Tab tab) {
if (!FeatureUtilities.isTabGroupsAndroidContinuationEnabled()) return "";
if (!mActionsOnAllRelatedTabs) return tab.getUrl(); if (!mActionsOnAllRelatedTabs) return tab.getUrl();
List<Tab> relatedTabs = getRelatedTabsForId(tab.getId()); List<Tab> relatedTabs = getRelatedTabsForId(tab.getId());
......
...@@ -115,8 +115,11 @@ import java.util.List; ...@@ -115,8 +115,11 @@ import java.util.List;
*/ */
@RunWith(LocalRobolectricTestRunner.class) @RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
// clang-format off
@Features.EnableFeatures(ChromeFeatureList.TAB_TO_GTS_ANIMATION) @Features.EnableFeatures(ChromeFeatureList.TAB_TO_GTS_ANIMATION)
@Features.DisableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public class TabListMediatorUnitTest { public class TabListMediatorUnitTest {
// clang-format on
@Rule @Rule
public TestRule mProcessor = new Features.JUnitProcessor(); public TestRule mProcessor = new Features.JUnitProcessor();
...@@ -1491,8 +1494,9 @@ public class TabListMediatorUnitTest { ...@@ -1491,8 +1494,9 @@ public class TabListMediatorUnitTest {
doReturn(NEW_URL).when(mTab1).getUrl(); doReturn(NEW_URL).when(mTab1).getUrl();
mTabObserverCaptor.getValue().onUrlUpdated(mTab1); mTabObserverCaptor.getValue().onUrlUpdated(mTab1);
assertEquals(NEW_URL, mModel.get(POSITION1).model.get(TabProperties.URL)); // TabProperties.URL is empty string if TabGroupsAndroidContinuationEnabled is false.
assertEquals(TAB2_URL, mModel.get(POSITION2).model.get(TabProperties.URL)); assertEquals("", mModel.get(POSITION1).model.get(TabProperties.URL));
assertEquals("", mModel.get(POSITION2).model.get(TabProperties.URL));
} }
@Test @Test
...@@ -1788,9 +1792,6 @@ public class TabListMediatorUnitTest { ...@@ -1788,9 +1792,6 @@ public class TabListMediatorUnitTest {
assertThat(mModel.get(0).model.get(TabProperties.FAVICON), instanceOf(Drawable.class)); assertThat(mModel.get(0).model.get(TabProperties.FAVICON), instanceOf(Drawable.class));
assertThat(mModel.get(1).model.get(TabProperties.FAVICON), instanceOf(Drawable.class)); assertThat(mModel.get(1).model.get(TabProperties.FAVICON), instanceOf(Drawable.class));
assertThat(mModel.get(0).model.get(TabProperties.URL), equalTo(TAB1_URL));
assertThat(mModel.get(1).model.get(TabProperties.URL), equalTo(TAB2_URL));
assertThat(mModel.get(0).model.get(TabProperties.IS_SELECTED), equalTo(true)); assertThat(mModel.get(0).model.get(TabProperties.IS_SELECTED), equalTo(true));
assertThat(mModel.get(1).model.get(TabProperties.IS_SELECTED), equalTo(false)); assertThat(mModel.get(1).model.get(TabProperties.IS_SELECTED), 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