Commit 987fb106 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Don't subclass ChromeActivityTestRule in SyncTestRule

Removes subclassing of ChromeActivityTestRule in SyncTestRule. This
subclassing meant that every test using SyncTestRule would start
ChromeActivity before starting the test. This was producing several
issues:
1. It's hard and confusing to use SyncTestRule in tests that start
  other activity types: FRE tests, bookmark tests, settings tests.
2. It makes tests longer.
3. It might make tests flaky.

Some tests need ChromeActivity to be started, so this CL adds a bunch of
explicit ChromeTabbedActivityTestRule fields along with calls to
startMainActivityOnBlankPage.

This CL also fixes and cleans up FirstRunTest. Tests will be enabled in
a separate CL (in case they're still flaky).

Bug: 616456, 1135990
Change-Id: I5a3d4a27f051cdfc4df2d4dc12a27899084b91db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450291
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818891}
parent 7123f634
...@@ -33,6 +33,7 @@ import org.chromium.chrome.browser.flags.ChromeSwitches; ...@@ -33,6 +33,7 @@ import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.infobar.InfoBarContainer; import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.sync.SyncTestRule; 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.components.browser_ui.modaldialog.AppModalPresenter; import org.chromium.components.browser_ui.modaldialog.AppModalPresenter;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.DOMUtils; import org.chromium.content_public.browser.test.util.DOMUtils;
...@@ -52,6 +53,10 @@ public class PasswordGenerationIntegrationTest { ...@@ -52,6 +53,10 @@ public class PasswordGenerationIntegrationTest {
@Rule @Rule
public SyncTestRule mSyncTestRule = new SyncTestRule(); public SyncTestRule mSyncTestRule = new SyncTestRule();
@Rule
public final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
private static final String PASSWORD_NODE_ID = "password_field"; private static final String PASSWORD_NODE_ID = "password_field";
private static final String PASSWORD_NODE_ID_MANUAL = "password_field_manual"; private static final String PASSWORD_NODE_ID_MANUAL = "password_field_manual";
private static final String SUBMIT_NODE_ID = "input_submit_button"; private static final String SUBMIT_NODE_ID = "input_submit_button";
...@@ -62,7 +67,7 @@ public class PasswordGenerationIntegrationTest { ...@@ -62,7 +67,7 @@ public class PasswordGenerationIntegrationTest {
private static final String ELIGIBLE_FOR_GENERATION = "1"; private static final String ELIGIBLE_FOR_GENERATION = "1";
private static final String INFOBAR_MESSAGE = "Password saved"; private static final String INFOBAR_MESSAGE = "Password saved";
private final ManualFillingTestHelper mHelper = new ManualFillingTestHelper(mSyncTestRule); private final ManualFillingTestHelper mHelper = new ManualFillingTestHelper(mActivityTestRule);
@Before @Before
public void setUp() throws InterruptedException { public void setUp() throws InterruptedException {
...@@ -191,7 +196,7 @@ public class PasswordGenerationIntegrationTest { ...@@ -191,7 +196,7 @@ public class PasswordGenerationIntegrationTest {
private void waitForGenerationDialog() { private void waitForGenerationDialog() {
waitForModalDialogPresenter(); waitForModalDialogPresenter();
ModalDialogManager manager = TestThreadUtils.runOnUiThreadBlockingNoException( ModalDialogManager manager = TestThreadUtils.runOnUiThreadBlockingNoException(
mSyncTestRule.getActivity()::getModalDialogManager); mActivityTestRule.getActivity()::getModalDialogManager);
Window window = ((AppModalPresenter) manager.getCurrentPresenterForTest()).getWindow(); Window window = ((AppModalPresenter) manager.getCurrentPresenterForTest()).getWindow();
mHelper.waitForViewOnRoot( mHelper.waitForViewOnRoot(
window.getDecorView().getRootView(), withId(password_generation_dialog)); window.getDecorView().getRootView(), withId(password_generation_dialog));
...@@ -199,7 +204,7 @@ public class PasswordGenerationIntegrationTest { ...@@ -199,7 +204,7 @@ public class PasswordGenerationIntegrationTest {
private void waitForModalDialogPresenter() { private void waitForModalDialogPresenter() {
CriteriaHelper.pollUiThread(() CriteriaHelper.pollUiThread(()
-> mSyncTestRule.getActivity() -> mActivityTestRule.getActivity()
.getModalDialogManager() .getModalDialogManager()
.getCurrentPresenterForTest() .getCurrentPresenterForTest()
!= null); != null);
...@@ -207,8 +212,9 @@ public class PasswordGenerationIntegrationTest { ...@@ -207,8 +212,9 @@ public class PasswordGenerationIntegrationTest {
private void assertNoInfobarsAreShown() { private void assertNoInfobarsAreShown() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertFalse(InfoBarContainer.from(mSyncTestRule.getActivity().getActivityTab()) Assert.assertFalse(
.hasInfoBars()); InfoBarContainer.from(mActivityTestRule.getActivity().getActivityTab())
.hasInfoBars());
}); });
} }
......
...@@ -32,6 +32,7 @@ import org.chromium.chrome.browser.profiles.Profile; ...@@ -32,6 +32,7 @@ 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.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;
...@@ -47,6 +48,10 @@ public class BookmarkPersonalizedSigninPromoDismissTest { ...@@ -47,6 +48,10 @@ public class BookmarkPersonalizedSigninPromoDismissTest {
private final BookmarkTestRule mBookmarkTestRule = new BookmarkTestRule(); private final BookmarkTestRule mBookmarkTestRule = new BookmarkTestRule();
@Rule
public final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
// As bookmarks need the fake AccountManagerFacade in SyncTestRule, // As bookmarks need the fake AccountManagerFacade in SyncTestRule,
// BookmarkTestRule should be initialized after and destroyed before the // BookmarkTestRule should be initialized after and destroyed before the
// SyncTestRule. // SyncTestRule.
...@@ -59,9 +64,10 @@ public class BookmarkPersonalizedSigninPromoDismissTest { ...@@ -59,9 +64,10 @@ public class BookmarkPersonalizedSigninPromoDismissTest {
BookmarkPromoHeader.setPrefPersonalizedSigninPromoDeclinedForTests(false); BookmarkPromoHeader.setPrefPersonalizedSigninPromoDeclinedForTests(false);
SigninPromoController.setSigninPromoImpressionsCountBookmarksForTests(0); SigninPromoController.setSigninPromoImpressionsCountBookmarksForTests(0);
mActivityTestRule.startMainActivityOnBlankPage();
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,20 @@ public class BookmarkPersonalizedSigninPromoDismissTest { ...@@ -76,20 +82,20 @@ 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 =
(ChromeTabbedActivity) mSyncTestRule.getActivity(); (ChromeTabbedActivity) mActivityTestRule.getActivity();
ChromeTabUtils.closeCurrentTab( ChromeTabUtils.closeCurrentTab(
InstrumentationRegistry.getInstrumentation(), chromeTabbedActivity); InstrumentationRegistry.getInstrumentation(), chromeTabbedActivity);
} else { } else {
...@@ -102,7 +108,7 @@ public class BookmarkPersonalizedSigninPromoDismissTest { ...@@ -102,7 +108,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 +116,7 @@ public class BookmarkPersonalizedSigninPromoDismissTest { ...@@ -110,7 +116,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());
} }
......
...@@ -37,6 +37,7 @@ import org.chromium.chrome.browser.flags.ChromeSwitches; ...@@ -37,6 +37,7 @@ 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.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.components.signin.metrics.SigninAccessPoint; import org.chromium.components.signin.metrics.SigninAccessPoint;
...@@ -50,6 +51,10 @@ public class BookmarkPersonalizedSigninPromoTest { ...@@ -50,6 +51,10 @@ public class BookmarkPersonalizedSigninPromoTest {
private final BookmarkTestRule mBookmarkTestRule = new BookmarkTestRule(); private final BookmarkTestRule mBookmarkTestRule = new BookmarkTestRule();
@Rule
public final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
// As bookmarks need the fake AccountManagerFacade in SyncTestRule, // As bookmarks need the fake AccountManagerFacade in SyncTestRule,
// BookmarkTestRule should be initialized after and destroyed before the // BookmarkTestRule should be initialized after and destroyed before the
// SyncTestRule. // SyncTestRule.
...@@ -64,6 +69,7 @@ public class BookmarkPersonalizedSigninPromoTest { ...@@ -64,6 +69,7 @@ public class BookmarkPersonalizedSigninPromoTest {
BookmarkPromoHeader.forcePromoStateForTests( BookmarkPromoHeader.forcePromoStateForTests(
BookmarkPromoHeader.PromoState.PROMO_SIGNIN_PERSONALIZED); BookmarkPromoHeader.PromoState.PROMO_SIGNIN_PERSONALIZED);
SigninActivityLauncherImpl.setLauncherForTest(mMockSigninActivityLauncherImpl); SigninActivityLauncherImpl.setLauncherForTest(mMockSigninActivityLauncherImpl);
mActivityTestRule.startMainActivityOnBlankPage();
} }
@After @After
...@@ -114,7 +120,7 @@ public class BookmarkPersonalizedSigninPromoTest { ...@@ -114,7 +120,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()));
} }
} }
...@@ -22,6 +22,7 @@ import org.chromium.chrome.browser.sync.SyncTestRule; ...@@ -22,6 +22,7 @@ import org.chromium.chrome.browser.sync.SyncTestRule;
import org.chromium.chrome.browser.sync.settings.SyncSettingsUtils; import org.chromium.chrome.browser.sync.settings.SyncSettingsUtils;
import org.chromium.chrome.browser.sync.settings.SyncSettingsUtils.SyncError; import org.chromium.chrome.browser.sync.settings.SyncSettingsUtils.SyncError;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeRenderTestRule; import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.InfoBarUtil; import org.chromium.chrome.test.util.InfoBarUtil;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
...@@ -48,6 +49,10 @@ import java.io.IOException; ...@@ -48,6 +49,10 @@ import java.io.IOException;
} }
}; };
@Rule
public final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule @Rule
public final ChromeRenderTestRule mRenderTestRule = public final ChromeRenderTestRule mRenderTestRule =
ChromeRenderTestRule.Builder.withPublicCorpus().build(); ChromeRenderTestRule.Builder.withPublicCorpus().build();
...@@ -56,58 +61,58 @@ import java.io.IOException; ...@@ -56,58 +61,58 @@ import java.io.IOException;
public void setUp() { public void setUp() {
deleteSyncErrorInfoBarShowTimePref(); deleteSyncErrorInfoBarShowTimePref();
mFakeProfileSyncService = (FakeProfileSyncService) mSyncTestRule.getProfileSyncService(); mFakeProfileSyncService = (FakeProfileSyncService) mSyncTestRule.getProfileSyncService();
mSyncTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
} }
@Test @Test
@LargeTest @LargeTest
public void testSyncErrorInfoBarShownForAuthError() throws Exception { public void testSyncErrorInfoBarShownForAuthError() throws Exception {
Assert.assertEquals("InfoBar should not be shown before signing in", 0, Assert.assertEquals("InfoBar should not be shown before signing in", 0,
mSyncTestRule.getInfoBars().size()); mActivityTestRule.getInfoBars().size());
showSyncErrorInfoBarForAuthError(); showSyncErrorInfoBarForAuthError();
Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size()); Assert.assertEquals("InfoBar should be shown", 1, mActivityTestRule.getInfoBars().size());
// Resolving the error should not show the infobar again. // Resolving the error should not show the infobar again.
deleteSyncErrorInfoBarShowTimePref(); deleteSyncErrorInfoBarShowTimePref();
mFakeProfileSyncService.setAuthError(GoogleServiceAuthError.State.NONE); mFakeProfileSyncService.setAuthError(GoogleServiceAuthError.State.NONE);
InfoBarUtil.waitUntilNoInfoBarsExist(mSyncTestRule.getInfoBars()); InfoBarUtil.waitUntilNoInfoBarsExist(mActivityTestRule.getInfoBars());
} }
@Test @Test
@LargeTest @LargeTest
public void testSyncErrorInfoBarShownForSyncSetupIncomplete() { public void testSyncErrorInfoBarShownForSyncSetupIncomplete() {
Assert.assertEquals("InfoBar should not be shown before signing in", 0, Assert.assertEquals("InfoBar should not be shown before signing in", 0,
mSyncTestRule.getInfoBars().size()); mActivityTestRule.getInfoBars().size());
showSyncErrorInfoBarForSyncSetupIncomplete(); showSyncErrorInfoBarForSyncSetupIncomplete();
Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size()); Assert.assertEquals("InfoBar should be shown", 1, mActivityTestRule.getInfoBars().size());
// Resolving the error should not show the infobar again. // Resolving the error should not show the infobar again.
deleteSyncErrorInfoBarShowTimePref(); deleteSyncErrorInfoBarShowTimePref();
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
mFakeProfileSyncService.setFirstSetupComplete(SyncFirstSetupCompleteSource.BASIC_FLOW); mFakeProfileSyncService.setFirstSetupComplete(SyncFirstSetupCompleteSource.BASIC_FLOW);
}); });
InfoBarUtil.waitUntilNoInfoBarsExist(mSyncTestRule.getInfoBars()); InfoBarUtil.waitUntilNoInfoBarsExist(mActivityTestRule.getInfoBars());
} }
@Test @Test
@LargeTest @LargeTest
public void testSyncErrorInfoBarShownForPassphraseRequired() { public void testSyncErrorInfoBarShownForPassphraseRequired() {
Assert.assertEquals("InfoBar should not be shown before signing in", 0, Assert.assertEquals("InfoBar should not be shown before signing in", 0,
mSyncTestRule.getInfoBars().size()); mActivityTestRule.getInfoBars().size());
showSyncErrorInfoBarForPassphraseRequired(); showSyncErrorInfoBarForPassphraseRequired();
Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size()); Assert.assertEquals("InfoBar should be shown", 1, mActivityTestRule.getInfoBars().size());
// Resolving the error should not show the infobar again. // Resolving the error should not show the infobar again.
deleteSyncErrorInfoBarShowTimePref(); deleteSyncErrorInfoBarShowTimePref();
mFakeProfileSyncService.setPassphraseRequiredForPreferredDataTypes(false); mFakeProfileSyncService.setPassphraseRequiredForPreferredDataTypes(false);
InfoBarUtil.waitUntilNoInfoBarsExist(mSyncTestRule.getInfoBars()); InfoBarUtil.waitUntilNoInfoBarsExist(mActivityTestRule.getInfoBars());
} }
@Test @Test
@LargeTest @LargeTest
public void testSyncErrorInfoBarNotShownWhenNoError() { public void testSyncErrorInfoBarNotShownWhenNoError() {
Assert.assertEquals("InfoBar should not be shown before signing in", 0, Assert.assertEquals("InfoBar should not be shown before signing in", 0,
mSyncTestRule.getInfoBars().size()); mActivityTestRule.getInfoBars().size());
mSyncTestRule.setUpAccountAndEnableSyncForTesting(); mSyncTestRule.setUpAccountAndEnableSyncForTesting();
SyncTestUtil.waitForSyncActive(); SyncTestUtil.waitForSyncActive();
mFakeProfileSyncService.setEngineInitialized(true); mFakeProfileSyncService.setEngineInitialized(true);
...@@ -125,7 +130,7 @@ import java.io.IOException; ...@@ -125,7 +130,7 @@ import java.io.IOException;
Assert.assertTrue(syncError != SyncError.SYNC_SETUP_INCOMPLETE); Assert.assertTrue(syncError != SyncError.SYNC_SETUP_INCOMPLETE);
Assert.assertEquals("InfoBar should not be shown when there is no error", 0, Assert.assertEquals("InfoBar should not be shown when there is no error", 0,
mSyncTestRule.getInfoBars().size()); mActivityTestRule.getInfoBars().size());
} }
@Test @Test
...@@ -133,14 +138,14 @@ import java.io.IOException; ...@@ -133,14 +138,14 @@ import java.io.IOException;
public void testSyncErrorInfoBarIsNotShownBeforeMinimalIntervalPassed() { public void testSyncErrorInfoBarIsNotShownBeforeMinimalIntervalPassed() {
// Initiate auth error to show the infobar. // Initiate auth error to show the infobar.
Assert.assertEquals("InfoBar should not be shown before signing in", 0, Assert.assertEquals("InfoBar should not be shown before signing in", 0,
mSyncTestRule.getInfoBars().size()); mActivityTestRule.getInfoBars().size());
showSyncErrorInfoBarForAuthError(); showSyncErrorInfoBarForAuthError();
Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size()); Assert.assertEquals("InfoBar should be shown", 1, mActivityTestRule.getInfoBars().size());
// Create another new tab. // Create another new tab.
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL); mActivityTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
Assert.assertEquals("InfoBar should not be shown again before minimum interval passed", 0, Assert.assertEquals("InfoBar should not be shown again before minimum interval passed", 0,
mSyncTestRule.getInfoBars().size()); mActivityTestRule.getInfoBars().size());
// Override the time of last seen infobar to minimum required time before current time. // Override the time of last seen infobar to minimum required time before current time.
ContextUtils.getAppSharedPreferences() ContextUtils.getAppSharedPreferences()
...@@ -149,9 +154,9 @@ import java.io.IOException; ...@@ -149,9 +154,9 @@ import java.io.IOException;
System.currentTimeMillis() System.currentTimeMillis()
- SyncErrorInfoBar.MINIMAL_DURATION_BETWEEN_INFOBARS_MS) - SyncErrorInfoBar.MINIMAL_DURATION_BETWEEN_INFOBARS_MS)
.apply(); .apply();
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL); mActivityTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
Assert.assertEquals("InfoBar should be shown again after minimum interval passed", 1, Assert.assertEquals("InfoBar should be shown again after minimum interval passed", 1,
mSyncTestRule.getInfoBars().size()); mActivityTestRule.getInfoBars().size());
} }
@Test @Test
...@@ -159,7 +164,7 @@ import java.io.IOException; ...@@ -159,7 +164,7 @@ import java.io.IOException;
@Feature("RenderTest") @Feature("RenderTest")
public void testSyncErrorInfoBarForAuthErrorView() throws IOException { public void testSyncErrorInfoBarForAuthErrorView() throws IOException {
showSyncErrorInfoBarForAuthError(); showSyncErrorInfoBarForAuthError();
mRenderTestRule.render(mSyncTestRule.getInfoBarContainer().getContainerViewForTesting(), mRenderTestRule.render(mActivityTestRule.getInfoBarContainer().getContainerViewForTesting(),
"sync_error_infobar_auth_error"); "sync_error_infobar_auth_error");
} }
...@@ -168,7 +173,7 @@ import java.io.IOException; ...@@ -168,7 +173,7 @@ import java.io.IOException;
@Feature("RenderTest") @Feature("RenderTest")
public void testSyncErrorInfoBarForSyncSetupIncompleteView() throws IOException { public void testSyncErrorInfoBarForSyncSetupIncompleteView() throws IOException {
showSyncErrorInfoBarForSyncSetupIncomplete(); showSyncErrorInfoBarForSyncSetupIncomplete();
mRenderTestRule.render(mSyncTestRule.getInfoBarContainer().getContainerViewForTesting(), mRenderTestRule.render(mActivityTestRule.getInfoBarContainer().getContainerViewForTesting(),
"sync_error_infobar_sync_setup_incomplete"); "sync_error_infobar_sync_setup_incomplete");
} }
...@@ -177,26 +182,26 @@ import java.io.IOException; ...@@ -177,26 +182,26 @@ import java.io.IOException;
@Feature("RenderTest") @Feature("RenderTest")
public void testSyncErrorInfoBarForPassphraseRequiredView() throws IOException { public void testSyncErrorInfoBarForPassphraseRequiredView() throws IOException {
showSyncErrorInfoBarForPassphraseRequired(); showSyncErrorInfoBarForPassphraseRequired();
mRenderTestRule.render(mSyncTestRule.getInfoBarContainer().getContainerViewForTesting(), mRenderTestRule.render(mActivityTestRule.getInfoBarContainer().getContainerViewForTesting(),
"sync_error_infobar_passphrase_required"); "sync_error_infobar_passphrase_required");
} }
private void showSyncErrorInfoBarForAuthError() { private void showSyncErrorInfoBarForAuthError() {
mSyncTestRule.setUpAccountAndEnableSyncForTesting(); mSyncTestRule.setUpAccountAndEnableSyncForTesting();
mFakeProfileSyncService.setAuthError(GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS); mFakeProfileSyncService.setAuthError(GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS);
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL); mActivityTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
} }
private void showSyncErrorInfoBarForPassphraseRequired() { private void showSyncErrorInfoBarForPassphraseRequired() {
mSyncTestRule.setUpAccountAndEnableSyncForTesting(); mSyncTestRule.setUpAccountAndEnableSyncForTesting();
mFakeProfileSyncService.setEngineInitialized(true); mFakeProfileSyncService.setEngineInitialized(true);
mFakeProfileSyncService.setPassphraseRequiredForPreferredDataTypes(true); mFakeProfileSyncService.setPassphraseRequiredForPreferredDataTypes(true);
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL); mActivityTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
} }
private void showSyncErrorInfoBarForSyncSetupIncomplete() { private void showSyncErrorInfoBarForSyncSetupIncomplete() {
mSyncTestRule.setUpTestAccountAndSignInWithSyncSetupAsIncomplete(); mSyncTestRule.setUpTestAccountAndSignInWithSyncSetupAsIncomplete();
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL); mActivityTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
} }
private void deleteSyncErrorInfoBarShowTimePref() { private void deleteSyncErrorInfoBarShowTimePref() {
......
...@@ -28,6 +28,7 @@ import androidx.test.filters.MediumTest; ...@@ -28,6 +28,7 @@ import androidx.test.filters.MediumTest;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -41,6 +42,7 @@ import org.chromium.chrome.browser.profiles.Profile; ...@@ -41,6 +42,7 @@ import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.sync.ProfileSyncService; import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.SyncTestRule; 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.ActivityUtils; import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.ApplicationTestUtils; import org.chromium.chrome.test.util.ApplicationTestUtils;
import org.chromium.chrome.test.util.ChromeRenderTestRule; import org.chromium.chrome.test.util.ChromeRenderTestRule;
...@@ -64,12 +66,21 @@ public class SigninFragmentTest { ...@@ -64,12 +66,21 @@ public class SigninFragmentTest {
@Rule @Rule
public final SyncTestRule mSyncTestRule = new SyncTestRule(); public final SyncTestRule mSyncTestRule = new SyncTestRule();
@Rule
public final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule @Rule
public final ChromeRenderTestRule mRenderTestRule = public final ChromeRenderTestRule mRenderTestRule =
ChromeRenderTestRule.Builder.withPublicCorpus().build(); ChromeRenderTestRule.Builder.withPublicCorpus().build();
private SigninActivity mSigninActivity; private SigninActivity mSigninActivity;
@Before
public void setUp() {
mActivityTestRule.startMainActivityOnBlankPage();
}
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
// Since SigninActivity is launched inside this test class, we need to // Since SigninActivity is launched inside this test class, we need to
...@@ -86,7 +97,7 @@ public class SigninFragmentTest { ...@@ -86,7 +97,7 @@ public class SigninFragmentTest {
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoAddAccountFlow( SigninActivityLauncherImpl.get().launchActivityForPromoAddAccountFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER); mActivityTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER);
}); });
mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container), mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container),
"signin_fragment_new_account"); "signin_fragment_new_account");
...@@ -101,7 +112,7 @@ public class SigninFragmentTest { ...@@ -101,7 +112,7 @@ public class SigninFragmentTest {
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoChooseAccountFlow( SigninActivityLauncherImpl.get().launchActivityForPromoChooseAccountFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER, mActivityTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER,
account.name); account.name);
}); });
mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container), mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container),
...@@ -118,7 +129,7 @@ public class SigninFragmentTest { ...@@ -118,7 +129,7 @@ public class SigninFragmentTest {
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoChooseAccountFlow( SigninActivityLauncherImpl.get().launchActivityForPromoChooseAccountFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER, mActivityTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER,
secondAccountName); secondAccountName);
}); });
mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container), mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container),
...@@ -133,7 +144,7 @@ public class SigninFragmentTest { ...@@ -133,7 +144,7 @@ public class SigninFragmentTest {
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow( SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER, mActivityTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER,
account.name); account.name);
}); });
mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container), mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container),
...@@ -147,7 +158,8 @@ public class SigninFragmentTest { ...@@ -147,7 +158,8 @@ public class SigninFragmentTest {
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow( SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.SETTINGS, account.name); mActivityTestRule.getActivity(), SigninAccessPoint.SETTINGS,
account.name);
}); });
onView(withText(account.name)).check(matches(isDisplayed())); onView(withText(account.name)).check(matches(isDisplayed()));
onView(withId(R.id.signin_details_description)).perform(clickOnClickableSpan()); onView(withId(R.id.signin_details_description)).perform(clickOnClickableSpan());
...@@ -171,7 +183,7 @@ public class SigninFragmentTest { ...@@ -171,7 +183,7 @@ public class SigninFragmentTest {
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivity( SigninActivityLauncherImpl.get().launchActivity(
mSyncTestRule.getActivity(), SigninAccessPoint.SETTINGS); mActivityTestRule.getActivity(), SigninAccessPoint.SETTINGS);
}); });
onView(withId(R.id.positive_button)).check(matches(withText(R.string.signin_add_account))); onView(withId(R.id.positive_button)).check(matches(withText(R.string.signin_add_account)));
onView(withId(R.id.negative_button)).check(matches(withText(R.string.cancel))); onView(withId(R.id.negative_button)).check(matches(withText(R.string.cancel)));
...@@ -186,7 +198,7 @@ public class SigninFragmentTest { ...@@ -186,7 +198,7 @@ public class SigninFragmentTest {
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow( SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER, mActivityTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER,
defaultAccount.name); defaultAccount.name);
}); });
onView(withText(defaultAccount.name)).check(matches(isDisplayed())).perform(click()); onView(withText(defaultAccount.name)).check(matches(isDisplayed())).perform(click());
......
...@@ -5,15 +5,13 @@ ...@@ -5,15 +5,13 @@
package org.chromium.chrome.browser.sync; package org.chromium.chrome.browser.sync;
import android.accounts.Account; import android.accounts.Account;
import android.app.Activity; import android.content.ComponentName;
import android.app.Instrumentation;
import android.app.Instrumentation.ActivityMonitor;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest; import androidx.test.filters.LargeTest;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
...@@ -26,14 +24,15 @@ import org.chromium.base.CommandLine; ...@@ -26,14 +24,15 @@ import org.chromium.base.CommandLine;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.FlakyTest; import org.chromium.chrome.browser.SyncFirstSetupCompleteSource;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.firstrun.FirstRunActivity; import org.chromium.chrome.browser.firstrun.FirstRunActivity;
import org.chromium.chrome.browser.firstrun.FirstRunActivity.FirstRunActivityObserver; import org.chromium.chrome.browser.firstrun.FirstRunActivity.FirstRunActivityObserver;
import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer;
import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.settings.SettingsActivity; import org.chromium.chrome.browser.settings.SettingsActivity;
import org.chromium.chrome.browser.sync.settings.AccountManagementFragment; import org.chromium.chrome.browser.sync.settings.SyncAndServicesSettings;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ActivityUtils; import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
...@@ -48,51 +47,7 @@ import java.util.concurrent.TimeoutException; ...@@ -48,51 +47,7 @@ import java.util.concurrent.TimeoutException;
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
public class FirstRunTest { public class FirstRunTest {
@Rule @Rule
public SyncTestRule mSyncTestRule = new SyncTestRule() { public SyncTestRule mSyncTestRule = new SyncTestRule();
@Override
public void startMainActivityForSyncTest() {
FirstRunActivity.setObserverForTest(mTestObserver);
// Starts up and waits for the FirstRunActivity to be ready.
// This isn't exactly what startMainActivity is supposed to be doing, but short of a
// refactoring of SyncTestBase to use something other than ChromeTabbedActivity,
// it's the only way to reuse the rest of the setup and initialization code inside of
// it.
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
final Context context = instrumentation.getTargetContext();
// Create an Intent that causes Chrome to run.
final Intent intent = new Intent(TEST_ACTION);
intent.setPackage(context.getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Start the FRE.
final ActivityMonitor freMonitor =
new ActivityMonitor(FirstRunActivity.class.getName(), null, false);
instrumentation.addMonitor(freMonitor);
TestThreadUtils.runOnUiThreadBlocking(() -> {
FirstRunFlowSequencer.launch(context, intent, false /* requiresBroadcast */,
false /* preferLightweightFre */);
});
// Wait for the FRE to be ready to use.
Activity activity =
freMonitor.waitForActivityWithTimeout(CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
instrumentation.removeMonitor(freMonitor);
mActivity = (FirstRunActivity) activity;
try {
mTestObserver.flowIsKnownCallback.waitForCallback(0);
} catch (TimeoutException e) {
Assert.fail();
}
CriteriaHelper.pollUiThread((() -> mActivity.isNativeSideIsInitializedForTest()),
"native never initialized.");
}
};
private static final String TEST_ACTION = "com.artificial.package.TEST_ACTION";
private static final class TestObserver implements FirstRunActivityObserver { private static final class TestObserver implements FirstRunActivityObserver {
public final CallbackHelper flowIsKnownCallback = new CallbackHelper(); public final CallbackHelper flowIsKnownCallback = new CallbackHelper();
...@@ -125,6 +80,29 @@ public class FirstRunTest { ...@@ -125,6 +80,29 @@ public class FirstRunTest {
public void setUp() { public void setUp() {
Assert.assertFalse( Assert.assertFalse(
CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)); CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE));
FirstRunActivity.setObserverForTest(mTestObserver);
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setPackage(context.getPackageName());
intent.setComponent(new ComponentName(context, ChromeLauncherActivity.class));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Runnable activityTrigger = () -> TestThreadUtils.runOnUiThreadBlocking(() -> {
FirstRunFlowSequencer.launch(context, intent, false /* requiresBroadcast */,
false /* preferLightweightFre */);
});
mActivity = ActivityUtils.waitForActivity(InstrumentationRegistry.getInstrumentation(),
FirstRunActivity.class, activityTrigger);
try {
mTestObserver.flowIsKnownCallback.waitForCallback(0);
} catch (TimeoutException e) {
Assert.fail();
}
CriteriaHelper.pollUiThread(
(() -> mActivity.isNativeSideIsInitializedForTest()), "native never initialized.");
} }
@After @After
...@@ -133,12 +111,10 @@ public class FirstRunTest { ...@@ -133,12 +111,10 @@ public class FirstRunTest {
} }
// Test that signing in through FirstRun signs in and starts sync. // Test that signing in through FirstRun signs in and starts sync.
/*
* @SmallTest
* @Feature({"Sync"})
*/
@Test @Test
@FlakyTest(message = "https://crbug.com/616456") @LargeTest
@Feature({"Sync"})
@DisabledTest(message = "https://crbug.com/616456")
public void testSignIn() { public void testSignIn() {
Account testAccount = mSyncTestRule.addTestAccount(); Account testAccount = mSyncTestRule.addTestAccount();
Assert.assertNull(mSyncTestRule.getCurrentSignedInAccount()); Assert.assertNull(mSyncTestRule.getCurrentSignedInAccount());
...@@ -151,12 +127,10 @@ public class FirstRunTest { ...@@ -151,12 +127,10 @@ public class FirstRunTest {
// Test that signing in and opening settings through FirstRun signs in and doesn't fully start // Test that signing in and opening settings through FirstRun signs in and doesn't fully start
// sync until the settings page is closed. // sync until the settings page is closed.
/*
* @SmallTest
* @Feature({"Sync"})
*/
@Test @Test
@FlakyTest(message = "https://crbug.com/616456") @LargeTest
@Feature({"Sync"})
@DisabledTest(message = "https://crbug.com/616456")
public void testSignInWithOpenSettings() { public void testSignInWithOpenSettings() {
final Account testAccount = mSyncTestRule.addTestAccount(); final Account testAccount = mSyncTestRule.addTestAccount();
final SettingsActivity settingsActivity = final SettingsActivity settingsActivity =
...@@ -169,20 +143,27 @@ public class FirstRunTest { ...@@ -169,20 +143,27 @@ public class FirstRunTest {
Assert.assertFalse(SyncTestUtil.isSyncActive()); Assert.assertFalse(SyncTestUtil.isSyncActive());
// Close the settings fragment. // Close the settings fragment.
AccountManagementFragment fragment = SyncAndServicesSettings fragment =
(AccountManagementFragment) settingsActivity.getMainFragment(); (SyncAndServicesSettings) settingsActivity.getMainFragment();
Assert.assertNotNull(fragment); Assert.assertNotNull(fragment);
settingsActivity.getSupportFragmentManager().beginTransaction().remove(fragment).commit(); settingsActivity.getSupportFragmentManager().beginTransaction().remove(fragment).commit();
// Sync should immediately become active. TestThreadUtils.runOnUiThreadBlocking(() -> {
// First setup should not be marked as complete just by closing the fragment.
Assert.assertFalse(mSyncTestRule.getProfileSyncService().isFirstSetupComplete());
// Marking the first setup as complete should make sync active.
mSyncTestRule.getProfileSyncService().setFirstSetupComplete(
SyncFirstSetupCompleteSource.BASIC_FLOW);
});
Assert.assertTrue(SyncTestUtil.isSyncActive()); Assert.assertTrue(SyncTestUtil.isSyncActive());
} }
// Test that not signing in through FirstRun does not sign in sync. // Test that not signing in through FirstRun does not sign in sync.
@Test @Test
@SmallTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
@DisabledTest // https://crbug.com/901488 @DisabledTest(message = "https://crbug.com/616456")
public void testNoSignIn() { public void testNoSignIn() {
mSyncTestRule.addTestAccount(); mSyncTestRule.addTestAccount();
Assert.assertFalse(SyncTestUtil.isSyncRequested()); Assert.assertFalse(SyncTestUtil.isSyncRequested());
......
...@@ -24,6 +24,7 @@ import org.chromium.chrome.browser.flags.ChromeSwitches; ...@@ -24,6 +24,7 @@ import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelUtils; import org.chromium.chrome.browser.tabmodel.TabModelUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.sync.protocol.EntitySpecifics; import org.chromium.components.sync.protocol.EntitySpecifics;
import org.chromium.components.sync.protocol.SessionHeader; import org.chromium.components.sync.protocol.SessionHeader;
...@@ -51,6 +52,10 @@ public class OpenTabsTest { ...@@ -51,6 +52,10 @@ public class OpenTabsTest {
@Rule @Rule
public SyncTestRule mSyncTestRule = new SyncTestRule(); public SyncTestRule mSyncTestRule = new SyncTestRule();
@Rule
public final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
private static final String TAG = "OpenTabsTest"; private static final String TAG = "OpenTabsTest";
private static final String OPEN_TABS_TYPE = "Sessions"; private static final String OPEN_TABS_TYPE = "Sessions";
...@@ -96,6 +101,8 @@ public class OpenTabsTest { ...@@ -96,6 +101,8 @@ public class OpenTabsTest {
mSyncTestRule.setUpAccountAndEnableSyncForTesting(); mSyncTestRule.setUpAccountAndEnableSyncForTesting();
mClientName = getClientName(); mClientName = getClientName();
mSessionTagCounter = 0; mSessionTagCounter = 0;
mActivityTestRule.startMainActivityOnBlankPage();
} }
// Test syncing an open tab from client to server. // Test syncing an open tab from client to server.
...@@ -103,7 +110,7 @@ public class OpenTabsTest { ...@@ -103,7 +110,7 @@ public class OpenTabsTest {
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testUploadOpenTab() { public void testUploadOpenTab() {
mSyncTestRule.loadUrl(URL); mActivityTestRule.loadUrl(URL);
waitForLocalTabsForClient(mClientName, URL); waitForLocalTabsForClient(mClientName, URL);
waitForServerTabs(URL); waitForServerTabs(URL);
} }
...@@ -113,9 +120,9 @@ public class OpenTabsTest { ...@@ -113,9 +120,9 @@ public class OpenTabsTest {
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testUploadMultipleOpenTabs() { public void testUploadMultipleOpenTabs() {
mSyncTestRule.loadUrl(URL); mActivityTestRule.loadUrl(URL);
mSyncTestRule.loadUrlInNewTab(URL2); mActivityTestRule.loadUrlInNewTab(URL2);
mSyncTestRule.loadUrlInNewTab(URL3); mActivityTestRule.loadUrlInNewTab(URL3);
waitForLocalTabsForClient(mClientName, URL, URL2, URL3); waitForLocalTabsForClient(mClientName, URL, URL2, URL3);
waitForServerTabs(URL, URL2, URL3); waitForServerTabs(URL, URL2, URL3);
} }
...@@ -125,14 +132,14 @@ public class OpenTabsTest { ...@@ -125,14 +132,14 @@ public class OpenTabsTest {
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testUploadAndCloseOpenTab() { public void testUploadAndCloseOpenTab() {
mSyncTestRule.loadUrl(URL); mActivityTestRule.loadUrl(URL);
// Can't have zero tabs, so we have to open two to test closing one. // Can't have zero tabs, so we have to open two to test closing one.
mSyncTestRule.loadUrlInNewTab(URL2); mActivityTestRule.loadUrlInNewTab(URL2);
waitForLocalTabsForClient(mClientName, URL, URL2); waitForLocalTabsForClient(mClientName, URL, URL2);
waitForServerTabs(URL, URL2); waitForServerTabs(URL, URL2);
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
TabModelSelector selector = mSyncTestRule.getActivity().getTabModelSelector(); TabModelSelector selector = mActivityTestRule.getActivity().getTabModelSelector();
Assert.assertTrue(TabModelUtils.closeCurrentTab(selector.getCurrentModel())); Assert.assertTrue(TabModelUtils.closeCurrentTab(selector.getCurrentModel()));
}); });
......
...@@ -16,19 +16,17 @@ import androidx.annotation.Nullable; ...@@ -16,19 +16,17 @@ import androidx.annotation.Nullable;
import androidx.preference.TwoStatePreference; import androidx.preference.TwoStatePreference;
import org.junit.Assert; import org.junit.Assert;
import org.junit.rules.TestRule;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import org.chromium.base.Promise; import org.chromium.base.Promise;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.autofill.PersonalDataManager; import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.init.ProcessInitializationHandler;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.UnifiedConsentServiceBridge; import org.chromium.chrome.browser.signin.UnifiedConsentServiceBridge;
import org.chromium.chrome.browser.uid.UniqueIdentificationGenerator;
import org.chromium.chrome.browser.uid.UniqueIdentificationGeneratorFactory; import org.chromium.chrome.browser.uid.UniqueIdentificationGeneratorFactory;
import org.chromium.chrome.browser.uid.UuidBasedUniqueIdentificationGenerator;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule; import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; import org.chromium.chrome.test.util.browser.signin.SigninTestUtil;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
...@@ -52,7 +50,7 @@ import java.util.concurrent.Callable; ...@@ -52,7 +50,7 @@ import java.util.concurrent.Callable;
/** /**
* TestRule for common functionality between sync tests. * TestRule for common functionality between sync tests.
*/ */
public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { public class SyncTestRule implements TestRule {
private static final String TAG = "SyncTestBase"; private static final String TAG = "SyncTestBase";
private static final String CLIENT_ID = "Client_ID"; private static final String CLIENT_ID = "Client_ID";
...@@ -142,9 +140,7 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -142,9 +140,7 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
ProfileSyncService.resetForTests(); ProfileSyncService.resetForTests();
} }
public SyncTestRule() { public SyncTestRule() {}
super(ChromeActivity.class);
}
/**Getters for Test variables */ /**Getters for Test variables */
public Context getTargetContext() { public Context getTargetContext() {
...@@ -163,12 +159,6 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -163,12 +159,6 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
return mSyncContentResolver; return mSyncContentResolver;
} }
public void startMainActivityForSyncTest() throws Exception {
// Start the activity by opening about:blank. This URL is ideal because it is not synced as
// a typed URL. If another URL is used, it could interfere with test data.
startMainActivityOnBlankPage();
}
/** /**
* Adds an account of default account name to AccountManagerFacade and waits for the seeding. * Adds an account of default account name to AccountManagerFacade and waits for the seeding.
*/ */
...@@ -315,7 +305,7 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -315,7 +305,7 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
@Override @Override
public Statement apply(final Statement statement, final Description desc) { public Statement apply(final Statement statement, final Description desc) {
final Statement base = super.apply(new Statement() { return mAccountManagerTestRule.apply(new Statement() {
@Override @Override
public void evaluate() throws Throwable { public void evaluate() throws Throwable {
mSyncContentResolver = new MockSyncContentResolverDelegate(); mSyncContentResolver = new MockSyncContentResolverDelegate();
...@@ -328,6 +318,9 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -328,6 +318,9 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
// Load native since the FakeServer needs it and possibly ProfileSyncService as well // Load native since the FakeServer needs it and possibly ProfileSyncService as well
// (depends on what fake is provided by |createProfileSyncService()|). // (depends on what fake is provided by |createProfileSyncService()|).
TestThreadUtils.runOnUiThreadBlocking(() -> {
ProcessInitializationHandler.getInstance().initializePreNative();
});
NativeLibraryTestUtils.loadNativeLibraryAndInitBrowserProcess(); NativeLibraryTestUtils.loadNativeLibraryAndInitBrowserProcess();
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
...@@ -343,27 +336,13 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -343,27 +336,13 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
}); });
UniqueIdentificationGeneratorFactory.registerGenerator( UniqueIdentificationGeneratorFactory.registerGenerator(
UuidBasedUniqueIdentificationGenerator.GENERATOR_ID, SyncController.GENERATOR_ID, salt -> CLIENT_ID, true);
new UniqueIdentificationGenerator() {
@Override
public String getUniqueId(String salt) {
return CLIENT_ID;
}
},
true);
startMainActivityForSyncTest();
// Ensure SyncController is created. // Ensure SyncController is created.
TestThreadUtils.runOnUiThreadBlocking(() -> SyncController.get()); TestThreadUtils.runOnUiThreadBlocking(() -> SyncController.get());
statement.evaluate(); statement.evaluate();
}
}, desc);
return mAccountManagerTestRule.apply(new Statement() {
@Override
public void evaluate() throws Throwable {
base.evaluate();
ruleTearDown(); ruleTearDown();
} }
}, desc); }, desc);
......
...@@ -21,6 +21,7 @@ import org.chromium.base.test.util.CommandLineFlags; ...@@ -21,6 +21,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.protocol.EntitySpecifics; import org.chromium.components.sync.protocol.EntitySpecifics;
...@@ -45,6 +46,10 @@ public class TypedUrlsTest { ...@@ -45,6 +46,10 @@ public class TypedUrlsTest {
@Rule @Rule
public SyncTestRule mSyncTestRule = new SyncTestRule(); public SyncTestRule mSyncTestRule = new SyncTestRule();
@Rule
public final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
private static final String TAG = "TypedUrlsTest"; private static final String TAG = "TypedUrlsTest";
private static final String TYPED_URLS_TYPE = "Typed URLs"; private static final String TYPED_URLS_TYPE = "Typed URLs";
...@@ -70,6 +75,7 @@ public class TypedUrlsTest { ...@@ -70,6 +75,7 @@ public class TypedUrlsTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mSyncTestRule.setUpAccountAndEnableSyncForTesting(); mSyncTestRule.setUpAccountAndEnableSyncForTesting();
mActivityTestRule.startMainActivityOnBlankPage();
// Make sure the initial state is clean. // Make sure the initial state is clean.
assertClientTypedUrlCount(0); assertClientTypedUrlCount(0);
assertServerTypedUrlCountWithName(0, URL); assertServerTypedUrlCountWithName(0, URL);
...@@ -122,7 +128,7 @@ public class TypedUrlsTest { ...@@ -122,7 +128,7 @@ public class TypedUrlsTest {
private void loadUrlByTyping(final String url) { private void loadUrlByTyping(final String url) {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
LoadUrlParams params = new LoadUrlParams(url, PageTransition.TYPED); LoadUrlParams params = new LoadUrlParams(url, PageTransition.TYPED);
mSyncTestRule.getActivity().getActivityTab().loadUrl(params); mActivityTestRule.getActivity().getActivityTab().loadUrl(params);
}); });
} }
......
...@@ -12,6 +12,7 @@ import android.widget.ListView; ...@@ -12,6 +12,7 @@ import android.widget.ListView;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -23,6 +24,7 @@ import org.chromium.chrome.R; ...@@ -23,6 +24,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.sync.SyncTestRule; 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.components.sync.PassphraseType; import org.chromium.components.sync.PassphraseType;
/** /**
...@@ -34,6 +36,10 @@ public class PassphraseTypeDialogFragmentTest { ...@@ -34,6 +36,10 @@ public class PassphraseTypeDialogFragmentTest {
@Rule @Rule
public SyncTestRule mSyncTestRule = new SyncTestRule(); public SyncTestRule mSyncTestRule = new SyncTestRule();
@Rule
public final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
private static final String TAG = "PassphraseTypeDialogFragmentTest"; private static final String TAG = "PassphraseTypeDialogFragmentTest";
private static final boolean ENABLED = true; private static final boolean ENABLED = true;
...@@ -54,6 +60,11 @@ public class PassphraseTypeDialogFragmentTest { ...@@ -54,6 +60,11 @@ public class PassphraseTypeDialogFragmentTest {
private PassphraseTypeDialogFragment mTypeFragment; private PassphraseTypeDialogFragment mTypeFragment;
@Before
public void setUp() {
mActivityTestRule.startMainActivityOnBlankPage();
}
@Test @Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
...@@ -119,7 +130,7 @@ public class PassphraseTypeDialogFragmentTest { ...@@ -119,7 +130,7 @@ public class PassphraseTypeDialogFragmentTest {
public void createFragment(@PassphraseType int type, boolean isEncryptEverythingAllowed) { public void createFragment(@PassphraseType int type, boolean isEncryptEverythingAllowed) {
mTypeFragment = PassphraseTypeDialogFragment.create(type, 0, isEncryptEverythingAllowed); mTypeFragment = PassphraseTypeDialogFragment.create(type, 0, isEncryptEverythingAllowed);
mTypeFragment.show(mSyncTestRule.getActivity().getSupportFragmentManager(), TAG); mTypeFragment.show(mActivityTestRule.getActivity().getSupportFragmentManager(), TAG);
InstrumentationRegistry.getInstrumentation().waitForIdleSync(); InstrumentationRegistry.getInstrumentation().waitForIdleSync();
} }
......
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