/** This is a regression test for http://crbug.com/469890. */
  @SmallTest
  @Feature({"Sync"})
  @RetryOnFailure
  public void testCallbackAfterBackgrounded() throws Exception {
    getInstrumentation().waitForIdleSync();
    SigninTestUtil.addAndSignInTestAccount();

    // Override before creating the activity so we know initialized is false.
    overrideProfileSyncService();

    // PassphraseActivity won't start if an account isn't set.
    assertNotNull(ChromeSigninController.get(mContext).getSignedInAccountName());

    // Create the activity.
    final PassphraseActivity activity = launchPassphraseActivity();
    assertNotNull(activity);
    ThreadUtils.runOnUiThreadBlocking(
        new Runnable() {
          @Override
          public void run() {
            // Fake backgrounding the activity.
            Bundle bundle = new Bundle();
            getInstrumentation().callActivityOnPause(activity);
            getInstrumentation().callActivityOnSaveInstanceState(activity, bundle);
            // Fake sync's backend finishing its initialization.
            FakeProfileSyncService pss = (FakeProfileSyncService) ProfileSyncService.get();
            pss.setSyncInitialized(true);
            pss.syncStateChanged();
          }
        });
    // Nothing crashed; success!
  }
 @VisibleForTesting
 protected boolean isSignedIn() {
   return ChromeSigninController.get(mActivity).isSignedIn();
 }