Fix robotests in settings/panel
Remove @Ignore for tests in settings/panel after testing. Also update VolumePanelTest according to the recent changes to remote volume slice. Test: atest PanelFragmentTest Test: atest SettingsPanelActivityTest Test: VolumePanelTest Fixes: 130896218 Change-Id: Iaa99e65d959cafd382d7209664f2fdbf660c29e0
This commit is contained in:
@@ -36,20 +36,19 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.robolectric.Robolectric;
|
import org.robolectric.Robolectric;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.android.controller.ActivityController;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class PanelFragmentTest {
|
public class PanelFragmentTest {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PanelFragment mPanelFragment;
|
private PanelFragment mPanelFragment;
|
||||||
|
private FakeSettingsPanelActivity mActivity;
|
||||||
private FakeFeatureFactory mFakeFeatureFactory;
|
private FakeFeatureFactory mFakeFeatureFactory;
|
||||||
private PanelFeatureProvider mPanelFeatureProvider;
|
private PanelFeatureProvider mPanelFeatureProvider;
|
||||||
private FakePanelContent mFakePanelContent;
|
private FakePanelContent mFakePanelContent;
|
||||||
@@ -66,16 +65,12 @@ public class PanelFragmentTest {
|
|||||||
mFakePanelContent = new FakePanelContent();
|
mFakePanelContent = new FakePanelContent();
|
||||||
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
|
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
|
||||||
|
|
||||||
ActivityController<FakeSettingsPanelActivity> activityController =
|
mActivity = spy(Robolectric.buildActivity(FakeSettingsPanelActivity.class).setup().get());
|
||||||
Robolectric.buildActivity(FakeSettingsPanelActivity.class);
|
|
||||||
activityController.setup();
|
|
||||||
|
|
||||||
mPanelFragment =
|
mPanelFragment =
|
||||||
spy((PanelFragment)
|
spy((PanelFragment)
|
||||||
activityController
|
mActivity.getSupportFragmentManager().findFragmentById(R.id.main_content));
|
||||||
.get()
|
doReturn(mActivity).when(mPanelFragment).getActivity();
|
||||||
.getSupportFragmentManager()
|
|
||||||
.findFragmentById(R.id.main_content));
|
|
||||||
|
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT, FAKE_EXTRA);
|
bundle.putString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT, FAKE_EXTRA);
|
||||||
@@ -106,23 +101,23 @@ public class PanelFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("b/130896218")
|
|
||||||
public void onDestroy_logCloseEvent() {
|
public void onDestroy_logCloseEvent() {
|
||||||
mPanelFragment.onDestroy();
|
mPanelFragment.onDestroyView();
|
||||||
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
||||||
0,
|
0,
|
||||||
SettingsEnums.PAGE_VISIBLE,
|
SettingsEnums.PAGE_HIDE,
|
||||||
mFakePanelContent.getMetricsCategory(),
|
mFakePanelContent.getMetricsCategory(),
|
||||||
any(String.class),
|
PanelLoggingContract.PanelClosedKeys.KEY_OTHERS,
|
||||||
0); }
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("b/130896218")
|
|
||||||
public void panelSeeMoreClick_logsCloseEvent() {
|
public void panelSeeMoreClick_logsCloseEvent() {
|
||||||
final View.OnClickListener listener = mPanelFragment.getSeeMoreListener();
|
final View.OnClickListener listener = mPanelFragment.getSeeMoreListener();
|
||||||
|
|
||||||
listener.onClick(null);
|
listener.onClick(null);
|
||||||
|
verify(mActivity).finish();
|
||||||
|
|
||||||
|
mPanelFragment.onDestroyView();
|
||||||
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
||||||
0,
|
0,
|
||||||
SettingsEnums.PAGE_HIDE,
|
SettingsEnums.PAGE_HIDE,
|
||||||
@@ -133,12 +128,12 @@ public class PanelFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("b/130896218")
|
|
||||||
public void panelDoneClick_logsCloseEvent() {
|
public void panelDoneClick_logsCloseEvent() {
|
||||||
final View.OnClickListener listener = mPanelFragment.getCloseListener();
|
final View.OnClickListener listener = mPanelFragment.getCloseListener();
|
||||||
|
|
||||||
listener.onClick(null);
|
listener.onClick(null);
|
||||||
|
verify(mActivity).finish();
|
||||||
|
|
||||||
|
mPanelFragment.onDestroyView();
|
||||||
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
||||||
0,
|
0,
|
||||||
SettingsEnums.PAGE_HIDE,
|
SettingsEnums.PAGE_HIDE,
|
||||||
|
@@ -35,7 +35,6 @@ import android.view.MotionEvent;
|
|||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.Robolectric;
|
import org.robolectric.Robolectric;
|
||||||
@@ -52,8 +51,8 @@ public class SettingsPanelActivityTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mSettingsPanelActivity = Robolectric.buildActivity(FakeSettingsPanelActivity.class)
|
mSettingsPanelActivity = spy(
|
||||||
.create().get();
|
Robolectric.buildActivity(FakeSettingsPanelActivity.class).create().get());
|
||||||
mPanelFeatureProvider = spy(new PanelFeatureProviderImpl());
|
mPanelFeatureProvider = spy(new PanelFeatureProviderImpl());
|
||||||
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
|
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
|
||||||
mFakePanelContent = new FakePanelContent();
|
mFakePanelContent = new FakePanelContent();
|
||||||
@@ -88,21 +87,4 @@ public class SettingsPanelActivityTest {
|
|||||||
assertThat(activity.mBundle.getString(KEY_PANEL_TYPE_ARGUMENT))
|
assertThat(activity.mBundle.getString(KEY_PANEL_TYPE_ARGUMENT))
|
||||||
.isEqualTo("com.android.settings.panel.action.MEDIA_OUTPUT");
|
.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 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 android.net.Uri;
|
||||||
|
|
||||||
|
import com.android.settings.notification.RemoteVolumePreferenceController;
|
||||||
import com.android.settings.slices.CustomSliceRegistry;
|
import com.android.settings.slices.CustomSliceRegistry;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class VolumePanelTest {
|
public class VolumePanelTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private MediaSessionManager mMediaSessionManager;
|
||||||
|
@Mock
|
||||||
|
private MediaController mMediaController;
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private ISessionController mStub;
|
||||||
|
|
||||||
|
|
||||||
private VolumePanel mPanel;
|
private VolumePanel mPanel;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
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
|
@Test
|
||||||
@Ignore("b/130896218")
|
public void getSlices_hasActiveRemoteToken_containsRemoteMediaUri() {
|
||||||
public void getSlices_containsNecessarySlices() {
|
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();
|
final List<Uri> uris = mPanel.getSlices();
|
||||||
|
|
||||||
assertThat(uris).containsExactly(
|
assertThat(uris).containsExactly(
|
||||||
@@ -55,6 +94,22 @@ public class VolumePanelTest {
|
|||||||
CustomSliceRegistry.VOLUME_ALARM_URI);
|
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
|
@Test
|
||||||
public void getSeeMoreIntent_notNull() {
|
public void getSeeMoreIntent_notNull() {
|
||||||
assertThat(mPanel.getSeeMoreIntent()).isNotNull();
|
assertThat(mPanel.getSeeMoreIntent()).isNotNull();
|
||||||
|
Reference in New Issue
Block a user