1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.cts.devicepolicy.accountmanagement; 18 19 import android.accounts.Account; 20 import android.accounts.AccountManager; 21 import android.accounts.AccountManagerFuture; 22 import android.accounts.AuthenticatorException; 23 import android.accounts.OperationCanceledException; 24 import android.content.Context; 25 import android.os.Bundle; 26 import android.test.AndroidTestCase; 27 28 import java.io.IOException; 29 30 /** 31 * Functionality tests for 32 * {@link android.app.admin.DevicePolicyManager#setAccountManagementDisabled} 33 * and (@link android.os.UserManager#DISALLOW_MODIFY_ACCOUNTS} 34 * 35 * This test depends on {@link MockAccountService}, which provides authenticator of type 36 * {@link MockAccountService#ACCOUNT_TYPE}. 37 */ 38 public class AccountUtilsTest extends AndroidTestCase { 39 40 // Account type for MockAccountAuthenticator 41 private final static Account ACCOUNT = new Account("user0", 42 MockAccountAuthenticator.ACCOUNT_TYPE); 43 44 private AccountManager mAccountManager; 45 46 @Override 47 protected void setUp() throws Exception { 48 super.setUp(); 49 mAccountManager = (AccountManager) mContext.getSystemService(Context.ACCOUNT_SERVICE); 50 } 51 52 public void testAddAccountExplicitly() throws Exception { 53 assertEquals(0, mAccountManager.getAccountsByType(MockAccountAuthenticator.ACCOUNT_TYPE) 54 .length); 55 assertTrue(mAccountManager.addAccountExplicitly(ACCOUNT, "password", null)); 56 assertEquals(1, mAccountManager.getAccountsByType(MockAccountAuthenticator.ACCOUNT_TYPE) 57 .length); 58 } 59 60 public void testRemoveAccountExplicitly() throws Exception { 61 assertEquals(1, mAccountManager.getAccountsByType(MockAccountAuthenticator.ACCOUNT_TYPE) 62 .length); 63 mAccountManager.removeAccountExplicitly(ACCOUNT); 64 assertEquals(0, mAccountManager.getAccountsByType(MockAccountAuthenticator.ACCOUNT_TYPE) 65 .length); 66 } 67 } 68 69