Snap for 4939473 from 06c9bd2cdb to qt-release
Change-Id: I23c0115549f1abfe533b7cb053cd03e2cc8071b4
This commit is contained in:
@@ -56,9 +56,10 @@
|
||||
android:key="zen_mode_settings_category_schedule"
|
||||
android:title="@string/zen_category_schedule">
|
||||
<!-- DND duration settings -->
|
||||
<Preference
|
||||
<com.android.settings.notification.ZenDurationDialogPreference
|
||||
android:key="zen_mode_duration_settings"
|
||||
android:title="@string/zen_mode_duration_settings_title" />
|
||||
android:title="@string/zen_mode_duration_settings_title"
|
||||
android:widgetLayout="@null"/>
|
||||
|
||||
<!-- Automatic rules -->
|
||||
<Preference
|
||||
|
||||
@@ -64,7 +64,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
|
||||
@VisibleForTesting
|
||||
static final String STATE_CONDITION_EXPANDED = "condition_expanded";
|
||||
|
||||
static final String META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB = "com.android.settings.bg.argb";
|
||||
private final IconCache mCache;
|
||||
private final Context mContext;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -320,15 +320,25 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
if (!TextUtils.equals(tileIcon.getResPackage(), mContext.getPackageName())
|
||||
&& !(icon instanceof RoundedHomepageIcon)) {
|
||||
icon = new RoundedHomepageIcon(mContext, icon);
|
||||
final Bundle metaData = tile.getMetaData();
|
||||
try {
|
||||
final Bundle metaData = tile.getMetaData();
|
||||
if (metaData != null) {
|
||||
final int colorRes = metaData.getInt(
|
||||
TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT, 0 /* default */);
|
||||
if (colorRes != 0) {
|
||||
final int bgColor = mContext.getPackageManager()
|
||||
.getResourcesForApplication(tileIcon.getResPackage())
|
||||
.getColor(colorRes, null /* theme */);
|
||||
// Load from bg.argb first
|
||||
int bgColor = metaData.getInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB,
|
||||
0 /* default */);
|
||||
// Not found, load from bg.hint
|
||||
if (bgColor == 0) {
|
||||
final int colorRes = metaData.getInt(
|
||||
TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
|
||||
0 /* default */);
|
||||
if (colorRes != 0) {
|
||||
bgColor = mContext.getPackageManager()
|
||||
.getResourcesForApplication(tileIcon.getResPackage())
|
||||
.getColor(colorRes, null /* theme */);
|
||||
}
|
||||
}
|
||||
// If found anything, use it.
|
||||
if (bgColor != 0) {
|
||||
((RoundedHomepageIcon) icon).setBackgroundColor(bgColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settingslib.CustomDialogPreferenceCompat;
|
||||
import com.android.settingslib.notification.ZenDurationDialog;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
public class ZenDurationDialogPreference extends CustomDialogPreferenceCompat {
|
||||
|
||||
public ZenDurationDialogPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public ZenDurationDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public ZenDurationDialogPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder,
|
||||
DialogInterface.OnClickListener listener) {
|
||||
super.onPrepareDialogBuilder(builder, listener);
|
||||
|
||||
ZenDurationDialog zenDialog = new ZenDurationDialog(getContext());
|
||||
zenDialog.setupDialog(builder);
|
||||
}
|
||||
}
|
||||
@@ -22,21 +22,13 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
public class ZenModeDurationPreferenceController extends AbstractZenModePreferenceController
|
||||
implements PreferenceControllerMixin, Preference.OnPreferenceClickListener {
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
private static final String TAG = "ZenModeDurationDialog";
|
||||
protected static final String KEY = "zen_mode_duration_settings";
|
||||
private FragmentManager mFragment;
|
||||
|
||||
public ZenModeDurationPreferenceController(Context context, Lifecycle lifecycle, FragmentManager
|
||||
fragment) {
|
||||
public ZenModeDurationPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, KEY, lifecycle);
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,16 +42,8 @@ public class ZenModeDurationPreferenceController extends AbstractZenModePreferen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
screen.findPreference(KEY).setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
String summary = "";
|
||||
public CharSequence getSummary() {
|
||||
String summary;
|
||||
int zenDuration = getZenDuration();
|
||||
if (zenDuration < 0) {
|
||||
summary = mContext.getString(R.string.zen_mode_duration_summary_always_prompt);
|
||||
@@ -76,12 +60,6 @@ public class ZenModeDurationPreferenceController extends AbstractZenModePreferen
|
||||
}
|
||||
}
|
||||
|
||||
preference.setSummary(summary);
|
||||
return summary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new SettingsZenDurationDialog().show(mFragment, TAG);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +86,7 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
controllers.add(new ZenModeBehaviorSoundPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeBehaviorCallsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle,
|
||||
fragmentManager));
|
||||
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeAutomationPreferenceController(context));
|
||||
controllers.add(new ZenModeButtonPreferenceController(context, lifecycle, fragmentManager));
|
||||
controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle));
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.android.settingslib.drawable.CircleFramedDrawable;
|
||||
import java.io.File;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
/**
|
||||
@@ -103,9 +104,8 @@ public class EditUserInfoController {
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
mWaitingForActivityResult = false;
|
||||
|
||||
if (mEditUserInfoDialog != null && mEditUserInfoDialog.isShowing()
|
||||
&& mEditUserPhotoController.onActivityResult(requestCode, resultCode, data)) {
|
||||
return;
|
||||
if (mEditUserInfoDialog != null) {
|
||||
mEditUserPhotoController.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class EditUserInfoController {
|
||||
Activity activity = fragment.getActivity();
|
||||
mUser = user;
|
||||
if (mUserManager == null) {
|
||||
mUserManager = UserManager.get(activity);
|
||||
mUserManager = activity.getSystemService(UserManager.class);
|
||||
}
|
||||
LayoutInflater inflater = activity.getLayoutInflater();
|
||||
View content = inflater.inflate(R.layout.edit_user_info_dialog_content, null);
|
||||
@@ -136,8 +136,7 @@ public class EditUserInfoController {
|
||||
}
|
||||
}
|
||||
userPhotoView.setImageDrawable(drawable);
|
||||
mEditUserPhotoController = new EditUserPhotoController(fragment, userPhotoView,
|
||||
mSavedPhoto, drawable, mWaitingForActivityResult);
|
||||
mEditUserPhotoController = createEditUserPhotoController(fragment, userPhotoView, drawable);
|
||||
mEditUserInfoDialog = new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.profile_info_settings_title)
|
||||
.setView(content)
|
||||
@@ -195,4 +194,11 @@ public class EditUserInfoController {
|
||||
|
||||
return mEditUserInfoDialog;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
EditUserPhotoController createEditUserPhotoController(Fragment fragment,
|
||||
ImageView userPhotoView, Drawable drawable) {
|
||||
return new EditUserPhotoController(fragment, userPhotoView,
|
||||
mSavedPhoto, drawable, mWaitingForActivityResult);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ public class FingerprintEnrollEnrollingTest {
|
||||
anyInt(),
|
||||
nullable(String.class),
|
||||
any(VibrationEffect.class),
|
||||
nullable(String.class),
|
||||
nullable(AudioAttributes.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,8 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.HeadsetProfile;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -61,12 +58,6 @@ public class BluetoothDeviceUpdaterTest {
|
||||
private SettingsActivity mSettingsActivity;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalManager;
|
||||
@Mock
|
||||
private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
|
||||
@Mock
|
||||
private HeadsetProfile mHeadsetProfile;
|
||||
@Mock
|
||||
private A2dpProfile mA2dpProfile;
|
||||
|
||||
private Context mContext;
|
||||
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||
@@ -79,9 +70,6 @@ public class BluetoothDeviceUpdaterTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
doReturn(mContext).when(mDashboardFragment).getContext();
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
||||
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
|
||||
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
|
||||
|
||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
|
||||
mBluetoothDeviceUpdater =
|
||||
|
||||
@@ -241,6 +241,30 @@ public class DashboardAdapterTest {
|
||||
.isInstanceOf(RoundedHomepageIcon.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindTile_externalTileWithBackgroundColorRawValue_shouldUpdateIcon() {
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
|
||||
final DashboardAdapter.DashboardItemHolder holder =
|
||||
new DashboardAdapter.DashboardItemHolder(view);
|
||||
final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
|
||||
tile.getMetaData().putInt(DashboardAdapter.META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB,
|
||||
0xff0000);
|
||||
doReturn(Icon.createWithResource(context, R.drawable.ic_settings))
|
||||
.when(tile).getIcon(context);
|
||||
final IconCache iconCache = new IconCache(context);
|
||||
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
|
||||
|
||||
doReturn("another.package").when(context).getPackageName();
|
||||
mDashboardAdapter.onBindTile(holder, tile);
|
||||
|
||||
final RoundedHomepageIcon homepageIcon = (RoundedHomepageIcon) iconCache.getIcon(
|
||||
tile.getIcon(context));
|
||||
assertThat(homepageIcon.mBackgroundColor).isEqualTo(0xff0000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindTile_externalTileWithBackgroundColorHint_shouldUpdateIcon() {
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
@@ -38,10 +38,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class ZenModeDurationPreferenceControllerTest {
|
||||
private ZenModeDurationPreferenceController mController;
|
||||
@@ -51,11 +47,7 @@ public class ZenModeDurationPreferenceControllerTest {
|
||||
@Mock
|
||||
private NotificationManager mNotificationManager;
|
||||
@Mock
|
||||
private Preference mockPref;
|
||||
@Mock
|
||||
private NotificationManager.Policy mPolicy;
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
private ContentResolver mContentResolver;
|
||||
private Context mContext;
|
||||
|
||||
@@ -67,34 +59,27 @@ public class ZenModeDurationPreferenceControllerTest {
|
||||
|
||||
mContext = shadowApplication.getApplicationContext();
|
||||
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||
mController = new ZenModeDurationPreferenceController(mContext, mock(Lifecycle.class),
|
||||
mock(FragmentManager.class));
|
||||
mController = new ZenModeDurationPreferenceController(mContext, mock(Lifecycle.class));
|
||||
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
|
||||
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
|
||||
mockPref);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_DurationForever() {
|
||||
Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
|
||||
Settings.Secure.ZEN_DURATION_FOREVER);
|
||||
final Preference mockPref = mock(Preference.class);
|
||||
mController.updateState(mockPref);
|
||||
|
||||
verify(mockPref).setSummary(mContext.getString(R.string.zen_mode_duration_summary_forever));
|
||||
assertEquals(mContext.getString(R.string.zen_mode_duration_summary_forever),
|
||||
mController.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_DurationPrompt() {
|
||||
Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
|
||||
Settings.Secure.ZEN_DURATION_PROMPT);
|
||||
final Preference mockPref = mock(Preference.class);
|
||||
mController.updateState(mockPref);
|
||||
|
||||
verify(mockPref).setSummary(mContext.getString(
|
||||
R.string.zen_mode_duration_summary_always_prompt));
|
||||
assertEquals(mContext.getString(R.string.zen_mode_duration_summary_always_prompt),
|
||||
mController.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,10 +87,8 @@ public class ZenModeDurationPreferenceControllerTest {
|
||||
int zenDuration = 45;
|
||||
Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
|
||||
zenDuration);
|
||||
final Preference mockPref = mock(Preference.class);
|
||||
mController.updateState(mockPref);
|
||||
|
||||
verify(mockPref).setSummary(mContext.getResources().getString(
|
||||
R.string.zen_mode_duration_summary_time_minutes, zenDuration));
|
||||
assertEquals(mContext.getString(R.string.zen_mode_duration_summary_time_minutes,
|
||||
zenDuration), mController.getSummary());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ public class ShadowVibrator {
|
||||
public final Vibrator delegate = mock(Vibrator.class);
|
||||
|
||||
@Implementation
|
||||
public void vibrate(int uid, String opPkg, VibrationEffect vibe, AudioAttributes attributes) {
|
||||
delegate.vibrate(uid, opPkg, vibe, attributes);
|
||||
public void vibrate(int uid, String opPkg, VibrationEffect vibe, String reason,
|
||||
AudioAttributes attributes) {
|
||||
delegate.vibrate(uid, opPkg, vibe, reason, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.users;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.Robolectric;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
|
||||
import org.junit.After;
|
||||
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.annotation.Config;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowUserManager.class})
|
||||
public class EditUserInfoControllerTest {
|
||||
@Mock
|
||||
private Fragment mFragment;
|
||||
@Mock
|
||||
private LayoutInflater mInflater;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UserInfo mUserInfo;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private View mDialogContent;
|
||||
@Mock
|
||||
private EditText mUserName;
|
||||
@Mock
|
||||
private ImageView mPhotoView;
|
||||
@Mock
|
||||
private Drawable mCurrentIcon;
|
||||
|
||||
private ShadowUserManager mUserManager;
|
||||
private FragmentActivity mActivity;
|
||||
private TestEditUserInfoController mController;
|
||||
|
||||
public class TestEditUserInfoController extends EditUserInfoController {
|
||||
private EditUserPhotoController mPhotoController;
|
||||
|
||||
public EditUserPhotoController getPhotoController() {
|
||||
return mPhotoController;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EditUserPhotoController createEditUserPhotoController(Fragment fragment,
|
||||
ImageView userPhotoView, Drawable drawable) {
|
||||
mPhotoController = mock(EditUserPhotoController.class, Answers.RETURNS_DEEP_STUBS);
|
||||
return mPhotoController;
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mUserManager = ShadowUserManager.getShadow();
|
||||
mUserManager.setUserInfo(0, mUserInfo);
|
||||
mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).get());
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getLayoutInflater()).thenReturn(mInflater);
|
||||
when(mInflater.inflate(eq(R.layout.edit_user_info_dialog_content), any())).thenReturn(
|
||||
mDialogContent);
|
||||
when(mDialogContent.findViewById(eq(R.id.user_name))).thenReturn(mUserName);
|
||||
when(mDialogContent.findViewById(eq(R.id.user_photo))).thenReturn(mPhotoView);
|
||||
when(mPhotoView.getContext()).thenReturn((Context) mActivity);
|
||||
mController = new TestEditUserInfoController();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
mUserManager.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void photoControllerOnActivityResult_whenWaiting_isCalled() {
|
||||
mController.createDialog(mFragment, mCurrentIcon, "test user",
|
||||
R.string.profile_info_settings_title, null, android.os.Process.myUserHandle());
|
||||
mController.startingActivityForResult();
|
||||
Intent resultData = new Intent();
|
||||
mController.onActivityResult(0, 0, resultData);
|
||||
EditUserPhotoController photoController = mController.getPhotoController();
|
||||
assertThat(photoController).isNotNull();
|
||||
verify(photoController).onActivityResult(eq(0), eq(0), same(resultData));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user