Commit b083e7d3 authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Commit Bot

[Test] Refactor BookmarkPersonalizedSigninPromoTest

Refactor BookmarkPersonalizedSigninPromoTest to use
AccountManagerTestRule and ChromeActivityTestRule instead of
SyncTestRule so that it can be batched easily.

Bug: 1145843
Change-Id: I257fde4a0d726825f4cf0de199ce917ab1a6e765
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2529119Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827807}
parent 259f710b
...@@ -34,9 +34,10 @@ import org.chromium.base.test.util.CommandLineFlags; ...@@ -34,9 +34,10 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.signin.SigninActivityLauncherImpl; import org.chromium.chrome.browser.signin.SigninActivityLauncherImpl;
import org.chromium.chrome.browser.sync.SyncTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.BookmarkTestRule; import org.chromium.chrome.test.util.BookmarkTestRule;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.components.signin.base.CoreAccountInfo; import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.metrics.SigninAccessPoint; import org.chromium.components.signin.metrics.SigninAccessPoint;
...@@ -46,21 +47,27 @@ import org.chromium.components.signin.metrics.SigninAccessPoint; ...@@ -46,21 +47,27 @@ import org.chromium.components.signin.metrics.SigninAccessPoint;
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class BookmarkPersonalizedSigninPromoTest { public class BookmarkPersonalizedSigninPromoTest {
private final SyncTestRule mSyncTestRule = new SyncTestRule(); private final AccountManagerTestRule mAccountManagerTestRule = new AccountManagerTestRule();
private final BookmarkTestRule mBookmarkTestRule = new BookmarkTestRule(); private final BookmarkTestRule mBookmarkTestRule = new BookmarkTestRule();
// As bookmarks need the fake AccountManagerFacade in SyncTestRule, @Rule
public final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
// As bookmarks need the fake AccountManagerFacade in AccountManagerTestRule,
// BookmarkTestRule should be initialized after and destroyed before the // BookmarkTestRule should be initialized after and destroyed before the
// SyncTestRule. // AccountManagerTestRule.
@Rule @Rule
public final RuleChain chain = RuleChain.outerRule(mSyncTestRule).around(mBookmarkTestRule); public final RuleChain chain =
RuleChain.outerRule(mAccountManagerTestRule).around(mBookmarkTestRule);
private final SigninActivityLauncherImpl mMockSigninActivityLauncherImpl = private final SigninActivityLauncherImpl mMockSigninActivityLauncherImpl =
mock(SigninActivityLauncherImpl.class); mock(SigninActivityLauncherImpl.class);
@Before @Before
public void setUp() { public void setUp() {
mActivityTestRule.startMainActivityOnBlankPage();
BookmarkPromoHeader.forcePromoStateForTests( BookmarkPromoHeader.forcePromoStateForTests(
BookmarkPromoHeader.PromoState.PROMO_SIGNIN_PERSONALIZED); BookmarkPromoHeader.PromoState.PROMO_SIGNIN_PERSONALIZED);
SigninActivityLauncherImpl.setLauncherForTest(mMockSigninActivityLauncherImpl); SigninActivityLauncherImpl.setLauncherForTest(mMockSigninActivityLauncherImpl);
...@@ -78,7 +85,8 @@ public class BookmarkPersonalizedSigninPromoTest { ...@@ -78,7 +85,8 @@ public class BookmarkPersonalizedSigninPromoTest {
doNothing() doNothing()
.when(SigninActivityLauncherImpl.get()) .when(SigninActivityLauncherImpl.get())
.launchActivityForPromoDefaultFlow(any(Context.class), anyInt(), anyString()); .launchActivityForPromoDefaultFlow(any(Context.class), anyInt(), anyString());
CoreAccountInfo accountInfo = mSyncTestRule.addTestAccount(); CoreAccountInfo accountInfo =
mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
showBookmarkManagerAndCheckSigninPromoIsDisplayed(); showBookmarkManagerAndCheckSigninPromoIsDisplayed();
onView(withId(R.id.signin_promo_signin_button)).perform(click()); onView(withId(R.id.signin_promo_signin_button)).perform(click());
verify(mMockSigninActivityLauncherImpl) verify(mMockSigninActivityLauncherImpl)
...@@ -92,7 +100,8 @@ public class BookmarkPersonalizedSigninPromoTest { ...@@ -92,7 +100,8 @@ public class BookmarkPersonalizedSigninPromoTest {
doNothing() doNothing()
.when(SigninActivityLauncherImpl.get()) .when(SigninActivityLauncherImpl.get())
.launchActivityForPromoChooseAccountFlow(any(Context.class), anyInt(), anyString()); .launchActivityForPromoChooseAccountFlow(any(Context.class), anyInt(), anyString());
CoreAccountInfo accountInfo = mSyncTestRule.addTestAccount(); CoreAccountInfo accountInfo =
mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
showBookmarkManagerAndCheckSigninPromoIsDisplayed(); showBookmarkManagerAndCheckSigninPromoIsDisplayed();
onView(withId(R.id.signin_promo_choose_account_button)).perform(click()); onView(withId(R.id.signin_promo_choose_account_button)).perform(click());
verify(mMockSigninActivityLauncherImpl) verify(mMockSigninActivityLauncherImpl)
...@@ -114,7 +123,7 @@ public class BookmarkPersonalizedSigninPromoTest { ...@@ -114,7 +123,7 @@ public class BookmarkPersonalizedSigninPromoTest {
} }
private void showBookmarkManagerAndCheckSigninPromoIsDisplayed() { private void showBookmarkManagerAndCheckSigninPromoIsDisplayed() {
mBookmarkTestRule.showBookmarkManager(mSyncTestRule.getActivity()); mBookmarkTestRule.showBookmarkManager(mActivityTestRule.getActivity());
onView(withId(R.id.signin_promo_view_container)).check(matches(isDisplayed())); onView(withId(R.id.signin_promo_view_container)).check(matches(isDisplayed()));
} }
} }
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