blob: 1fb4c371a408485f4210c603897f3b8187c7f690 [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
17package com.android.systemui.statusbar;
18
Julia Reynoldsfc640012018-02-21 12:25:27 -050019import static org.mockito.ArgumentMatchers.any;
Selim Cinekf868efe2017-02-01 11:43:18 -080020import static org.mockito.ArgumentMatchers.anyFloat;
21import static org.mockito.Mockito.doNothing;
22import static org.mockito.Mockito.doReturn;
Julia Reynoldsfc640012018-02-21 12:25:27 -050023import static org.mockito.Mockito.mock;
24import static org.mockito.Mockito.never;
Selim Cinekf868efe2017-02-01 11:43:18 -080025import static org.mockito.Mockito.spy;
Julia Reynoldsfc640012018-02-21 12:25:27 -050026import static org.mockito.Mockito.times;
27import static org.mockito.Mockito.verify;
28import static org.mockito.Mockito.when;
Selim Cinekf868efe2017-02-01 11:43:18 -080029
Julia Reynoldsfc640012018-02-21 12:25:27 -050030import android.app.AppOpsManager;
Jason Monkc429f692017-06-27 13:13:49 -040031import android.support.test.annotation.UiThreadTest;
32import android.support.test.filters.SmallTest;
33import android.support.test.runner.AndroidJUnit4;
Julia Reynoldsfc640012018-02-21 12:25:27 -050034import android.util.ArraySet;
35import android.view.NotificationHeaderView;
Jason Monkc429f692017-06-27 13:13:49 -040036import android.view.View;
37
Jason Monkfba8faf2017-05-23 10:42:59 -040038import com.android.systemui.SysuiTestCase;
39
Jason Monkc429f692017-06-27 13:13:49 -040040import org.junit.Assert;
41import org.junit.Before;
42import org.junit.Test;
43import org.junit.runner.RunWith;
44
Adrian Roose18033c2017-01-17 15:22:49 -080045@SmallTest
46@RunWith(AndroidJUnit4.class)
Jason Monkfba8faf2017-05-23 10:42:59 -040047public class NotificationContentViewTest extends SysuiTestCase {
Adrian Roose18033c2017-01-17 15:22:49 -080048
49 NotificationContentView mView;
Adrian Roose18033c2017-01-17 15:22:49 -080050
51 @Before
Selim Cinekf868efe2017-02-01 11:43:18 -080052 @UiThreadTest
Adrian Roose18033c2017-01-17 15:22:49 -080053 public void setup() {
Adrian Roose18033c2017-01-17 15:22:49 -080054 mView = new NotificationContentView(mContext, null);
Selim Cinekf868efe2017-02-01 11:43:18 -080055 ExpandableNotificationRow row = new ExpandableNotificationRow(mContext, null);
56 ExpandableNotificationRow mockRow = spy(row);
57 doNothing().when(mockRow).updateBackgroundAlpha(anyFloat());
58 doReturn(10).when(mockRow).getIntrinsicHeight();
59
60 mView.setContainingNotification(mockRow);
Adrian Roose18033c2017-01-17 15:22:49 -080061 mView.setHeights(10, 20, 30, 40);
62
63 mView.setContractedChild(createViewWithHeight(10));
64 mView.setExpandedChild(createViewWithHeight(20));
65 mView.setHeadsUpChild(createViewWithHeight(30));
66 mView.setAmbientChild(createViewWithHeight(40));
67
68 mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
69 mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight());
70 }
71
72 private View createViewWithHeight(int height) {
73 View view = new View(mContext, null);
74 view.setMinimumHeight(height);
75 return view;
76 }
77
78 @Test
79 @UiThreadTest
80 public void animationStartType_getsClearedAfterUpdatingVisibilitiesWithoutAnimation() {
81 mView.setHeadsUp(true);
82 mView.setDark(true, false, 0);
83 mView.setDark(false, true, 0);
84 mView.setHeadsUpAnimatingAway(true);
85 Assert.assertFalse(mView.isAnimatingVisibleType());
86 }
Julia Reynoldsfc640012018-02-21 12:25:27 -050087
88 @Test
89 @UiThreadTest
90 public void testShowAppOpsIcons() {
91 NotificationHeaderView mockContracted = mock(NotificationHeaderView.class);
92 when(mockContracted.findViewById(com.android.internal.R.id.notification_header))
93 .thenReturn(mockContracted);
94 NotificationHeaderView mockExpanded = mock(NotificationHeaderView.class);
95 when(mockExpanded.findViewById(com.android.internal.R.id.notification_header))
96 .thenReturn(mockExpanded);
97 NotificationHeaderView mockHeadsUp = mock(NotificationHeaderView.class);
98 when(mockHeadsUp.findViewById(com.android.internal.R.id.notification_header))
99 .thenReturn(mockHeadsUp);
100 NotificationHeaderView mockAmbient = mock(NotificationHeaderView.class);
101 when(mockAmbient.findViewById(com.android.internal.R.id.notification_header))
102 .thenReturn(mockAmbient);
103
104 mView.setContractedChild(mockContracted);
105 mView.setExpandedChild(mockExpanded);
106 mView.setHeadsUpChild(mockHeadsUp);
107 mView.setAmbientChild(mockAmbient);
108
109 ArraySet<Integer> ops = new ArraySet<>();
110 ops.add(AppOpsManager.OP_ANSWER_PHONE_CALLS);
111 mView.showAppOpsIcons(ops);
112
113 verify(mockContracted, times(1)).showAppOpsIcons(ops);
114 verify(mockExpanded, times(1)).showAppOpsIcons(ops);
115 verify(mockAmbient, never()).showAppOpsIcons(ops);
116 verify(mockHeadsUp, times(1)).showAppOpsIcons(any());
117 }
Adrian Roose18033c2017-01-17 15:22:49 -0800118}