Пример #1
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    clearAppData();

    // Mock out the account manager on the device.
    mContext = new SyncTestUtil.SyncTestContext(getInstrumentation().getTargetContext());
    mAccountManager = new MockAccountManager(mContext, getInstrumentation().getContext());
    AccountManagerHelper.overrideAccountManagerHelperForTests(mContext, mAccountManager);
    MockSyncContentResolverDelegate syncContentResolverDelegate =
        new MockSyncContentResolverDelegate();
    syncContentResolverDelegate.setMasterSyncAutomatically(true);
    SyncStatusHelper.overrideSyncStatusHelperForTests(mContext, syncContentResolverDelegate);
    // This call initializes the ChromeSigninController to use our test context.
    ChromeSigninController.get(mContext);
    startChromeBrowserProcessSync(getInstrumentation().getTargetContext());
    ThreadUtils.runOnUiThreadBlocking(
        new Runnable() {
          @Override
          public void run() {
            mSyncController = SyncController.get(mContext);
          }
        });
    SyncTestUtil.verifySyncServerIsRunning();
  }
 private void setupSync(boolean syncEnabled) {
   MockSyncContentResolverDelegate contentResolver = new MockSyncContentResolverDelegate();
   // Android master sync can safely always be on.
   contentResolver.setMasterSyncAutomatically(true);
   // We don't want to use the system content resolver, so we override it.
   SyncStatusHelper.overrideSyncStatusHelperForTests(mContext, contentResolver);
   Account account = AccountManagerHelper.createAccountFromName("*****@*****.**");
   SyncStatusHelper syncStatusHelper = SyncStatusHelper.get(mContext);
   syncStatusHelper.setSignedInAccountName(account.name);
   if (syncEnabled) {
     syncStatusHelper.enableAndroidSync(account);
   } else {
     syncStatusHelper.disableAndroidSync(account);
   }
 }