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; ...@@ -30,11 +30,12 @@ import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.SigninPromoController; 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.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.BookmarkTestUtil; import org.chromium.chrome.test.util.BookmarkTestUtil;
import org.chromium.chrome.test.util.ChromeTabUtils; 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; import org.chromium.content_public.browser.test.util.TestThreadUtils;
/** /**
...@@ -43,25 +44,30 @@ 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) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class BookmarkPersonalizedSigninPromoDismissTest { public class BookmarkPersonalizedSigninPromoDismissTest {
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);
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mActivityTestRule.startMainActivityOnBlankPage();
BookmarkPromoHeader.forcePromoStateForTests(null); BookmarkPromoHeader.forcePromoStateForTests(null);
BookmarkPromoHeader.setPrefPersonalizedSigninPromoDeclinedForTests(false); BookmarkPromoHeader.setPrefPersonalizedSigninPromoDeclinedForTests(false);
SigninPromoController.setSigninPromoImpressionsCountBookmarksForTests(0); SigninPromoController.setSigninPromoImpressionsCountBookmarksForTests(0);
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
BookmarkModel bookmarkModel = new BookmarkModel(Profile.fromWebContents( BookmarkModel bookmarkModel = new BookmarkModel(Profile.fromWebContents(
mSyncTestRule.getActivity().getActivityTab().getWebContents())); mActivityTestRule.getActivity().getActivityTab().getWebContents()));
bookmarkModel.loadFakePartnerBookmarkShimForTesting(); bookmarkModel.loadFakePartnerBookmarkShimForTesting();
}); });
BookmarkTestUtil.waitForBookmarkModelLoaded(); BookmarkTestUtil.waitForBookmarkModelLoaded();
...@@ -76,20 +82,19 @@ public class BookmarkPersonalizedSigninPromoDismissTest { ...@@ -76,20 +82,19 @@ public class BookmarkPersonalizedSigninPromoDismissTest {
@Test @Test
@MediumTest @MediumTest
public void testPromoNotShownAfterBeingDismissed() { 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_view_container)).check(matches(isDisplayed()));
onView(withId(R.id.signin_promo_close_button)).perform(click()); onView(withId(R.id.signin_promo_close_button)).perform(click());
onView(withId(R.id.signin_promo_view_container)).check(doesNotExist()); onView(withId(R.id.signin_promo_view_container)).check(doesNotExist());
closeBookmarkManager(); closeBookmarkManager();
mBookmarkTestRule.showBookmarkManager(mSyncTestRule.getActivity()); mBookmarkTestRule.showBookmarkManager(mActivityTestRule.getActivity());
onView(withId(R.id.signin_promo_view_container)).check(doesNotExist()); onView(withId(R.id.signin_promo_view_container)).check(doesNotExist());
} }
private void closeBookmarkManager() { private void closeBookmarkManager() {
if (mSyncTestRule.getActivity().isTablet()) { if (mActivityTestRule.getActivity().isTablet()) {
ChromeTabbedActivity chromeTabbedActivity = ChromeTabbedActivity chromeTabbedActivity = mActivityTestRule.getActivity();
(ChromeTabbedActivity) mSyncTestRule.getActivity();
ChromeTabUtils.closeCurrentTab( ChromeTabUtils.closeCurrentTab(
InstrumentationRegistry.getInstrumentation(), chromeTabbedActivity); InstrumentationRegistry.getInstrumentation(), chromeTabbedActivity);
} else { } else {
...@@ -102,7 +107,7 @@ public class BookmarkPersonalizedSigninPromoDismissTest { ...@@ -102,7 +107,7 @@ public class BookmarkPersonalizedSigninPromoDismissTest {
public void testPromoNotExistWhenImpressionLimitReached() { public void testPromoNotExistWhenImpressionLimitReached() {
SigninPromoController.setSigninPromoImpressionsCountBookmarksForTests( SigninPromoController.setSigninPromoImpressionsCountBookmarksForTests(
SigninPromoController.getMaxImpressionsBookmarksForTests()); SigninPromoController.getMaxImpressionsBookmarksForTests());
mBookmarkTestRule.showBookmarkManager(mSyncTestRule.getActivity()); mBookmarkTestRule.showBookmarkManager(mActivityTestRule.getActivity());
onView(withId(R.id.signin_promo_view_container)).check(doesNotExist()); onView(withId(R.id.signin_promo_view_container)).check(doesNotExist());
} }
...@@ -110,7 +115,7 @@ public class BookmarkPersonalizedSigninPromoDismissTest { ...@@ -110,7 +115,7 @@ public class BookmarkPersonalizedSigninPromoDismissTest {
@MediumTest @MediumTest
public void testPromoImpressionCountIncrementAfterDisplayingSigninPromo() { public void testPromoImpressionCountIncrementAfterDisplayingSigninPromo() {
assertEquals(0, SigninPromoController.getSigninPromoImpressionsCountBookmarks()); assertEquals(0, SigninPromoController.getSigninPromoImpressionsCountBookmarks());
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()));
assertEquals(1, SigninPromoController.getSigninPromoImpressionsCountBookmarks()); 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