blob: 8879e83b4d0e94377f142c90f63a8ddab167397c [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
17import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_QS_MORE_SETTINGS;
18
19import static org.mockito.Matchers.any;
20import static org.mockito.Matchers.anyInt;
21import static org.mockito.Matchers.eq;
22import static org.mockito.Mockito.mock;
23import static org.mockito.Mockito.verify;
24import static org.mockito.Mockito.when;
25
26import android.testing.AndroidTestingRunner;
27import android.testing.TestableLooper;
28import android.testing.TestableLooper.RunWithLooper;
29import android.testing.ViewUtils;
30import android.view.LayoutInflater;
31import android.view.View;
32
Brett Chabot84151d92019-02-27 15:37:59 -080033import androidx.test.filters.SmallTest;
34
Jason Monk8c09ac72017-03-16 11:53:40 -040035import com.android.internal.logging.MetricsLogger;
36import com.android.systemui.R;
37import com.android.systemui.SysuiTestCase;
38import com.android.systemui.plugins.ActivityStarter;
39import com.android.systemui.plugins.qs.DetailAdapter;
40
Jason Monk8c09ac72017-03-16 11:53:40 -040041import org.junit.Before;
42import org.junit.Test;
43import org.junit.runner.RunWith;
44
45@RunWith(AndroidTestingRunner.class)
46@RunWithLooper
Jason Monkfba8faf2017-05-23 10:42:59 -040047@SmallTest
Jason Monk8c09ac72017-03-16 11:53:40 -040048public class QSDetailTest extends SysuiTestCase {
49
50 private MetricsLogger mMetricsLogger;
51 private QSDetail mQsDetail;
52 private QSPanel mQsPanel;
53 private QuickStatusBarHeader mQuickHeader;
54 private ActivityStarter mActivityStarter;
55 private DetailAdapter mMockDetailAdapter;
56 private TestableLooper mTestableLooper;
57
58 @Before
59 public void setup() throws Exception {
60 mTestableLooper = TestableLooper.get(this);
61 mTestableLooper.runWithLooper(() -> {
62 mMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class);
63 mActivityStarter = mDependency.injectMockDependency(ActivityStarter.class);
64 mQsDetail = (QSDetail) LayoutInflater.from(mContext).inflate(R.layout.qs_detail, null);
65 mQsPanel = mock(QSPanel.class);
66 mQuickHeader = mock(QuickStatusBarHeader.class);
Jason Monkb4ec0b92017-06-13 13:47:54 -040067 mQsDetail.setQsPanel(mQsPanel, mQuickHeader, mock(View.class));
Jason Monk8c09ac72017-03-16 11:53:40 -040068
69 mMockDetailAdapter = mock(DetailAdapter.class);
70 when(mMockDetailAdapter.createDetailView(any(), any(), any()))
71 .thenReturn(mock(View.class));
72 });
73 }
74
75 @Test
76 public void testShowDetail_Metrics() {
77 ViewUtils.attachView(mQsDetail);
78 mTestableLooper.processAllMessages();
79
80 mQsDetail.handleShowingDetail(mMockDetailAdapter, 0, 0, false);
81 verify(mMetricsLogger).visible(eq(mMockDetailAdapter.getMetricsCategory()));
82 mQsDetail.handleShowingDetail(null, 0, 0, false);
83 verify(mMetricsLogger).hidden(eq(mMockDetailAdapter.getMetricsCategory()));
84
85 ViewUtils.detachView(mQsDetail);
86 mTestableLooper.processAllMessages();
87 }
88
89 @Test
90 public void testMoreSettingsButton() {
91 ViewUtils.attachView(mQsDetail);
92 mTestableLooper.processAllMessages();
93
94 mQsDetail.handleShowingDetail(mMockDetailAdapter, 0, 0, false);
95 mQsDetail.findViewById(android.R.id.button2).performClick();
96
97 int metricsCategory = mMockDetailAdapter.getMetricsCategory();
98 verify(mMetricsLogger).action(eq(ACTION_QS_MORE_SETTINGS), eq(metricsCategory));
99
100 verify(mActivityStarter).postStartActivityDismissingKeyguard(any(), anyInt());
101
102 ViewUtils.detachView(mQsDetail);
103 mTestableLooper.processAllMessages();
104 }
Jason Monk6997da72017-04-03 15:22:54 -0400105
106 @Test
107 public void testNullAdapterClick() {
108 mQsDetail.setupDetailFooter(mock(DetailAdapter.class));
109 mQsDetail.findViewById(android.R.id.button2).performClick();
110 }
Jason Monk8c09ac72017-03-16 11:53:40 -0400111}