Merge "Add logging for SettingsPanels"
This commit is contained in:
committed by
Android (Google) Code Review
commit
57b076fa76
@@ -18,6 +18,7 @@ package com.android.settings.panel;
|
||||
|
||||
import static com.android.settings.slices.CustomSliceRegistry.WIFI_SLICE_URI;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
@@ -53,4 +54,9 @@ public class FakePanelContent implements PanelContent {
|
||||
public Intent getSeeMoreIntent() {
|
||||
return INTENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.TESTING;
|
||||
}
|
||||
}
|
||||
|
@@ -22,10 +22,13 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -71,13 +74,14 @@ public class PanelFragmentTest {
|
||||
.get()
|
||||
.getSupportFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT, FAKE_EXTRA);
|
||||
doReturn(bundle).when(mPanelFragment).getArguments();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateView_adapterGetsDataset() {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT, FAKE_EXTRA);
|
||||
doReturn(bundle).when(mPanelFragment).getArguments();
|
||||
mPanelFragment.onCreateView(LayoutInflater.from(mContext),
|
||||
new LinearLayout(mContext), null);
|
||||
PanelSlicesAdapter adapter = mPanelFragment.mAdapter;
|
||||
@@ -85,4 +89,43 @@ public class PanelFragmentTest {
|
||||
assertThat(adapter.getData()).containsAllIn(mFakePanelContent.getSlices());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreate_logsOpenEvent() {
|
||||
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
||||
0,
|
||||
SettingsEnums.PAGE_VISIBLE,
|
||||
mFakePanelContent.getMetricsCategory(),
|
||||
null,
|
||||
0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void panelSeeMoreClick_logsCloseEvent() {
|
||||
final View.OnClickListener listener = mPanelFragment.getSeeMoreListener();
|
||||
|
||||
listener.onClick(null);
|
||||
|
||||
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
||||
0,
|
||||
SettingsEnums.PAGE_HIDE,
|
||||
mFakePanelContent.getMetricsCategory(),
|
||||
PanelLoggingContract.PanelClosedKeys.KEY_SEE_MORE,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void panelDoneClick_logsCloseEvent() {
|
||||
final View.OnClickListener listener = mPanelFragment.getCloseListener();
|
||||
|
||||
listener.onClick(null);
|
||||
|
||||
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
|
||||
0,
|
||||
SettingsEnums.PAGE_HIDE,
|
||||
mFakePanelContent.getMetricsCategory(),
|
||||
PanelLoggingContract.PanelClosedKeys.KEY_DONE,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
@@ -71,7 +71,7 @@ public class PanelSlicesAdapterTest {
|
||||
.getSupportFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
|
||||
mAdapter = new PanelSlicesAdapter(mPanelFragment, mFakePanelContent.getSlices());
|
||||
mAdapter = new PanelSlicesAdapter(mPanelFragment, mFakePanelContent);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -16,13 +16,25 @@
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_PACKAGE_NAME;
|
||||
import static com.android.settings.panel.SettingsPanelActivity.KEY_MEDIA_PACKAGE_NAME;
|
||||
import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Intent;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Intent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
@@ -31,6 +43,22 @@ import org.robolectric.RobolectricTestRunner;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SettingsPanelActivityTest {
|
||||
|
||||
private FakeFeatureFactory mFakeFeatureFactory;
|
||||
private FakeSettingsPanelActivity mSettingsPanelActivity;
|
||||
private PanelFeatureProvider mPanelFeatureProvider;
|
||||
private FakePanelContent mFakePanelContent;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mSettingsPanelActivity = Robolectric.buildActivity(FakeSettingsPanelActivity.class)
|
||||
.create().get();
|
||||
mPanelFeatureProvider = spy(new PanelFeatureProviderImpl());
|
||||
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
|
||||
mFakePanelContent = new FakePanelContent();
|
||||
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startMediaOutputSlice_withPackageName_bundleShouldHaveValue() {
|
||||
final Intent intent = new Intent()
|
||||
@@ -41,7 +69,7 @@ public class SettingsPanelActivityTest {
|
||||
final SettingsPanelActivity activity =
|
||||
Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
|
||||
|
||||
assertThat(activity.mBundle.getString(KEY_PANEL_PACKAGE_NAME))
|
||||
assertThat(activity.mBundle.getString(KEY_MEDIA_PACKAGE_NAME))
|
||||
.isEqualTo("com.google.android.music");
|
||||
assertThat(activity.mBundle.getString(KEY_PANEL_TYPE_ARGUMENT))
|
||||
.isEqualTo("com.android.settings.panel.action.MEDIA_OUTPUT");
|
||||
@@ -55,7 +83,23 @@ public class SettingsPanelActivityTest {
|
||||
final SettingsPanelActivity activity =
|
||||
Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
|
||||
|
||||
assertThat(activity.mBundle.containsKey(KEY_PANEL_PACKAGE_NAME)).isFalse();
|
||||
assertThat(activity.mBundle.containsKey(KEY_MEDIA_PACKAGE_NAME)).isFalse();
|
||||
assertThat(activity.mBundle.containsKey(KEY_PANEL_TYPE_ARGUMENT)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
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_CLICKED_OUT,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user