Commit 774b1f7d authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

Revert "[Android] Don't subclass ChromeActivityTestRule in SyncTestRule"

This reverts commit 987fb106.

Reason for revert: crbug.com/1140670
this CL make org.chromium.chrome.browser.sync.ManageSyncSettingsTest#testTrustedVaultKeyRetrieval flaky on Lollipop Phone Tester

Original change's description:
> [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: Marc Treib <treib@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#818891}

TBR=treib@chromium.org,bsazonov@chromium.org

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