Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 1 | /* |
| 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 Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 18 | |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 19 | import static org.junit.Assert.assertFalse; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 20 | import static org.mockito.ArgumentMatchers.any; |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 21 | import static org.mockito.ArgumentMatchers.anyFloat; |
| 22 | import static org.mockito.Mockito.doNothing; |
| 23 | import static org.mockito.Mockito.doReturn; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 24 | import static org.mockito.Mockito.mock; |
| 25 | import static org.mockito.Mockito.never; |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 26 | import static org.mockito.Mockito.spy; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 27 | import static org.mockito.Mockito.times; |
| 28 | import static org.mockito.Mockito.verify; |
| 29 | import static org.mockito.Mockito.when; |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 30 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 31 | import android.app.AppOpsManager; |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 32 | import android.graphics.drawable.Icon; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 33 | import android.util.ArraySet; |
| 34 | import android.view.NotificationHeaderView; |
Jason Monk | c429f69 | 2017-06-27 13:13:49 -0400 | [diff] [blame] | 35 | import android.view.View; |
| 36 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 37 | import androidx.test.annotation.UiThreadTest; |
| 38 | import androidx.test.filters.SmallTest; |
| 39 | import androidx.test.runner.AndroidJUnit4; |
| 40 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 41 | import com.android.systemui.SysuiTestCase; |
| 42 | |
Jason Monk | c429f69 | 2017-06-27 13:13:49 -0400 | [diff] [blame] | 43 | import org.junit.Before; |
| 44 | import org.junit.Test; |
| 45 | import org.junit.runner.RunWith; |
| 46 | |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 47 | @SmallTest |
| 48 | @RunWith(AndroidJUnit4.class) |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 49 | public class NotificationContentViewTest extends SysuiTestCase { |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 50 | |
| 51 | NotificationContentView mView; |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 52 | |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 53 | private Icon mActionIcon; |
| 54 | |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 55 | @Before |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 56 | @UiThreadTest |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 57 | public void setup() { |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 58 | mView = new NotificationContentView(mContext, null); |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 59 | 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 Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 65 | 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 Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 89 | assertFalse(mView.isAnimatingVisibleType()); |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 90 | } |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 91 | |
| 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 Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 122 | } |