Merge "Fix robotests in settings/panel" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3225026ed6
@@ -36,20 +36,19 @@ import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.android.controller.ActivityController;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PanelFragmentTest {
|
||||
|
||||
private Context mContext;
|
||||
private PanelFragment mPanelFragment;
|
||||
private FakeSettingsPanelActivity mActivity;
|
||||
private FakeFeatureFactory mFakeFeatureFactory;
|
||||
private PanelFeatureProvider mPanelFeatureProvider;
|
||||
private FakePanelContent mFakePanelContent;
|
||||
@@ -66,16 +65,12 @@ public class PanelFragmentTest {
|
||||
mFakePanelContent = new FakePanelContent();
|
||||
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
|
||||
|
||||
ActivityController<FakeSettingsPanelActivity> activityController =
|
||||
Robolectric.buildActivity(FakeSettingsPanelActivity.class);
|
||||
activityController.setup();
|
||||
mActivity = spy(Robolectric.buildActivity(FakeSettingsPanelActivity.class).setup().get());
|
||||
|
||||
mPanelFragment =
|
||||
spy((PanelFragment)
|
||||
activityController
|
||||
.get()
|
||||
.getSupportFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
mActivity.getSupportFragmentManager().findFragmentById(R.id.main_content));
|
||||
doReturn(mActivity).when(mPanelFragment).getActivity();
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT, FAKE_EXTRA);
|
||||
@@ -106,23 +101,23 @@ public class PanelFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/130896218")
|
||||
public void onDestroy_logCloseEvent() {
|
||||
mPanelFragment.onDestroy();
|
||||
mPanelFragment.onDestroyView();
|
||||
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
||||
0,
|
||||
SettingsEnums.PAGE_VISIBLE,
|
||||
SettingsEnums.PAGE_HIDE,
|
||||
mFakePanelContent.getMetricsCategory(),
|
||||
any(String.class),
|
||||
0); }
|
||||
PanelLoggingContract.PanelClosedKeys.KEY_OTHERS,
|
||||
0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/130896218")
|
||||
public void panelSeeMoreClick_logsCloseEvent() {
|
||||
final View.OnClickListener listener = mPanelFragment.getSeeMoreListener();
|
||||
|
||||
listener.onClick(null);
|
||||
verify(mActivity).finish();
|
||||
|
||||
mPanelFragment.onDestroyView();
|
||||
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
||||
0,
|
||||
SettingsEnums.PAGE_HIDE,
|
||||
@@ -133,12 +128,12 @@ public class PanelFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/130896218")
|
||||
public void panelDoneClick_logsCloseEvent() {
|
||||
final View.OnClickListener listener = mPanelFragment.getCloseListener();
|
||||
|
||||
listener.onClick(null);
|
||||
verify(mActivity).finish();
|
||||
|
||||
mPanelFragment.onDestroyView();
|
||||
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
||||
0,
|
||||
SettingsEnums.PAGE_HIDE,
|
||||
|
@@ -35,7 +35,6 @@ import android.view.MotionEvent;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
@@ -52,8 +51,8 @@ public class SettingsPanelActivityTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mSettingsPanelActivity = Robolectric.buildActivity(FakeSettingsPanelActivity.class)
|
||||
.create().get();
|
||||
mSettingsPanelActivity = spy(
|
||||
Robolectric.buildActivity(FakeSettingsPanelActivity.class).create().get());
|
||||
mPanelFeatureProvider = spy(new PanelFeatureProviderImpl());
|
||||
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
|
||||
mFakePanelContent = new FakePanelContent();
|
||||
@@ -88,21 +87,4 @@ public class SettingsPanelActivityTest {
|
||||
assertThat(activity.mBundle.getString(KEY_PANEL_TYPE_ARGUMENT))
|
||||
.isEqualTo("com.android.settings.panel.action.MEDIA_OUTPUT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/130896218")
|
||||
public void onTouchEvent_outsideAction_logsPanelClosed() {
|
||||
final MotionEvent event = mock(MotionEvent.class);
|
||||
when(event.getAction()).thenReturn(MotionEvent.ACTION_OUTSIDE);
|
||||
|
||||
mSettingsPanelActivity.onTouchEvent(event);
|
||||
|
||||
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
||||
0,
|
||||
SettingsEnums.PAGE_HIDE,
|
||||
SettingsEnums.TESTING,
|
||||
PanelLoggingContract.PanelClosedKeys.KEY_OTHERS,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -18,32 +18,71 @@ package com.android.settings.panel;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.session.ISessionController;
|
||||
import android.media.session.MediaController;
|
||||
import android.media.session.MediaSession;
|
||||
import android.media.session.MediaSessionManager;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.android.settings.notification.RemoteVolumePreferenceController;
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
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.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class VolumePanelTest {
|
||||
|
||||
@Mock
|
||||
private MediaSessionManager mMediaSessionManager;
|
||||
@Mock
|
||||
private MediaController mMediaController;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private ISessionController mStub;
|
||||
|
||||
|
||||
private VolumePanel mPanel;
|
||||
private Context mContext;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mPanel = VolumePanel.create(RuntimeEnvironment.application);
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getSystemService(MediaSessionManager.class)).thenReturn(mMediaSessionManager);
|
||||
|
||||
mPanel = VolumePanel.create(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/130896218")
|
||||
public void getSlices_containsNecessarySlices() {
|
||||
public void getSlices_hasActiveRemoteToken_containsRemoteMediaUri() {
|
||||
List<MediaController> activeSessions = new ArrayList<>();
|
||||
MediaSession.Token token = new MediaSession.Token(mStub);
|
||||
activeSessions.add(mMediaController);
|
||||
|
||||
when(mMediaSessionManager.getActiveSessions(null)).thenReturn(
|
||||
activeSessions);
|
||||
when(mMediaController.getPlaybackInfo()).thenReturn(new MediaController.PlaybackInfo(
|
||||
MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE, 0, 10, 5, null));
|
||||
when(mMediaController.getSessionToken()).thenReturn(new MediaSession.Token(mStub));
|
||||
when(RemoteVolumePreferenceController.getActiveRemoteToken(mContext)).thenReturn(token);
|
||||
|
||||
final List<Uri> uris = mPanel.getSlices();
|
||||
|
||||
assertThat(uris).containsExactly(
|
||||
@@ -55,6 +94,22 @@ public class VolumePanelTest {
|
||||
CustomSliceRegistry.VOLUME_ALARM_URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlices_doesNotHaveActiveRemoteToken_doesNotcontainRemoteMediaUri() {
|
||||
final List<Uri> uris = mPanel.getSlices();
|
||||
|
||||
when(RemoteVolumePreferenceController.getActiveRemoteToken(mContext))
|
||||
.thenReturn(null);
|
||||
|
||||
assertThat(uris).doesNotContain(CustomSliceRegistry.VOLUME_REMOTE_MEDIA_URI);
|
||||
assertThat(uris).containsExactly(
|
||||
CustomSliceRegistry.VOLUME_CALL_URI,
|
||||
CustomSliceRegistry.VOLUME_MEDIA_URI,
|
||||
CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI,
|
||||
CustomSliceRegistry.VOLUME_RINGER_URI,
|
||||
CustomSliceRegistry.VOLUME_ALARM_URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSeeMoreIntent_notNull() {
|
||||
assertThat(mPanel.getSeeMoreIntent()).isNotNull();
|
||||
|
Reference in New Issue
Block a user