Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | package com.android.systemui.qs; |
| 16 | |
| 17 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_QS_MORE_SETTINGS; |
| 18 | |
| 19 | import static org.mockito.Matchers.any; |
| 20 | import static org.mockito.Matchers.anyInt; |
| 21 | import static org.mockito.Matchers.eq; |
| 22 | import static org.mockito.Mockito.mock; |
| 23 | import static org.mockito.Mockito.verify; |
| 24 | import static org.mockito.Mockito.when; |
| 25 | |
| 26 | import android.testing.AndroidTestingRunner; |
| 27 | import android.testing.TestableLooper; |
| 28 | import android.testing.TestableLooper.RunWithLooper; |
| 29 | import android.testing.ViewUtils; |
| 30 | import android.view.LayoutInflater; |
| 31 | import android.view.View; |
| 32 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 33 | import androidx.test.filters.SmallTest; |
| 34 | |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 35 | import com.android.internal.logging.MetricsLogger; |
| 36 | import com.android.systemui.R; |
| 37 | import com.android.systemui.SysuiTestCase; |
| 38 | import com.android.systemui.plugins.ActivityStarter; |
| 39 | import com.android.systemui.plugins.qs.DetailAdapter; |
| 40 | |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 41 | import org.junit.Before; |
| 42 | import org.junit.Test; |
| 43 | import org.junit.runner.RunWith; |
| 44 | |
| 45 | @RunWith(AndroidTestingRunner.class) |
| 46 | @RunWithLooper |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 47 | @SmallTest |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 48 | public 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 Monk | b4ec0b9 | 2017-06-13 13:47:54 -0400 | [diff] [blame] | 67 | mQsDetail.setQsPanel(mQsPanel, mQuickHeader, mock(View.class)); |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 68 | |
| 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 Monk | 6997da7 | 2017-04-03 15:22:54 -0400 | [diff] [blame] | 105 | |
| 106 | @Test |
| 107 | public void testNullAdapterClick() { |
| 108 | mQsDetail.setupDetailFooter(mock(DetailAdapter.class)); |
| 109 | mQsDetail.findViewById(android.R.id.button2).performClick(); |
| 110 | } |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 111 | } |