Merge "Move profile selector dialog to Settings"
This commit is contained in:
committed by
Android (Google) Code Review
commit
eda8a01c23
@@ -29,6 +29,10 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.PendingIntent;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListUpdateCallback;
|
||||
|
||||
import com.android.settings.dashboard.conditional.AirplaneModeCondition;
|
||||
import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -46,10 +50,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListUpdateCallback;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class DashboardDataTest {
|
||||
|
||||
@@ -95,7 +95,6 @@ public class DashboardDataTest {
|
||||
|
||||
// Build category
|
||||
mTestCategoryTile.title = TEST_CATEGORY_TILE_TITLE;
|
||||
mDashboardCategory.title = "test";
|
||||
|
||||
mDashboardCategory.addTile(mTestCategoryTile);
|
||||
|
||||
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.dashboard.profileselector;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class ProfileSelectDialogTest {
|
||||
|
||||
private static final UserHandle NORMAL_USER = UserHandle.of(1111);
|
||||
private static final UserHandle REMOVED_USER = UserHandle.of(2222);
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
final UserInfo userInfo = new UserInfo(
|
||||
NORMAL_USER.getIdentifier(), "test_user", UserInfo.FLAG_RESTRICTED);
|
||||
when(mUserManager.getUserInfo(NORMAL_USER.getIdentifier())).thenReturn(userInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateUserHandlesIfNeeded_Normal() {
|
||||
final Tile tile = new Tile(new ActivityInfo());
|
||||
tile.intent = new Intent();
|
||||
tile.userHandle.add(NORMAL_USER);
|
||||
|
||||
ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
|
||||
|
||||
assertThat(tile.userHandle).hasSize(1);
|
||||
assertThat(tile.userHandle.get(0).getIdentifier()).isEqualTo(NORMAL_USER.getIdentifier());
|
||||
verify(mUserManager, never()).getUserInfo(NORMAL_USER.getIdentifier());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateUserHandlesIfNeeded_Remove() {
|
||||
final Tile tile = new Tile(new ActivityInfo());
|
||||
tile.intent = new Intent();
|
||||
tile.userHandle.add(REMOVED_USER);
|
||||
tile.userHandle.add(NORMAL_USER);
|
||||
tile.userHandle.add(REMOVED_USER);
|
||||
|
||||
ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
|
||||
|
||||
assertThat(tile.userHandle).hasSize(1);
|
||||
assertThat(tile.userHandle.get(0).getIdentifier()).isEqualTo(NORMAL_USER.getIdentifier());
|
||||
verify(mUserManager, times(1)).getUserInfo(NORMAL_USER.getIdentifier());
|
||||
verify(mUserManager, times(2)).getUserInfo(REMOVED_USER.getIdentifier());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user