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

[Test] Refactor BookmarkPersonalizedSigninPromoDismissTest

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

Bug: 1145843
Change-Id: Ia005508ccd84c439b04b25a65af0930b5a15ee0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2527021
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Reviewed-by: default avatarAlice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827278}
parent 2161388a
......@@ -30,11 +30,12 @@ import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.SigninPromoController;
import org.chromium.chrome.browser.sync.SyncTestRule;
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.BookmarkTestUtil;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/**
......@@ -43,25 +44,30 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class BookmarkPersonalizedSigninPromoDismissTest {
private final SyncTestRule mSyncTestRule = new SyncTestRule();
private final AccountManagerTestRule mAccountManagerTestRule = new AccountManagerTestRule();
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
// SyncTestRule.
// AccountManagerTestRule.
@Rule
public final RuleChain chain = RuleChain.outerRule(mSyncTestRule).around(mBookmarkTestRule);
public final RuleChain chain =
RuleChain.outerRule(mAccountManagerTestRule).around(mBookmarkTestRule);
@Before
public void setUp() throws Exception {
mActivityTestRule.startMainActivityOnBlankPage();
BookmarkPromoHeader.forcePromoStateForTests(null);
BookmarkPromoHeader.setPrefPersonalizedSigninPromoDeclinedForTests(false);
SigninPromoController.setSigninPromoImpressionsCountBookmarksForTests(0);
TestThreadUtils.runOnUiThreadBlocking(() -> {
BookmarkModel bookmarkModel = new BookmarkModel(Profile.fromWebContents(
mSyncTestRule.getActivity().getActivityTab().getWebContents()));
mActivityTestRule.getActivity().getActivityTab().getWebContents()));
bookmarkModel.loadFakePartnerBookmarkShimForTesting();
});
BookmarkTestUtil.waitForBookmarkModelLoaded();
......@@ -76,20 +82,19 @@ public class BookmarkPersonalizedSigninPromoDismissTest {
@Test
@MediumTest
public void testPromoNotShownAfterBeingDismissed() {
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_close_button)).perform(click());
onView(withId(R.id.signin_promo_view_container)).check(doesNotExist());
closeBookmarkManager();
mBookmarkTestRule.showBookmarkManager(mSyncTestRule.getActivity());
mBookmarkTestRule.showBookmarkManager(mActivityTestRule.getActivity());
onView(withId(R.id.signin_promo_view_container)).check(doesNotExist());
}
private void closeBookmarkManager() {
if (mSyncTestRule.getActivity().isTablet()) {
ChromeTabbedActivity chromeTabbedActivity =
(ChromeTabbedActivity) mSyncTestRule.getActivity();
if (mActivityTestRule.getActivity().isTablet()) {
ChromeTabbedActivity chromeTabbedActivity = mActivityTestRule.getActivity();
ChromeTabUtils.closeCurrentTab(
InstrumentationRegistry.getInstrumentation(), chromeTabbedActivity);
} else {
......@@ -102,7 +107,7 @@ public class BookmarkPersonalizedSigninPromoDismissTest {
public void testPromoNotExistWhenImpressionLimitReached() {
SigninPromoController.setSigninPromoImpressionsCountBookmarksForTests(
SigninPromoController.getMaxImpressionsBookmarksForTests());
mBookmarkTestRule.showBookmarkManager(mSyncTestRule.getActivity());
mBookmarkTestRule.showBookmarkManager(mActivityTestRule.getActivity());
onView(withId(R.id.signin_promo_view_container)).check(doesNotExist());
}
......@@ -110,7 +115,7 @@ public class BookmarkPersonalizedSigninPromoDismissTest {
@MediumTest
public void testPromoImpressionCountIncrementAfterDisplayingSigninPromo() {
assertEquals(0, SigninPromoController.getSigninPromoImpressionsCountBookmarks());
mBookmarkTestRule.showBookmarkManager(mSyncTestRule.getActivity());
mBookmarkTestRule.showBookmarkManager(mActivityTestRule.getActivity());
onView(withId(R.id.signin_promo_view_container)).check(matches(isDisplayed()));
assertEquals(1, SigninPromoController.getSigninPromoImpressionsCountBookmarks());
}
......
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