Skip to content

Commit

Permalink
[M112] Fix tab is closed when back is performed on start surface
Browse files Browse the repository at this point in the history
On start surface, getActivityTab still returns a valid tab. If
the tab happens to be closable or navigatable, back press is consumed
to close tab or navigate it back, rather than exiting app.

This CL adds a check to make app exit if back press is performed
on start surface.

(cherry picked from commit 85d08a1)

Bug: 1416719
Change-Id: I84d03ba11ebed34cea2bb7eeb0d01154a8785530
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4262319
Reviewed-by: Donn Denman <donnd@chromium.org>
Reviewed-by: Xi Han <hanxi@chromium.org>
Commit-Queue: Lijin Shen <lazzzis@google.com>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1109268}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4294386
Cr-Commit-Position: refs/branch-heads/5615@{#50}
Cr-Branched-From: 9c6408e-refs/heads/main@{#1109224}
  • Loading branch information
Lijin Shen authored and Chromium LUCI CQ committed Feb 28, 2023
1 parent 5ab109c commit 0942a4e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import android.os.Build;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.lifecycle.Stage;
import android.view.View;

import androidx.test.espresso.contrib.RecyclerViewActions;
Expand All @@ -36,6 +37,7 @@
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterSet;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.ApplicationTestUtils;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.CriteriaHelper;
Expand Down Expand Up @@ -150,6 +152,39 @@ public void onFinishedShowing(@LayoutType int layoutType) {
mMostVisitedSites = StartSurfaceTestUtils.setMVTiles(mSuggestionsDeps);
}

// Test that back press on start surface should exit app rather than closing tab.
@Test
@MediumTest
@Feature({"StartSurface"})
@DisableFeatures({ChromeFeatureList.BACK_GESTURE_REFACTOR})
@CommandLineFlags.Add({START_SURFACE_TEST_SINGLE_ENABLED_PARAMS})
public void testShow_SingleAsHomepage_BackButton_ClosableTab() {
if (!mImmediateReturn) {
StartSurfaceTestUtils.pressHomePageButton(mActivityTestRule.getActivity());
}

ChromeTabbedActivity cta = mActivityTestRule.getActivity();
StartSurfaceTestUtils.waitForStartSurfaceVisible(
mLayoutChangedCallbackHelper, mCurrentlyActiveLayout, cta);
mActivityTestRule.loadUrlInNewTab("about:blank", false, TabLaunchType.FROM_LINK);
StartSurfaceTestUtils.pressHomePageButton(mActivityTestRule.getActivity());
StartSurfaceTestUtils.waitForStartSurfaceVisible(
mLayoutChangedCallbackHelper, mCurrentlyActiveLayout, cta);
onViewWaiting(withId(R.id.primary_tasks_surface_view));
StartSurfaceTestUtils.pressBack(mActivityTestRule);
TabUiTestHelper.verifyTabModelTabCount(cta, 2, 0);
ApplicationTestUtils.waitForActivityState(cta, Stage.STOPPED);
}

@Test
@MediumTest
@Feature({"StartSurface"})
@EnableFeatures({ChromeFeatureList.BACK_GESTURE_REFACTOR})
@CommandLineFlags.Add({START_SURFACE_TEST_SINGLE_ENABLED_PARAMS})
public void testShow_SingleAsHomepage_BackButton_ClosableTab_BackGestureRefactor() {
testShow_SingleAsHomepage_BackButton_ClosableTab();
}

@Test
@MediumTest
@Feature({"StartSurface"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2297,7 +2297,10 @@ && getToolbarManager().unfocusUrlBarOnBackPress()) {
return true;
}

final Tab currentTab = getActivityTab();
// crbug.com/1416719: back press on start surface should close the app.
final boolean isStartSurfaceHomepageShowing =
mStartSurfaceSupplier.hasValue() && mStartSurfaceSupplier.get().isHomepageShown();
final Tab currentTab = isStartSurfaceHomepageShowing ? null : getActivityTab();
if (currentTab == null) {
BackPressManager.record(BackPressHandler.Type.MINIMIZE_APP_AND_CLOSE_TAB);
MinimizeAppAndCloseTabBackPressHandler.record(MinimizeAppAndCloseTabType.MINIMIZE_APP);
Expand Down Expand Up @@ -2379,7 +2382,9 @@ && getToolbarManager().unfocusUrlBarOnBackPress()) {
}

private void assertOnLastBackPress() {
var currentTab = getActivityTab();
final boolean isStartSurfaceHomepageShowing =
mStartSurfaceSupplier.hasValue() && mStartSurfaceSupplier.get().isHomepageShown();
final Tab currentTab = isStartSurfaceHomepageShowing ? null : getActivityTab();
var activityTab = getActivityTabProvider().get();
MinimizeAppAndCloseTabBackPressHandler.assertOnLastBackPress(currentTab, activityTab,
this::backShouldCloseTab, mLayoutStateProviderSupplier,
Expand Down

0 comments on commit 0942a4e

Please sign in to comment.