Commit 4f2f5ec9 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Signin][Android] Clean up SigninTestUtil

This CL cleans up some unused methods and method return values in
SigninTestUtil and IdentityManagerIntegrationTest.

Bug: 1004418
Change-Id: I09c3126d2b954304defffa4a7eefc64bb2423cba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2054093
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742090}
parent 259eb917
...@@ -59,7 +59,6 @@ public class IdentityManagerIntegrationTest { ...@@ -59,7 +59,6 @@ public class IdentityManagerIntegrationTest {
private IdentityMutator mIdentityMutator; private IdentityMutator mIdentityMutator;
private IdentityManager mIdentityManager; private IdentityManager mIdentityManager;
private ChromeSigninController mChromeSigninController;
@Before @Before
public void setUp() { public void setUp() {
...@@ -69,8 +68,7 @@ public class IdentityManagerIntegrationTest { ...@@ -69,8 +68,7 @@ public class IdentityManagerIntegrationTest {
mActivityTestRule.loadNativeLibraryAndInitBrowserProcess(); mActivityTestRule.loadNativeLibraryAndInitBrowserProcess();
// Make sure there is no account signed in yet. // Make sure there is no account signed in yet.
mChromeSigninController = ChromeSigninController.get(); ChromeSigninController.get().setSignedInAccountName(null);
mChromeSigninController.setSignedInAccountName(null);
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
seedAccountTrackerService(); seedAccountTrackerService();
...@@ -190,9 +188,8 @@ public class IdentityManagerIntegrationTest { ...@@ -190,9 +188,8 @@ public class IdentityManagerIntegrationTest {
mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId()); mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId());
Assert.assertEquals("Signed in and two accounts available", Assert.assertEquals("Signed in and two accounts available",
new HashSet<CoreAccountInfo>(Arrays.asList(mTestAccount1, mTestAccount2)), new HashSet<>(Arrays.asList(mTestAccount1, mTestAccount2)),
new HashSet<CoreAccountInfo>( new HashSet<>(Arrays.asList(mIdentityManager.getAccountsWithRefreshTokens())));
Arrays.asList(mIdentityManager.getAccountsWithRefreshTokens())));
}); });
} }
...@@ -208,9 +205,8 @@ public class IdentityManagerIntegrationTest { ...@@ -208,9 +205,8 @@ public class IdentityManagerIntegrationTest {
mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId()); mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId());
Assert.assertEquals("Signed in and two accounts available", Assert.assertEquals("Signed in and two accounts available",
new HashSet<CoreAccountInfo>(Arrays.asList(mTestAccount1, mTestAccount2)), new HashSet<>(Arrays.asList(mTestAccount1, mTestAccount2)),
new HashSet<CoreAccountInfo>( new HashSet<>(Arrays.asList(mIdentityManager.getAccountsWithRefreshTokens())));
Arrays.asList(mIdentityManager.getAccountsWithRefreshTokens())));
}); });
removeAccount(TEST_ACCOUNT_HOLDER_2); removeAccount(TEST_ACCOUNT_HOLDER_2);
...@@ -236,9 +232,8 @@ public class IdentityManagerIntegrationTest { ...@@ -236,9 +232,8 @@ public class IdentityManagerIntegrationTest {
mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId()); mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId());
Assert.assertEquals("Signed in and two accounts available", Assert.assertEquals("Signed in and two accounts available",
new HashSet<CoreAccountInfo>(Arrays.asList(mTestAccount1, mTestAccount2)), new HashSet<>(Arrays.asList(mTestAccount1, mTestAccount2)),
new HashSet<CoreAccountInfo>( new HashSet<>(Arrays.asList(mIdentityManager.getAccountsWithRefreshTokens())));
Arrays.asList(mIdentityManager.getAccountsWithRefreshTokens())));
}); });
// Remove all. // Remove all.
...@@ -266,9 +261,8 @@ public class IdentityManagerIntegrationTest { ...@@ -266,9 +261,8 @@ public class IdentityManagerIntegrationTest {
mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId()); mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId());
Assert.assertEquals("Signed in and two accounts available", Assert.assertEquals("Signed in and two accounts available",
new HashSet<CoreAccountInfo>(Arrays.asList(mTestAccount1, mTestAccount2)), new HashSet<>(Arrays.asList(mTestAccount1, mTestAccount2)),
new HashSet<CoreAccountInfo>( new HashSet<>(Arrays.asList(mIdentityManager.getAccountsWithRefreshTokens())));
Arrays.asList(mIdentityManager.getAccountsWithRefreshTokens())));
}); });
removeAccount(TEST_ACCOUNT_HOLDER_1); removeAccount(TEST_ACCOUNT_HOLDER_1);
...@@ -278,8 +272,8 @@ public class IdentityManagerIntegrationTest { ...@@ -278,8 +272,8 @@ public class IdentityManagerIntegrationTest {
// Re-validate and run checks. // Re-validate and run checks.
mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(null); mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(null);
Assert.assertEquals("Not signed in and no accounts available", new CoreAccountInfo[] {}, Assert.assertArrayEquals("Not signed in and no accounts available",
mIdentityManager.getAccountsWithRefreshTokens()); new CoreAccountInfo[] {}, mIdentityManager.getAccountsWithRefreshTokens());
}); });
} }
...@@ -295,9 +289,8 @@ public class IdentityManagerIntegrationTest { ...@@ -295,9 +289,8 @@ public class IdentityManagerIntegrationTest {
mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId()); mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId());
Assert.assertEquals("Signed in and two accounts available", Assert.assertEquals("Signed in and two accounts available",
new HashSet<CoreAccountInfo>(Arrays.asList(mTestAccount1, mTestAccount2)), new HashSet<>(Arrays.asList(mTestAccount1, mTestAccount2)),
new HashSet<CoreAccountInfo>( new HashSet<>(Arrays.asList(mIdentityManager.getAccountsWithRefreshTokens())));
Arrays.asList(mIdentityManager.getAccountsWithRefreshTokens())));
}); });
} }
...@@ -308,7 +301,7 @@ public class IdentityManagerIntegrationTest { ...@@ -308,7 +301,7 @@ public class IdentityManagerIntegrationTest {
// Run test. // Run test.
mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId()); mIdentityMutator.reloadAllAccountsFromSystemWithPrimaryAccount(mTestAccount1.getId());
Assert.assertEquals("No accounts available", new CoreAccountInfo[] {}, Assert.assertArrayEquals("No accounts available", new CoreAccountInfo[] {},
mIdentityManager.getAccountsWithRefreshTokens()); mIdentityManager.getAccountsWithRefreshTokens());
}); });
} }
......
...@@ -24,8 +24,6 @@ import java.util.List; ...@@ -24,8 +24,6 @@ import java.util.List;
* Utility class for test signin functionality. * Utility class for test signin functionality.
*/ */
public final class SigninTestUtil { public final class SigninTestUtil {
private static final String TAG = "Signin";
private static final String DEFAULT_ACCOUNT = "test@gmail.com"; private static final String DEFAULT_ACCOUNT = "test@gmail.com";
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
...@@ -80,7 +78,7 @@ public final class SigninTestUtil { ...@@ -80,7 +78,7 @@ public final class SigninTestUtil {
AccountHolder accountHolder = AccountHolder.builder(account).alwaysAccept(true).build(); AccountHolder accountHolder = AccountHolder.builder(account).alwaysAccept(true).build();
sAccountManager.addAccountHolderBlocking(accountHolder); sAccountManager.addAccountHolderBlocking(accountHolder);
sAddedAccounts.add(accountHolder); sAddedAccounts.add(accountHolder);
TestThreadUtils.runOnUiThreadBlocking(SigninTestUtil::seedAccounts); seedAccounts();
return account; return account;
} }
...@@ -88,18 +86,9 @@ public final class SigninTestUtil { ...@@ -88,18 +86,9 @@ public final class SigninTestUtil {
* Add and sign in an account with the default name. * Add and sign in an account with the default name.
*/ */
public static Account addAndSignInTestAccount() { public static Account addAndSignInTestAccount() {
return addAndSignInTestAccount(DEFAULT_ACCOUNT); Account account = addTestAccount(DEFAULT_ACCOUNT);
} ChromeSigninController.get().setSignedInAccountName(DEFAULT_ACCOUNT);
seedAccounts();
/**
* Add and sign in an account with a given name.
*/
public static Account addAndSignInTestAccount(String name) {
Account account = addTestAccount(name);
TestThreadUtils.runOnUiThreadBlocking(() -> {
ChromeSigninController.get().setSignedInAccountName(name);
seedAccounts();
});
return account; return account;
} }
...@@ -111,8 +100,10 @@ public final class SigninTestUtil { ...@@ -111,8 +100,10 @@ public final class SigninTestUtil {
accountNames[i] = accounts[i].name; accountNames[i] = accounts[i].name;
accountIds[i] = sAccountManager.getAccountGaiaId(accounts[i].name); accountIds[i] = sAccountManager.getAccountGaiaId(accounts[i].name);
} }
IdentityServicesProvider.get().getAccountTrackerService().syncForceRefreshForTest( TestThreadUtils.runOnUiThreadBlocking(() -> {
accountIds, accountNames); IdentityServicesProvider.get().getAccountTrackerService().syncForceRefreshForTest(
accountIds, accountNames);
});
} }
/** /**
......
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