Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [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 android.view; |
| 18 | |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 19 | import static android.view.InsetsState.TYPE_IME; |
| 20 | import static android.view.InsetsState.TYPE_NAVIGATION_BAR; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 21 | import static android.view.InsetsState.TYPE_TOP_BAR; |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 22 | import static android.view.WindowInsets.Type.topBar; |
Jorim Jaggi | 648e588 | 2019-01-24 13:24:02 +0100 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
Tadashi G. Takaoka | 82eb7a5 | 2019-03-26 18:22:01 +0900 | [diff] [blame] | 24 | |
| 25 | import static org.junit.Assert.assertEquals; |
| 26 | import static org.junit.Assert.assertFalse; |
| 27 | import static org.junit.Assert.assertNull; |
| 28 | import static org.junit.Assert.assertTrue; |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 29 | import static org.mockito.ArgumentMatchers.any; |
| 30 | import static org.mockito.ArgumentMatchers.anyInt; |
| 31 | import static org.mockito.Mockito.mock; |
| 32 | import static org.mockito.Mockito.never; |
| 33 | import static org.mockito.Mockito.verify; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 34 | |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 35 | import android.content.Context; |
| 36 | import android.graphics.Insets; |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 37 | import android.graphics.Point; |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 38 | import android.graphics.Rect; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 39 | import android.platform.test.annotations.Presubmit; |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 40 | import android.view.WindowInsets.Type; |
| 41 | import android.view.WindowManager.BadTokenException; |
| 42 | import android.view.WindowManager.LayoutParams; |
| 43 | import android.widget.TextView; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 44 | |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 45 | import androidx.test.InstrumentationRegistry; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 46 | import androidx.test.runner.AndroidJUnit4; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 47 | |
| 48 | import org.junit.Before; |
| 49 | import org.junit.Test; |
| 50 | import org.junit.runner.RunWith; |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 51 | import org.mockito.ArgumentCaptor; |
| 52 | |
| 53 | import java.util.concurrent.CountDownLatch; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 54 | |
Tadashi G. Takaoka | 82eb7a5 | 2019-03-26 18:22:01 +0900 | [diff] [blame] | 55 | /** |
| 56 | * Tests for {@link InsetsController}. |
| 57 | * |
| 58 | * <p>Build/Install/Run: |
| 59 | * atest FrameworksCoreTests:InsetsControllerTest |
| 60 | * |
| 61 | * <p>This test class is a part of Window Manager Service tests and specified in |
| 62 | * {@link com.android.server.wm.test.filters.FrameworksTestsFilter}. |
| 63 | */ |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 64 | @Presubmit |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 65 | @RunWith(AndroidJUnit4.class) |
| 66 | public class InsetsControllerTest { |
| 67 | |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 68 | private InsetsController mController; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 69 | private SurfaceSession mSession = new SurfaceSession(); |
| 70 | private SurfaceControl mLeash; |
| 71 | |
| 72 | @Before |
| 73 | public void setup() { |
| 74 | mLeash = new SurfaceControl.Builder(mSession) |
| 75 | .setName("testSurface") |
| 76 | .build(); |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 77 | InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { |
| 78 | Context context = InstrumentationRegistry.getTargetContext(); |
| 79 | // cannot mock ViewRootImpl since it's final. |
| 80 | ViewRootImpl viewRootImpl = new ViewRootImpl(context, context.getDisplay()); |
| 81 | try { |
| 82 | viewRootImpl.setView(new TextView(context), new LayoutParams(), null); |
| 83 | } catch (BadTokenException e) { |
| 84 | // activity isn't running, we will ignore BadTokenException. |
| 85 | } |
| 86 | mController = new InsetsController(viewRootImpl); |
| 87 | final Rect rect = new Rect(5, 5, 5, 5); |
| 88 | mController.calculateInsets( |
| 89 | false, |
| 90 | false, |
| 91 | new DisplayCutout( |
| 92 | Insets.of(10, 10, 10, 10), rect, rect, rect, rect), |
Jorim Jaggi | 648e588 | 2019-01-24 13:24:02 +0100 | [diff] [blame] | 93 | rect, rect, SOFT_INPUT_ADJUST_RESIZE); |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 94 | mController.onFrameChanged(new Rect(0, 0, 100, 100)); |
| 95 | mController.getState().setDisplayFrame(new Rect(0, 0, 100, 100)); |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 96 | }); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 97 | InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Test |
| 101 | public void testControlsChanged() { |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 102 | InsetsSourceControl control = new InsetsSourceControl(TYPE_TOP_BAR, mLeash, new Point()); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 103 | mController.onControlsChanged(new InsetsSourceControl[] { control }); |
| 104 | assertEquals(mLeash, |
| 105 | mController.getSourceConsumer(TYPE_TOP_BAR).getControl().getLeash()); |
| 106 | } |
| 107 | |
| 108 | @Test |
| 109 | public void testControlsRevoked() { |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 110 | InsetsSourceControl control = new InsetsSourceControl(TYPE_TOP_BAR, mLeash, new Point()); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 111 | mController.onControlsChanged(new InsetsSourceControl[] { control }); |
| 112 | mController.onControlsChanged(new InsetsSourceControl[0]); |
| 113 | assertNull(mController.getSourceConsumer(TYPE_TOP_BAR).getControl()); |
| 114 | } |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 115 | |
| 116 | @Test |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 117 | public void testControlsRevoked_duringAnim() { |
| 118 | InsetsSourceControl control = new InsetsSourceControl(TYPE_TOP_BAR, mLeash, new Point()); |
| 119 | mController.onControlsChanged(new InsetsSourceControl[] { control }); |
| 120 | |
| 121 | WindowInsetsAnimationControlListener mockListener = |
| 122 | mock(WindowInsetsAnimationControlListener.class); |
| 123 | mController.controlWindowInsetsAnimation(topBar(), mockListener); |
| 124 | verify(mockListener).onReady(any(), anyInt()); |
| 125 | mController.onControlsChanged(new InsetsSourceControl[0]); |
| 126 | verify(mockListener).onCancelled(); |
| 127 | } |
| 128 | |
| 129 | @Test |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 130 | public void testFrameDoesntMatchDisplay() { |
| 131 | mController.onFrameChanged(new Rect(0, 0, 100, 100)); |
| 132 | mController.getState().setDisplayFrame(new Rect(0, 0, 200, 200)); |
| 133 | WindowInsetsAnimationControlListener controlListener = |
| 134 | mock(WindowInsetsAnimationControlListener.class); |
| 135 | mController.controlWindowInsetsAnimation(0, controlListener); |
| 136 | verify(controlListener).onCancelled(); |
| 137 | verify(controlListener, never()).onReady(any(), anyInt()); |
| 138 | } |
| 139 | |
| 140 | @Test |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 141 | public void testAnimationEndState() { |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 142 | InsetsSourceControl[] controls = prepareControls(); |
| 143 | InsetsSourceControl navBar = controls[0]; |
| 144 | InsetsSourceControl topBar = controls[1]; |
| 145 | InsetsSourceControl ime = controls[2]; |
| 146 | |
| 147 | InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { |
Tarandeep Singh | 92d2dd3 | 2019-08-07 14:45:01 -0700 | [diff] [blame] | 148 | mController.getSourceConsumer(TYPE_IME).onWindowFocusGained(); |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 149 | // since there is no focused view, forcefully make IME visible. |
| 150 | mController.applyImeVisibility(true /* setVisible */); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 151 | mController.show(Type.all()); |
| 152 | // quickly jump to final state by cancelling it. |
| 153 | mController.cancelExistingAnimation(); |
| 154 | assertTrue(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 155 | assertTrue(mController.getSourceConsumer(topBar.getType()).isVisible()); |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 156 | assertTrue(mController.getSourceConsumer(ime.getType()).isVisible()); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 157 | |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 158 | mController.applyImeVisibility(false /* setVisible */); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 159 | mController.hide(Type.all()); |
| 160 | mController.cancelExistingAnimation(); |
| 161 | assertFalse(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 162 | assertFalse(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 163 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
Tarandeep Singh | 92d2dd3 | 2019-08-07 14:45:01 -0700 | [diff] [blame] | 164 | mController.getSourceConsumer(TYPE_IME).onWindowFocusLost(); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 165 | }); |
| 166 | InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 167 | } |
| 168 | |
| 169 | @Test |
| 170 | public void testApplyImeVisibility() { |
| 171 | final InsetsSourceControl ime = new InsetsSourceControl(TYPE_IME, mLeash, new Point()); |
| 172 | |
| 173 | InsetsSourceControl[] controls = new InsetsSourceControl[3]; |
| 174 | controls[0] = ime; |
| 175 | mController.onControlsChanged(controls); |
| 176 | InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { |
Tarandeep Singh | 92d2dd3 | 2019-08-07 14:45:01 -0700 | [diff] [blame] | 177 | mController.getSourceConsumer(TYPE_IME).onWindowFocusGained(); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 178 | mController.applyImeVisibility(true); |
| 179 | mController.cancelExistingAnimation(); |
| 180 | assertTrue(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 181 | mController.applyImeVisibility(false); |
| 182 | mController.cancelExistingAnimation(); |
| 183 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
Tarandeep Singh | 92d2dd3 | 2019-08-07 14:45:01 -0700 | [diff] [blame] | 184 | mController.getSourceConsumer(TYPE_IME).onWindowFocusLost(); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 185 | }); |
| 186 | InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 187 | } |
| 188 | |
| 189 | @Test |
| 190 | public void testShowHideSelectively() { |
| 191 | InsetsSourceControl[] controls = prepareControls(); |
| 192 | InsetsSourceControl navBar = controls[0]; |
| 193 | InsetsSourceControl topBar = controls[1]; |
| 194 | InsetsSourceControl ime = controls[2]; |
| 195 | |
| 196 | InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { |
| 197 | int types = Type.sideBars() | Type.systemBars(); |
| 198 | // test show select types. |
| 199 | mController.show(types); |
| 200 | mController.cancelExistingAnimation(); |
| 201 | assertTrue(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 202 | assertTrue(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 203 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 204 | |
| 205 | // test hide all |
| 206 | mController.hide(types); |
| 207 | mController.cancelExistingAnimation(); |
| 208 | assertFalse(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 209 | assertFalse(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 210 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 211 | }); |
| 212 | InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 213 | } |
| 214 | |
| 215 | @Test |
| 216 | public void testShowHideSingle() { |
| 217 | InsetsSourceControl[] controls = prepareControls(); |
| 218 | InsetsSourceControl navBar = controls[0]; |
| 219 | InsetsSourceControl topBar = controls[1]; |
| 220 | InsetsSourceControl ime = controls[2]; |
| 221 | |
| 222 | InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { |
| 223 | int types = Type.sideBars() | Type.systemBars(); |
| 224 | // test show select types. |
| 225 | mController.show(types); |
| 226 | mController.cancelExistingAnimation(); |
| 227 | assertTrue(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 228 | assertTrue(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 229 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 230 | |
| 231 | // test hide all |
| 232 | mController.hide(Type.all()); |
| 233 | mController.cancelExistingAnimation(); |
| 234 | assertFalse(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 235 | assertFalse(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 236 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 237 | |
| 238 | // test single show |
| 239 | mController.show(Type.sideBars()); |
| 240 | mController.cancelExistingAnimation(); |
| 241 | assertTrue(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 242 | assertFalse(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 243 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 244 | |
| 245 | // test single hide |
| 246 | mController.hide(Type.sideBars()); |
| 247 | assertFalse(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 248 | assertFalse(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 249 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 250 | |
| 251 | }); |
| 252 | InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 253 | } |
| 254 | |
| 255 | @Test |
| 256 | public void testShowHideMultiple() { |
| 257 | InsetsSourceControl[] controls = prepareControls(); |
| 258 | InsetsSourceControl navBar = controls[0]; |
| 259 | InsetsSourceControl topBar = controls[1]; |
| 260 | InsetsSourceControl ime = controls[2]; |
| 261 | |
| 262 | InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { |
| 263 | // start two animations and see if previous is cancelled and final state is reached. |
| 264 | mController.show(Type.sideBars()); |
| 265 | mController.show(Type.systemBars()); |
| 266 | mController.cancelExistingAnimation(); |
| 267 | assertTrue(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 268 | assertTrue(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 269 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 270 | |
| 271 | mController.hide(Type.sideBars()); |
| 272 | mController.hide(Type.systemBars()); |
| 273 | mController.cancelExistingAnimation(); |
| 274 | assertFalse(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 275 | assertFalse(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 276 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 277 | |
| 278 | int types = Type.sideBars() | Type.systemBars(); |
| 279 | // show two at a time and hide one by one. |
| 280 | mController.show(types); |
| 281 | mController.hide(Type.sideBars()); |
| 282 | mController.cancelExistingAnimation(); |
| 283 | assertFalse(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 284 | assertTrue(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 285 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 286 | |
| 287 | mController.hide(Type.systemBars()); |
| 288 | mController.cancelExistingAnimation(); |
| 289 | assertFalse(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 290 | assertFalse(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 291 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 292 | }); |
| 293 | InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 294 | } |
| 295 | |
| 296 | @Test |
| 297 | public void testShowMultipleHideOneByOne() { |
| 298 | InsetsSourceControl[] controls = prepareControls(); |
| 299 | InsetsSourceControl navBar = controls[0]; |
| 300 | InsetsSourceControl topBar = controls[1]; |
| 301 | InsetsSourceControl ime = controls[2]; |
| 302 | |
| 303 | InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { |
| 304 | int types = Type.sideBars() | Type.systemBars(); |
| 305 | // show two at a time and hide one by one. |
| 306 | mController.show(types); |
| 307 | mController.hide(Type.sideBars()); |
| 308 | mController.cancelExistingAnimation(); |
| 309 | assertFalse(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 310 | assertTrue(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 311 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 312 | |
| 313 | mController.hide(Type.systemBars()); |
| 314 | mController.cancelExistingAnimation(); |
| 315 | assertFalse(mController.getSourceConsumer(navBar.getType()).isVisible()); |
| 316 | assertFalse(mController.getSourceConsumer(topBar.getType()).isVisible()); |
| 317 | assertFalse(mController.getSourceConsumer(ime.getType()).isVisible()); |
| 318 | }); |
| 319 | InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 320 | } |
| 321 | |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 322 | @Test |
| 323 | public void testAnimationEndState_controller() throws Exception { |
| 324 | InsetsSourceControl control = new InsetsSourceControl(TYPE_TOP_BAR, mLeash, new Point()); |
| 325 | mController.onControlsChanged(new InsetsSourceControl[] { control }); |
| 326 | |
| 327 | InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { |
| 328 | WindowInsetsAnimationControlListener mockListener = |
| 329 | mock(WindowInsetsAnimationControlListener.class); |
| 330 | mController.controlWindowInsetsAnimation(topBar(), mockListener); |
| 331 | |
| 332 | ArgumentCaptor<WindowInsetsAnimationController> controllerCaptor = |
| 333 | ArgumentCaptor.forClass(WindowInsetsAnimationController.class); |
| 334 | verify(mockListener).onReady(controllerCaptor.capture(), anyInt()); |
| 335 | controllerCaptor.getValue().finish(0 /* shownTypes */); |
| 336 | }); |
| 337 | waitUntilNextFrame(); |
| 338 | InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { |
| 339 | assertFalse(mController.getSourceConsumer(TYPE_TOP_BAR).isVisible()); |
| 340 | }); |
| 341 | InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 342 | } |
| 343 | |
| 344 | private void waitUntilNextFrame() throws Exception { |
| 345 | final CountDownLatch latch = new CountDownLatch(1); |
| 346 | Choreographer.getMainThreadInstance().postCallback(Choreographer.CALLBACK_COMMIT, |
| 347 | latch::countDown, null /* token */); |
| 348 | latch.await(); |
| 349 | } |
| 350 | |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 351 | private InsetsSourceControl[] prepareControls() { |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 352 | final InsetsSourceControl navBar = new InsetsSourceControl(TYPE_NAVIGATION_BAR, mLeash, |
| 353 | new Point()); |
| 354 | final InsetsSourceControl topBar = new InsetsSourceControl(TYPE_TOP_BAR, mLeash, |
| 355 | new Point()); |
| 356 | final InsetsSourceControl ime = new InsetsSourceControl(TYPE_IME, mLeash, new Point()); |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 357 | |
| 358 | InsetsSourceControl[] controls = new InsetsSourceControl[3]; |
| 359 | controls[0] = navBar; |
| 360 | controls[1] = topBar; |
| 361 | controls[2] = ime; |
| 362 | mController.onControlsChanged(controls); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 363 | return controls; |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 364 | } |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 365 | } |