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

[Instant Start] Fix bug in GridTabSwitcher initialization (1)

In TabListMediator, TabModelObserver is registered in constructor. This
assumes that when constructor is called, the TabModel side should be
ready to accept observers, which is no longer true with instant start
as the constructor for TabListMediator for GridTabSwitcher is now
called before native is ready. This CL fixes this issue by registering
the TabModelObserver after native is ready.

Bug: 1110783
Change-Id: Ia944a1cb7fef30933b4094adb1045e664e3df1a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2328038Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795511}
parent 52a7d96d
......@@ -1988,6 +1988,24 @@ public class StartSurfaceLayoutTest {
verifyTabSwitcherCardCount(cta, 3);
}
@Test
@MediumTest
// clang-format off
@EnableFeatures({ChromeFeatureList.INSTANT_START})
// TODO(crbug.com/1112557): Remove this test when critical tests in StartSurfaceLayoutTest are
// running with InstantStart on.
public void testSetup_WithInstantStart() throws Exception {
// clang-format on
ChromeTabbedActivity cta = mActivityTestRule.getActivity();
enterTabSwitcher(cta);
verifyTabSwitcherCardCount(cta, 1);
// Verify TabModelObserver is correctly setup by checking if tab switcher changes with tab
// closure.
closeFirstTabInTabSwitcher();
verifyTabSwitcherCardCount(cta, 0);
}
private void enterTabGroupManualSelection(ChromeTabbedActivity cta) {
MenuUtils.invokeCustomMenuActionSync(
InstrumentationRegistry.getInstrumentation(), cta, R.id.menu_group_tabs);
......
......@@ -567,8 +567,6 @@ class TabListMediator {
}
};
mTabModelSelector.getTabModelFilterProvider().addTabModelFilterObserver(mTabModelObserver);
if (mTabModelSelector.getTabModelFilterProvider().getCurrentTabModelFilter()
instanceof TabGroupModelFilter) {
mTabGroupObserver = new EmptyTabGroupModelFilterObserver() {
......@@ -766,6 +764,8 @@ class TabListMediator {
public void initWithNative(Profile profile) {
mTabListFaviconProvider.initWithNative(profile);
mTabModelSelector.getTabModelFilterProvider().addTabModelFilterObserver(mTabModelObserver);
if (TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled()) {
mTabGroupTitleEditor = new TabGroupTitleEditor(mTabModelSelector) {
@Override
......
......@@ -323,9 +323,13 @@ public class TabListMediatorUnitTest {
mTabContentManager::getTabThumbnailWithCallback, mTitleProvider,
mTabListFaviconProvider, false, null, mGridCardOnClickListenerProvider, null,
getClass().getSimpleName(), UiType.CLOSABLE);
mMediator.initWithNative(mProfile);
mMediator.registerOrientationListener(mGridLayoutManager);
TrackerFactory.setTrackerForTests(mTracker);
// TabModelObserver is registered when native is ready.
assertThat(mTabModelObserverCaptor.getAllValues().isEmpty(), equalTo(true));
mMediator.initWithNative(mProfile);
assertThat(mTabModelObserverCaptor.getAllValues().isEmpty(), equalTo(false));
}
@After
......
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