Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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.keyguard; |
| 18 | |
| 19 | import static android.view.View.GONE; |
| 20 | import static android.view.View.VISIBLE; |
| 21 | |
| 22 | import static com.google.common.truth.Truth.assertThat; |
| 23 | |
| 24 | import static org.mockito.Mockito.doReturn; |
| 25 | import static org.mockito.Mockito.mock; |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 26 | import static org.mockito.Mockito.never; |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 27 | import static org.mockito.Mockito.verify; |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 28 | import static org.mockito.Mockito.when; |
| 29 | |
| 30 | import android.graphics.Color; |
| 31 | import android.graphics.Paint.Style; |
| 32 | import android.test.suitebuilder.annotation.SmallTest; |
| 33 | import android.testing.AndroidTestingRunner; |
| 34 | import android.testing.TestableLooper.RunWithLooper; |
| 35 | import android.text.TextPaint; |
| 36 | import android.view.LayoutInflater; |
Robert Snoeberger | 6085408 | 2019-01-04 13:13:17 -0500 | [diff] [blame] | 37 | import android.view.View; |
Robert Snoeberger | e3b3e78 | 2018-12-17 13:32:15 -0500 | [diff] [blame] | 38 | import android.widget.FrameLayout; |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 39 | import android.widget.TextClock; |
| 40 | |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 41 | import com.android.keyguard.clock.ClockManager; |
Robert Snoeberger | be35b76 | 2019-03-15 14:33:02 -0400 | [diff] [blame] | 42 | import com.android.systemui.SystemUIFactory; |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 43 | import com.android.systemui.SysuiTestCase; |
| 44 | import com.android.systemui.plugins.ClockPlugin; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 45 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Robert Snoeberger | 6085408 | 2019-01-04 13:13:17 -0500 | [diff] [blame] | 46 | import com.android.systemui.statusbar.StatusBarState; |
Robert Snoeberger | be35b76 | 2019-03-15 14:33:02 -0400 | [diff] [blame] | 47 | import com.android.systemui.util.InjectionInflationController; |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 48 | |
| 49 | import org.junit.Before; |
| 50 | import org.junit.Test; |
| 51 | import org.junit.runner.RunWith; |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 52 | import org.mockito.InjectMocks; |
| 53 | import org.mockito.Mock; |
| 54 | import org.mockito.MockitoAnnotations; |
| 55 | |
| 56 | @SmallTest |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 57 | @RunWith(AndroidTestingRunner.class) |
Robert Snoeberger | e3b3e78 | 2018-12-17 13:32:15 -0500 | [diff] [blame] | 58 | // Need to run on the main thread because KeyguardSliceView$Row init checks for |
| 59 | // the main thread before acquiring a wake lock. This class is constructed when |
| 60 | // the keyguard_clcok_switch layout is inflated. |
| 61 | @RunWithLooper(setAsMainLooper = true) |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 62 | public class KeyguardClockSwitchTest extends SysuiTestCase { |
Robert Snoeberger | e3b3e78 | 2018-12-17 13:32:15 -0500 | [diff] [blame] | 63 | private FrameLayout mClockContainer; |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 64 | private FrameLayout mBigClockContainer; |
| 65 | private TextClock mBigClock; |
Robert Snoeberger | 6085408 | 2019-01-04 13:13:17 -0500 | [diff] [blame] | 66 | private StatusBarStateController.StateListener mStateListener; |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 67 | |
| 68 | @Mock |
| 69 | TextClock mClockView; |
| 70 | @InjectMocks |
| 71 | KeyguardClockSwitch mKeyguardClockSwitch; |
| 72 | |
| 73 | @Before |
| 74 | public void setUp() { |
Robert Snoeberger | be35b76 | 2019-03-15 14:33:02 -0400 | [diff] [blame] | 75 | InjectionInflationController inflationController = new InjectionInflationController( |
| 76 | SystemUIFactory.getInstance().getRootComponent()); |
| 77 | LayoutInflater layoutInflater = inflationController |
| 78 | .injectable(LayoutInflater.from(getContext())); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 79 | mKeyguardClockSwitch = |
| 80 | (KeyguardClockSwitch) layoutInflater.inflate(R.layout.keyguard_clock_switch, null); |
Robert Snoeberger | e3b3e78 | 2018-12-17 13:32:15 -0500 | [diff] [blame] | 81 | mClockContainer = mKeyguardClockSwitch.findViewById(R.id.clock_view); |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 82 | mBigClockContainer = new FrameLayout(getContext()); |
| 83 | mBigClock = new TextClock(getContext()); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 84 | MockitoAnnotations.initMocks(this); |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 85 | when(mClockView.getPaint()).thenReturn(mock(TextPaint.class)); |
Robert Snoeberger | 6085408 | 2019-01-04 13:13:17 -0500 | [diff] [blame] | 86 | mStateListener = mKeyguardClockSwitch.getStateListener(); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Test |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 90 | public void onPluginConnected_showPluginClock() { |
| 91 | ClockPlugin plugin = mock(ClockPlugin.class); |
| 92 | TextClock pluginView = new TextClock(getContext()); |
| 93 | when(plugin.getView()).thenReturn(pluginView); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 94 | |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 95 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 96 | |
| 97 | verify(mClockView).setVisibility(GONE); |
Robert Snoeberger | e3b3e78 | 2018-12-17 13:32:15 -0500 | [diff] [blame] | 98 | assertThat(plugin.getView().getParent()).isEqualTo(mClockContainer); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | @Test |
Robert Snoeberger | 6a0140a | 2018-12-20 12:46:17 -0500 | [diff] [blame] | 102 | public void onPluginConnected_showPluginBigClock() { |
| 103 | // GIVEN that the container for the big clock has visibility GONE |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 104 | mBigClockContainer.setVisibility(GONE); |
| 105 | mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer); |
Robert Snoeberger | 6a0140a | 2018-12-20 12:46:17 -0500 | [diff] [blame] | 106 | // AND the plugin returns a view for the big clock |
| 107 | ClockPlugin plugin = mock(ClockPlugin.class); |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 108 | when(plugin.getBigClockView()).thenReturn(mBigClock); |
Robert Snoeberger | 9831239 | 2019-03-15 16:53:51 -0400 | [diff] [blame] | 109 | // AND in the keyguard state |
| 110 | mStateListener.onStateChanged(StatusBarState.KEYGUARD); |
Robert Snoeberger | 6a0140a | 2018-12-20 12:46:17 -0500 | [diff] [blame] | 111 | // WHEN the plugin is connected |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 112 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
Robert Snoeberger | 6a0140a | 2018-12-20 12:46:17 -0500 | [diff] [blame] | 113 | // THEN the big clock container is visible and it is the parent of the |
| 114 | // big clock view. |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 115 | assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.VISIBLE); |
| 116 | assertThat(mBigClock.getParent()).isEqualTo(mBigClockContainer); |
Robert Snoeberger | 6a0140a | 2018-12-20 12:46:17 -0500 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | @Test |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 120 | public void onPluginConnected_nullView() { |
| 121 | ClockPlugin plugin = mock(ClockPlugin.class); |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 122 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 123 | verify(mClockView, never()).setVisibility(GONE); |
| 124 | } |
| 125 | |
| 126 | @Test |
| 127 | public void onPluginConnected_showSecondPluginClock() { |
| 128 | // GIVEN a plugin has already connected |
| 129 | ClockPlugin plugin1 = mock(ClockPlugin.class); |
| 130 | when(plugin1.getView()).thenReturn(new TextClock(getContext())); |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 131 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin1); |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 132 | // WHEN a second plugin is connected |
| 133 | ClockPlugin plugin2 = mock(ClockPlugin.class); |
| 134 | when(plugin2.getView()).thenReturn(new TextClock(getContext())); |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 135 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin2); |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 136 | // THEN only the view from the second plugin should be a child of KeyguardClockSwitch. |
Robert Snoeberger | e3b3e78 | 2018-12-17 13:32:15 -0500 | [diff] [blame] | 137 | assertThat(plugin2.getView().getParent()).isEqualTo(mClockContainer); |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 138 | assertThat(plugin1.getView().getParent()).isNull(); |
| 139 | } |
| 140 | |
| 141 | @Test |
Robert Snoeberger | 58f2315 | 2019-01-10 15:51:32 -0500 | [diff] [blame] | 142 | public void onPluginConnected_darkAmountInitialized() { |
| 143 | // GIVEN that the dark amount has already been set |
| 144 | mKeyguardClockSwitch.setDarkAmount(0.5f); |
| 145 | // WHEN a plugin is connected |
| 146 | ClockPlugin plugin = mock(ClockPlugin.class); |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 147 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
Robert Snoeberger | 58f2315 | 2019-01-10 15:51:32 -0500 | [diff] [blame] | 148 | // THEN dark amount should be initalized on the plugin. |
| 149 | verify(plugin).setDarkAmount(0.5f); |
| 150 | } |
| 151 | |
| 152 | @Test |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 153 | public void onPluginDisconnected_showDefaultClock() { |
| 154 | ClockPlugin plugin = mock(ClockPlugin.class); |
| 155 | TextClock pluginView = new TextClock(getContext()); |
| 156 | when(plugin.getView()).thenReturn(pluginView); |
| 157 | mClockView.setVisibility(GONE); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 158 | |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 159 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
| 160 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(null); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 161 | |
| 162 | verify(mClockView).setVisibility(VISIBLE); |
| 163 | assertThat(plugin.getView().getParent()).isNull(); |
| 164 | } |
| 165 | |
| 166 | @Test |
Robert Snoeberger | 6a0140a | 2018-12-20 12:46:17 -0500 | [diff] [blame] | 167 | public void onPluginDisconnected_hidePluginBigClock() { |
| 168 | // GIVEN that the big clock container is visible |
| 169 | FrameLayout bigClockContainer = new FrameLayout(getContext()); |
| 170 | bigClockContainer.setVisibility(VISIBLE); |
| 171 | mKeyguardClockSwitch.setBigClockContainer(bigClockContainer); |
| 172 | // AND the plugin returns a view for the big clock |
| 173 | ClockPlugin plugin = mock(ClockPlugin.class); |
| 174 | TextClock pluginView = new TextClock(getContext()); |
| 175 | when(plugin.getBigClockView()).thenReturn(pluginView); |
Robert Snoeberger | 9831239 | 2019-03-15 16:53:51 -0400 | [diff] [blame] | 176 | // AND in the keyguard state |
| 177 | mStateListener.onStateChanged(StatusBarState.KEYGUARD); |
Robert Snoeberger | 8bf1a3c | 2019-01-10 10:30:09 -0500 | [diff] [blame] | 178 | // WHEN the plugin is connected and then disconnected |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 179 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
| 180 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(null); |
Robert Snoeberger | 6a0140a | 2018-12-20 12:46:17 -0500 | [diff] [blame] | 181 | // THEN the big lock container is GONE and the big clock view doesn't have |
| 182 | // a parent. |
| 183 | assertThat(bigClockContainer.getVisibility()).isEqualTo(GONE); |
| 184 | assertThat(pluginView.getParent()).isNull(); |
| 185 | } |
| 186 | |
| 187 | @Test |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 188 | public void onPluginDisconnected_nullView() { |
| 189 | ClockPlugin plugin = mock(ClockPlugin.class); |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 190 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
| 191 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(null); |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 192 | verify(mClockView, never()).setVisibility(GONE); |
| 193 | } |
| 194 | |
| 195 | @Test |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 196 | public void onPluginDisconnected_secondOfTwoDisconnected() { |
| 197 | // GIVEN two plugins are connected |
| 198 | ClockPlugin plugin1 = mock(ClockPlugin.class); |
| 199 | when(plugin1.getView()).thenReturn(new TextClock(getContext())); |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 200 | ClockManager.ClockChangedListener listener = mKeyguardClockSwitch.getClockChangedListener(); |
| 201 | listener.onClockChanged(plugin1); |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 202 | ClockPlugin plugin2 = mock(ClockPlugin.class); |
| 203 | when(plugin2.getView()).thenReturn(new TextClock(getContext())); |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 204 | listener.onClockChanged(plugin2); |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 205 | // WHEN the second plugin is disconnected |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 206 | listener.onClockChanged(null); |
Robert Snoeberger | 33ce6d9 | 2018-10-26 10:52:38 -0400 | [diff] [blame] | 207 | // THEN the default clock should be shown. |
| 208 | verify(mClockView).setVisibility(VISIBLE); |
| 209 | assertThat(plugin1.getView().getParent()).isNull(); |
| 210 | assertThat(plugin2.getView().getParent()).isNull(); |
| 211 | } |
| 212 | |
| 213 | @Test |
Robert Snoeberger | 3358cfb | 2019-04-03 13:09:55 -0400 | [diff] [blame] | 214 | public void onPluginDisconnected_onDestroyView() { |
| 215 | // GIVEN a plugin is connected |
| 216 | ClockPlugin clockPlugin = mock(ClockPlugin.class); |
| 217 | when(clockPlugin.getView()).thenReturn(new TextClock(getContext())); |
| 218 | ClockManager.ClockChangedListener listener = mKeyguardClockSwitch.getClockChangedListener(); |
| 219 | listener.onClockChanged(clockPlugin); |
| 220 | // WHEN the plugin is disconnected |
| 221 | listener.onClockChanged(null); |
| 222 | // THEN onDestroyView is called on the plugin |
| 223 | verify(clockPlugin).onDestroyView(); |
| 224 | } |
| 225 | |
| 226 | @Test |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 227 | public void setTextColor_defaultClockSetTextColor() { |
| 228 | mKeyguardClockSwitch.setTextColor(Color.YELLOW); |
| 229 | |
| 230 | verify(mClockView).setTextColor(Color.YELLOW); |
| 231 | } |
| 232 | |
| 233 | @Test |
| 234 | public void setTextColor_pluginClockSetTextColor() { |
| 235 | ClockPlugin plugin = mock(ClockPlugin.class); |
| 236 | TextClock pluginView = new TextClock(getContext()); |
| 237 | when(plugin.getView()).thenReturn(pluginView); |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 238 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 239 | |
| 240 | mKeyguardClockSwitch.setTextColor(Color.WHITE); |
| 241 | |
| 242 | verify(plugin).setTextColor(Color.WHITE); |
| 243 | } |
| 244 | |
| 245 | @Test |
| 246 | public void setStyle_defaultClockSetStyle() { |
| 247 | TextPaint paint = mock(TextPaint.class); |
| 248 | Style style = mock(Style.class); |
| 249 | doReturn(paint).when(mClockView).getPaint(); |
| 250 | |
| 251 | mKeyguardClockSwitch.setStyle(style); |
| 252 | |
| 253 | verify(paint).setStyle(style); |
| 254 | } |
| 255 | |
| 256 | @Test |
| 257 | public void setStyle_pluginClockSetStyle() { |
| 258 | ClockPlugin plugin = mock(ClockPlugin.class); |
| 259 | TextClock pluginView = new TextClock(getContext()); |
| 260 | when(plugin.getView()).thenReturn(pluginView); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 261 | Style style = mock(Style.class); |
Robert Snoeberger | 15b4af1 | 2019-01-18 15:37:27 -0500 | [diff] [blame] | 262 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 263 | |
| 264 | mKeyguardClockSwitch.setStyle(style); |
| 265 | |
| 266 | verify(plugin).setStyle(style); |
| 267 | } |
Robert Snoeberger | 6085408 | 2019-01-04 13:13:17 -0500 | [diff] [blame] | 268 | |
| 269 | @Test |
Robert Snoeberger | 9831239 | 2019-03-15 16:53:51 -0400 | [diff] [blame] | 270 | public void onStateChanged_GoneInShade() { |
Robert Snoeberger | 6085408 | 2019-01-04 13:13:17 -0500 | [diff] [blame] | 271 | // GIVEN that the big clock container is visible |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 272 | mBigClockContainer.setVisibility(View.VISIBLE); |
| 273 | mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer); |
Robert Snoeberger | 6085408 | 2019-01-04 13:13:17 -0500 | [diff] [blame] | 274 | // WHEN transitioned to SHADE state |
| 275 | mStateListener.onStateChanged(StatusBarState.SHADE); |
Robert Snoeberger | 9831239 | 2019-03-15 16:53:51 -0400 | [diff] [blame] | 276 | // THEN the container is gone. |
| 277 | assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.GONE); |
Robert Snoeberger | 6085408 | 2019-01-04 13:13:17 -0500 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | @Test |
| 281 | public void onStateChanged_VisibleInKeyguard() { |
Robert Snoeberger | 9831239 | 2019-03-15 16:53:51 -0400 | [diff] [blame] | 282 | // GIVEN that the big clock container is gone |
| 283 | mBigClockContainer.setVisibility(View.GONE); |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 284 | mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer); |
Robert Snoeberger | 9831239 | 2019-03-15 16:53:51 -0400 | [diff] [blame] | 285 | // AND GIVEN that a plugin is active. |
| 286 | ClockPlugin plugin = mock(ClockPlugin.class); |
| 287 | when(plugin.getBigClockView()).thenReturn(mBigClock); |
| 288 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
Robert Snoeberger | 6085408 | 2019-01-04 13:13:17 -0500 | [diff] [blame] | 289 | // WHEN transitioned to KEYGUARD state |
| 290 | mStateListener.onStateChanged(StatusBarState.KEYGUARD); |
| 291 | // THEN the container is visible. |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 292 | assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.VISIBLE); |
| 293 | } |
| 294 | |
| 295 | @Test |
| 296 | public void setBigClockContainer_visible() { |
| 297 | // GIVEN that the big clock container is visible |
| 298 | mBigClockContainer.setVisibility(View.VISIBLE); |
| 299 | // AND GIVEN that a plugin is active. |
| 300 | ClockPlugin plugin = mock(ClockPlugin.class); |
| 301 | when(plugin.getBigClockView()).thenReturn(mBigClock); |
| 302 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
Robert Snoeberger | 9831239 | 2019-03-15 16:53:51 -0400 | [diff] [blame] | 303 | // AND in the keyguard state |
| 304 | mStateListener.onStateChanged(StatusBarState.KEYGUARD); |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 305 | // WHEN the container is associated with the clock switch |
| 306 | mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer); |
| 307 | // THEN the container remains visible. |
| 308 | assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.VISIBLE); |
| 309 | } |
| 310 | |
| 311 | @Test |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 312 | public void setBigClockContainer_gone() { |
| 313 | // GIVEN that the big clock container is gone |
| 314 | mBigClockContainer.setVisibility(View.GONE); |
| 315 | // AND GIVEN that a plugin is active. |
| 316 | ClockPlugin plugin = mock(ClockPlugin.class); |
| 317 | when(plugin.getBigClockView()).thenReturn(mBigClock); |
| 318 | mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin); |
Robert Snoeberger | 9831239 | 2019-03-15 16:53:51 -0400 | [diff] [blame] | 319 | // AND in the keyguard state |
| 320 | mStateListener.onStateChanged(StatusBarState.KEYGUARD); |
Robert Snoeberger | a1df7fb | 2019-02-11 14:00:14 -0500 | [diff] [blame] | 321 | // WHEN the container is associated with the clock switch |
| 322 | mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer); |
| 323 | // THEN the container is made visible. |
| 324 | assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.VISIBLE); |
Robert Snoeberger | 6085408 | 2019-01-04 13:13:17 -0500 | [diff] [blame] | 325 | } |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 326 | } |