OSDN Git Service

Add logging for SettingsPanels
[android-x86/packages-apps-Settings.git] / tests / robotests / src / com / android / settings / panel / SettingsPanelActivityTest.java
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.settings.panel;
18
19 import static com.android.settings.panel.SettingsPanelActivity.KEY_MEDIA_PACKAGE_NAME;
20 import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT;
21
22 import static com.google.common.truth.Truth.assertThat;
23
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.spy;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
30
31 import android.app.settings.SettingsEnums;
32 import android.content.Intent;
33 import android.view.MotionEvent;
34
35 import com.android.settings.testutils.FakeFeatureFactory;
36
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.robolectric.Robolectric;
41 import org.robolectric.RobolectricTestRunner;
42
43 @RunWith(RobolectricTestRunner.class)
44 public class SettingsPanelActivityTest {
45
46     private FakeFeatureFactory mFakeFeatureFactory;
47     private FakeSettingsPanelActivity mSettingsPanelActivity;
48     private PanelFeatureProvider mPanelFeatureProvider;
49     private FakePanelContent mFakePanelContent;
50
51     @Before
52     public void setUp() {
53         mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
54         mSettingsPanelActivity = Robolectric.buildActivity(FakeSettingsPanelActivity.class)
55                 .create().get();
56         mPanelFeatureProvider = spy(new PanelFeatureProviderImpl());
57         mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
58         mFakePanelContent = new FakePanelContent();
59         doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
60     }
61
62     @Test
63     public void startMediaOutputSlice_withPackageName_bundleShouldHaveValue() {
64         final Intent intent = new Intent()
65                 .setAction("com.android.settings.panel.action.MEDIA_OUTPUT")
66                 .putExtra("com.android.settings.panel.extra.PACKAGE_NAME",
67                         "com.google.android.music");
68
69         final SettingsPanelActivity activity =
70                 Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
71
72         assertThat(activity.mBundle.getString(KEY_MEDIA_PACKAGE_NAME))
73                 .isEqualTo("com.google.android.music");
74         assertThat(activity.mBundle.getString(KEY_PANEL_TYPE_ARGUMENT))
75                 .isEqualTo("com.android.settings.panel.action.MEDIA_OUTPUT");
76     }
77
78     @Test
79     public void startMediaOutputSlice_withoutPackageName_bundleShouldNotHaveValue() {
80         final Intent intent = new Intent()
81                 .setAction("com.android.settings.panel.action.MEDIA_OUTPUT");
82
83         final SettingsPanelActivity activity =
84                 Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
85
86         assertThat(activity.mBundle.containsKey(KEY_MEDIA_PACKAGE_NAME)).isFalse();
87         assertThat(activity.mBundle.containsKey(KEY_PANEL_TYPE_ARGUMENT)).isFalse();
88     }
89
90     @Test
91     public void onTouchEvent_outsideAction_logsPanelClosed() {
92         final MotionEvent event = mock(MotionEvent.class);
93         when(event.getAction()).thenReturn(MotionEvent.ACTION_OUTSIDE);
94
95         mSettingsPanelActivity.onTouchEvent(event);
96
97         verify(mFakeFeatureFactory.metricsFeatureProvider).action(
98                 0,
99                 SettingsEnums.PAGE_HIDE,
100                 SettingsEnums.TESTING,
101                 PanelLoggingContract.PanelClosedKeys.KEY_CLICKED_OUT,
102                 0
103         );
104     }
105 }