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