blob: 12a122a5c7344b15cd58e26349e8df8abd3af9ad [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
Jason Monkfba8faf2017-05-23 10:42:59 -040026import android.support.test.filters.SmallTest;
Jason Monk8c09ac72017-03-16 11:53:40 -040027import android.testing.AndroidTestingRunner;
28import android.testing.TestableLooper;
29import android.testing.TestableLooper.RunWithLooper;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040030import android.view.ViewGroup;
31import android.widget.FrameLayout;
Jason Monk8c09ac72017-03-16 11:53:40 -040032
33import com.android.internal.logging.MetricsLogger;
34import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
35import com.android.systemui.SysuiTestCase;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040036import com.android.systemui.plugins.qs.QSTile;
37import com.android.systemui.plugins.qs.QSTileView;
Jason Monk8c09ac72017-03-16 11:53:40 -040038import com.android.systemui.qs.customize.QSCustomizer;
39
40import org.junit.Before;
41import org.junit.Test;
42import org.junit.runner.RunWith;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040043import org.mockito.Mock;
44import org.mockito.MockitoAnnotations;
Jason Monk8c09ac72017-03-16 11:53:40 -040045
46import java.util.Collections;
47
48@RunWith(AndroidTestingRunner.class)
49@RunWithLooper
Jason Monkfba8faf2017-05-23 10:42:59 -040050@SmallTest
Jason Monk8c09ac72017-03-16 11:53:40 -040051public class QSPanelTest extends SysuiTestCase {
52
53 private MetricsLogger mMetricsLogger;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040054 private TestableLooper mTestableLooper;
Jason Monk8c09ac72017-03-16 11:53:40 -040055 private QSPanel mQsPanel;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040056 @Mock
Jason Monk8c09ac72017-03-16 11:53:40 -040057 private QSTileHost mHost;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040058 @Mock
Jason Monk8c09ac72017-03-16 11:53:40 -040059 private QSCustomizer mCustomizer;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040060 @Mock
61 private QSTile dndTile;
62 private ViewGroup mParentView;
63 @Mock
64 private QSDetail.Callback mCallback;
Jason Monk8c09ac72017-03-16 11:53:40 -040065
66 @Before
67 public void setup() throws Exception {
Fabian Kozynskie3137e32018-09-28 11:20:04 -040068 MockitoAnnotations.initMocks(this);
69
70 mTestableLooper = TestableLooper.get(this);
71 mTestableLooper.runWithLooper(() -> {
Jason Monk8c09ac72017-03-16 11:53:40 -040072 mMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class);
73 mQsPanel = new QSPanel(mContext, null);
Fabian Kozynskie3137e32018-09-28 11:20:04 -040074 // Provides a parent with non-zero size for QSPanel
75 mParentView = new FrameLayout(mContext);
76 mParentView.addView(mQsPanel);
77
78 when(dndTile.getTileSpec()).thenReturn("dnd");
Jason Monk8c09ac72017-03-16 11:53:40 -040079 when(mHost.getTiles()).thenReturn(Collections.emptyList());
Fabian Kozynskie3137e32018-09-28 11:20:04 -040080 when(mHost.createTileView(any(), anyBoolean())).thenReturn(mock(QSTileView.class));
81
Jason Monk8c09ac72017-03-16 11:53:40 -040082 mQsPanel.setHost(mHost, mCustomizer);
Fabian Kozynskie3137e32018-09-28 11:20:04 -040083 mQsPanel.addTile(dndTile, true);
84 mQsPanel.setCallback(mCallback);
Jason Monk8c09ac72017-03-16 11:53:40 -040085 });
86 }
87
88 @Test
89 public void testSetExpanded_Metrics() {
90 mQsPanel.setExpanded(true);
91 verify(mMetricsLogger).visibility(eq(MetricsEvent.QS_PANEL), eq(true));
92 mQsPanel.setExpanded(false);
93 verify(mMetricsLogger).visibility(eq(MetricsEvent.QS_PANEL), eq(false));
94 }
Fabian Kozynskie3137e32018-09-28 11:20:04 -040095
96 @Test
97 public void testOpenDetailsWithExistingTile_NoException() {
98 mTestableLooper.processAllMessages();
99 mQsPanel.openDetails("dnd");
100 mTestableLooper.processAllMessages();
101
102 verify(mCallback).onShowingDetail(any(), anyInt(), anyInt());
103 }
104
105/* @Test
106 public void testOpenDetailsWithNullParameter_NoException() {
107 mTestableLooper.processAllMessages();
108 mQsPanel.openDetails(null);
109 mTestableLooper.processAllMessages();
110
111 verify(mCallback, never()).onShowingDetail(any(), anyInt(), anyInt());
112 }*/
113
114 @Test
115 public void testOpenDetailsWithNonExistingTile_NoException() {
116 mTestableLooper.processAllMessages();
117 mQsPanel.openDetails("invalid-name");
118 mTestableLooper.processAllMessages();
119
120 verify(mCallback, never()).onShowingDetail(any(), anyInt(), anyInt());
121 }
Jason Monk8c09ac72017-03-16 11:53:40 -0400122}