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 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.any; |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 20 | import static org.mockito.ArgumentMatchers.anyFloat; |
| 21 | import static org.mockito.Mockito.doNothing; |
| 22 | import static org.mockito.Mockito.doReturn; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 23 | import static org.mockito.Mockito.mock; |
| 24 | import static org.mockito.Mockito.never; |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 25 | import static org.mockito.Mockito.spy; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 26 | import static org.mockito.Mockito.times; |
| 27 | import static org.mockito.Mockito.verify; |
| 28 | import static org.mockito.Mockito.when; |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 29 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 30 | import android.app.AppOpsManager; |
Jason Monk | c429f69 | 2017-06-27 13:13:49 -0400 | [diff] [blame] | 31 | import android.support.test.annotation.UiThreadTest; |
| 32 | import android.support.test.filters.SmallTest; |
| 33 | import android.support.test.runner.AndroidJUnit4; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 34 | import android.util.ArraySet; |
| 35 | import android.view.NotificationHeaderView; |
Jason Monk | c429f69 | 2017-06-27 13:13:49 -0400 | [diff] [blame] | 36 | import android.view.View; |
| 37 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 38 | import com.android.systemui.SysuiTestCase; |
| 39 | |
Jason Monk | c429f69 | 2017-06-27 13:13:49 -0400 | [diff] [blame] | 40 | import org.junit.Assert; |
| 41 | import org.junit.Before; |
| 42 | import org.junit.Test; |
| 43 | import org.junit.runner.RunWith; |
| 44 | |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 45 | @SmallTest |
| 46 | @RunWith(AndroidJUnit4.class) |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 47 | public class NotificationContentViewTest extends SysuiTestCase { |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 48 | |
| 49 | NotificationContentView mView; |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 50 | |
| 51 | @Before |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 52 | @UiThreadTest |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 53 | public void setup() { |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 54 | mView = new NotificationContentView(mContext, null); |
Selim Cinek | f868efe | 2017-02-01 11:43:18 -0800 | [diff] [blame] | 55 | 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 Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 61 | 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 Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 87 | |
| 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 Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 118 | } |