blob: 5cd0ca7efa9effb2c2f050fae4cc292c84cacc38 [file] [log] [blame]
Adrian Roose18033c2017-01-17 15:22:49 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
Rohan Shah20790b82018-07-02 17:21:04 -070017package com.android.systemui.statusbar.notification.row;
Adrian Roose18033c2017-01-17 15:22:49 -080018
Gustav Senntoneab53682018-11-01 16:30:23 +000019import static org.junit.Assert.assertFalse;
Julia Reynoldsfc640012018-02-21 12:25:27 -050020import static org.mockito.ArgumentMatchers.any;
Selim Cinekf868efe2017-02-01 11:43:18 -080021import static org.mockito.ArgumentMatchers.anyFloat;
22import static org.mockito.Mockito.doNothing;
23import static org.mockito.Mockito.doReturn;
Julia Reynoldsfc640012018-02-21 12:25:27 -050024import static org.mockito.Mockito.mock;
25import static org.mockito.Mockito.never;
Selim Cinekf868efe2017-02-01 11:43:18 -080026import static org.mockito.Mockito.spy;
Julia Reynoldsfc640012018-02-21 12:25:27 -050027import static org.mockito.Mockito.times;
28import static org.mockito.Mockito.verify;
29import static org.mockito.Mockito.when;
Selim Cinekf868efe2017-02-01 11:43:18 -080030
Julia Reynoldsfc640012018-02-21 12:25:27 -050031import android.app.AppOpsManager;
Gustav Senntoneab53682018-11-01 16:30:23 +000032import android.graphics.drawable.Icon;
Julia Reynoldsfc640012018-02-21 12:25:27 -050033import android.util.ArraySet;
34import android.view.NotificationHeaderView;
Jason Monkc429f692017-06-27 13:13:49 -040035import android.view.View;
36
Brett Chabot84151d92019-02-27 15:37:59 -080037import androidx.test.annotation.UiThreadTest;
38import androidx.test.filters.SmallTest;
39import androidx.test.runner.AndroidJUnit4;
40
Jason Monkfba8faf2017-05-23 10:42:59 -040041import com.android.systemui.SysuiTestCase;
42
Jason Monkc429f692017-06-27 13:13:49 -040043import org.junit.Before;
44import org.junit.Test;
45import org.junit.runner.RunWith;
46
Adrian Roose18033c2017-01-17 15:22:49 -080047@SmallTest
48@RunWith(AndroidJUnit4.class)
Jason Monkfba8faf2017-05-23 10:42:59 -040049public class NotificationContentViewTest extends SysuiTestCase {
Adrian Roose18033c2017-01-17 15:22:49 -080050
51 NotificationContentView mView;
Adrian Roose18033c2017-01-17 15:22:49 -080052
Gustav Senntoneab53682018-11-01 16:30:23 +000053 private Icon mActionIcon;
54
Adrian Roose18033c2017-01-17 15:22:49 -080055 @Before
Selim Cinekf868efe2017-02-01 11:43:18 -080056 @UiThreadTest
Adrian Roose18033c2017-01-17 15:22:49 -080057 public void setup() {
Adrian Roose18033c2017-01-17 15:22:49 -080058 mView = new NotificationContentView(mContext, null);
Selim Cinekf868efe2017-02-01 11:43:18 -080059 ExpandableNotificationRow row = new ExpandableNotificationRow(mContext, null);
60 ExpandableNotificationRow mockRow = spy(row);
61 doNothing().when(mockRow).updateBackgroundAlpha(anyFloat());
62 doReturn(10).when(mockRow).getIntrinsicHeight();
63
64 mView.setContainingNotification(mockRow);
Adrian Roose18033c2017-01-17 15:22:49 -080065 mView.setHeights(10, 20, 30, 40);
66
67 mView.setContractedChild(createViewWithHeight(10));
68 mView.setExpandedChild(createViewWithHeight(20));
69 mView.setHeadsUpChild(createViewWithHeight(30));
70 mView.setAmbientChild(createViewWithHeight(40));
71
72 mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
73 mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight());
74 }
75
76 private View createViewWithHeight(int height) {
77 View view = new View(mContext, null);
78 view.setMinimumHeight(height);
79 return view;
80 }
81
82 @Test
83 @UiThreadTest
84 public void animationStartType_getsClearedAfterUpdatingVisibilitiesWithoutAnimation() {
85 mView.setHeadsUp(true);
86 mView.setDark(true, false, 0);
87 mView.setDark(false, true, 0);
88 mView.setHeadsUpAnimatingAway(true);
Gustav Senntoneab53682018-11-01 16:30:23 +000089 assertFalse(mView.isAnimatingVisibleType());
Adrian Roose18033c2017-01-17 15:22:49 -080090 }
Julia Reynoldsfc640012018-02-21 12:25:27 -050091
92 @Test
93 @UiThreadTest
94 public void testShowAppOpsIcons() {
95 NotificationHeaderView mockContracted = mock(NotificationHeaderView.class);
96 when(mockContracted.findViewById(com.android.internal.R.id.notification_header))
97 .thenReturn(mockContracted);
98 NotificationHeaderView mockExpanded = mock(NotificationHeaderView.class);
99 when(mockExpanded.findViewById(com.android.internal.R.id.notification_header))
100 .thenReturn(mockExpanded);
101 NotificationHeaderView mockHeadsUp = mock(NotificationHeaderView.class);
102 when(mockHeadsUp.findViewById(com.android.internal.R.id.notification_header))
103 .thenReturn(mockHeadsUp);
104 NotificationHeaderView mockAmbient = mock(NotificationHeaderView.class);
105 when(mockAmbient.findViewById(com.android.internal.R.id.notification_header))
106 .thenReturn(mockAmbient);
107
108 mView.setContractedChild(mockContracted);
109 mView.setExpandedChild(mockExpanded);
110 mView.setHeadsUpChild(mockHeadsUp);
111 mView.setAmbientChild(mockAmbient);
112
113 ArraySet<Integer> ops = new ArraySet<>();
114 ops.add(AppOpsManager.OP_ANSWER_PHONE_CALLS);
115 mView.showAppOpsIcons(ops);
116
117 verify(mockContracted, times(1)).showAppOpsIcons(ops);
118 verify(mockExpanded, times(1)).showAppOpsIcons(ops);
119 verify(mockAmbient, never()).showAppOpsIcons(ops);
120 verify(mockHeadsUp, times(1)).showAppOpsIcons(any());
121 }
Adrian Roose18033c2017-01-17 15:22:49 -0800122}