Commit 5d973bac authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][Test] Refactor SyncTestRule#setUpAccountAndSignInForTesting()

This CL refactors SyncTestRule#setUpAccountAndSignInForTesting() by
using AccountManagerTestRule to handle the sign-in instead of handling
it directly in SyncTestRule.

Bug: 1126814
Change-Id: Ib8c3941ecad3642f6749915142562d68a8ff4a5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401345
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805743}
parent 28dc85db
...@@ -202,8 +202,10 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -202,8 +202,10 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
* @return the test account that is signed in. * @return the test account that is signed in.
*/ */
public Account setUpAccountAndSignInForTesting() { public Account setUpAccountAndSignInForTesting() {
Account account = addTestAccount(); Account account = mAccountManagerTestRule.addAndSignInTestAccount(mProfileSyncService);
signinAndEnableSync(account); enableUKM();
SyncTestUtil.waitForSyncActive();
SyncTestUtil.triggerSyncAndWaitForCompletion();
return account; return account;
} }
...@@ -429,10 +431,8 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -429,10 +431,8 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
Assert.fail("Sign-in was aborted"); Assert.fail("Sign-in was aborted");
} }
}); });
// Outside of tests, URL-keyed anonymized data collection is enabled by sign-in UI.
UnifiedConsentServiceBridge.setUrlKeyedAnonymizedDataCollectionEnabled(
Profile.getLastUsedRegularProfile(), true);
}); });
enableUKM();
if (setFirstSetupComplete) { if (setFirstSetupComplete) {
SyncTestUtil.waitForSyncActive(); SyncTestUtil.waitForSyncActive();
SyncTestUtil.triggerSyncAndWaitForCompletion(); SyncTestUtil.triggerSyncAndWaitForCompletion();
...@@ -441,4 +441,12 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -441,4 +441,12 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
} }
Assert.assertEquals(account, mAccountManagerTestRule.getCurrentSignedInAccount()); Assert.assertEquals(account, mAccountManagerTestRule.getCurrentSignedInAccount());
} }
private static void enableUKM() {
TestThreadUtils.runOnUiThreadBlocking(() -> {
// Outside of tests, URL-keyed anonymized data collection is enabled by sign-in UI.
UnifiedConsentServiceBridge.setUrlKeyedAnonymizedDataCollectionEnabled(
Profile.getLastUsedRegularProfile(), true);
});
}
} }
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