Add a criteria check for sign-in to child accounts on Android tests.

Given that Chrome needs to handle the asynchronous update of child
settings propagation as of crrev.com/c/6163746, this patch adds an
additional wait to ensure the settings are correctly propagated before
checking subsequent UI actions.

Bug: 389052725
Change-Id: I4b98a22fe83f125489836db361bf18f6c6ed9b38
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6198180
Commit-Queue: Nohemi Fernandez <fernandex@google.com>
Reviewed-by: Samar Chehade-Lepleux <samarchehade@google.com>
Cr-Commit-Position: refs/heads/main@{#1410894}
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/signin/SigninTestRule.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/signin/SigninTestRule.java
index bcb34a7..e7a1eff 100644
--- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/signin/SigninTestRule.java
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/signin/SigninTestRule.java
@@ -16,6 +16,7 @@
 import org.chromium.chrome.browser.profiles.ProfileManager;
 import org.chromium.chrome.browser.signin.services.IdentityServicesProvider;
 import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
+import org.chromium.components.signin.Tribool;
 import org.chromium.components.signin.base.AccountInfo;
 import org.chromium.components.signin.base.CoreAccountInfo;
 import org.chromium.components.signin.identitymanager.ConsentLevel;
@@ -149,9 +150,13 @@
 
         addAccount(testChildAccount);
 
-        // The child will be force signed in (by SigninChecker).
+        // The account will be force signed in (by SigninChecker).
         // Wait for this to complete before enabling sync.
         waitForSignin(testChildAccount);
+
+        // Wait for child status properties to be populated through asynchronous callbacks triggered
+        // after sign-in completes.
+        waitForChildSettingPropagation(testChildAccount);
         return testChildAccount;
     }
 
@@ -219,4 +224,26 @@
     public void completeDeviceLockIfOnAutomotive() {
         SigninTestUtil.completeDeviceLockIfOnAutomotive(mDeviceLockActivityLauncher);
     }
+
+    /** Waits for the account manager to set corresponding child properties. */
+    private void waitForChildSettingPropagation(AccountInfo accountInfo) {
+        CriteriaHelper.pollUiThread(
+                () -> {
+                    // The child sign-in triggers two changes to preferences in native code used
+                    // to determine the child status to trigger Android UI changes.
+                    // Check that `IsSubjectToParentalControls` is updated to `Tribool.TRUE` as
+                    // expected for supervised accounts.
+                    Criteria.checkThat(
+                            IdentityServicesProvider.get()
+                                    .getIdentityManager(ProfileManager.getLastUsedRegularProfile())
+                                    .findExtendedAccountInfoByEmailAddress(accountInfo.getEmail())
+                                    .getAccountCapabilities()
+                                    .isSubjectToParentalControls(),
+                            is(Tribool.TRUE));
+                    // Check that the `kSupervisedUserId` preference is populated, which backs the
+                    // Java `Profile.isChild` implementation.
+                    Criteria.checkThat(
+                            ProfileManager.getLastUsedRegularProfile().isChild(), is(true));
+                });
+    }
 }