Commit 32410c4f authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][Incognito] Remove the dependency of account_picker in incognito

This CL removes the dependency of account_picker package in the package
incognito_interstial to facilitate the modularization of the incognito
interstitial package.

Bug: 1148718
Change-Id: I155fe25ba66611d201aabd3540e8b6559d6e86ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536441
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarRohit Agarwal <roagarwal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827734}
parent d6526dfd
......@@ -27,13 +27,15 @@ public class IncognitoInterstitialCoordinator {
* @param view The incognito interstitial view.
* @param incognitoInterstitialDelegate A delegate providing the functionality of the Incognito
* interstitial.
* @param onIncognitoTabOpened Runnable to be called when an incognito tab is opened.
*/
@MainThread
public IncognitoInterstitialCoordinator(
View view, IncognitoInterstitialDelegate incognitoInterstitialDelegate) {
public IncognitoInterstitialCoordinator(View view,
IncognitoInterstitialDelegate incognitoInterstitialDelegate,
Runnable onIncognitoTabOpened) {
IncognitoInterstitialViewBinder.setUpView(view);
IncognitoInterstitialMediator mediator =
new IncognitoInterstitialMediator(incognitoInterstitialDelegate);
IncognitoInterstitialMediator mediator = new IncognitoInterstitialMediator(
incognitoInterstitialDelegate, onIncognitoTabOpened);
PropertyModelChangeProcessor.create(
mediator.getModel(), view, IncognitoInterstitialViewBinder::bindView);
}
......
......@@ -12,8 +12,6 @@ import org.chromium.base.ThreadUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncher;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.account_picker.AccountConsistencyPromoAction;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerDelegate;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabCreator;
......@@ -68,8 +66,6 @@ public class IncognitoInterstitialDelegate {
@MainThread
public void openCurrentUrlInIncognitoTab() {
ThreadUtils.assertOnUiThread();
AccountPickerDelegate.recordAccountConsistencyPromoAction(
AccountConsistencyPromoAction.STARTED_INCOGNITO_SESSION);
Tab currentRegularTab = TabModelUtils.getCurrentTab(mRegularTabModel);
mIncognitoTabCreator.launchUrl(
currentRegularTab.getUrlString(), TabLaunchType.FROM_CHROME_UI);
......
......@@ -16,11 +16,14 @@ import org.chromium.ui.modelutil.PropertyModel;
class IncognitoInterstitialMediator {
private final PropertyModel mModel;
private final IncognitoInterstitialDelegate mIncognitoInterstitialDelegate;
private final Runnable mOnIncognitoTabOpened;
IncognitoInterstitialMediator(IncognitoInterstitialDelegate incognitoInterstitialDelegate) {
IncognitoInterstitialMediator(IncognitoInterstitialDelegate incognitoInterstitialDelegate,
Runnable onIncognitoTabOpened) {
mModel = IncognitoInterstitialProperties.createModel(
this::onLearnMoreClicked, this::onContinueClicked);
mIncognitoInterstitialDelegate = incognitoInterstitialDelegate;
mOnIncognitoTabOpened = onIncognitoTabOpened;
}
PropertyModel getModel() {
......@@ -40,6 +43,7 @@ class IncognitoInterstitialMediator {
*/
@MainThread
private void onContinueClicked() {
mOnIncognitoTabOpened.run();
mIncognitoInterstitialDelegate.openCurrentUrlInIncognitoTab();
}
}
......@@ -72,7 +72,10 @@ public class AccountPickerBottomSheetCoordinator {
/* showIncognitoRow= */ IncognitoUtils.isIncognitoModeEnabled());
IncognitoInterstitialCoordinator incognitoInterstitialCoordinator =
new IncognitoInterstitialCoordinator(
mView.getIncognitoInterstitialView(), incognitoInterstitialDelegate);
mView.getIncognitoInterstitialView(), incognitoInterstitialDelegate, () -> {
AccountPickerDelegate.recordAccountConsistencyPromoAction(
AccountConsistencyPromoAction.STARTED_INCOGNITO_SESSION);
});
mBottomSheetController = bottomSheetController;
PropertyModelChangeProcessor.create(mAccountPickerBottomSheetMediator.getModel(), mView,
AccountPickerBottomSheetViewBinder::bind);
......
......@@ -10,6 +10,7 @@ import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import android.support.test.rule.ActivityTestRule;
......@@ -42,6 +43,9 @@ public class IncognitoInterstitialTest {
@Mock
private IncognitoInterstitialDelegate mIncognitoInterstitialDelegateMock;
@Mock
private Runnable mOnIncognitoTabOpenedMock;
@Rule
public final ActivityTestRule<DummyUiActivity> mActivityTestRule =
new ActivityTestRule<>(DummyUiActivity.class);
......@@ -62,8 +66,8 @@ public class IncognitoInterstitialTest {
TestThreadUtils.runOnUiThreadBlocking(() -> {
View contentView = mActivityTestRule.getActivity().findViewById(android.R.id.content);
IncognitoInterstitialCoordinator incognitoInterstitialCoordinator =
new IncognitoInterstitialCoordinator(
contentView, mIncognitoInterstitialDelegateMock);
new IncognitoInterstitialCoordinator(contentView,
mIncognitoInterstitialDelegateMock, mOnIncognitoTabOpenedMock);
});
}
......@@ -79,12 +83,14 @@ public class IncognitoInterstitialTest {
public void testClickOnLearnMoreButton() {
onView(withId(R.id.incognito_interstitial_learn_more)).perform(click());
verify(mIncognitoInterstitialDelegateMock).openLearnMorePage();
verify(mOnIncognitoTabOpenedMock, never()).run();
}
@Test
@MediumTest
public void testClickOnContinueButton() {
onView(withId(R.id.incognito_interstitial_continue_button)).perform(click());
verify(mOnIncognitoTabOpenedMock).run();
verify(mIncognitoInterstitialDelegateMock).openCurrentUrlInIncognitoTab();
}
}
\ No newline at end of file
......@@ -560,10 +560,14 @@ public class AccountPickerBottomSheetTest {
@Test
@MediumTest
public void testContinueButtonOnIncognitoInterstitial() {
MetricsUtils.HistogramDelta accountConsistencyHistogram =
new HistogramDelta("Signin.AccountConsistencyPromoAction",
AccountConsistencyPromoAction.STARTED_INCOGNITO_SESSION);
buildAndShowExpandedBottomSheet();
onView(withText(R.string.signin_incognito_button)).perform(click());
onView(withId(R.id.incognito_interstitial_continue_button)).perform(click());
verify(mIncognitoInterstitialDelegateMock).openCurrentUrlInIncognitoTab();
Assert.assertEquals(1, accountConsistencyHistogram.getDelta());
}
private void checkIncognitoInterstitialSheet() {
......
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