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