Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [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.statusbar.phone; |
| 16 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 17 | import static android.view.Display.DEFAULT_DISPLAY; |
| 18 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 19 | import static org.junit.Assert.assertEquals; |
| 20 | import static org.mockito.Matchers.eq; |
Jason Monk | 60033fc | 2017-03-24 11:26:35 -0400 | [diff] [blame] | 21 | import static org.mockito.Mockito.atLeast; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 22 | import static org.mockito.Mockito.mock; |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 23 | import static org.mockito.Mockito.reset; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 24 | import static org.mockito.Mockito.when; |
| 25 | |
| 26 | import android.app.StatusBarManager; |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 27 | import android.support.test.filters.SmallTest; |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 28 | import android.testing.AndroidTestingRunner; |
| 29 | import android.testing.TestableLooper.RunWithLooper; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 30 | import android.view.View; |
| 31 | import android.view.ViewPropertyAnimator; |
| 32 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 33 | import com.android.systemui.R; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 34 | import com.android.systemui.SysuiBaseFragmentTest; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 35 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 36 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 37 | import com.android.systemui.tuner.TunerService; |
| 38 | |
| 39 | import org.junit.Before; |
| 40 | import org.junit.Test; |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 41 | import org.junit.runner.RunWith; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 42 | import org.mockito.Mockito; |
| 43 | |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 44 | @RunWith(AndroidTestingRunner.class) |
Aaron Heuckroth | 5acf9ec | 2018-11-29 13:05:21 -0500 | [diff] [blame] | 45 | @RunWithLooper() |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 46 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 47 | public class CollapsedStatusBarFragmentTest extends SysuiBaseFragmentTest { |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 48 | |
| 49 | private NotificationIconAreaController mMockNotificiationAreaController; |
| 50 | private View mNotificationAreaInner; |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 51 | private StatusBarStateController mStatusBarStateController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 52 | |
| 53 | public CollapsedStatusBarFragmentTest() { |
| 54 | super(CollapsedStatusBarFragment.class); |
| 55 | } |
| 56 | |
| 57 | @Before |
| 58 | public void setup() { |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 59 | mSysuiContext.putComponent(CommandQueue.class, mock(CommandQueue.class)); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 60 | StatusBar statusBar = mock(StatusBar.class); |
| 61 | mSysuiContext.putComponent(StatusBar.class, statusBar); |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 62 | mSysuiContext.putComponent(TunerService.class, mock(TunerService.class)); |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 63 | mStatusBarStateController = mDependency |
| 64 | .injectMockDependency(StatusBarStateController.class); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 65 | injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); |
| 66 | mMockNotificiationAreaController = mock(NotificationIconAreaController.class); |
| 67 | mNotificationAreaInner = mock(View.class); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 68 | when(statusBar.getPanel()).thenReturn(mock(NotificationPanelView.class)); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 69 | when(mNotificationAreaInner.animate()).thenReturn(mock(ViewPropertyAnimator.class)); |
| 70 | when(mMockNotificiationAreaController.getNotificationInnerAreaView()).thenReturn( |
| 71 | mNotificationAreaInner); |
| 72 | } |
| 73 | |
| 74 | @Test |
| 75 | public void testDisableNone() throws Exception { |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 76 | mFragments.dispatchResume(); |
| 77 | processAllMessages(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 78 | |
| 79 | CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; |
| 80 | fragment.initNotificationIconArea(mMockNotificiationAreaController); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 81 | fragment.disable(DEFAULT_DISPLAY, 0, 0, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 82 | |
| 83 | assertEquals(View.VISIBLE, mFragment.getView().findViewById(R.id.system_icon_area) |
| 84 | .getVisibility()); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 85 | assertEquals(View.VISIBLE, mFragment.getView().findViewById(R.id.clock) |
| 86 | .getVisibility()); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void testDisableSystemInfo() throws Exception { |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 91 | mFragments.dispatchResume(); |
| 92 | processAllMessages(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 93 | |
| 94 | CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; |
| 95 | fragment.initNotificationIconArea(mMockNotificiationAreaController); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 96 | fragment.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_SYSTEM_INFO, 0, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 97 | |
| 98 | assertEquals(View.INVISIBLE, mFragment.getView().findViewById(R.id.system_icon_area) |
| 99 | .getVisibility()); |
| 100 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 101 | fragment.disable(DEFAULT_DISPLAY, 0, 0, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 102 | |
| 103 | assertEquals(View.VISIBLE, mFragment.getView().findViewById(R.id.system_icon_area) |
| 104 | .getVisibility()); |
| 105 | } |
| 106 | |
| 107 | @Test |
| 108 | public void testDisableNotifications() throws Exception { |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 109 | mFragments.dispatchResume(); |
| 110 | processAllMessages(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 111 | |
| 112 | CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; |
| 113 | fragment.initNotificationIconArea(mMockNotificiationAreaController); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 114 | fragment.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_NOTIFICATION_ICONS, 0, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 115 | |
| 116 | Mockito.verify(mNotificationAreaInner).setVisibility(eq(View.INVISIBLE)); |
| 117 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 118 | fragment.disable(DEFAULT_DISPLAY, 0, 0, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 119 | |
Jason Monk | 60033fc | 2017-03-24 11:26:35 -0400 | [diff] [blame] | 120 | Mockito.verify(mNotificationAreaInner, atLeast(1)).setVisibility(eq(View.VISIBLE)); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 121 | } |
Evan Laird | 4b68e2f7 | 2018-03-29 18:21:48 -0400 | [diff] [blame] | 122 | |
| 123 | @Test |
| 124 | public void testDisableClock() throws Exception { |
| 125 | mFragments.dispatchResume(); |
| 126 | processAllMessages(); |
| 127 | |
| 128 | CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; |
| 129 | fragment.initNotificationIconArea(mMockNotificiationAreaController); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 130 | fragment.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_CLOCK, 0, false); |
Evan Laird | 4b68e2f7 | 2018-03-29 18:21:48 -0400 | [diff] [blame] | 131 | |
Evan Laird | 74435e6 | 2018-05-04 11:58:30 -0400 | [diff] [blame] | 132 | assertEquals(View.GONE, mFragment.getView().findViewById(R.id.clock).getVisibility()); |
Evan Laird | 4b68e2f7 | 2018-03-29 18:21:48 -0400 | [diff] [blame] | 133 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 134 | fragment.disable(DEFAULT_DISPLAY, 0, 0, false); |
Evan Laird | 4b68e2f7 | 2018-03-29 18:21:48 -0400 | [diff] [blame] | 135 | |
| 136 | assertEquals(View.VISIBLE, mFragment.getView().findViewById(R.id.clock).getVisibility()); |
| 137 | } |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 138 | |
| 139 | @Test |
| 140 | public void testOnDozingChanged() throws Exception { |
| 141 | mFragments.dispatchResume(); |
| 142 | processAllMessages(); |
| 143 | |
| 144 | CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; |
| 145 | fragment.initNotificationIconArea(mMockNotificiationAreaController); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 146 | fragment.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_NOTIFICATION_ICONS, 0, false); |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 147 | |
| 148 | Mockito.verify(mNotificationAreaInner).setVisibility(eq(View.INVISIBLE)); |
| 149 | |
| 150 | reset(mStatusBarStateController); |
| 151 | when(mStatusBarStateController.isDozing()).thenReturn(true); |
| 152 | fragment.onDozingChanged(true); |
| 153 | |
| 154 | Mockito.verify(mStatusBarStateController).isDozing(); |
| 155 | Mockito.verify(mNotificationAreaInner, atLeast(1)).setVisibility(eq(View.VISIBLE)); |
| 156 | } |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 157 | } |