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; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 35 | import com.android.systemui.statusbar.CommandQueue; |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 36 | import com.android.systemui.statusbar.StatusBarStateController; |
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)); |
| 60 | mSysuiContext.putComponent(StatusBar.class, mock(StatusBar.class)); |
| 61 | mSysuiContext.putComponent(TunerService.class, mock(TunerService.class)); |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 62 | mStatusBarStateController = mDependency |
| 63 | .injectMockDependency(StatusBarStateController.class); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 64 | injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); |
| 65 | mMockNotificiationAreaController = mock(NotificationIconAreaController.class); |
| 66 | mNotificationAreaInner = mock(View.class); |
| 67 | when(mNotificationAreaInner.animate()).thenReturn(mock(ViewPropertyAnimator.class)); |
| 68 | when(mMockNotificiationAreaController.getNotificationInnerAreaView()).thenReturn( |
| 69 | mNotificationAreaInner); |
| 70 | } |
| 71 | |
| 72 | @Test |
| 73 | public void testDisableNone() throws Exception { |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 74 | mFragments.dispatchResume(); |
| 75 | processAllMessages(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 76 | |
| 77 | CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; |
| 78 | fragment.initNotificationIconArea(mMockNotificiationAreaController); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 79 | fragment.disable(DEFAULT_DISPLAY, 0, 0, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 80 | |
| 81 | assertEquals(View.VISIBLE, mFragment.getView().findViewById(R.id.system_icon_area) |
| 82 | .getVisibility()); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 83 | assertEquals(View.VISIBLE, mFragment.getView().findViewById(R.id.clock) |
| 84 | .getVisibility()); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Test |
| 88 | public void testDisableSystemInfo() throws Exception { |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 89 | mFragments.dispatchResume(); |
| 90 | processAllMessages(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 91 | |
| 92 | CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; |
| 93 | fragment.initNotificationIconArea(mMockNotificiationAreaController); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 94 | fragment.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_SYSTEM_INFO, 0, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 95 | |
| 96 | assertEquals(View.INVISIBLE, mFragment.getView().findViewById(R.id.system_icon_area) |
| 97 | .getVisibility()); |
| 98 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 99 | fragment.disable(DEFAULT_DISPLAY, 0, 0, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 100 | |
| 101 | assertEquals(View.VISIBLE, mFragment.getView().findViewById(R.id.system_icon_area) |
| 102 | .getVisibility()); |
| 103 | } |
| 104 | |
| 105 | @Test |
| 106 | public void testDisableNotifications() throws Exception { |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 107 | mFragments.dispatchResume(); |
| 108 | processAllMessages(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 109 | |
| 110 | CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; |
| 111 | fragment.initNotificationIconArea(mMockNotificiationAreaController); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 112 | fragment.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_NOTIFICATION_ICONS, 0, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 113 | |
| 114 | Mockito.verify(mNotificationAreaInner).setVisibility(eq(View.INVISIBLE)); |
| 115 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 116 | fragment.disable(DEFAULT_DISPLAY, 0, 0, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 117 | |
Jason Monk | 60033fc | 2017-03-24 11:26:35 -0400 | [diff] [blame] | 118 | Mockito.verify(mNotificationAreaInner, atLeast(1)).setVisibility(eq(View.VISIBLE)); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 119 | } |
Evan Laird | 4b68e2f7 | 2018-03-29 18:21:48 -0400 | [diff] [blame] | 120 | |
| 121 | @Test |
| 122 | public void testDisableClock() throws Exception { |
| 123 | mFragments.dispatchResume(); |
| 124 | processAllMessages(); |
| 125 | |
| 126 | CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; |
| 127 | fragment.initNotificationIconArea(mMockNotificiationAreaController); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 128 | fragment.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_CLOCK, 0, false); |
Evan Laird | 4b68e2f7 | 2018-03-29 18:21:48 -0400 | [diff] [blame] | 129 | |
Evan Laird | 74435e6 | 2018-05-04 11:58:30 -0400 | [diff] [blame] | 130 | assertEquals(View.GONE, mFragment.getView().findViewById(R.id.clock).getVisibility()); |
Evan Laird | 4b68e2f7 | 2018-03-29 18:21:48 -0400 | [diff] [blame] | 131 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 132 | fragment.disable(DEFAULT_DISPLAY, 0, 0, false); |
Evan Laird | 4b68e2f7 | 2018-03-29 18:21:48 -0400 | [diff] [blame] | 133 | |
| 134 | assertEquals(View.VISIBLE, mFragment.getView().findViewById(R.id.clock).getVisibility()); |
| 135 | } |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 136 | |
| 137 | @Test |
| 138 | public void testOnDozingChanged() throws Exception { |
| 139 | mFragments.dispatchResume(); |
| 140 | processAllMessages(); |
| 141 | |
| 142 | CollapsedStatusBarFragment fragment = (CollapsedStatusBarFragment) mFragment; |
| 143 | fragment.initNotificationIconArea(mMockNotificiationAreaController); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 144 | fragment.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_NOTIFICATION_ICONS, 0, false); |
Lucas Dupin | 2e43cfc | 2018-11-12 14:07:18 -0800 | [diff] [blame] | 145 | |
| 146 | Mockito.verify(mNotificationAreaInner).setVisibility(eq(View.INVISIBLE)); |
| 147 | |
| 148 | reset(mStatusBarStateController); |
| 149 | when(mStatusBarStateController.isDozing()).thenReturn(true); |
| 150 | fragment.onDozingChanged(true); |
| 151 | |
| 152 | Mockito.verify(mStatusBarStateController).isDozing(); |
| 153 | Mockito.verify(mNotificationAreaInner, atLeast(1)).setVisibility(eq(View.VISIBLE)); |
| 154 | } |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 155 | } |