Merge "Add current user handle to tile intent in account detail page."

This commit is contained in:
TreeHugger Robot
2019-02-01 02:31:10 +00:00
committed by Android (Google) Code Review
4 changed files with 81 additions and 5 deletions

View File

@@ -15,6 +15,8 @@
*/
package com.android.settings.accounts;
import static android.content.Intent.EXTRA_USER;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_TITLE;
@@ -160,6 +162,20 @@ public class AccountDetailDashboardFragmentTest {
assertThat(intent.getStringExtra("extra.accountName")).isEqualTo("name1@abc.com");
}
@Test
public void displayTile_shouldAddUserHandleToTileIntent() {
mFragment.mUserHandle = new UserHandle(1);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
mActivityInfo.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
mActivityInfo.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
mFragment.displayTile(tile);
final UserHandle userHandle = tile.getIntent().getParcelableExtra(EXTRA_USER);
assertThat(userHandle.getIdentifier()).isEqualTo(1);
}
@Test
public void onResume_accountMissing_shouldFinish() {
ShadowUserManager userManager =

View File

@@ -16,6 +16,8 @@
package com.android.settings.dashboard;
import static android.content.Intent.EXTRA_USER;
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_ORDER;
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
@@ -67,6 +69,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
@@ -412,4 +415,44 @@ public class DashboardFeatureProviderImplTest {
.startActivityForResult(any(Intent.class), eq(0));
verify(mActivity, never()).getSupportFragmentManager();
}
@Test
public void openTileIntent_profileSelectionDialog_validUserHandleShouldNotShow() {
final int userId = 10;
ShadowUserManager.getShadow().addUser(userId, "Someone", 0);
final UserHandle userHandle = new UserHandle(userId);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.getIntent().putExtra(EXTRA_USER, userHandle);
final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0));
handles.add(userHandle);
tile.userHandle = handles;
mImpl.openTileIntent(mActivity, tile);
final ArgumentCaptor<UserHandle> argument = ArgumentCaptor.forClass(UserHandle.class);
verify(mActivity)
.startActivityForResultAsUser(any(Intent.class), anyInt(), argument.capture());
assertThat(argument.getValue().getIdentifier()).isEqualTo(userId);
verify(mActivity, never()).getSupportFragmentManager();
}
@Test
public void openTileIntent_profileSelectionDialog_invalidUserHandleShouldShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.getIntent().putExtra(EXTRA_USER, new UserHandle(30));
final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0));
handles.add(new UserHandle(10));
tile.userHandle = handles;
mImpl.openTileIntent(mActivity, tile);
verify(mActivity, never())
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
verify(mActivity).getSupportFragmentManager();
}
}