Merge "Add handling for account tiles for specific account type."
This commit is contained in:
committed by
Android (Google) Code Review
commit
7aad8a97a4
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
package com.android.settings.accounts;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AccountDetailDashboardFragmentTest {
|
||||
|
||||
private static final String METADATA_CATEGORY = "com.android.settings.category";
|
||||
private static final String METADATA_ACCOUNT_TYPE = "com.android.settings.ia.account";
|
||||
|
||||
private AccountDetailDashboardFragment mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mFragment = new AccountDetailDashboardFragment();
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(METADATA_ACCOUNT_TYPE, "com.abc");
|
||||
mFragment.mAccountType = "com.abc";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCategory_isAccount() {
|
||||
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDashboardTiles_HasAccountType_shouldDisplay() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
|
||||
tile.metaData = metaData;
|
||||
|
||||
assertThat(mFragment.displayTile(tile)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDashboardTiles_NoAccountType_shouldNotDisplay() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
tile.metaData = metaData;
|
||||
|
||||
assertThat(mFragment.displayTile(tile)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDashboardTiles_OtherAccountType_shouldNotDisplay() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
metaData.putString(METADATA_ACCOUNT_TYPE, "com.other");
|
||||
tile.metaData = metaData;
|
||||
|
||||
assertThat(mFragment.displayTile(tile)).isFalse();
|
||||
}
|
||||
|
||||
}
|
@@ -21,6 +21,7 @@ import android.accounts.AuthenticatorDescription;
|
||||
import android.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserManager;
|
||||
import android.os.UserHandle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
@@ -28,6 +29,7 @@ import android.support.v14.preference.PreferenceFragment;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.settings.AccessiblePreferenceCategory;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
@@ -265,4 +267,37 @@ public class AccountPreferenceControllerTest {
|
||||
assertThat(data.size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_twoAccountsOfSameType_shouldAddThreePreferences() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
when(mUserManager.isManagedProfile()).thenReturn(false);
|
||||
when(mUserManager.isLinkedUser()).thenReturn(false);
|
||||
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
|
||||
Account[] accounts = {new Account("Account1", "com.acct1")};
|
||||
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
|
||||
|
||||
Account[] accountType1 = new Account[2];
|
||||
accountType1[0] = new Account("Account11", "com.acct1");
|
||||
accountType1[1] = new Account("Account12", "com.acct1");
|
||||
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class)))
|
||||
.thenReturn(accountType1);
|
||||
|
||||
AuthenticatorDescription[] authDescs = {
|
||||
new AuthenticatorDescription("com.acct1", "com.android.settings",
|
||||
R.string.account_settings_title, 0, 0, 0, false)
|
||||
};
|
||||
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
|
||||
|
||||
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
|
||||
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(
|
||||
preferenceGroup);
|
||||
|
||||
mController.onResume();
|
||||
|
||||
// should add 2 individual account and the Add account preference
|
||||
verify(preferenceGroup, times(3)).addPreference(any(Preference.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.accounts;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AccountSyncPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_shouldStartFragment() {
|
||||
final ShadowApplication application = ShadowApplication.getInstance();
|
||||
final Context context = application.getApplicationContext();
|
||||
final Preference preference = new Preference(context);
|
||||
preference.setKey("account_sync");
|
||||
AccountSyncPreferenceController controller = new AccountSyncPreferenceController(context);
|
||||
controller.init(new Account("acct1", "type1"), mock(UserHandle.class));
|
||||
|
||||
controller.handlePreferenceTreeClick(preference);
|
||||
|
||||
assertThat(application.getNextStartedActivity().getStringExtra(
|
||||
SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(AccountSyncSettings.class.getName());
|
||||
}
|
||||
|
||||
}
|
@@ -15,18 +15,15 @@
|
||||
*/
|
||||
package com.android.settings.accounts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@@ -36,21 +33,39 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class UserAndAccountDashboardFragmentTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private static final String METADATA_CATEGORY = "com.android.settings.category";
|
||||
private static final String METADATA_ACCOUNT_TYPE = "com.android.settings.ia.account";
|
||||
|
||||
private UserAndAccountDashboardFragment mFragment;
|
||||
private UserAndAccountDashboardFragment mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFragment = new UserAndAccountDashboardFragment();
|
||||
}
|
||||
@Before
|
||||
public void setUp() {
|
||||
mFragment = new UserAndAccountDashboardFragment();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCategory_isConnectedDevice() {
|
||||
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
|
||||
}
|
||||
@Test
|
||||
public void testCategory_isAccount() {
|
||||
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDashboardTiles_HasAccountType_shouldNotDisplay() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
|
||||
tile.metaData = metaData;
|
||||
|
||||
assertThat(mFragment.displayTile(tile)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDashboardTiles_NoAccountType_shouldDisplay() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
tile.metaData = metaData;
|
||||
|
||||
assertThat(mFragment.displayTile(tile)).isTrue();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user