Skip to content

Commit

Permalink
[Android] [IncognitoReauth] Add check on activity type before accessing
Browse files Browse the repository at this point in the history
start surface supplier.

M103 merge, approved at crbug.com/1325331#c14

Currently, we are referencing the mStartSurfaceSupplier.get() to get
the TabSwitcherCustomViewManager without checking the underlying
activity type. The mStartSurfaceSupplier.get() can return null for
activity type other than Tabbed type.

This CL adds a check on activity type before referencing methods
from start surface.

(cherry picked from commit 3e22a2e)

Bug: 1325331, 1227656
Change-Id: Iab33426c2bf69fd797a3a71bad5da69ed2cf4c11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3647868
Commit-Queue: Rohit Agarwal <roagarwal@chromium.org>
Reviewed-by: Matthew Jones <mdjones@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1004818}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3669899
Auto-Submit: Rohit Agarwal <roagarwal@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Cr-Commit-Position: refs/branch-heads/5060@{#308}
Cr-Branched-From: b83393d-refs/heads/main@{#1002911}
  • Loading branch information
Rohit Agarwal authored and Chromium LUCI CQ committed May 27, 2022
1 parent 79b5b25 commit 34757d8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -721,23 +721,25 @@ public void onFinishNativeInitialization() {
// OneshotSupplierImpl<TabSwitcherCustomViewManager> instance.
OneshotSupplierImpl<IncognitoReauthTabSwitcherDelegate>
incognitoReauthTabSwitcherSupplier = new OneshotSupplierImpl<>();
mTabSwitcherCustomViewController = new CallbackController();
mStartSurfaceSupplier.get().getTabSwitcherCustomViewManagerSupplier().onAvailable(
mTabSwitcherCustomViewController.makeCancelable(tabSwitcherCustomViewManager
-> incognitoReauthTabSwitcherSupplier.set(
new IncognitoReauthTabSwitcherDelegate() {
@Override
public boolean addReauthScreenInTabSwitcher(
@NonNull View customView) {
return tabSwitcherCustomViewManager.requestView(
customView);
}

@Override
public boolean removeReauthScreenFromTabSwitcher() {
return tabSwitcherCustomViewManager.releaseView();
}
})));
if (mActivityType == ActivityType.TABBED) {
mTabSwitcherCustomViewController = new CallbackController();
mStartSurfaceSupplier.get().getTabSwitcherCustomViewManagerSupplier().onAvailable(
mTabSwitcherCustomViewController.makeCancelable(tabSwitcherCustomViewManager
-> incognitoReauthTabSwitcherSupplier.set(
new IncognitoReauthTabSwitcherDelegate() {
@Override
public boolean addReauthScreenInTabSwitcher(
@NonNull View customView) {
return tabSwitcherCustomViewManager.requestView(
customView);
}

@Override
public boolean removeReauthScreenFromTabSwitcher() {
return tabSwitcherCustomViewManager.releaseView();
}
})));
}

IncognitoReauthCoordinatorFactory incognitoReauthCoordinatorFactory =
new IncognitoReauthCoordinatorFactory(mActivity, tabModelSelector,
Expand Down Expand Up @@ -1347,6 +1349,11 @@ public ScrimCoordinator getScrimCoordinatorForTesting() {
return mScrimCoordinator;
}

@VisibleForTesting
public IncognitoReauthController getIncognitoReauthControllerForTesting() {
return mIncognitoReauthController;
}

@VisibleForTesting
public void destroyActivityForTesting() {
// Actually destroying or finishing the activity hinders the shutdown process after
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.incognito.IncognitoDataTestUtils;
import org.chromium.chrome.browser.incognito.reauth.IncognitoReauthController;
import org.chromium.chrome.browser.incognito.reauth.IncognitoReauthManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.appmenu.AppMenuItemProperties;
import org.chromium.chrome.browser.ui.appmenu.AppMenuTestSupport;
Expand Down Expand Up @@ -513,4 +515,23 @@ public void ensureHiddenTabIsBlockedForIncognitoWithoutExtraInConnection() throw
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
connection.cleanUpSession(token);
}

/**
* Regression test for crbug.com/1325331.
*/
@Test
@MediumTest
@Features.EnableFeatures({ChromeFeatureList.INCOGNITO_REAUTHENTICATION_FOR_ANDROID,
ChromeFeatureList.CCT_INCOGNITO})
public void
testIncognitoReauthControllerCreated_WhenReauthFeatureIsEnabled() throws InterruptedException {
IncognitoReauthManager.setIsIncognitoReauthFeatureAvailableForTesting(true);
Intent intent = createMinimalIncognitoCustomTabIntent();
CustomTabActivity customTabActivity = launchIncognitoCustomTab(intent);

// Ensure that we did indeed create the re-auth controller.
IncognitoReauthController controller = customTabActivity.getRootUiCoordinatorForTesting()
.getIncognitoReauthControllerForTesting();
assertNotNull(controller);
}
}

0 comments on commit 34757d8

Please sign in to comment.