2 * Copyright (C) 2019 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.panel;
19 import static com.android.settings.panel.SettingsPanelActivity.KEY_MEDIA_PACKAGE_NAME;
20 import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT;
22 import static com.google.common.truth.Truth.assertThat;
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;
31 import android.app.settings.SettingsEnums;
32 import android.content.Intent;
33 import android.view.MotionEvent;
35 import com.android.settings.testutils.FakeFeatureFactory;
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;
43 @RunWith(RobolectricTestRunner.class)
44 public class SettingsPanelActivityTest {
46 private FakeFeatureFactory mFakeFeatureFactory;
47 private FakeSettingsPanelActivity mSettingsPanelActivity;
48 private PanelFeatureProvider mPanelFeatureProvider;
49 private FakePanelContent mFakePanelContent;
53 mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
54 mSettingsPanelActivity = Robolectric.buildActivity(FakeSettingsPanelActivity.class)
56 mPanelFeatureProvider = spy(new PanelFeatureProviderImpl());
57 mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
58 mFakePanelContent = new FakePanelContent();
59 doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
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");
69 final SettingsPanelActivity activity =
70 Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
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");
79 public void startMediaOutputSlice_withoutPackageName_bundleShouldNotHaveValue() {
80 final Intent intent = new Intent()
81 .setAction("com.android.settings.panel.action.MEDIA_OUTPUT");
83 final SettingsPanelActivity activity =
84 Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
86 assertThat(activity.mBundle.containsKey(KEY_MEDIA_PACKAGE_NAME)).isFalse();
87 assertThat(activity.mBundle.containsKey(KEY_PANEL_TYPE_ARGUMENT)).isFalse();
91 public void onTouchEvent_outsideAction_logsPanelClosed() {
92 final MotionEvent event = mock(MotionEvent.class);
93 when(event.getAction()).thenReturn(MotionEvent.ACTION_OUTSIDE);
95 mSettingsPanelActivity.onTouchEvent(event);
97 verify(mFakeFeatureFactory.metricsFeatureProvider).action(
99 SettingsEnums.PAGE_HIDE,
100 SettingsEnums.TESTING,
101 PanelLoggingContract.PanelClosedKeys.KEY_CLICKED_OUT,