private Account setupTestAccount(String accountName) { Account account = AccountManagerHelper.createAccountFromName(accountName); AccountHolder.Builder accountHolder = AccountHolder.create().account(account).password("password").alwaysAccept(true); mAccountManager.addAccountHolderExplicitly(accountHolder.build()); return account; }
@HostDrivenTest public void testDisableAndEnableSync() throws InterruptedException { setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID); Account account = AccountManagerHelper.createAccountFromName(SyncTestUtil.DEFAULT_TEST_ACCOUNT); // Disabling Android sync should turn Chrome sync engine off. SyncStatusHelper.get(mContext).disableAndroidSync(account); SyncTestUtil.verifySyncIsDisabled(mContext, account); // Enabling Android sync should turn Chrome sync engine on. SyncStatusHelper.get(mContext).enableAndroidSync(account); SyncTestUtil.ensureSyncInitialized(mContext); SyncTestUtil.verifySignedInWithAccount(mContext, account); }
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); } }
@SmallTest @Feature({"Sync"}) public void testRefreshShouldReadValuesFromDiskWithSpecificTypes() { // Store some preferences for ModelTypes and account. We are using the helper class // for this, so we don't have to deal with low-level details such as preference keys. InvalidationPreferences invalidationPreferences = new InvalidationPreferences(mContext); InvalidationPreferences.EditContext edit = invalidationPreferences.edit(); Set<String> storedModelTypes = new HashSet<String>(); storedModelTypes.add(ModelType.BOOKMARK.name()); storedModelTypes.add(ModelType.TYPED_URL.name()); invalidationPreferences.setSyncTypes(edit, storedModelTypes); Account storedAccount = AccountManagerHelper.createAccountFromName("*****@*****.**"); invalidationPreferences.setAccount(edit, storedAccount); invalidationPreferences.commit(edit); // Ensure all calls to {@link InvalidationController#setRegisteredTypes} store values // we can inspect in the test. final AtomicReference<Account> resultAccount = new AtomicReference<Account>(); final AtomicBoolean resultAllTypes = new AtomicBoolean(); final AtomicReference<Set<ModelType>> resultTypes = new AtomicReference<Set<ModelType>>(); InvalidationController controller = new InvalidationController(mContext) { @Override public void setRegisteredTypes(Account account, boolean allTypes, Set<ModelType> types) { resultAccount.set(account); resultAllTypes.set(allTypes); resultTypes.set(types); } }; // Execute the test. controller.refreshRegisteredTypes(); // Validate the values. assertEquals(storedAccount, resultAccount.get()); assertEquals(false, resultAllTypes.get()); assertEquals(ModelType.syncTypesToModelTypes(storedModelTypes), resultTypes.get()); }