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

[Test] Migrate account related methods in SyncTestRule

The sign in API uses CoreAccountInfo. So in the long run its better to
use CoreAccountInfo for helper methods that interact with sign in API.
This cl refactors SyncTestRule so that the methods to add account and
toggle sync states return CoreAccountInfo.

Bug: 1135510, 1117006
Change-Id: I333f9dd87b093d781311a7ee286c04f274ee13ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523112
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825339}
parent a5afb10b
...@@ -18,7 +18,6 @@ import static org.mockito.Mockito.doNothing; ...@@ -18,7 +18,6 @@ import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import android.accounts.Account;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
...@@ -38,6 +37,7 @@ import org.chromium.chrome.browser.signin.SigninActivityLauncherImpl; ...@@ -38,6 +37,7 @@ 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.util.BookmarkTestRule; import org.chromium.chrome.test.util.BookmarkTestRule;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.metrics.SigninAccessPoint; import org.chromium.components.signin.metrics.SigninAccessPoint;
/** /**
...@@ -78,12 +78,12 @@ public class BookmarkPersonalizedSigninPromoTest { ...@@ -78,12 +78,12 @@ public class BookmarkPersonalizedSigninPromoTest {
doNothing() doNothing()
.when(SigninActivityLauncherImpl.get()) .when(SigninActivityLauncherImpl.get())
.launchActivityForPromoDefaultFlow(any(Context.class), anyInt(), anyString()); .launchActivityForPromoDefaultFlow(any(Context.class), anyInt(), anyString());
Account account = mSyncTestRule.addTestAccount(); CoreAccountInfo accountInfo = mSyncTestRule.addTestAccount();
showBookmarkManagerAndCheckSigninPromoIsDisplayed(); showBookmarkManagerAndCheckSigninPromoIsDisplayed();
onView(withId(R.id.signin_promo_signin_button)).perform(click()); onView(withId(R.id.signin_promo_signin_button)).perform(click());
verify(mMockSigninActivityLauncherImpl) verify(mMockSigninActivityLauncherImpl)
.launchActivityForPromoDefaultFlow(any(Activity.class), .launchActivityForPromoDefaultFlow(any(Activity.class),
eq(SigninAccessPoint.BOOKMARK_MANAGER), eq(account.name)); eq(SigninAccessPoint.BOOKMARK_MANAGER), eq(accountInfo.getEmail()));
} }
@Test @Test
...@@ -92,12 +92,12 @@ public class BookmarkPersonalizedSigninPromoTest { ...@@ -92,12 +92,12 @@ public class BookmarkPersonalizedSigninPromoTest {
doNothing() doNothing()
.when(SigninActivityLauncherImpl.get()) .when(SigninActivityLauncherImpl.get())
.launchActivityForPromoChooseAccountFlow(any(Context.class), anyInt(), anyString()); .launchActivityForPromoChooseAccountFlow(any(Context.class), anyInt(), anyString());
Account account = mSyncTestRule.addTestAccount(); CoreAccountInfo accountInfo = mSyncTestRule.addTestAccount();
showBookmarkManagerAndCheckSigninPromoIsDisplayed(); showBookmarkManagerAndCheckSigninPromoIsDisplayed();
onView(withId(R.id.signin_promo_choose_account_button)).perform(click()); onView(withId(R.id.signin_promo_choose_account_button)).perform(click());
verify(mMockSigninActivityLauncherImpl) verify(mMockSigninActivityLauncherImpl)
.launchActivityForPromoChooseAccountFlow(any(Activity.class), .launchActivityForPromoChooseAccountFlow(any(Activity.class),
eq(SigninAccessPoint.BOOKMARK_MANAGER), eq(account.name)); eq(SigninAccessPoint.BOOKMARK_MANAGER), eq(accountInfo.getEmail()));
} }
@Test @Test
......
...@@ -12,7 +12,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; ...@@ -12,7 +12,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText; import static androidx.test.espresso.matcher.ViewMatchers.withText;
import android.accounts.Account;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.text.Spanned; import android.text.Spanned;
import android.text.style.ClickableSpan; import android.text.style.ClickableSpan;
...@@ -46,6 +45,7 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner; ...@@ -46,6 +45,7 @@ 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.ChromeRenderTestRule; import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.metrics.SigninAccessPoint; import org.chromium.components.signin.metrics.SigninAccessPoint;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.test.util.DisableAnimationsTestRule; import org.chromium.ui.test.util.DisableAnimationsTestRule;
...@@ -96,13 +96,13 @@ public class SigninFragmentTest { ...@@ -96,13 +96,13 @@ public class SigninFragmentTest {
@LargeTest @LargeTest
@Feature("RenderTest") @Feature("RenderTest")
public void testSigninFragmentNotDefaultAccountWithPrimaryAccount() throws IOException { public void testSigninFragmentNotDefaultAccountWithPrimaryAccount() throws IOException {
Account account = mSyncTestRule.addTestAccount(); CoreAccountInfo accountInfo = mSyncTestRule.addTestAccount();
mSyncTestRule.addAccount("test.second.account@gmail.com"); mSyncTestRule.addAccount("test.second.account@gmail.com");
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, mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER,
account.name); accountInfo.getEmail());
}); });
mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container), mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container),
"signin_fragment_choose_primary_account"); "signin_fragment_choose_primary_account");
...@@ -129,12 +129,12 @@ public class SigninFragmentTest { ...@@ -129,12 +129,12 @@ public class SigninFragmentTest {
@LargeTest @LargeTest
@Feature("RenderTest") @Feature("RenderTest")
public void testSigninFragmentDefaultAccount() throws IOException { public void testSigninFragmentDefaultAccount() throws IOException {
Account account = mSyncTestRule.addTestAccount(); CoreAccountInfo accountInfo = mSyncTestRule.addTestAccount();
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, mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER,
account.name); accountInfo.getEmail());
}); });
mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container), mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container),
"signin_fragment_default_account"); "signin_fragment_default_account");
...@@ -143,13 +143,14 @@ public class SigninFragmentTest { ...@@ -143,13 +143,14 @@ public class SigninFragmentTest {
@Test @Test
@LargeTest @LargeTest
public void testClickingSettingsDoesNotSetFirstSetupComplete() { public void testClickingSettingsDoesNotSetFirstSetupComplete() {
Account account = mSyncTestRule.addTestAccount(); CoreAccountInfo accountInfo = mSyncTestRule.addTestAccount();
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); mSyncTestRule.getActivity(), SigninAccessPoint.SETTINGS,
accountInfo.getEmail());
}); });
onView(withText(account.name)).check(matches(isDisplayed())); onView(withText(accountInfo.getEmail())).check(matches(isDisplayed()));
onView(withId(R.id.signin_details_description)).perform(clickOnClickableSpan()); onView(withId(R.id.signin_details_description)).perform(clickOnClickableSpan());
// Wait for sign in process to finish. // Wait for sign in process to finish.
CriteriaHelper.pollUiThread(() -> { CriteriaHelper.pollUiThread(() -> {
...@@ -180,20 +181,22 @@ public class SigninFragmentTest { ...@@ -180,20 +181,22 @@ public class SigninFragmentTest {
@Test @Test
@MediumTest @MediumTest
public void testSelectNonDefaultAccountInAccountPickerDialog() { public void testSelectNonDefaultAccountInAccountPickerDialog() {
Account defaultAccount = mSyncTestRule.addTestAccount(); CoreAccountInfo defaultAccountInfo = mSyncTestRule.addTestAccount();
String nonDefaultAccountName = "test.account.nondefault@gmail.com"; String nonDefaultAccountName = "test.account.nondefault@gmail.com";
mSyncTestRule.addAccount(nonDefaultAccountName); mSyncTestRule.addAccount(nonDefaultAccountName);
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, mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER,
defaultAccount.name); defaultAccountInfo.getEmail());
}); });
onView(withText(defaultAccount.name)).check(matches(isDisplayed())).perform(click()); onView(withText(defaultAccountInfo.getEmail()))
.check(matches(isDisplayed()))
.perform(click());
onView(withText(nonDefaultAccountName)).inRoot(isDialog()).perform(click()); onView(withText(nonDefaultAccountName)).inRoot(isDialog()).perform(click());
// We should return to the signin promo screen where the previous account is // We should return to the signin promo screen where the previous account is
// not shown anymore. // not shown anymore.
onView(withText(defaultAccount.name)).check(doesNotExist()); onView(withText(defaultAccountInfo.getEmail())).check(doesNotExist());
onView(withText(nonDefaultAccountName)).check(matches(isDisplayed())); onView(withText(nonDefaultAccountName)).check(matches(isDisplayed()));
} }
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.sync; package org.chromium.chrome.browser.sync;
import android.accounts.Account;
import android.app.Activity; import android.app.Activity;
import android.app.Instrumentation; import android.app.Instrumentation;
import android.app.Instrumentation.ActivityMonitor; import android.app.Instrumentation.ActivityMonitor;
...@@ -38,6 +37,7 @@ import org.chromium.chrome.browser.sync.settings.AccountManagementFragment; ...@@ -38,6 +37,7 @@ import org.chromium.chrome.browser.sync.settings.AccountManagementFragment;
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;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
...@@ -140,12 +140,12 @@ public class FirstRunTest { ...@@ -140,12 +140,12 @@ public class FirstRunTest {
@Test @Test
@FlakyTest(message = "https://crbug.com/616456") @FlakyTest(message = "https://crbug.com/616456")
public void testSignIn() { public void testSignIn() {
Account testAccount = mSyncTestRule.addTestAccount(); CoreAccountInfo testAccountInfo = mSyncTestRule.addTestAccount();
Assert.assertNull(mSyncTestRule.getCurrentSignedInAccount()); Assert.assertNull(mSyncTestRule.getCurrentSignedInAccount());
Assert.assertFalse(SyncTestUtil.isSyncRequested()); Assert.assertFalse(SyncTestUtil.isSyncRequested());
processFirstRun(testAccount.name, false /* ShowSettings */); processFirstRun(testAccountInfo.getEmail(), false /* ShowSettings */);
Assert.assertEquals(testAccount, mSyncTestRule.getCurrentSignedInAccount()); Assert.assertEquals(testAccountInfo, mSyncTestRule.getCurrentSignedInAccount());
SyncTestUtil.waitForSyncActive(); SyncTestUtil.waitForSyncActive();
} }
...@@ -158,13 +158,13 @@ public class FirstRunTest { ...@@ -158,13 +158,13 @@ public class FirstRunTest {
@Test @Test
@FlakyTest(message = "https://crbug.com/616456") @FlakyTest(message = "https://crbug.com/616456")
public void testSignInWithOpenSettings() { public void testSignInWithOpenSettings() {
final Account testAccount = mSyncTestRule.addTestAccount(); CoreAccountInfo testAccountInfo = mSyncTestRule.addTestAccount();
final SettingsActivity settingsActivity = final SettingsActivity settingsActivity =
processFirstRun(testAccount.name, true /* ShowSettings */); processFirstRun(testAccountInfo.getEmail(), true /* ShowSettings */);
// User should be signed in and the sync backend should initialize, but sync should not // User should be signed in and the sync backend should initialize, but sync should not
// become fully active until the settings page is closed. // become fully active until the settings page is closed.
Assert.assertEquals(testAccount, mSyncTestRule.getCurrentSignedInAccount()); Assert.assertEquals(testAccountInfo, mSyncTestRule.getCurrentSignedInAccount());
SyncTestUtil.waitForEngineInitialized(); SyncTestUtil.waitForEngineInitialized();
Assert.assertFalse(SyncTestUtil.isSyncActive()); Assert.assertFalse(SyncTestUtil.isSyncActive());
......
...@@ -29,6 +29,7 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner; ...@@ -29,6 +29,7 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.signin.MockChangeEventChecker; import org.chromium.chrome.test.util.browser.signin.MockChangeEventChecker;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
/** /**
...@@ -49,14 +50,14 @@ public class SyncTest { ...@@ -49,14 +50,14 @@ public class SyncTest {
@Feature({"Sync"}) @Feature({"Sync"})
@DisabledTest(message = "crbug.com/1144221") @DisabledTest(message = "crbug.com/1144221")
public void testSignInAndOut() { public void testSignInAndOut() {
Account account = mSyncTestRule.setUpAccountAndEnableSyncForTesting(); CoreAccountInfo accountInfo = mSyncTestRule.setUpAccountAndEnableSyncForTesting();
// Signing out should disable sync. // Signing out should disable sync.
mSyncTestRule.signOut(); mSyncTestRule.signOut();
Assert.assertFalse(SyncTestUtil.isSyncRequested()); Assert.assertFalse(SyncTestUtil.isSyncRequested());
// Signing back in should re-enable sync. // Signing back in should re-enable sync.
mSyncTestRule.signinAndEnableSync(account); mSyncTestRule.signinAndEnableSync(accountInfo);
Assert.assertTrue("Sync should be re-enabled.", SyncTestUtil.isSyncActive()); Assert.assertTrue("Sync should be re-enabled.", SyncTestUtil.isSyncActive());
} }
...@@ -96,8 +97,10 @@ public class SyncTest { ...@@ -96,8 +97,10 @@ public class SyncTest {
@DisabledTest(message = "crbug.com/588050,crbug.com/595893") @DisabledTest(message = "crbug.com/588050,crbug.com/595893")
public void testRename() { public void testRename() {
// The two accounts object that would represent the account rename. // The two accounts object that would represent the account rename.
final Account oldAccount = mSyncTestRule.setUpAccountAndEnableSyncForTesting(); final Account oldAccount = CoreAccountInfo.getAndroidAccountFrom(
final Account newAccount = mSyncTestRule.addAccount("test2@gmail.com"); mSyncTestRule.setUpAccountAndEnableSyncForTesting());
final Account newAccount =
CoreAccountInfo.getAndroidAccountFrom(mSyncTestRule.addAccount("test2@gmail.com"));
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
// First, we force a call to updateAccountRenameData. In the real world, // First, we force a call to updateAccountRenameData. In the real world,
...@@ -125,7 +128,8 @@ public class SyncTest { ...@@ -125,7 +128,8 @@ public class SyncTest {
}); });
CriteriaHelper.pollInstrumentationThread(() -> { CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(mSyncTestRule.getCurrentSignedInAccount(), Matchers.is(newAccount)); Criteria.checkThat(mSyncTestRule.getCurrentSignedInAccount().getEmail(),
Matchers.is(newAccount.name));
}); });
SyncTestUtil.waitForSyncActive(); SyncTestUtil.waitForSyncActive();
} }
...@@ -134,10 +138,10 @@ public class SyncTest { ...@@ -134,10 +138,10 @@ public class SyncTest {
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testStopAndStartSync() { public void testStopAndStartSync() {
Account account = mSyncTestRule.setUpAccountAndEnableSyncForTesting(); CoreAccountInfo accountInfo = mSyncTestRule.setUpAccountAndEnableSyncForTesting();
mSyncTestRule.stopSync(); mSyncTestRule.stopSync();
Assert.assertEquals(account, mSyncTestRule.getCurrentSignedInAccount()); Assert.assertEquals(accountInfo, mSyncTestRule.getCurrentSignedInAccount());
Assert.assertFalse(SyncTestUtil.isSyncRequested()); Assert.assertFalse(SyncTestUtil.isSyncRequested());
mSyncTestRule.startSyncAndWait(); mSyncTestRule.startSyncAndWait();
...@@ -147,7 +151,8 @@ public class SyncTest { ...@@ -147,7 +151,8 @@ public class SyncTest {
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testStopAndStartSyncThroughAndroidChromeSync() { public void testStopAndStartSyncThroughAndroidChromeSync() {
Account account = mSyncTestRule.setUpAccountAndEnableSyncForTesting(); Account account = CoreAccountInfo.getAndroidAccountFrom(
mSyncTestRule.setUpAccountAndEnableSyncForTesting());
String authority = AndroidSyncSettings.getContractAuthority(); String authority = AndroidSyncSettings.getContractAuthority();
Assert.assertTrue(AndroidSyncSettingsTestUtils.getIsSyncEnabledOnUiThread()); Assert.assertTrue(AndroidSyncSettingsTestUtils.getIsSyncEnabledOnUiThread());
...@@ -188,7 +193,8 @@ public class SyncTest { ...@@ -188,7 +193,8 @@ public class SyncTest {
@Features.DisableFeatures(ChromeFeatureList.DECOUPLE_SYNC_FROM_ANDROID_MASTER_SYNC) @Features.DisableFeatures(ChromeFeatureList.DECOUPLE_SYNC_FROM_ANDROID_MASTER_SYNC)
@DisabledTest(message = "Test is flaky crbug.com/1100890") @DisabledTest(message = "Test is flaky crbug.com/1100890")
public void testReenableMasterSyncFirst() { public void testReenableMasterSyncFirst() {
Account account = mSyncTestRule.setUpAccountAndEnableSyncForTesting(); Account account = CoreAccountInfo.getAndroidAccountFrom(
mSyncTestRule.setUpAccountAndEnableSyncForTesting());
String authority = AndroidSyncSettings.getContractAuthority(); String authority = AndroidSyncSettings.getContractAuthority();
Assert.assertTrue(AndroidSyncSettingsTestUtils.getIsSyncEnabledOnUiThread()); Assert.assertTrue(AndroidSyncSettingsTestUtils.getIsSyncEnabledOnUiThread());
...@@ -221,7 +227,8 @@ public class SyncTest { ...@@ -221,7 +227,8 @@ public class SyncTest {
@Features.DisableFeatures(ChromeFeatureList.DECOUPLE_SYNC_FROM_ANDROID_MASTER_SYNC) @Features.DisableFeatures(ChromeFeatureList.DECOUPLE_SYNC_FROM_ANDROID_MASTER_SYNC)
@Feature({"Sync"}) @Feature({"Sync"})
public void testReenableChromeSyncFirst() { public void testReenableChromeSyncFirst() {
Account account = mSyncTestRule.setUpAccountAndEnableSyncForTesting(); Account account = CoreAccountInfo.getAndroidAccountFrom(
mSyncTestRule.setUpAccountAndEnableSyncForTesting());
String authority = AndroidSyncSettings.getContractAuthority(); String authority = AndroidSyncSettings.getContractAuthority();
Assert.assertTrue(AndroidSyncSettingsTestUtils.getIsSyncEnabledOnUiThread()); Assert.assertTrue(AndroidSyncSettingsTestUtils.getIsSyncEnabledOnUiThread());
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.sync; package org.chromium.chrome.browser.sync;
import android.accounts.Account;
import android.app.Activity; import android.app.Activity;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
...@@ -32,7 +31,6 @@ import org.chromium.chrome.test.ChromeTabbedActivityTestRule; ...@@ -32,7 +31,6 @@ import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
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;
import org.chromium.components.signin.AccountUtils;
import org.chromium.components.signin.base.CoreAccountInfo; import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.protocol.AutofillWalletSpecifics; import org.chromium.components.sync.protocol.AutofillWalletSpecifics;
...@@ -169,44 +167,40 @@ public class SyncTestRule extends ChromeTabbedActivityTestRule { ...@@ -169,44 +167,40 @@ public class SyncTestRule extends ChromeTabbedActivityTestRule {
/** /**
* 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.
* TODO(https://crbug.com/1117006): Return CoreAccountInfo object
*/ */
public Account addTestAccount() { public CoreAccountInfo addTestAccount() {
return addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL); return addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
} }
/** /**
* Adds an account of given account name to AccountManagerFacade and waits for the seeding. * Adds an account of given account name to AccountManagerFacade and waits for the seeding.
*/ */
public Account addAccount(String accountName) { public CoreAccountInfo addAccount(String accountName) {
CoreAccountInfo coreAccountInfo = CoreAccountInfo coreAccountInfo =
mAccountManagerTestRule.addAccountAndWaitForSeeding(accountName); mAccountManagerTestRule.addAccountAndWaitForSeeding(accountName);
Assert.assertFalse(SyncTestUtil.isSyncRequested()); Assert.assertFalse(SyncTestUtil.isSyncRequested());
return CoreAccountInfo.getAndroidAccountFrom(coreAccountInfo); return coreAccountInfo;
} }
/** /**
* Returns the currently signed in account. * Returns the currently signed in account.
* TODO(https://crbug.com/1117006): Return CoreAccountInfo object
*/ */
public Account getCurrentSignedInAccount() { public CoreAccountInfo getCurrentSignedInAccount() {
return CoreAccountInfo.getAndroidAccountFrom( return mAccountManagerTestRule.getCurrentSignedInAccount();
mAccountManagerTestRule.getCurrentSignedInAccount());
} }
/** /**
* Set up a test account, sign in and enable sync. FirstSetupComplete bit will be set after * Set up a test account, sign in and enable sync. FirstSetupComplete bit will be set after
* this. For most purposes this function should be used as this emulates the basic sign in flow. * this. For most purposes this function should be used as this emulates the basic sign in flow.
* @return the test account that is signed in. * @return the test account that is signed in.
* TODO(https://crbug.com/1135510): Return CoreAccountInfo object
*/ */
public Account setUpAccountAndEnableSyncForTesting() { public CoreAccountInfo setUpAccountAndEnableSyncForTesting() {
CoreAccountInfo accountInfo = CoreAccountInfo accountInfo =
mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync(mProfileSyncService); mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync(mProfileSyncService);
enableUKM(); enableUKM();
SyncTestUtil.waitForSyncActive(); SyncTestUtil.waitForSyncActive();
SyncTestUtil.triggerSyncAndWaitForCompletion(); SyncTestUtil.triggerSyncAndWaitForCompletion();
return AccountUtils.createAccountFromName(accountInfo.getEmail()); return accountInfo;
} }
/** /**
...@@ -222,14 +216,13 @@ public class SyncTestRule extends ChromeTabbedActivityTestRule { ...@@ -222,14 +216,13 @@ public class SyncTestRule extends ChromeTabbedActivityTestRule {
/** /**
* Set up a test account, sign in but don't mark sync setup complete. * Set up a test account, sign in but don't mark sync setup complete.
* @return the test account that is signed in. * @return the test account that is signed in.
* TODO(https://crbug.com/1135510): Return CoreAccountInfo object
*/ */
public Account setUpTestAccountAndSignInWithSyncSetupAsIncomplete() { public CoreAccountInfo setUpTestAccountAndSignInWithSyncSetupAsIncomplete() {
CoreAccountInfo accountInfo = mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync( CoreAccountInfo accountInfo = mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync(
/* profileSyncService= */ null); /* profileSyncService= */ null);
enableUKM(); enableUKM();
SyncTestUtil.waitForSyncTransportActive(); SyncTestUtil.waitForSyncTransportActive();
return AccountUtils.createAccountFromName(accountInfo.getEmail()); return accountInfo;
} }
public void startSync() { public void startSync() {
...@@ -246,9 +239,8 @@ public class SyncTestRule extends ChromeTabbedActivityTestRule { ...@@ -246,9 +239,8 @@ public class SyncTestRule extends ChromeTabbedActivityTestRule {
InstrumentationRegistry.getInstrumentation().waitForIdleSync(); InstrumentationRegistry.getInstrumentation().waitForIdleSync();
} }
public void signinAndEnableSync(final Account account) { public void signinAndEnableSync(final CoreAccountInfo accountInfo) {
SigninTestUtil.signinAndEnableSync( SigninTestUtil.signinAndEnableSync(accountInfo, mProfileSyncService);
mAccountManagerTestRule.toCoreAccountInfo(account.name), mProfileSyncService);
enableUKM(); enableUKM();
SyncTestUtil.waitForSyncActive(); SyncTestUtil.waitForSyncActive();
SyncTestUtil.triggerSyncAndWaitForCompletion(); SyncTestUtil.triggerSyncAndWaitForCompletion();
......
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