The old logging only include see_more, done, and clicked_out when hiding the panel page. We were missing many cases that user might use back button, app switch button to close the page. Update the hide page keys to change the clicked_out to others to include all the other cases which hide the page. Test: Manual verification Test: atest PanelFragmentTest SettingsPanelActivityTest Fixes: 130169553 Change-Id: Icede9a8dcb84565cba183963c9fb554507631c98
107 lines
4.1 KiB
Java
107 lines
4.1 KiB
Java
/*
|
|
* Copyright (C) 2019 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.panel;
|
|
|
|
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 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;
|
|
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()
|
|
.setAction("com.android.settings.panel.action.MEDIA_OUTPUT")
|
|
.putExtra("com.android.settings.panel.extra.PACKAGE_NAME",
|
|
"com.google.android.music");
|
|
|
|
final SettingsPanelActivity activity =
|
|
Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
|
|
|
|
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");
|
|
}
|
|
|
|
@Test
|
|
public void startMediaOutputSlice_withoutPackageName_bundleShouldHaveValue() {
|
|
final Intent intent = new Intent()
|
|
.setAction("com.android.settings.panel.action.MEDIA_OUTPUT");
|
|
|
|
final SettingsPanelActivity activity =
|
|
Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
|
|
|
|
assertThat(activity.mBundle.containsKey(KEY_MEDIA_PACKAGE_NAME)).isTrue();
|
|
assertThat(activity.mBundle.getString(KEY_PANEL_TYPE_ARGUMENT))
|
|
.isEqualTo("com.android.settings.panel.action.MEDIA_OUTPUT");
|
|
}
|
|
|
|
@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_OTHERS,
|
|
0
|
|
);
|
|
}
|
|
}
|