blob: c6b31d03ff3b9e131cda13d67a1ea91e89f68b4d [file] [log] [blame]
Jason Monk8c09ac72017-03-16 11:53:40 -04001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.qs;
16
Fabian Kozynskie3137e32018-09-28 11:20:04 -040017import static org.mockito.ArgumentMatchers.any;
18import static org.mockito.ArgumentMatchers.anyBoolean;
19import static org.mockito.ArgumentMatchers.anyInt;
Jason Monk8c09ac72017-03-16 11:53:40 -040020import static org.mockito.ArgumentMatchers.eq;
21import static org.mockito.Mockito.mock;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040022import static org.mockito.Mockito.never;
Jason Monk8c09ac72017-03-16 11:53:40 -040023import static org.mockito.Mockito.verify;
Jason Monkfba8faf2017-05-23 10:42:59 -040024import static org.mockito.Mockito.when;
Jason Monk8c09ac72017-03-16 11:53:40 -040025
26import android.testing.AndroidTestingRunner;
27import android.testing.TestableLooper;
28import android.testing.TestableLooper.RunWithLooper;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040029import android.view.ViewGroup;
30import android.widget.FrameLayout;
Jason Monk8c09ac72017-03-16 11:53:40 -040031
Brett Chabot84151d92019-02-27 15:37:59 -080032import androidx.test.filters.SmallTest;
33
Jason Monk8c09ac72017-03-16 11:53:40 -040034import com.android.internal.logging.MetricsLogger;
35import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
36import com.android.systemui.SysuiTestCase;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040037import com.android.systemui.plugins.qs.QSTile;
38import com.android.systemui.plugins.qs.QSTileView;
Jason Monk8c09ac72017-03-16 11:53:40 -040039import com.android.systemui.qs.customize.QSCustomizer;
40
41import org.junit.Before;
42import org.junit.Test;
43import org.junit.runner.RunWith;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040044import org.mockito.Mock;
45import org.mockito.MockitoAnnotations;
Jason Monk8c09ac72017-03-16 11:53:40 -040046
47import java.util.Collections;
48
49@RunWith(AndroidTestingRunner.class)
50@RunWithLooper
Jason Monkfba8faf2017-05-23 10:42:59 -040051@SmallTest
Jason Monk8c09ac72017-03-16 11:53:40 -040052public class QSPanelTest extends SysuiTestCase {
53
54 private MetricsLogger mMetricsLogger;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040055 private TestableLooper mTestableLooper;
Jason Monk8c09ac72017-03-16 11:53:40 -040056 private QSPanel mQsPanel;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040057 @Mock
Jason Monk8c09ac72017-03-16 11:53:40 -040058 private QSTileHost mHost;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040059 @Mock
Jason Monk8c09ac72017-03-16 11:53:40 -040060 private QSCustomizer mCustomizer;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040061 @Mock
62 private QSTile dndTile;
63 private ViewGroup mParentView;
64 @Mock
65 private QSDetail.Callback mCallback;
Jason Monk8c09ac72017-03-16 11:53:40 -040066
67 @Before
68 public void setup() throws Exception {
Fabian Kozynskie3137e32018-09-28 11:20:04 -040069 MockitoAnnotations.initMocks(this);
70
71 mTestableLooper = TestableLooper.get(this);
72 mTestableLooper.runWithLooper(() -> {
Jason Monk8c09ac72017-03-16 11:53:40 -040073 mMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class);
74 mQsPanel = new QSPanel(mContext, null);
Fabian Kozynskie3137e32018-09-28 11:20:04 -040075 // Provides a parent with non-zero size for QSPanel
76 mParentView = new FrameLayout(mContext);
77 mParentView.addView(mQsPanel);
78
79 when(dndTile.getTileSpec()).thenReturn("dnd");
Jason Monk8c09ac72017-03-16 11:53:40 -040080 when(mHost.getTiles()).thenReturn(Collections.emptyList());
Fabian Kozynskie3137e32018-09-28 11:20:04 -040081 when(mHost.createTileView(any(), anyBoolean())).thenReturn(mock(QSTileView.class));
82
Jason Monk8c09ac72017-03-16 11:53:40 -040083 mQsPanel.setHost(mHost, mCustomizer);
Fabian Kozynskie3137e32018-09-28 11:20:04 -040084 mQsPanel.addTile(dndTile, true);
85 mQsPanel.setCallback(mCallback);
Jason Monk8c09ac72017-03-16 11:53:40 -040086 });
87 }
88
89 @Test
90 public void testSetExpanded_Metrics() {
91 mQsPanel.setExpanded(true);
92 verify(mMetricsLogger).visibility(eq(MetricsEvent.QS_PANEL), eq(true));
93 mQsPanel.setExpanded(false);
94 verify(mMetricsLogger).visibility(eq(MetricsEvent.QS_PANEL), eq(false));
95 }
Fabian Kozynskie3137e32018-09-28 11:20:04 -040096
97 @Test
98 public void testOpenDetailsWithExistingTile_NoException() {
99 mTestableLooper.processAllMessages();
100 mQsPanel.openDetails("dnd");
101 mTestableLooper.processAllMessages();
102
103 verify(mCallback).onShowingDetail(any(), anyInt(), anyInt());
104 }
105
106/* @Test
107 public void testOpenDetailsWithNullParameter_NoException() {
108 mTestableLooper.processAllMessages();
109 mQsPanel.openDetails(null);
110 mTestableLooper.processAllMessages();
111
112 verify(mCallback, never()).onShowingDetail(any(), anyInt(), anyInt());
113 }*/
114
115 @Test
116 public void testOpenDetailsWithNonExistingTile_NoException() {
117 mTestableLooper.processAllMessages();
118 mQsPanel.openDetails("invalid-name");
119 mTestableLooper.processAllMessages();
120
121 verify(mCallback, never()).onShowingDetail(any(), anyInt(), anyInt());
122 }
Jason Monk8c09ac72017-03-16 11:53:40 -0400123}